3
# Author: Eldar Abusalimov
7
embox_o := $(OBJ_DIR)/embox.o
9
embox_o := $(OBJ_DIR)/embox-2.o
10
$(embox_o) : $(OBJ_DIR)/embox.o
13
image_lds := $(OBJ_DIR)/mk/image.lds
16
all : $(embox_o) $(image_lds)
20
include mk/image_lib.mk
22
include $(MKGEN_DIR)/build.mk
24
include mk/flags.mk # It must be included after a user-defined config.
28
include $(MKGEN_DIR)/include.mk
29
include $(__include_image)
30
include $(__include_initfs)
33
initfs_cp_prerequisites = $(src_file) $(common_prereqs)
36
$(shell $(CP) --version 2>&1 | grep -l GNU >/dev/null && echo -T)
38
# This rule is necessary because otherwise, when considering a rule for
39
# creating the $(ROOTFS_DIR) directory (required through $(common_prereqs)
40
# using the secondarily-expanded order-only '| $(@D)/.' prerequisite),
41
# the '$(ROOTFS_DIR)/%' rule takes precedence over the proper '%/.' one, since
42
# the former needs a shorter stem ('.') than the latter ('build/.../rootfs').
43
# This is reproduced only on GNU Make >= 3.82, because of the change in how
44
# implicit rule search works in Make.
51
$(CP) -r $(cp_T_if_supported) $(src_file) $@$(if \
52
$(and $(chmod),$(findstring $(chmod),'')),,;chmod $(chmod) $@)
53
@touch $@ # workaround when copying directories
54
@find $@ -name .gitkeep -type f -print0 | xargs -0 rm -rf
56
fmt_line = $(addprefix \$(\n)$(\t)$(\t),$1)
58
initfs_prerequisites = $(cpio_files) \
59
$(wildcard $(USER_ROOTFS_DIR) $(USER_ROOTFS_DIR)/*) $(common_prereqs)
61
@mkdir -p $(ROOTFS_DIR)
63
&& find * -depth -print | $(CPIO) -L --quiet -H newc -o -O $(abspath $@)
64
if [ -d $(USER_ROOTFS_DIR) ]; \
66
cd $(USER_ROOTFS_DIR) \
67
&& find * -depth -print | $(CPIO) -L --quiet -H newc -o -A -O $(abspath $@); \
69
@FILES=`find $(cpio_files) $(USER_ROOTFS_DIR)/* -depth -print 2>/dev/null`; \
71
printf '$(ROOTFS_IMAGE):'; \
73
do printf ' \\\n\t%s' "$$dep"; done; \
76
do printf '\n%s:\n' "$$dep"; done; \
78
-include $(ROOTFS_IMAGE).d
81
$(OBJ_DIR)/src/fs/driver/initfs/initfs_cpio.o : $(ROOTFS_IMAGE)
84
initfs_cp_prerequisites += FORCE
85
initfs_prerequisites += FORCE
89
module_prereqs = $(o_files) $(a_files) $(common_prereqs)
91
# Return sections like .bss, .bss._something, etc. But preserve .bss..something
92
# and .bss.embox.something since it is used for Embox's internal purpuses.
93
# The same is for text, rodata, data sections.
96
# 2. Section name - text, rodata, data, bss
97
get_sections = $(filter .$2%, $(filter-out .$2..% .$2.embox%, $(shell $(OBJDUMP) -h $1)))
100
$(shell grep LDS_SECTION_VMA_$1 $(SRCGEN_DIR)/config.lds.h)
102
# 1. File name (objects *.o or libraries *.a)
103
# 2. Section name - text, rodata, data, bss
104
# 3. Name of section specified with @LinkerSection annonation
106
$(if $(and $3,$(call section_in_region,$3)), \
107
$(foreach section, $(call get_sections,$1,$2), \
108
$(section)=.$3.$(section).module.$(module_id)), \
109
$(foreach section, $(call get_sections,$1,$2), \
110
$(section)=$(section).module.$(module_id)) \
113
# Here we also rename .ARM.exidx section because some ARM none-eabi
114
# compilers crash with Seg Fault for some reason.
115
$(OBJ_DIR)/module/% : objcopy_options = \
116
$(patsubst %, --rename-section %, \
117
$(sort $(foreach f,$(o_files) $(a_files), \
118
$(call rename_section,$f,text,$(linker_section_text)) \
119
$(call rename_section,$f,rodata,$(linker_section_rodata)) \
120
$(call rename_section,$f,data,$(linker_section_data)) \
121
$(call rename_section,$f,bss,$(linker_section_bss)) \
122
$(call rename_section,$f,ARM.exidx,$(linker_section_arm_exidx)) \
123
$(call rename_section,$f,ARM.extab,$(linker_section_arm_extab)) \
127
# Execv segfault workaround: Due to possibly very long objcopy_options
128
# we should to pass objcopy_options partially. First 10000 options,
129
# then next 10000 options and so on.
135
$(eval tmp_file=$2.objcopy_options.txt) \
136
$(foreach i,$(shell seq 1 10000 $(words $1)), \
137
$(if $(wordlist $(i),$(words $1),$1), \
138
$(file >>$(tmp_file), $(wordlist 1,10000,$(wordlist $(i),$(words $1),$1))) \
141
$(EXTERNAL_MAKE_FLAGS) $(abspath $(ROOT_DIR))/mk/objcopy_helper.sh $(tmp_file) $2; \
144
ar_prerequisites = $(module_prereqs)
145
$(OBJ_DIR)/module/%.a : mk/arhelper.mk
146
@$(MAKE) -f mk/arhelper.mk TARGET='$@' \
147
AR='$(AR)' ARFLAGS='$(ARFLAGS)' \
148
A_FILES='$(a_files)' \
149
O_FILES='$(o_files)' \
151
@$(call do_objcopy, $(objcopy_options), $@)
153
ld_prerequisites = $(module_prereqs)
154
obj_build=$(if $(strip $(value mod_postbuild)),$@.build.o,$@)
156
$(OBJ_DIR)/module/%.o :
157
$(LD) -r -o $(obj_build) $(ldflags) $(call fmt_line,$(o_files) \
158
$(if $(a_files),--whole-archive $(a_files) --no-whole-archive))
159
@$(if $(module_id),$(call do_objcopy, $(objcopy_options), $(obj_build)))
162
# Here goes image creation rules...
164
$(embox_o): ldflags_all = $(LDFLAGS) \
165
$(call fmt_line,$(call ld_scripts_flag,$(ld_scripts)))
167
mkdir -p $(OBJ_DIR)/mk;
168
$(ROOT_DIR)/mk/gen_buildinfo.sh > $(OBJ_DIR)/mk/buildinfo.ld;
169
$(LD) -r $(ldflags_all) \
170
$(call fmt_line,$(ld_objs)) \
172
$(call fmt_line,$(ld_libs)) \
177
stages := $(wordlist 1,$(STAGE),1 2)
179
image_prereqs = $(ld_scripts) $(ld_objs) $(ld_libs) $(common_prereqs)
181
$(embox_o) : $$(image_prereqs)
182
$(embox_o) : mk_file = $(__image_mk_file)
183
$(embox_o) : ld_scripts = $(__image_ld_scripts1) # TODO check this twice
184
$(embox_o) : ld_objs = $(foreach s,$(stages),$(__image_ld_objs$s))
185
$(embox_o) : ld_libs = $(foreach s,$(stages),$(__image_ld_libs$s))
187
$(image_lds) : $$(common_prereqs)
188
$(image_lds) : flags_before :=
189
$(image_lds) : flags = \
190
$(addprefix -include ,$(wildcard \
191
$(SRC_DIR)/arch/$(ARCH)/embox.lds.S \
192
$(if $(value PLATFORM), \
193
$(PLATFORM_DIR)/$(PLATFORM)/arch/$(ARCH)/platform.lds.S)))
194
-include $(image_lds).d