Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / seabios / Makefile
1 # SeaBIOS build system
2 #
3 # Copyright (C) 2008-2012  Kevin O'Connor <kevin@koconnor.net>
4 #
5 # This file may be distributed under the terms of the GNU LGPLv3 license.
6
7 # Output directory
8 OUT=out/
9
10 # Common command definitions
11 export HOSTCC             := $(CC)
12 export CONFIG_SHELL       := sh
13 export KCONFIG_AUTOHEADER := autoconf.h
14 export KCONFIG_CONFIG     := $(CURDIR)/.config
15 export LC_ALL             := C
16 CROSS_PREFIX=
17 ifneq ($(CROSS_PREFIX),)
18 CC=$(CROSS_PREFIX)gcc
19 endif
20 AS=$(CROSS_PREFIX)as
21 LD=$(CROSS_PREFIX)ld
22 OBJCOPY=$(CROSS_PREFIX)objcopy
23 OBJDUMP=$(CROSS_PREFIX)objdump
24 STRIP=$(CROSS_PREFIX)strip
25 PYTHON=python
26 CPP=cpp
27 IASL:=iasl
28 LD32BIT_FLAG:=-melf_i386
29
30 # Source files
31 SRCBOTH=misc.c stacks.c output.c string.c block.c cdrom.c disk.c mouse.c kbd.c \
32     system.c serial.c clock.c resume.c pnpbios.c vgahooks.c pcibios.c apm.c \
33     hw/pci.c hw/timer.c hw/rtc.c hw/dma.c hw/pic.c hw/ps2port.c hw/serialio.c \
34     hw/usb.c hw/usb-uhci.c hw/usb-ohci.c hw/usb-ehci.c \
35     hw/usb-hid.c hw/usb-msc.c hw/usb-uas.c \
36     hw/blockcmd.c hw/floppy.c hw/ata.c hw/ramdisk.c \
37     hw/virtio-ring.c hw/virtio-pci.c hw/virtio-blk.c hw/virtio-scsi.c \
38     hw/lsi-scsi.c hw/esp-scsi.c hw/megasas.c
39 SRC16=$(SRCBOTH)
40 SRC32FLAT=$(SRCBOTH) post.c memmap.c malloc.c romfile.c x86.c optionroms.c \
41     pmm.c font.c boot.c bootsplash.c jpeg.c bmp.c \
42     hw/ahci.c hw/pvscsi.c hw/usb-xhci.c hw/usb-hub.c hw/sdcard.c \
43     fw/coreboot.c fw/lzmadecode.c fw/csm.c fw/biostables.c \
44     fw/paravirt.c fw/shadow.c fw/pciinit.c fw/smm.c fw/smp.c fw/mtrr.c fw/xen.c \
45     fw/acpi.c fw/mptable.c fw/pirtable.c fw/smbios.c fw/romfile_loader.c
46 SRC32SEG=string.c output.c pcibios.c apm.c stacks.c hw/pci.c hw/serialio.c
47 DIRS=src src/hw src/fw vgasrc
48
49 # Default compiler flags
50 cc-option=$(shell if test -z "`$(1) $(2) -S -o /dev/null -xc /dev/null 2>&1`" \
51     ; then echo "$(2)"; else echo "$(3)"; fi ;)
52
53 CPPFLAGS = -P -MD -MT $@
54
55 COMMONCFLAGS := -I$(OUT) -Isrc -Os -MD -g \
56     -Wall -Wno-strict-aliasing -Wold-style-definition \
57     $(call cc-option,$(CC),-Wtype-limits,) \
58     -m32 -march=i386 -mregparm=3 -mpreferred-stack-boundary=2 \
59     -minline-all-stringops -fomit-frame-pointer \
60     -freg-struct-return -ffreestanding -fno-delete-null-pointer-checks \
61     -ffunction-sections -fdata-sections -fno-common -fno-merge-constants
62 COMMONCFLAGS += $(call cc-option,$(CC),-nopie,)
63 COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
64 COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,)
65 COMMA := ,
66
67 CFLAGS32FLAT := $(COMMONCFLAGS) -DMODE16=0 -DMODESEGMENT=0
68 CFLAGSSEG := $(COMMONCFLAGS) -DMODESEGMENT=1 -fno-defer-pop \
69     $(call cc-option,$(CC),-fno-jump-tables,-DMANUAL_NO_JUMP_TABLE) \
70     $(call cc-option,$(CC),-fno-tree-switch-conversion,)
71 CFLAGS32SEG := $(CFLAGSSEG) -DMODE16=0
72 CFLAGS16 := $(CFLAGSSEG) -DMODE16=1 \
73     $(call cc-option,$(CC),-m16,-Wa$(COMMA)src/code16gcc.s) \
74     $(call cc-option,$(CC),--param large-stack-frame=4,-fno-inline)
75
76 # Run with "make V=1" to see the actual compile commands
77 ifdef V
78 Q=
79 else
80 Q=@
81 MAKEFLAGS += --no-print-directory
82 endif
83
84 # Default targets
85 -include $(KCONFIG_CONFIG)
86
87 target-y :=
88 target-$(CONFIG_QEMU) += $(OUT)bios.bin
89 target-$(CONFIG_CSM) += $(OUT)Csm16.bin
90 target-$(CONFIG_COREBOOT) += $(OUT)bios.bin.elf
91 target-$(CONFIG_BUILD_VGABIOS) += $(OUT)vgabios.bin
92
93 all: $(target-y)
94
95 # Make definitions
96 .PHONY : all clean distclean FORCE
97 .DELETE_ON_ERROR:
98
99
100 ################ Common build rules
101
102 # Verify the build environment works.
103 TESTGCC:=$(shell OUT="$(OUT)" CC="$(CC)" LD="$(LD)" IASL="$(IASL)" scripts/test-build.sh)
104 ifeq "$(TESTGCC)" "-1"
105 $(error "Please upgrade the build environment")
106 endif
107
108 ifeq "$(TESTGCC)" "0"
109 # Use -fwhole-program
110 CFLAGSWHOLE=-fwhole-program -DWHOLE_PROGRAM
111 endif
112
113 # Do a whole file compile by textually including all C code.
114 define whole-compile
115 @echo "  Compiling whole program $3"
116 $(Q)printf '$(foreach i,$2,#include "$i"\n)' > $3.tmp.c
117 $(Q)$(CC) -I. $1 $(CFLAGSWHOLE) -c $3.tmp.c -o $3
118 endef
119
120 %.strip.o: %.o
121         @echo "  Stripping $@"
122         $(Q)$(STRIP) $< -o $@
123
124 $(OUT)%.s: %.c
125         @echo "  Compiling to assembler $@"
126         $(Q)$(CC) $(CFLAGS16) -S -c $< -o $@
127
128 $(OUT)%.o: %.c $(OUT)autoconf.h
129         @echo "  Compile checking $@"
130         $(Q)$(CC) $(CFLAGS32FLAT) -c $< -o $@
131
132 $(OUT)%.lds: %.lds.S
133         @echo "  Precompiling $@"
134         $(Q)$(CPP) $(CPPFLAGS) -D__ASSEMBLY__ $< -o $@
135
136
137 ################ Main BIOS build rules
138
139 $(OUT)asm-offsets.s: $(OUT)autoconf.h
140
141 $(OUT)asm-offsets.h: $(OUT)src/asm-offsets.s
142         @echo "  Generating offset file $@"
143         $(Q)./scripts/gen-offsets.sh $< $@
144
145 $(OUT)ccode16.o: $(OUT)autoconf.h $(patsubst %.c, $(OUT)src/%.o,$(SRC16)) ; $(call whole-compile, $(CFLAGS16), $(addprefix src/, $(SRC16)),$@)
146
147 $(OUT)code32seg.o: $(OUT)autoconf.h $(patsubst %.c, $(OUT)src/%.o,$(SRC32SEG)) ; $(call whole-compile, $(CFLAGS32SEG), $(addprefix src/, $(SRC32SEG)),$@)
148
149 $(OUT)ccode32flat.o: $(OUT)autoconf.h $(patsubst %.c, $(OUT)src/%.o,$(SRC32FLAT)) ; $(call whole-compile, $(CFLAGS32FLAT), $(addprefix src/, $(SRC32FLAT)),$@)
150
151 $(OUT)romlayout.o: src/romlayout.S $(OUT)autoconf.h $(OUT)asm-offsets.h
152         @echo "  Compiling (16bit) $@"
153         $(Q)$(CC) $(CFLAGS16) -c -D__ASSEMBLY__ $< -o $@
154
155 $(OUT)romlayout16.lds: $(OUT)ccode32flat.o $(OUT)code32seg.o $(OUT)ccode16.o $(OUT)romlayout.o scripts/layoutrom.py scripts/buildversion.sh
156         @echo "  Building ld scripts"
157         $(Q)BUILD_VERSION="$(VERSION)" ./scripts/buildversion.sh $(OUT)version.c
158         $(Q)$(CC) $(CFLAGS32FLAT) -c $(OUT)version.c -o $(OUT)version.o
159         $(Q)$(LD) $(LD32BIT_FLAG) -r $(OUT)ccode32flat.o $(OUT)version.o -o $(OUT)code32flat.o
160         $(Q)$(LD) $(LD32BIT_FLAG) -r $(OUT)ccode16.o $(OUT)romlayout.o -o $(OUT)code16.o
161         $(Q)$(OBJDUMP) -thr $(OUT)code32flat.o > $(OUT)code32flat.o.objdump
162         $(Q)$(OBJDUMP) -thr $(OUT)code32seg.o > $(OUT)code32seg.o.objdump
163         $(Q)$(OBJDUMP) -thr $(OUT)code16.o > $(OUT)code16.o.objdump
164         $(Q)$(PYTHON) ./scripts/layoutrom.py $(OUT)code16.o.objdump $(OUT)code32seg.o.objdump $(OUT)code32flat.o.objdump $(OUT)$(KCONFIG_AUTOHEADER) $(OUT)romlayout16.lds $(OUT)romlayout32seg.lds $(OUT)romlayout32flat.lds
165
166 # These are actually built by scripts/layoutrom.py above, but by pulling them
167 # into an extra rule we prevent make -j from spawning layoutrom.py 4 times.
168 $(OUT)romlayout32seg.lds $(OUT)romlayout32flat.lds $(OUT)code32flat.o $(OUT)code16.o: $(OUT)romlayout16.lds
169
170 $(OUT)rom16.o: $(OUT)code16.o $(OUT)romlayout16.lds
171         @echo "  Linking $@"
172         $(Q)$(LD) -T $(OUT)romlayout16.lds $< -o $@
173
174 $(OUT)rom32seg.o: $(OUT)code32seg.o $(OUT)romlayout32seg.lds
175         @echo "  Linking $@"
176         $(Q)$(LD) -T $(OUT)romlayout32seg.lds $< -o $@
177
178 $(OUT)rom.o: $(OUT)rom16.strip.o $(OUT)rom32seg.strip.o $(OUT)code32flat.o $(OUT)romlayout32flat.lds
179         @echo "  Linking $@"
180         $(Q)$(LD) -T $(OUT)romlayout32flat.lds $(OUT)rom16.strip.o $(OUT)rom32seg.strip.o $(OUT)code32flat.o -o $@
181
182 $(OUT)bios.bin.prep: $(OUT)rom.o scripts/checkrom.py
183         @echo "  Prepping $@"
184         $(Q)rm -f $(OUT)bios.bin $(OUT)Csm16.bin $(OUT)bios.bin.elf
185         $(Q)$(OBJDUMP) -thr $< > $<.objdump
186         $(Q)$(OBJCOPY) -O binary $< $(OUT)bios.bin.raw
187         $(Q)$(PYTHON) ./scripts/checkrom.py $<.objdump $(CONFIG_ROM_SIZE) $(OUT)bios.bin.raw $(OUT)bios.bin.prep
188
189 $(OUT)bios.bin: $(OUT)bios.bin.prep
190         @echo "  Creating $@"
191         $(Q)cp $< $@
192
193 $(OUT)Csm16.bin: $(OUT)bios.bin.prep
194         @echo "  Creating $@"
195         $(Q)cp $< $@
196
197 $(OUT)bios.bin.elf: $(OUT)rom.o $(OUT)bios.bin.prep
198         @echo "  Creating $@"
199         $(Q)$(STRIP) -R .comment $< -o $(OUT)bios.bin.elf
200
201
202 ################ VGA build rules
203
204 # VGA src files
205 SRCVGA=src/output.c src/string.c src/hw/pci.c src/hw/serialio.c \
206     vgasrc/vgainit.c vgasrc/vgabios.c vgasrc/vgafb.c \
207     vgasrc/vgafonts.c vgasrc/vbe.c \
208     vgasrc/stdvga.c vgasrc/stdvgamodes.c vgasrc/stdvgaio.c \
209     vgasrc/clext.c vgasrc/bochsvga.c vgasrc/geodevga.c \
210     src/fw/coreboot.c vgasrc/cbvga.c
211
212 ifeq "$(CONFIG_VGA_FIXUP_ASM)" "y"
213 $(OUT)vgaccode16.raw.s: $(OUT)autoconf.h $(patsubst %.c, $(OUT)%.o,$(SRCVGA)) ; $(call whole-compile, $(filter-out -fomit-frame-pointer,$(CFLAGS16)) -fno-omit-frame-pointer -S -Isrc, $(SRCVGA),$@)
214
215 $(OUT)vgaccode16.o: $(OUT)vgaccode16.raw.s scripts/vgafixup.py
216         @echo "  Fixup VGA rom assembler"
217         $(Q)$(PYTHON) ./scripts/vgafixup.py $< $(OUT)vgaccode16.s
218         $(Q)$(AS) --32 src/code16gcc.s $(OUT)vgaccode16.s -o $@
219 else
220 $(OUT)vgaccode16.o: $(OUT)autoconf.h $(patsubst %.c, $(OUT)%.o,$(SRCVGA)) ; $(call whole-compile, $(CFLAGS16) -Isrc, $(SRCVGA),$@)
221 endif
222
223 $(OUT)vgaentry.o: vgasrc/vgaentry.S $(OUT)autoconf.h $(OUT)asm-offsets.h
224         @echo "  Compiling (16bit) $@"
225         $(Q)$(CC) $(CFLAGS16) -c -D__ASSEMBLY__ $< -o $@
226
227 $(OUT)vgarom.o: $(OUT)vgaccode16.o $(OUT)vgaentry.o $(OUT)vgasrc/vgalayout.lds scripts/buildversion.sh
228         @echo "  Linking $@"
229         $(Q)BUILD_VERSION="$(VERSION)" ./scripts/buildversion.sh $(OUT)vgaversion.c VAR16
230         $(Q)$(CC) $(CFLAGS16) -c $(OUT)vgaversion.c -o $(OUT)vgaversion.o
231         $(Q)$(LD) --gc-sections -T $(OUT)vgasrc/vgalayout.lds $(OUT)vgaccode16.o $(OUT)vgaentry.o $(OUT)vgaversion.o -o $@
232
233 $(OUT)vgabios.bin.raw: $(OUT)vgarom.o
234         @echo "  Extracting binary $@"
235         $(Q)$(OBJCOPY) -O binary $< $@
236
237 $(OUT)vgabios.bin: $(OUT)vgabios.bin.raw scripts/buildrom.py
238         @echo "  Finalizing rom $@"
239         $(Q)$(PYTHON) ./scripts/buildrom.py $< $@
240
241
242 ################ DSDT build rules
243
244 iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
245     ; then echo "$(2)"; else echo "$(3)"; fi ;)
246
247 $(OUT)%.hex: %.dsl ./scripts/acpi_extract_preprocess.py ./scripts/acpi_extract.py
248         @echo "  Compiling IASL $@"
249         $(Q)$(CPP) $(CPPFLAGS) $< -o $(OUT)$*.dsl.i.orig
250         $(Q)$(PYTHON) ./scripts/acpi_extract_preprocess.py $(OUT)$*.dsl.i.orig > $(OUT)$*.dsl.i
251         $(Q)$(IASL) $(call iasl-option,$(IASL),-Pn,) -vs -l -tc -p $(OUT)$* $(OUT)$*.dsl.i
252         $(Q)$(PYTHON) ./scripts/acpi_extract.py $(OUT)$*.lst > $(OUT)$*.off
253         $(Q)cat $(OUT)$*.off > $@
254
255 $(OUT)src/fw/acpi.o: $(OUT)src/fw/acpi-dsdt.hex $(OUT)src/fw/ssdt-proc.hex $(OUT)src/fw/ssdt-pcihp.hex $(OUT)src/fw/ssdt-misc.hex $(OUT)src/fw/q35-acpi-dsdt.hex
256
257 ################ Kconfig rules
258
259 define do-kconfig
260 $(Q)mkdir -p $(OUT)/scripts/kconfig/lxdialog
261 $(Q)mkdir -p $(OUT)/include/config
262 $(Q)mkdir -p $(addprefix $(OUT), $(DIRS))
263 $(Q)$(MAKE) -C $(OUT) -f $(CURDIR)/scripts/kconfig/Makefile srctree=$(CURDIR) src=scripts/kconfig obj=scripts/kconfig Q=$(Q) Kconfig=$(CURDIR)/src/Kconfig $1
264 endef
265
266 $(OUT)autoconf.h : $(KCONFIG_CONFIG) ; $(call do-kconfig, silentoldconfig)
267 $(KCONFIG_CONFIG): src/Kconfig vgasrc/Kconfig ; $(call do-kconfig, olddefconfig)
268 %onfig: ; $(call do-kconfig, $@)
269 help: ; $(call do-kconfig, $@)
270
271
272 ################ Generic rules
273
274 clean:
275         $(Q)rm -rf $(OUT)
276
277 distclean: clean
278         $(Q)rm -f .config .config.old
279
280 -include $(patsubst %,$(OUT)%/*.d,$(DIRS))