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.
7 # Don't compile ACPI DSDT by default
8 # Uncomment the below line in case you want to compile DSDT yourself.
9 # Note: "iasl" package is required to compile.
17 SRC16=floppy.c disk.c system.c clock.c serial.c kbd.c mouse.c output.c \
18 boot.c ata.c cdrom.c apm.c
19 SRC32=post.c output.c smbios.c acpi.c smm.c smp.c pci.c
20 TABLESRC=font.c cbt.c floppy_dbt.c
22 cc-option = $(shell if test -z "`$(1) $(2) -S -o /dev/null -xc \
23 /dev/null 2>&1`"; then echo "$(2)"; else echo "$(3)"; fi ;)
25 # Default compiler flags
26 COMMONCFLAGS = -Wall -Os -MD -m32 -march=i386 -mregparm=2 \
27 -ffreestanding -fwhole-program
28 COMMONCFLAGS += $(call cc-option,$(CC),-nopie,)
29 COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
30 COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,)
32 CFLAGS = $(COMMONCFLAGS) -g
33 CFLAGS16INC = $(COMMONCFLAGS) -DMODE16 -fno-jump-tables
34 CFLAGS16 = $(CFLAGS16INC) -g
36 TABLETMP=$(addprefix $(OUT), $(patsubst %.c,%.16.s,$(TABLESRC)))
38 all: $(OUT) $(OUT)rom.bin $(TABLETMP)
40 # Run with "make V=1" to see the actual compile commands
52 ################ Build rules
54 # Do a whole file compile - two methods are supported. The first
55 # involves including all the content textually via #include
56 # directives. The second method uses gcc's "-combine" option.
60 @echo " Compiling whole program $3"
61 $(Q)/bin/echo -e '$(foreach i,$2,#include "../$i"\n)' > $3.tmp.c
62 $(Q)$(CC) $1 -c $3.tmp.c -o $3
65 # Ugly way to get gcc to generate .d files correctly.
66 DEPHACK=-combine src/null.c
68 @echo " Compiling whole program $3"
69 $(Q)$(CC) $1 -combine -c $2 -o $3
74 $(OUT)%.proc.16.s: $(OUT)%.16.s
75 @echo " Moving data sections to text in $<"
76 $(Q)sed 's/\t\.section\t\.rodata.*// ; s/\t\.data//' < $< > $@
79 @echo " Generating assembler for $<"
80 $(Q)$(CC) $(CFLAGS16INC) $(DEPHACK) -S -c $< -o $@
83 @echo " Precompiling $<"
84 $(Q)$(CPP) -P $< -o $@
86 $(OUT)%.bin: $(OUT)%.o
87 @echo " Extracting binary $@"
88 $(Q)objcopy -O binary $< $@
90 $(OUT)%.offset.auto.h: $(OUT)%.o
91 @echo " Generating symbol offset header $@"
92 $(Q)nm $< | ./tools/defsyms.py $@
94 $(OUT)blob.16.s: ; $(call whole-compile, $(CFLAGS16) -S, $(addprefix src/, $(SRC16)),$@)
96 TABLEASM=$(addprefix $(OUT), $(patsubst %.c,%.proc.16.s,$(TABLESRC)))
97 $(OUT)romlayout16.o: romlayout.S $(OUT)blob.proc.16.s $(TABLEASM)
98 @echo " Generating 16bit layout of $@"
99 $(Q)$(CC) $(CFLAGS16) -c $< -o $@
101 $(OUT)rom16.o: $(OUT)romlayout16.o
103 $(Q)ld -melf_i386 -e post16 -Ttext 0 $< -o $@
105 $(OUT)rom16.bin: $(OUT)rom16.o
106 @echo " Extracting binary $@"
107 $(Q)objcopy -O binary $< $@
109 $(OUT)romlayout32.o: $(OUT)acpi-dsdt.hex $(OUT)rom16.offset.auto.h ; $(call whole-compile, $(CFLAGS), $(addprefix src/, $(SRC32)),$@)
111 ifeq ($(BUILD_ACPI), 1)
112 $(OUT)acpi-dsdt.hex: src/acpi-dsdt.dsl
115 $(OUT)acpi-dsdt.hex: src/acpi-dsdt.hex
116 cp src/acpi-dsdt.hex $(OUT)
119 $(OUT)rom32.o: $(OUT)romlayout32.o $(OUT)rombios32.lds
121 $(Q)ld -T $(OUT)rombios32.lds $< -o $@
123 $(OUT)rom.bin: $(OUT)rom16.bin $(OUT)rom32.bin $(OUT)rom16.offset.auto.h $(OUT)rom32.offset.auto.h
125 $(Q)./tools/buildrom.py
127 ####### Generic rules