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