This patch adds the BIOS support for SMP, ACPI, PCI, SMM, SMBIOS.
[seabios.git] / Makefile
1 # Legacy Bios build system
2 #
3 # Copyright (C) 2008  Kevin O'Connor <kevin@koconnor.net>
4 #
5 # This file may be distributed under the terms of the GNU GPLv3 license.
6
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.
10 #BUILD_ACPI = 1
11 BUILD_ACPI = 0
12
13 # Output directory
14 OUT=out/
15
16 # Source files
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
21
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 ;)
24
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,)
31
32 CFLAGS = $(COMMONCFLAGS) -g
33 CFLAGS16INC = $(COMMONCFLAGS) -DMODE16 -fno-jump-tables
34 CFLAGS16 = $(CFLAGS16INC) -g
35
36 TABLETMP=$(addprefix $(OUT), $(patsubst %.c,%.16.s,$(TABLESRC)))
37
38 all: $(OUT) $(OUT)rom.bin $(TABLETMP)
39
40 # Run with "make V=1" to see the actual compile commands
41 ifdef V
42 Q=
43 else
44 Q=@
45 endif
46
47 .PHONY : all FORCE
48
49 vpath %.c src
50 vpath %.S src
51
52 ################ Build rules
53
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.
57 ifdef AVOIDCOMBINE
58 DEPHACK=
59 define whole-compile
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
63 endef
64 else
65 # Ugly way to get gcc to generate .d files correctly.
66 DEPHACK=-combine src/null.c
67 define whole-compile
68 @echo "  Compiling whole program $3"
69 $(Q)$(CC) $1 -combine -c $2 -o $3
70 endef
71 endif
72
73
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//' < $< > $@
77
78 $(OUT)%.16.s: %.c
79         @echo "  Generating assembler for $<"
80         $(Q)$(CC) $(CFLAGS16INC) $(DEPHACK) -S -c $< -o $@
81
82 $(OUT)%.lds: %.lds.S
83         @echo "  Precompiling $<"
84         $(Q)$(CPP) -P $< -o $@
85
86 $(OUT)%.bin: $(OUT)%.o
87         @echo "  Extracting binary $@"
88         $(Q)objcopy -O binary $< $@
89
90 $(OUT)%.offset.auto.h: $(OUT)%.o
91         @echo "  Generating symbol offset header $@"
92         $(Q)nm $< | ./tools/defsyms.py $@
93
94 $(OUT)blob.16.s: ; $(call whole-compile, $(CFLAGS16) -S, $(addprefix src/, $(SRC16)),$@)
95
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 $@
100
101 $(OUT)rom16.o: $(OUT)romlayout16.o
102         @echo "  Linking $@"
103         $(Q)ld -melf_i386 -e post16 -Ttext 0 $< -o $@
104
105 $(OUT)rom16.bin: $(OUT)rom16.o
106         @echo "  Extracting binary $@"
107         $(Q)objcopy -O binary $< $@
108
109 $(OUT)romlayout32.o: $(OUT)acpi-dsdt.hex $(OUT)rom16.offset.auto.h ; $(call whole-compile, $(CFLAGS), $(addprefix src/, $(SRC32)),$@)
110
111 ifeq ($(BUILD_ACPI), 1)
112 $(OUT)acpi-dsdt.hex: src/acpi-dsdt.dsl
113         iasl -tc -p $@ $<
114 else
115 $(OUT)acpi-dsdt.hex: src/acpi-dsdt.hex
116         cp src/acpi-dsdt.hex $(OUT)
117 endif
118
119 $(OUT)rom32.o: $(OUT)romlayout32.o $(OUT)rombios32.lds
120         @echo "  Linking $@"
121         $(Q)ld -T $(OUT)rombios32.lds $< -o $@
122
123 $(OUT)rom.bin: $(OUT)rom16.bin $(OUT)rom32.bin $(OUT)rom16.offset.auto.h $(OUT)rom32.offset.auto.h
124         @echo "  Building $@"
125         $(Q)./tools/buildrom.py
126
127 ####### Generic rules
128 .PHONY : clean
129 clean:
130         rm -rf $(OUT)
131
132 $(OUT):
133         mkdir $@
134
135 -include $(OUT)*.d