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 SRC16=floppy.c disk.c system.c clock.c serial.c kbd.c mouse.c output.c \
14 TABLESRC=font.c cbt.c floppy_dbt.c
16 cc-option = $(shell if test -z "`$(1) $(2) -S -o /dev/null -xc \
17 /dev/null 2>&1`"; then echo "$(2)"; else echo "$(3)"; fi ;)
19 # Default compiler flags
20 COMMONCFLAGS = -Wall -Os -MD -m32 -march=i386 -mregparm=2 \
21 -ffreestanding -fwhole-program
22 COMMONCFLAGS += $(call cc-option,$(CC),-nopie,)
23 COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
24 COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,)
26 CFLAGS = $(COMMONCFLAGS) -g
27 CFLAGS16INC = $(COMMONCFLAGS) -DMODE16 -fno-jump-tables
28 CFLAGS16 = $(CFLAGS16INC) -g
30 TABLETMP=$(addprefix $(OUT), $(patsubst %.c,%.16.s,$(TABLESRC)))
31 all: $(OUT) $(OUT)rom.bin $(TABLETMP)
33 # Run with "make V=1" to see the actual compile commands
45 ################ Build rules
47 # Do a whole file compile - two methods are supported. The first
48 # involves including all the content textually via #include
49 # directives. The second method uses gcc's "-combine" option.
53 @echo " Compiling whole program $3"
54 $(Q)/bin/echo -e '$(foreach i,$2,#include "../$i"\n)' > $3.tmp.c
55 $(Q)$(CC) $1 -c $3.tmp.c -o $3
58 # Ugly way to get gcc to generate .d files correctly.
59 DEPHACK=-combine src/null.c
61 @echo " Compiling whole program $3"
62 $(Q)$(CC) $1 -combine -c $2 -o $3
67 $(OUT)%.proc.16.s: $(OUT)%.16.s
68 @echo " Moving data sections to text in $<"
69 $(Q)sed 's/\t\.section\t\.rodata.*// ; s/\t\.data//' < $< > $@
72 @echo " Generating assembler for $<"
73 $(Q)$(CC) $(CFLAGS16INC) $(DEPHACK) -S -c $< -o $@
76 @echo " Precompiling $<"
77 $(Q)$(CPP) -P $< -o $@
79 $(OUT)%.bin: $(OUT)%.o
80 @echo " Extracting binary $@"
81 $(Q)objcopy -O binary $< $@
83 $(OUT)%.offset.auto.h: $(OUT)%.o
84 @echo " Generating symbol offset header $@"
85 $(Q)nm $< | ./tools/defsyms.py $@
87 $(OUT)blob.16.s: ; $(call whole-compile, $(CFLAGS16) -S, $(addprefix src/, $(SRC16)),$@)
89 TABLEASM=$(addprefix $(OUT), $(patsubst %.c,%.proc.16.s,$(TABLESRC)))
90 $(OUT)romlayout16.o: romlayout.S $(OUT)blob.proc.16.s $(TABLEASM)
91 @echo " Generating 16bit layout of $@"
92 $(Q)$(CC) $(CFLAGS16) -c $< -o $@
94 $(OUT)rom16.o: $(OUT)romlayout16.o
96 $(Q)ld -melf_i386 -e post16 -Ttext 0 $< -o $@
98 $(OUT)rom16.bin: $(OUT)rom16.o
99 @echo " Extracting binary $@"
100 $(Q)objcopy -O binary $< $@
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)rom.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