Initial PnP bios call support.
[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 # Output directory
8 OUT=out/
9
10 # Source files
11 SRCBOTH=output.c util.c floppy.c ata.c system.c mouse.c kbd.c pci.c \
12         serial.c clock.c pic.c cdrom.c ps2port.c smpdetect.c resume.c \
13         pnpbios.c
14 SRC16=$(SRCBOTH) disk.c apm.c pcibios.c vgahooks.c
15 SRC32=$(SRCBOTH) post.c shadow.c post_menu.c memmap.c coreboot.c boot.c \
16       acpi.c pirtable.c smm.c mptable.c smbios.c pciinit.c \
17       optionroms.c
18 TABLESRC=font.c cbt.c floppy_dbt.c
19
20 cc-option = $(shell if test -z "`$(1) $(2) -S -o /dev/null -xc \
21               /dev/null 2>&1`"; then echo "$(2)"; else echo "$(3)"; fi ;)
22
23 # Default compiler flags
24 COMMONCFLAGS = -Wall -Os -MD -m32 -march=i386 -mregparm=3 \
25                -mpreferred-stack-boundary=2 -mrtd \
26                -ffreestanding -fwhole-program -fomit-frame-pointer \
27                -fno-delete-null-pointer-checks
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 override CFLAGS = $(COMMONCFLAGS) -g -DMODE16=0
33 CFLAGS16INC = $(COMMONCFLAGS) -DMODE16=1 -fno-jump-tables -fno-defer-pop \
34               $(call cc-option,$(CC),--param large-stack-frame=8,)
35 CFLAGS16 = $(CFLAGS16INC) -g
36
37 TABLETMP=$(addprefix $(OUT), $(patsubst %.c,%.16.s,$(TABLESRC)))
38 all: $(OUT) $(OUT)bios.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 OBJCOPY=objcopy
48 NM=nm
49 STRIP=strip
50
51 .PHONY : all FORCE
52
53 vpath %.c src
54 vpath %.S src
55
56 ################ Build rules
57
58 # Do a whole file compile - two methods are supported.  The first
59 # involves including all the content textually via #include
60 # directives.  The second method uses gcc's "-combine" option.
61 ifdef AVOIDCOMBINE
62 DEPHACK=
63 define whole-compile
64 @echo "  Compiling whole program $3"
65 $(Q)printf '$(foreach i,$2,#include "../$i"\n)' > $3.tmp.c
66 $(Q)$(CC) $1 -c $3.tmp.c -o $3
67 endef
68 else
69 # Ugly way to get gcc to generate .d files correctly.
70 DEPHACK=-combine src/null.c
71 define whole-compile
72 @echo "  Compiling whole program $3"
73 $(Q)$(CC) $1 -combine -c $2 -o $3
74 endef
75 endif
76
77
78 $(OUT)%.proc.16.s: $(OUT)%.16.s
79         @echo "  Moving data sections to text in $@"
80         $(Q)sed 's/\t\.section\t\.rodata.*// ; s/\t\.data//' < $< > $@
81
82 $(OUT)%.16.s: %.c
83         @echo "  Compiling to assembler $@"
84         $(Q)$(CC) $(CFLAGS16INC) $(DEPHACK) -S -c $< -o $@
85
86 $(OUT)%.lds: %.lds.S
87         @echo "  Precompiling $@"
88         $(Q)$(CPP) -P -D__ASSEMBLY__ $< -o $@
89
90 $(OUT)asm-offsets.h: $(OUT)asm-offsets.16.s
91         @echo "  Generating offset file $@"
92         $(Q)./tools/gen-offsets.sh $< $@
93
94 $(OUT)ccode.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)ccode.16.s $(OUT)asm-offsets.h $(TABLEASM)
98         @echo "  Compiling (16bit) $@"
99         $(Q)$(CC) $(CFLAGS16INC) -c -D__ASSEMBLY__ $< -o $@
100
101 $(OUT)ccode32.o: ; $(call whole-compile, $(CFLAGS), $(addprefix src/, $(SRC32)),$@)
102
103 $(OUT)rom32.o: $(OUT)ccode32.o $(OUT)rombios32.lds
104         @echo "  Linking (no relocs) $@"
105         $(Q)$(LD) -r -d -T $(OUT)rombios32.lds $< -o $@
106
107 $(OUT)rom16.o: $(OUT)romlayout16.o $(OUT)rom32.o $(OUT)rombios16.lds
108         @echo "  Linking (16bit) $@"
109         $(Q)$(OBJCOPY) --prefix-symbols=_code32_ $(OUT)rom32.o $(OUT)rom32.rename.o
110         $(Q)$(LD) -T $(OUT)rombios16.lds -R $(OUT)rom32.rename.o $< -o $@
111
112 $(OUT)rom.o: $(OUT)rom16.o $(OUT)rom32.o $(OUT)rombios.lds
113         @echo "  Linking $@"
114         $(Q)$(LD) -T $(OUT)rombios.lds $(OUT)rom16.o $(OUT)rom32.o -o $@
115
116 $(OUT)bios.bin.elf: $(OUT)rom.o
117         @echo "  Prepping $@"
118         $(Q)$(NM) $< | ./tools/checkrom.py
119         $(Q)$(STRIP) $< -o $@
120
121 $(OUT)bios.bin: $(OUT)bios.bin.elf
122         @echo "  Extracting binary $@"
123         $(Q)$(OBJCOPY) -O binary $< $@
124
125
126 ####### Generic rules
127 clean:
128         $(Q)rm -rf $(OUT)
129
130 $(OUT):
131         $(Q)mkdir $@
132
133 -include $(OUT)*.d