1 # Legacy Bios build system
3 # Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
5 # This file may be distributed under the terms of the GNU GPLv3 license.
11 SRCBOTH=output.c util.c floppy.c ata.c kbd.c pci.c boot.c serial.c clock.c
12 SRC16=$(SRCBOTH) disk.c system.c mouse.c cdrom.c apm.c pcibios.c
13 SRC32=$(SRCBOTH) post.c shadow.c rombios32.c post_menu.c memmap.c coreboot.c \
15 TABLESRC=font.c cbt.c floppy_dbt.c
17 cc-option = $(shell if test -z "`$(1) $(2) -S -o /dev/null -xc \
18 /dev/null 2>&1`"; then echo "$(2)"; else echo "$(3)"; fi ;)
20 # Default compiler flags
21 COMMONCFLAGS = -Wall -Os -MD -m32 -march=i386 -mregparm=3 \
22 -mpreferred-stack-boundary=2 -mrtd \
23 -ffreestanding -fwhole-program -fomit-frame-pointer \
24 -fno-delete-null-pointer-checks
25 COMMONCFLAGS += $(call cc-option,$(CC),-nopie,)
26 COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
27 COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,)
29 CFLAGS = $(COMMONCFLAGS) -g
30 CFLAGS16INC = $(COMMONCFLAGS) -DMODE16 -fno-jump-tables -fno-defer-pop \
31 $(call cc-option,$(CC),--param large-stack-frame=8,)
32 CFLAGS16 = $(CFLAGS16INC) -g
34 TABLETMP=$(addprefix $(OUT), $(patsubst %.c,%.16.s,$(TABLESRC)))
35 all: $(OUT) $(OUT)bios.bin $(TABLETMP)
37 # Run with "make V=1" to see the actual compile commands
49 ################ Build rules
51 # Do a whole file compile - two methods are supported. The first
52 # involves including all the content textually via #include
53 # directives. The second method uses gcc's "-combine" option.
57 @echo " Compiling whole program $3"
58 $(Q)/bin/echo -e '$(foreach i,$2,#include "../$i"\n)' > $3.tmp.c
59 $(Q)$(CC) $1 -c $3.tmp.c -o $3
62 # Ugly way to get gcc to generate .d files correctly.
63 DEPHACK=-combine src/null.c
65 @echo " Compiling whole program $3"
66 $(Q)$(CC) $1 -combine -c $2 -o $3
71 $(OUT)%.proc.16.s: $(OUT)%.16.s
72 @echo " Moving data sections to text in $<"
73 $(Q)sed 's/\t\.section\t\.rodata.*// ; s/\t\.data//' < $< > $@
76 @echo " Generating assembler for $<"
77 $(Q)$(CC) $(CFLAGS16INC) $(DEPHACK) -S -c $< -o $@
80 @echo " Precompiling $<"
81 $(Q)$(CPP) -P $< -o $@
83 $(OUT)%.bin: $(OUT)%.o
84 @echo " Extracting binary $@"
85 $(Q)objcopy -O binary $< $@
87 $(OUT)%.offset.auto.h: $(OUT)%.o
88 @echo " Generating symbol offset header $@"
89 $(Q)nm $< | ./tools/defsyms.py $@
91 $(OUT)blob.16.s: ; $(call whole-compile, $(CFLAGS16) -S, $(addprefix src/, $(SRC16)),$@)
93 TABLEASM=$(addprefix $(OUT), $(patsubst %.c,%.proc.16.s,$(TABLESRC)))
94 $(OUT)romlayout16.o: romlayout.S $(OUT)blob.16.s $(TABLEASM)
95 @echo " Generating 16bit layout of $@"
96 $(Q)$(CC) $(CFLAGS16) -c $< -o $@
98 $(OUT)rom16.o: $(OUT)romlayout16.o $(OUT)rombios16.lds
100 $(Q)ld -T $(OUT)rombios16.lds $< -o $@
102 $(OUT)romlayout32.o: $(OUT)rom16.offset.auto.h ; $(call whole-compile, $(CFLAGS), $(addprefix src/, $(SRC32)),$@)
104 $(OUT)rom32.o: $(OUT)romlayout32.o $(OUT)rombios32.lds
106 $(Q)ld -T $(OUT)rombios32.lds $< -o $@
108 $(OUT)bios.bin: $(OUT)rom16.bin $(OUT)rom32.bin $(OUT)rom16.offset.auto.h $(OUT)rom32.offset.auto.h
110 $(Q)./tools/buildrom.py
112 ####### Generic rules