acpi: move \_SB.PCI0._CRS to separate file [q35]
[seabios.git] / Makefile
blob8e3267098c06165cd3a9a2da0197fb9a8c247a29
1 # SeaBIOS build system
3 # Copyright (C) 2008-2012 Kevin O'Connor <kevin@koconnor.net>
5 # This file may be distributed under the terms of the GNU LGPLv3 license.
7 # Output directory
8 OUT=out/
10 # Source files
11 SRCBOTH=misc.c stacks.c pmm.c output.c util.c block.c floppy.c ata.c mouse.c \
12 kbd.c pci.c serial.c clock.c pic.c cdrom.c ps2port.c smp.c resume.c \
13 pnpbios.c pirtable.c vgahooks.c ramdisk.c pcibios.c blockcmd.c \
14 usb.c usb-uhci.c usb-ohci.c usb-ehci.c usb-hid.c usb-msc.c \
15 virtio-ring.c virtio-pci.c virtio-blk.c virtio-scsi.c apm.c ahci.c \
16 usb-uas.c lsi-scsi.c esp-scsi.c megasas.c
17 SRC16=$(SRCBOTH) system.c disk.c font.c
18 SRC32FLAT=$(SRCBOTH) post.c shadow.c memmap.c coreboot.c boot.c \
19 acpi.c smm.c mptable.c smbios.c pciinit.c optionroms.c mtrr.c \
20 lzmadecode.c bootsplash.c jpeg.c usb-hub.c paravirt.c \
21 biostables.c xen.c bmp.c romfile.c
22 SRC32SEG=util.c output.c pci.c pcibios.c apm.c stacks.c
24 # Default compiler flags
25 cc-option=$(shell if test -z "`$(1) $(2) -S -o /dev/null -xc /dev/null 2>&1`" \
26 ; then echo "$(2)"; else echo "$(3)"; fi ;)
28 COMMONCFLAGS = -I$(OUT) -Os -MD -g \
29 -Wall -Wno-strict-aliasing -Wold-style-definition \
30 $(call cc-option,$(CC),-Wtype-limits,) \
31 -m32 -march=i386 -mregparm=3 -mpreferred-stack-boundary=2 \
32 -minline-all-stringops \
33 -freg-struct-return -ffreestanding -fno-delete-null-pointer-checks \
34 -ffunction-sections -fdata-sections -fno-common
35 COMMONCFLAGS += $(call cc-option,$(CC),-nopie,)
36 COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
37 COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,)
39 CFLAGS32FLAT = $(COMMONCFLAGS) -DMODE16=0 -DMODESEGMENT=0 -fomit-frame-pointer
40 CFLAGSSEG = $(COMMONCFLAGS) -DMODESEGMENT=1 -fno-defer-pop \
41 $(call cc-option,$(CC),-fno-jump-tables,-DMANUAL_NO_JUMP_TABLE) \
42 $(call cc-option,$(CC),-fno-tree-switch-conversion,)
43 CFLAGS32SEG = $(CFLAGSSEG) -DMODE16=0 -fomit-frame-pointer
44 CFLAGS16INC = $(CFLAGSSEG) -DMODE16=1 -Wa,src/code16gcc.s \
45 $(call cc-option,$(CC),--param large-stack-frame=4,-fno-inline)
46 CFLAGS16 = $(CFLAGS16INC) -fomit-frame-pointer
48 # Run with "make V=1" to see the actual compile commands
49 ifdef V
51 else
52 Q=@
53 MAKEFLAGS += --no-print-directory
54 endif
56 # Common command definitions
57 export HOSTCC := $(CC)
58 export CONFIG_SHELL := sh
59 export KCONFIG_AUTOHEADER := autoconf.h
60 export KCONFIG_CONFIG := $(CURDIR)/.config
61 AS=as
62 OBJCOPY=objcopy
63 OBJDUMP=objdump
64 STRIP=strip
65 PYTHON=python
66 IASL:=iasl
68 # Default targets
69 -include $(KCONFIG_CONFIG)
71 target-y = $(OUT) $(OUT)bios.bin
72 target-$(CONFIG_BUILD_VGABIOS) += $(OUT)vgabios.bin
74 all: $(target-y)
76 # Make definitions
77 .PHONY : all clean distclean FORCE
78 .DELETE_ON_ERROR:
80 vpath %.c src vgasrc
81 vpath %.S src vgasrc
84 ################ Common build rules
86 # Verify the build environment works.
87 TESTGCC:=$(shell CC="$(CC)" LD="$(LD)" IASL="$(IASL)" tools/test-build.sh)
88 ifeq "$(TESTGCC)" "-1"
89 $(error "Please upgrade the build environment")
90 endif
92 ifndef COMPSTRAT
93 COMPSTRAT=$(TESTGCC)
94 endif
96 # Do a whole file compile - three methods are supported.
97 ifeq "$(COMPSTRAT)" "1"
98 # First method - use -fwhole-program without -combine.
99 define whole-compile
100 @echo " Compiling whole program $3"
101 $(Q)printf '$(foreach i,$2,#include "../$i"\n)' > $3.tmp.c
102 $(Q)$(CC) $1 -fwhole-program -DWHOLE_PROGRAM -c $3.tmp.c -o $3
103 endef
104 else
105 ifeq "$(COMPSTRAT)" "2"
106 # Second menthod - don't use -fwhole-program at all.
107 define whole-compile
108 @echo " Compiling whole program $3"
109 $(Q)printf '$(foreach i,$2,#include "../$i"\n)' > $3.tmp.c
110 $(Q)$(CC) $1 -c $3.tmp.c -o $3
111 endef
112 else
113 # Third (and preferred) method - use -fwhole-program with -combine
114 define whole-compile
115 @echo " Compiling whole program $3"
116 $(Q)$(CC) $1 -fwhole-program -DWHOLE_PROGRAM -combine -c $2 -o $3
117 endef
118 endif
119 endif
121 %.strip.o: %.o
122 @echo " Stripping $@"
123 $(Q)$(STRIP) $< -o $@
125 $(OUT)%.s: %.c
126 @echo " Compiling to assembler $@"
127 $(Q)$(CC) $(CFLAGS16) -S -c $< -o $@
129 $(OUT)%.lds: %.lds.S
130 @echo " Precompiling $@"
131 $(Q)$(CPP) -P -D__ASSEMBLY__ $< -o $@
134 ################ Main BIOS build rules
136 $(OUT)asm-offsets.s: $(OUT)autoconf.h
138 $(OUT)asm-offsets.h: $(OUT)asm-offsets.s
139 @echo " Generating offset file $@"
140 $(Q)./tools/gen-offsets.sh $< $@
142 $(OUT)ccode16.o: $(OUT)autoconf.h ; $(call whole-compile, $(CFLAGS16), $(addprefix src/, $(SRC16)),$@)
144 $(OUT)code32seg.o: $(OUT)autoconf.h ; $(call whole-compile, $(CFLAGS32SEG), $(addprefix src/, $(SRC32SEG)),$@)
146 $(OUT)ccode32flat.o: $(OUT)autoconf.h ; $(call whole-compile, $(CFLAGS32FLAT), $(addprefix src/, $(SRC32FLAT)),$@)
148 $(OUT)romlayout.o: romlayout.S $(OUT)asm-offsets.h
149 @echo " Compiling (16bit) $@"
150 $(Q)$(CC) $(CFLAGS16) -c -D__ASSEMBLY__ $< -o $@
152 $(OUT)romlayout16.lds: $(OUT)ccode32flat.o $(OUT)code32seg.o $(OUT)ccode16.o $(OUT)romlayout.o tools/layoutrom.py
153 @echo " Building ld scripts"
154 $(Q)./tools/buildversion.sh $(OUT)version.c
155 $(Q)$(CC) $(CFLAGS32FLAT) -c $(OUT)version.c -o $(OUT)version.o
156 $(Q)$(LD) -melf_i386 -r $(OUT)ccode32flat.o $(OUT)version.o -o $(OUT)code32flat.o
157 $(Q)$(LD) -melf_i386 -r $(OUT)ccode16.o $(OUT)romlayout.o -o $(OUT)code16.o
158 $(Q)$(OBJDUMP) -thr $(OUT)code32flat.o > $(OUT)code32flat.o.objdump
159 $(Q)$(OBJDUMP) -thr $(OUT)code32seg.o > $(OUT)code32seg.o.objdump
160 $(Q)$(OBJDUMP) -thr $(OUT)code16.o > $(OUT)code16.o.objdump
161 $(Q)$(PYTHON) ./tools/layoutrom.py $(OUT)code16.o.objdump $(OUT)code32seg.o.objdump $(OUT)code32flat.o.objdump $(OUT)romlayout16.lds $(OUT)romlayout32seg.lds $(OUT)romlayout32flat.lds
163 # These are actually built by tools/layoutrom.py above, but by pulling them
164 # into an extra rule we prevent make -j from spawning layoutrom.py 4 times.
165 $(OUT)romlayout32seg.lds $(OUT)romlayout32flat.lds $(OUT)code32flat.o $(OUT)code16.o: $(OUT)romlayout16.lds
167 $(OUT)rom16.o: $(OUT)code16.o $(OUT)romlayout16.lds
168 @echo " Linking $@"
169 $(Q)$(LD) -T $(OUT)romlayout16.lds $< -o $@
171 $(OUT)rom32seg.o: $(OUT)code32seg.o $(OUT)romlayout32seg.lds
172 @echo " Linking $@"
173 $(Q)$(LD) -T $(OUT)romlayout32seg.lds $< -o $@
175 $(OUT)rom.o: $(OUT)rom16.strip.o $(OUT)rom32seg.strip.o $(OUT)code32flat.o $(OUT)romlayout32flat.lds
176 @echo " Linking $@"
177 $(Q)$(LD) -T $(OUT)romlayout32flat.lds $(OUT)rom16.strip.o $(OUT)rom32seg.strip.o $(OUT)code32flat.o -o $@
179 $(OUT)bios.bin.elf $(OUT)bios.bin: $(OUT)rom.o tools/checkrom.py
180 @echo " Prepping $@"
181 $(Q)$(OBJDUMP) -thr $< > $<.objdump
182 $(Q)$(OBJCOPY) -O binary $< $(OUT)bios.bin.raw
183 $(Q)$(PYTHON) ./tools/checkrom.py $<.objdump $(OUT)bios.bin.raw $(OUT)bios.bin
184 $(Q)$(STRIP) -R .comment $< -o $(OUT)bios.bin.elf
187 ################ VGA build rules
189 # VGA src files
190 SRCVGA=src/output.c src/util.c src/pci.c \
191 vgasrc/vgabios.c vgasrc/vgafb.c vgasrc/vgafonts.c vgasrc/vbe.c \
192 vgasrc/stdvga.c vgasrc/stdvgamodes.c vgasrc/stdvgaio.c \
193 vgasrc/clext.c vgasrc/bochsvga.c vgasrc/geodevga.c
195 CFLAGS16VGA = $(CFLAGS16INC) -Isrc
197 $(OUT)vgaccode16.raw.s: $(OUT)autoconf.h ; $(call whole-compile, $(CFLAGS16VGA) -S, $(SRCVGA),$@)
199 $(OUT)vgaccode16.o: $(OUT)vgaccode16.raw.s
200 @echo " Fixup VGA rom assembler"
201 $(Q)$(PYTHON) ./tools/vgafixup.py $< $(OUT)vgaccode16.s
202 $(Q)$(AS) --32 src/code16gcc.s $(OUT)vgaccode16.s -o $@
204 $(OUT)vgaentry.o: vgaentry.S $(OUT)autoconf.h
205 @echo " Compiling (16bit) $@"
206 $(Q)$(CC) $(CFLAGS16VGA) -c -D__ASSEMBLY__ $< -o $@
208 $(OUT)vgarom.o: $(OUT)vgaccode16.o $(OUT)vgaentry.o $(OUT)vgalayout.lds
209 @echo " Linking $@"
210 $(Q)./tools/buildversion.sh $(OUT)vgaversion.c VAR16
211 $(Q)$(CC) $(CFLAGS16VGA) -c $(OUT)vgaversion.c -o $(OUT)vgaversion.o
212 $(Q)$(LD) --gc-sections -T $(OUT)vgalayout.lds $(OUT)vgaccode16.o $(OUT)vgaentry.o $(OUT)vgaversion.o -o $@
214 $(OUT)vgabios.bin.raw: $(OUT)vgarom.o
215 @echo " Extracting binary $@"
216 $(Q)$(OBJCOPY) -O binary $< $@
218 $(OUT)vgabios.bin: $(OUT)vgabios.bin.raw tools/buildrom.py
219 @echo " Finalizing rom $@"
220 $(Q)$(PYTHON) ./tools/buildrom.py $< $@
223 ################ DSDT build rules
225 iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
226 ; then echo "$(2)"; else echo "$(3)"; fi ;)
228 $(OUT)%.hex: src/%.dsl ./tools/acpi_extract_preprocess.py ./tools/acpi_extract.py
229 @echo " Compiling IASL $@"
230 $(Q)cpp -P $< > $(OUT)$*.dsl.i.orig
231 $(Q)$(PYTHON) ./tools/acpi_extract_preprocess.py $(OUT)$*.dsl.i.orig > $(OUT)$*.dsl.i
232 $(Q)$(IASL) $(call iasl-option,$(IASL),-Pn,) -vs -l -tc -p $(OUT)$* $(OUT)$*.dsl.i
233 $(Q)$(PYTHON) ./tools/acpi_extract.py $(OUT)$*.lst > $(OUT)$*.off
234 $(Q)cat $(OUT)$*.off > $@
236 $(OUT)ccode32flat.o: $(OUT)acpi-dsdt.hex $(OUT)ssdt-proc.hex $(OUT)ssdt-pcihp.hex $(OUT)ssdt-susp.hex $(OUT)q35-acpi-dsdt.hex
238 ################ Kconfig rules
240 define do-kconfig
241 $(Q)mkdir -p $(OUT)/tools/kconfig/lxdialog
242 $(Q)mkdir -p $(OUT)/include/config
243 $(Q)$(MAKE) -C $(OUT) -f $(CURDIR)/tools/kconfig/Makefile srctree=$(CURDIR) src=tools/kconfig obj=tools/kconfig Q=$(Q) Kconfig=$(CURDIR)/src/Kconfig $1
244 endef
246 $(OUT)autoconf.h : $(KCONFIG_CONFIG) ; $(call do-kconfig, silentoldconfig)
247 $(KCONFIG_CONFIG): ; $(call do-kconfig, defconfig)
248 %onfig: ; $(call do-kconfig, $@)
249 help: ; $(call do-kconfig, $@)
252 ################ Generic rules
254 clean:
255 $(Q)rm -rf $(OUT)
257 distclean: clean
258 $(Q)rm -f .config .config.old
260 $(OUT):
261 $(Q)mkdir $@
263 -include $(OUT)*.d