embox

Форк
0
/
image2.mk 
194 строки · 6.2 Кб
1
#
2
#   Date: Jun 22, 2012
3
# Author: Eldar Abusalimov
4
#
5

6
ifeq ($(STAGE),1)
7
embox_o   := $(OBJ_DIR)/embox.o
8
else
9
embox_o   := $(OBJ_DIR)/embox-2.o
10
$(embox_o) : $(OBJ_DIR)/embox.o
11
endif
12

13
image_lds := $(OBJ_DIR)/mk/image.lds
14

15
.PHONY : all FORCE
16
all : $(embox_o) $(image_lds)
17

18
FORCE :
19

20
include mk/image_lib.mk
21

22
include $(MKGEN_DIR)/build.mk
23

24
include mk/flags.mk # It must be included after a user-defined config.
25

26
.SECONDEXPANSION:
27

28
include $(MKGEN_DIR)/include.mk
29
include $(__include_image)
30
include $(__include_initfs)
31
include $(__include)
32

33
initfs_cp_prerequisites = $(src_file) $(common_prereqs)
34

35
cp_T_if_supported := \
36
	$(shell $(CP) --version 2>&1 | grep -l GNU >/dev/null && echo -T)
37

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.
45
$(ROOTFS_DIR)/. :
46
	@mkdir -p $@
47
$(ROOTFS_DIR)/%/. :
48
	@mkdir -p $@
49

50
$(ROOTFS_DIR)/% :
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
55

56
fmt_line = $(addprefix \$(\n)$(\t)$(\t),$1)
57

58
initfs_prerequisites = $(cpio_files) \
59
	$(wildcard $(USER_ROOTFS_DIR) $(USER_ROOTFS_DIR)/*) $(common_prereqs)
60
$(ROOTFS_IMAGE) :
61
	@mkdir -p $(ROOTFS_DIR)
62
	cd $(ROOTFS_DIR) \
63
		&& find * -depth -print | $(CPIO) -L --quiet -H newc -o -O $(abspath $@)
64
	if [ -d $(USER_ROOTFS_DIR) ]; \
65
	then \
66
		cd $(USER_ROOTFS_DIR) \
67
			&& find * -depth -print | $(CPIO) -L --quiet -H newc -o -A -O $(abspath $@); \
68
	fi
69
	@FILES=`find $(cpio_files) $(USER_ROOTFS_DIR)/* -depth -print 2>/dev/null`; \
70
	{                                            \
71
		printf '$(ROOTFS_IMAGE):';               \
72
		for dep in $$FILES;                      \
73
			do printf ' \\\n\t%s' "$$dep"; done; \
74
		printf '\n';                             \
75
		for dep in $$FILES;                      \
76
			do printf '\n%s:\n' "$$dep"; done;   \
77
	} > $@.d
78
-include $(ROOTFS_IMAGE).d
79

80
#XXX
81
$(OBJ_DIR)/src/fs/driver/initfs/initfs_cpio.o : $(ROOTFS_IMAGE)
82

83
ifdef __REBUILD_ROOTFS
84
initfs_cp_prerequisites += FORCE
85
initfs_prerequisites    += FORCE
86
endif
87

88
# Module-level rules.
89
module_prereqs = $(o_files) $(a_files) $(common_prereqs)
90

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.
94
#
95
# 1. File
96
# 2. Section name - text, rodata, data, bss
97
get_sections = $(filter .$2%, $(filter-out .$2..% .$2.embox%, $(shell $(OBJDUMP) -h $1)))
98

99
section_in_region = \
100
	$(shell grep LDS_SECTION_VMA_$1 $(SRCGEN_DIR)/config.lds.h)
101

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
105
rename_section = \
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)) \
111
	)
112

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)) \
124
	)))
125

126
#
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.
130
#
131
# 1. objcopy options
132
# 2. File for objcopy
133
#
134
do_objcopy = \
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))) \
139
		) \
140
	) \
141
	$(EXTERNAL_MAKE_FLAGS) $(abspath $(ROOT_DIR))/mk/objcopy_helper.sh $(tmp_file) $2; \
142
	$(RM) $(tmp_file)
143

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)' \
150
		APP_ID='$(is_app)';
151
	@$(call do_objcopy, $(objcopy_options), $@)
152

153
ld_prerequisites = $(module_prereqs)
154
obj_build=$(if $(strip $(value mod_postbuild)),$@.build.o,$@)
155
obj_postbuild=$@
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)))
160
	$(mod_postbuild)
161

162
# Here goes image creation rules...
163
#
164
$(embox_o): ldflags_all = $(LDFLAGS) \
165
		$(call fmt_line,$(call ld_scripts_flag,$(ld_scripts)))
166
$(embox_o):
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)) \
171
		--start-group \
172
		$(call fmt_line,$(ld_libs)) \
173
		--end-group \
174
	--cref -Map $@.map \
175
	-o $@
176

177
stages := $(wordlist 1,$(STAGE),1 2)
178

179
image_prereqs = $(ld_scripts) $(ld_objs) $(ld_libs) $(common_prereqs)
180

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))
186

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
195

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.