]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/bootstrap/server/src/Make.rules
Update
[l4.git] / l4 / pkg / bootstrap / server / src / Make.rules
1 # vim:set ft=make:
2
3 # User definable variables for bootstrap:
4 # - BOOTSTRAP_CHECK_MD5 set this if you want MD5 checks for modules
5 # - BOOTSTRAP_SEARCH_PATH
6 # - BOOTSTRAP_ELF_NAME
7 # - BOOTSTRAP_MODULES_LIST
8 # - BOOTSTRAP_DO_RAW_IMAGE
9 # - BOOTSTRAP_DO_UIMAGE
10 # - BOOTSTRAP_DO_UEFI if set an image which is bootable by UEFI is built
11 # - BOOTSTRAP_NO_STRIP if set no stripping of image
12 # - BOOTSTRAP_UIMAGE_COMPRESSION: set to none, gzip, or bzip2
13 # - BOOTSTRAP_CMDLINE: compiled-in command line, only used if no cmdline
14 #                      given
15 # - BOOTSTRAP_OUTPUT_DIR: Optional alternative output directory for all
16 #                         images (and generated files), preferable some
17 #                         tmpfs directory
18
19 INTERNAL_CRT0       := y # the defualt is to use our internal crt0
20 DEFAULT_RELOC_arm   := 0x01000000
21 DEFAULT_RELOC_x86   := 0x002d0000
22 DEFAULT_RELOC_amd64 := 0x002d0000
23 DEFAULT_RELOC_ppc32 := 0x002d0000
24 DEFAULT_RELOC_sparc := 0x00800000
25 RELOC_PHYS          := y
26 LDFLAGS              = -nostdlib -static -Bstatic
27 EXTRA_GENERAL_D_DEP += .redo-change-tracker $(BID_RAM_BASE_DEP) \
28                        $(wildcard $(L4DIR)/conf/Makeconf.boot $(OBJ_BASE)/conf/Makeconf.boot) \
29                        $(SRC_DIR)/build.pl $(BOOTSTRAP_MODULES_LIST)
30 INCLUDE_MAKE_RULES   = $(SRC_DIR)/*/Make.rules
31 BOOTSTRAP_LD_dep    := $(SRC_DIR)/ldscript.inc
32
33 ifneq ($(BOOTSTRAP_CHECK_MD5),)
34   REQUIRES_LIBS       += libbsd-lite
35   DEFINES             += -DDO_CHECK_MD5
36 endif
37
38 include $(L4DIR)/mk/Makeconf
39 -include $(OBJ_DIR)/Makeconf.local
40 -include $(L4DIR)/conf/Makeconf.boot
41 -include $(OBJ_BASE)/conf/Makeconf.boot
42
43 SRC_CC_IS_CXX11    := y
44
45 # Checks added Nov 2010:
46 ifneq ($(wildcard $(L4DIR)/conf/Makeconf.bootstrap),)
47 $(error $(L4DIR)/conf/Makeconf.bootstrap not used anymore. Please use $(L4DIR)/conf/Makeconf.boot now)
48 endif
49 ifneq ($(wildcard $(OBJ_BASE)/Makeconf.bootstrap),)
50 $(error $(OBJ_BASE)/Makeconf.bootstrap not used anymore. Please use $(OBJ_BASE)/conf/Makeconf.boot now)
51 endif
52
53 ifeq ($(BOOTSTRAP_DO_UEFI),y)
54   # link to 0x0
55   DEFAULT_RELOC_x86   := 0x0
56   DEFAULT_RELOC_amd64 := 0x0
57
58   BUILD_PIE           := 1
59
60   # lib gnu-efi requirements
61   REQUIRES_LIBS       += gnu-efi
62   EFI_ARCH-amd64      := x86_64
63   EFI_ARCH-x86        := ia32
64   EFI_ARCH            := $(EFI_ARCH-$(ARCH))
65   EFI_BIN_FMT         := efi-app-$(EFI_ARCH)
66   CRTN_dyn_bin        :=
67   CRTEND_dyn_bin      :=
68   INTERNAL_CRT0       := n
69   CRT0                 = $(OBJ_BASE)/lib/$(SYSTEM)/crt0-efi-$(EFI_ARCH).o
70   EXTRA_LIBS           = -L$(OBJ_BASE)/lib/$(SYSTEM) -lefi -lgnuefi
71   CXXFLAGS            += -fshort-wchar
72   CFLAGS              += -fshort-wchar
73 endif
74
75 BOOTSTRAP_SEARCH_PATH        ?= $(OBJ_DIR)
76 BOOTSTRAP_MODULES_LIST       ?= $(SRC_DIR)/modules.list
77 BOOTSTRAP_MODULE_PATH_BINLIB ?= $(OBJ_BASE)/bin/$(SYSTEM)/$(BUILD_ABI):$(OBJ_BASE)/lib/$(SYSTEM)/$(BUILD_ABI):$(OBJ_BASE)/lib/$(SYSTEM)
78 BOOTSTRAP_ELF_NAME           ?= bootstrap.elf
79 MKIMAGE                      ?= mkimage
80 BOOTSTRAP_UIMAGE_COMPRESSION ?= none
81
82 ifeq ($(BUILD_ARCH),$(filter $(BUILD_ARCH),arm ppc32 sparc))
83   # ARM/PPC/SPARC always uses single image mode
84   # when no entry is given we build the useless auto-build target
85   ifeq ($(E)$(ENTRY),)
86     BOOTSTRAP_ELF_NAME := bootstrap.auto-build-useless.elf
87   endif
88   ENTRY := auto-build-entry
89 endif
90
91 od := $(if $(BOOTSTRAP_OUTPUT_DIR),$(if $(wildcard $(BOOTSTRAP_OUTPUT_DIR)),,$(shell mkdir $(BOOTSTRAP_OUTPUT_DIR))))
92 od := $(if $(BOOTSTRAP_OUTPUT_DIR),$(BOOTSTRAP_OUTPUT_DIR)/)
93
94 PRIVATE_INCDIR   = $(SRC_DIR) $(SRC_DIR)/ARCH-$(ARCH)
95
96 TARGET          := $(od)$(BOOTSTRAP_ELF_NAME)
97 TARGET_BIN       = $(od)$(BOOTSTRAP_ELF_NAME)
98 MODE             = lib
99
100 include $(SRC_DIR)/Makefile.platform
101
102 ifneq ($(DEFAULT_RELOC_arm-$(PLATFORM_TYPE)),)
103 DEFAULT_RELOC_arm         := $(DEFAULT_RELOC_arm-$(PLATFORM_TYPE))
104 endif
105
106 INTERNAL_CRT0 := $(strip $(INTERNAL_CRT0))
107
108 CXXFLAGS_amd64 += -mno-sse
109 CXXFLAGS_x86   += -mno-sse
110 CFLAGS_amd64 += -mno-sse
111 CFLAGS_x86   += -mno-sse
112
113 SRC_C           += exec.c module.c
114 SRC_CC          += region.cc startup.cc init_kip_f.cc \
115                    libc_support+.cc patch.cc koptions.cc \
116                    platform_common.cc memory.cc boot_modules.cc
117
118 SRC_CC_x86      += ARCH-x86/reboot.cc
119 SRC_CC_amd64    += ARCH-x86/reboot.cc
120 SRC_C_x86       += base_critical.c
121 SRC_C_amd64     += base_critical.c
122 SRC_CC_arm      += ARCH-arm/reboot.cc ARCH-arm/head.cc
123 SRC_CC_ppc32    += ARCH-ppc32/init_kip_v2-arch.cc \
124                    ARCH-ppc32/reboot.cc ARCH-ppc32/head.cc
125 SRC_CC_sparc    += ARCH-sparc/reboot.cc ARCH-sparc/head.cc
126 SRC_CC          += $(SUPPORT_CC_$(ARCH)-$(PLATFORM_TYPE))
127
128 SRC_S-$(INTERNAL_CRT0) += ARCH-$(ARCH)/crt0.S
129
130 OPTS             = -g -Os $(CARCHFLAGS_$(ARCH)) $(CARCHFLAGS_$(ARCH)_$(CPU)) \
131                    $(GCCNOFPU_$(ARCH))
132 DEFINES         += -DRAM_BASE=$(RAM_BASE) -DL4_MINIMAL_LIBC=1
133 DEFINES         += -DCMDLINE="\"$(BOOTSTRAP_CMDLINE)\""
134 DEFINES         += -DPLATFORM_TYPE=\"$(PLATFORM_TYPE)\"
135 DEFINES         += -DPLATFORM_TYPE_$(PLATFORM_TYPE)
136 DEFINES         += -DPLATFORM_UART_NR=$(PLATFORM_UART_NR)
137
138 MOD_ADDR         = 0x02000000
139
140 SRC_S           += $(SRC_S-y)
141 CPPFLAGS        += $(CPPFLAGS_$(ARCH)-$(PLATFORM_TYPE))
142 CPPFLAGS        += $(BID_PKG_CONFIG_CFLAGS)
143
144 ifeq ($(filter clean cleanall,$(MAKECMDGOALS)),)
145 ifeq ($(SUPPORT_CC_$(ARCH)-$(PLATFORM_TYPE)),)
146   $(info ERROR: PLATFORM_TYPE=$(PLATFORM_TYPE) has no assigned platform support file)
147   $(info ERROR: A proper PLATFORM_TYPE must be set for a build)
148   $(error .)
149 endif
150 endif
151
152 BOOTSTRAP_L4_LIBS := -lcxx_base -lcxx_io -luc_c_minimal
153 DRV_LIBS-ppc32   = -ldrivers_of
154 DRV_LIBS         = -ldrivers_uart $(DRV_LIBS-$(ARCH))
155 ifeq ($(INTERNAL_CRT0),y)
156 CRT0             =
157 endif
158 LDSCRIPT         = bootstrap.ld
159 LDNMAGIC         =
160
161 vpath bootstrap.ld.in $(SRC_DIR)/ARCH-$(ARCH)
162
163 # can be overwritten by Makeconf.local
164 COMPRESS        ?= 0
165 REALMODE_LOADING ?= 0
166 RML             ?= 0
167 BUILD_PIE       ?= 0
168 SPARSE_ELF      ?= n
169
170 ifeq ($(BUILD_PIE),1)
171 DRV_LIBS          := $(patsubst -l%,-l%.p,$(DRV_LIBS))
172 BOOTSTRAP_L4_LIBS := $(patsubst -l%,-l%.p,$(BOOTSTRAP_L4_LIBS))
173 CFLAGS            += -fpie
174 CXXFLAGS          += -fpie
175 DEFINES           += -D__PIC__
176 LDFLAGS           = -znocombreloc -nostdlib -pie -Bsymbolic
177 endif
178
179 ifneq ($(REALMODE_LOADING)$(RML),00)
180 REALMODE_LOADING := 1
181 $(error Info: Default reloc needs to be 0x00100000)
182 # And if you have done so you probably need to relink sigma0 and/or moe
183 endif
184
185 ifeq ($(ARCH),arm)
186 CPPFLAGS         += -DSINGLE_SECTION
187 endif
188
189
190
191 # convenience
192 ifneq ($(E),)
193 ENTRY           := $(E)
194 endif
195
196 ENTRY_FN := $(shell echo "$(ENTRY)" | tr '[ ]' '[_]' )
197
198
199 ifneq ($(ENTRY),)
200  ifeq ($(filter clean cleanall,$(MAKECMDGOALS)),)
201   BUILD_MOD_CMD = ( SEARCHPATH="$(BOOTSTRAP_SEARCH_PATH):$(BOOTSTRAP_MODULE_PATH_BINLIB)" \
202                     CC="$(CC)" LD="$(LD)" CROSS_COMPILE=$(CROSS_COMPILE) \
203                     MAKE_INC_FILE=$(PWD)/mod.make.inc \
204                     FLAGS_CC="$(CCXX_FLAGS) -I$(SRC_DIR)" \
205                     OUTPUT_DIR="$(BOOTSTRAP_OUTPUT_DIR)" \
206                     OPT_ARCH=$(ARCH) OPT_COMPRESS=$(COMPRESS) L4DIR=$(L4DIR) \
207                     $(SRC_DIR)/build.pl $(1) $(BOOTSTRAP_MODULES_LIST) "$(ENTRY)" || \
208                     (echo "processing-of-module-list-failed"; exit 1))
209  endif
210 endif
211
212
213 # we need to re-do if some things change
214 .redo-change-tracker: FORCE
215         $(VERBOSE)echo "$(ENTRY) '$(COMPRESS)' '$(BOOTSTRAP_CMDLINE)' '$(BOOTSTRAP_SEARCH_PATH):$(BOOTSTRAP_MODULE_PATH_BINLIB)' '$(RAM_SIZE_MB)' '$(PLATFORM_TYPE)' '$(PLATFORM_UART_NR)' '$(od)' '$(OPT_STRIP)'" > $@.tmp
216         $(if $(BUILD_MOD_CMD),$(VERBOSE)$(call BUILD_MOD_CMD,dump) >> $@.tmp)
217         $(call move_if_changed,$@,$@.tmp)
218
219 ifneq ($(ENTRY),)
220
221 INSTALL_FILES  = $(BOOTSTRAP_ELF_NAME) bootstrap_$(ENTRY_FN) bootstrap_$(ENTRY_FN).elf
222 ifeq ($(ARCH)$(BOOTSTRAP_DO_UEFI),amd64)
223 INSTALL_FILES += bootstrap32.elf
224 BOOTSTRAP_LINK_SOURCE = bootstrap32.elf
225 else
226 BOOTSTRAP_LINK_SOURCE = $(BOOTSTRAP_ELF_NAME)
227 endif
228
229 ifeq ($(BOOTSTRAP_DO_UEFI),y)
230 INSTALL_FILES += bootstrap_$(ENTRY_FN).efi bootstrap.efi
231 endif
232
233 $(od)bootstrap_$(ENTRY_FN): $(od)$(BOOTSTRAP_LINK_SOURCE)
234         $(VERBOSE)$(LN) -f $< $@
235
236 $(od)bootstrap_$(ENTRY_FN).elf: $(od)$(BOOTSTRAP_LINK_SOURCE)
237         $(VERBOSE)$(LN) -f $< $@
238
239 $(od)bootstrap_$(ENTRY_FN).%: $(od)bootstrap.%
240         $(VERBOSE)$(LN) -f $< $@
241
242  ifeq ($(ARCH),$(filter $(ARCH),arm ppc32))
243    BID_POST_PROG_LINK_MSG_$(od)$(BOOTSTRAP_ELF_NAME) = echo -e "  ==> Post-processing $@"
244    BID_POST_PROG_LINK_$(od)$(BOOTSTRAP_ELF_NAME)     = \
245       $(VERBOSE)LANG=C $(NM) -C $@ | \
246         LANG=C $(GREP) -E ' D __PLATFORMS_(BEGIN|END)$$' | \
247                 (read a i; read b i; \
248                  if [ "$$a" = "$$b" ]; then \
249                    echo -e "\nERROR: Missing at least one platform instantiation.\n"; \
250                    $(RM) $@; \
251                    exit 1; \
252                  fi ) || exit 1; \
253       $(if $(BOOTSTRAP_NO_STRIP),,$(STRIP) $@)
254
255    ifneq ($(BOOTSTRAP_DO_RAW_IMAGE)$(BOOTSTRAP_DO_UIMAGE),)
256      BOOTSTRAP_RAW      := $(od)bootstrap.raw
257      INSTALL_FILES      += bootstrap.raw bootstrap_$(ENTRY_FN).raw
258      ifneq ($(BOOTSTRAP_DO_UIMAGE),)
259        ifneq ($(shell command -v $(MKIMAGE)),)
260          BOOTSTRAP_UIMAGE := $(od)bootstrap.uimage
261          INSTALL_FILES    += bootstrap.uimage bootstrap_$(ENTRY_FN).uimage
262        else
263          $(error mkimage($(MKIMAGE)) host tool missing, cannot build bootstrap.uimage)
264        endif
265      endif
266    endif
267  endif
268
269 ifneq ($(ENTRY),auto-build-entry)
270 all:: $(addprefix $(IMAGES_DIR)/,$(INSTALL_FILES))
271         $(VERBOSE)echo "  Image size(s) in bytes:"
272         $(VERBOSE)for f in $(filter bootstrap_$(ENTRY_FN).elf bootstrap.raw bootstrap.uimage, $(INSTALL_FILES)); do \
273           find $(if $(od),$(od),.) -name $$f -printf " %30f:  %s\n"; \
274         done
275         $(if $(LDFLAGS_bootstrap.elf),$(VERBOSE)echo "  Start address: $(patsubst --defsym=__executable_start=%,%,$(LDFLAGS_bootstrap.elf))")
276         $(VERBOSE)echo "  --> Build-Nr: $$(cat .build_nr)"
277
278 # install images into easy to reach directory in build dir
279 $(IMAGES_DIR)/%: $(od)%
280         $(VERBOSE)echo "  ==> Installing $< in image directory"
281         $(VERBOSE)(cd $(dir $@) && $(LN) -sf $(if $(od),,$(PWD)/)$<)
282 endif # !auto-build-entry
283
284 else
285   INSTALL_FILES = bootstrap
286 endif # ENTRY
287
288 ifneq ($(REALMODE_LOADING),0)
289 CPPFLAGS        += -DREALMODE_LOADING -DSINGLE_SECTION
290 # don't install bootstrap_$(ENTRY_FN).elf
291 INSTALL_FILES    = bootstrap.load
292 MOD_ADDR         = 0x00150000
293 endif
294
295 ifneq ($(COMPRESS),0)
296 SRC_C           += uncompress.c gunzip.c
297 CFLAGS_gunzip.c := -fno-strict-aliasing
298 CPPFLAGS        += -DCOMPRESS
299 SPARSE_ELF      := n
300 endif
301
302 ifeq ($(SPARSE_ELF),y)
303 CPPFLAGS        += -DPLACE_MODULES_AT_MODADDR
304 endif
305
306 ifneq ($(RAM_SIZE_MB),)
307 CPPFLAGS        += -DRAM_SIZE_MB=$(RAM_SIZE_MB)
308 endif
309
310 CXXFLAGS += -fno-rtti -fno-exceptions
311 CXXFLAGS += $(call checkcxx,-fno-threadsafe-statics)
312
313 ifneq ($(BUILD_MOD_CMD),)
314  ifeq ($(filter clean cleanall,$(MAKECMDGOALS)),)
315
316 processing-of-module-list-failed:
317         @echo
318         @echo "  Processing of $(BOOTSTRAP_MODULES_LIST) failed!"
319         @echo
320         @exit 1
321
322 mod.make.inc $(od)mbi_modules.bin: $(GENERAL_D_LOC) $(shell $(call BUILD_MOD_CMD,list))
323         @echo Building entry \""$(ENTRY)"\".
324         $(VERBOSE)$(call BUILD_MOD_CMD,build)
325
326   -include mod.make.inc
327   BOOTSTRAP_LD_dep             += mod.make.inc
328   STARTUP_C_dep                := mod.make.inc
329   OBJS_$(od)$(BOOTSTRAP_ELF_NAME)   += $(MODULE_OBJECT_FILES)
330  endif
331
332  CPPFLAGS                     += -DIMAGE_MODE
333 endif
334
335 CPPFLAGS        += -DMODADDR=$(MOD_ADDR)
336
337 LIBS             =
338 L4_LIBS          = $(DRV_LIBS) $(BOOTSTRAP_L4_LIBS)
339 L4_LIBS         += $(GCCLIB) $(EXTRA_LIBS)
340
341 all:: $(BOOTSTRAP_RAW)
342
343 # image for use with pxelinux
344 bootstrap.load: $(TARGET_BIN) bootsect.o.img setup.o.img
345         @$(GEN_MESSAGE)
346         $(VERBOSE)objcopy -O binary -R .note -R .comment -S $< $<.load.bin
347         $(VERBOSE)cat bootsect.o.img setup.o.img $<.load.bin > $@
348
349 bootsect.o.img: ARCH-x86/bootsect.S $(SRC_DIR)/Makefile $(SRC_DIR)/Make.rules
350         @$(GEN_MESSAGE)
351         $(VERBOSE)$(CC) -traditional -nostdinc -nostdlib -c $<
352         $(VERBOSE)$(LD) -m elf_i386 -Ttext 0x0 -o $@ -s --oformat binary \
353           bootsect.o
354         $(VERBOSE)chmod -x $@
355
356 setup.o.img: ARCH-x86/setup.S $(SRC_DIR)/Makefile $(SRC_DIR)/Make.rules
357         @$(GEN_MESSAGE)
358         $(VERBOSE)$(CC) -traditional -nostdinc -nostdlib -DARCH_$(ARCH) -c $<
359         $(VERBOSE)$(LD) -m elf_i386 -Ttext 0x0 -o $@ -s --oformat binary \
360           -e begtext setup.o
361         $(VERBOSE)dd if=/dev/zero bs=1 count=$$((3072 - `wc -c < setup.o.img`)) >> setup.o.img 2> /dev/null
362         $(VERBOSE)chmod -x $@
363
364 # raw version without ELF, primarily useful for ARM
365 $(BOOTSTRAP_RAW): $(TARGET_BIN)
366         @$(GEN_MESSAGE)
367         $(VERBOSE)cp $< $@.tmp
368         $(VERBOSE)$(OBJCOPY) -O binary $@.tmp $@
369         $(VERBOSE)chmod -x $@
370         $(VERBOSE)$(RM) $@.tmp
371
372 %.gzip: %
373         gzip -c9 $^ > $@
374
375 %.bzip2: %
376         bzip2 -c9 $^ > $@
377
378 %.none: %
379         ln -sf $^ $@
380
381 MKIMAGE_ARCH = $(if $(filter ppc32,$(ARCH)),ppc,$(ARCH))
382
383 # u-boot image, based on raw-version
384 $(BOOTSTRAP_UIMAGE): $(BOOTSTRAP_RAW).$(BOOTSTRAP_UIMAGE_COMPRESSION)
385         @$(GEN_MESSAGE)
386         @# mkimage writes the same file which does not play well with hardlinks
387         $(VERBOSE)$(RM) -f $@
388         $(VERBOSE)$(MKIMAGE) -e $(call default_reloc,$(ARCH)) \
389            -a $(call default_reloc,$(ARCH)) -A $(MKIMAGE_ARCH)  \
390            -C $(BOOTSTRAP_UIMAGE_COMPRESSION) \
391            -n "L4 Image #$$(cat .build_nr)" \
392            -d $^ $@
393
394 $(TARGET): $(LDSCRIPT) $(OBJS_$(TARGET))
395
396
397 increment_build_nr = \
398    $(shell if [ -e .build_nr ]; then            \
399              nr=$$(($$(cat .build_nr) + 1));    \
400            else                                 \
401              nr=1;                              \
402            fi;                                  \
403            echo $$nr > .build_nr; echo $$nr)
404
405
406 startup.o: $(STARTUP_C_dep)
407 startup.o: CPPFLAGS += -DBUILD_DATE="\"$(shell date)\"" -DBUILD_NR=\"$(call increment_build_nr)\"
408
409 $(LDSCRIPT): $(LDSCRIPT).in $(GENERAL_D_LOC) $(BOOTSTRAP_LD_dep)
410         @$(GEN_MESSAGE)
411         $(VERBOSE)$(CROSS_COMPILE)cpp -P $(CPPFLAGS) -DLINKADDR=$(strip $(call default_reloc,$(ARCH))) $< $@;
412
413 clean::
414         $(VERBOSE)$(RM) mod.make.inc mod*.bin mbi_modules.bin $(LDSCRIPT)
415         $(VERBOSE)$(RM) setup.o.img bootsect.o.img
416         $(VERBOSE)$(RM) mod*.bin
417         $(VERBOSE)$(RM) $(SRC32_C:.c=.o32) $(SRC32_S:.S=.o32)
418         $(VERBOSE)$(RM) .redo-change-tracker
419
420 cleanall::
421         $(VERBOSE)$(RM) $(od)bootstrap_* $(od)bootstrap.*
422
423 bootstrap.efi: bootstrap.elf
424         $(OBJCOPY) -S -j .text -j .rodata -j .reloc -j .dynsym -j .dynstr -j .rel.dyn \
425                    -j .data \
426                    -j .data.module_info -j .dynamic -j .rela.dyn -j .rela.plt -j .reloc \
427                    -j .bss -j .module_data \
428                    --target=$(EFI_BIN_FMT) $< $@
429
430 ifeq ($(ARCH),amd64)
431
432 vpath %.c             $(SRC_DIR)/ARCH-amd64
433 vpath %.S             $(SRC_DIR)/ARCH-amd64
434 vpath %.c             $(SRC_DIR)/ARCH-amd64/boot32
435 vpath %.S             $(SRC_DIR)/ARCH-amd64/boot32
436 vpath bootstrap.ld.in $(SRC_DIR)/ARCH-x86
437
438 SRC32_C          = boot_cpu.c boot_kernel.c load_elf.c minilibc_support.c
439 SRC32_S          = boot.S boot_idt.S
440 OBJ32            = $(SRC32_S:.S=.o32) $(SRC32_C:.c=.o32)
441 CC32             = $(filter-out -m64, $(CC)) -m32
442 CFLAGS32         = $(filter-out -m64, $(CFLAGS) $(CFLAGS_$(ARCH))) -m32 $(GCCNOSTACKPROTOPT)
443
444 $(OBJ_DIR)/ARCH-amd64/libc32/OBJ-$(ARCH)_$(CPU)/libc32.a: FORCE
445         $(VERBOSE)$(MAKE) O=$(OBJ_BASE) -C $(SRC_DIR)/ARCH-amd64/libc32
446
447 bootstrap32.elf: $(OBJ32) bootstrap32.bin $(SRC_DIR)/ARCH-amd64/boot32/bootstrap32.ld $(OBJ_DIR)/ARCH-amd64/libc32/OBJ-$(ARCH)_$(CPU)/libc32.a
448         @$(LINK_MESSAGE)
449         $(VERBOSE)$(CC32) -o $@ -nostdlib -static \
450           -Wl,-T,$(SRC_DIR)/ARCH-amd64/boot32/bootstrap32.ld,--gc-sections $^ -lgcc
451         $(VERBOSE)chmod 755 $@
452
453 bootstrap: bootstrap32.elf
454         $(VERBOSE)$(LN) -f $^ $@
455
456 bootstrap32.bin: $(BOOTSTRAP_ELF_NAME)
457         @$(GEN_MESSAGE)
458         $(VERBOSE)$(OBJCOPY) -S $< bootstrap64.bin
459         $(VERBOSE)chmod -x bootstrap64.bin
460         $(VERBOSE)$(OBJCOPY) -B i386 -I binary -O elf32-i386 bootstrap64.bin $@
461
462 %.o32: %.c $(SRC_DIR)/Makefile $(SRC_DIR)/Make.rules
463         @$(COMP_MESSAGE)
464         $(VERBOSE)$(CC32) -o $@ -c $(DEPEND_FLAG) \
465           $(CPPFLAGS) $(CFLAGS32) $(call absfilename,$<)
466
467 %.o32: %.S $(SRC_DIR)/Makefile $(SRC_DIR)/Make.rules
468         @$(COMP_MESSAGE)
469         $(VERBOSE)$(CC32) -o $@ -c $(DEPEND_FLAG) \
470           $(CPPFLAGS) $(CFLAGS32) $(call absfilename,$<)
471
472 clean cleanall::
473         $(VERBOSE)PWD=$(call absfilename,$(SRC_DIR)/ARCH-amd64/libc32) \
474           $(MAKE) -C $(SRC_DIR)/ARCH-amd64/libc32 $@
475
476 else
477 bootstrap: $(BOOTSTRAP_ELF_NAME)
478         $(VERBOSE)$(LN) -f $^ $@
479 endif
480
481 INSTALL_TARGET := $(if $(od),,$(INSTALL_FILES))