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.
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
53
MAKEFLAGS += --no-print-directory
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
69
-include $(KCONFIG_CONFIG)
71
target-y = $(OUT) $(OUT)bios.bin
72
target-$(CONFIG_BUILD_VGABIOS) += $(OUT)vgabios.bin
77
.PHONY : all clean distclean FORCE
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")
94
CFLAGSWHOLE=-fwhole-program -DWHOLE_PROGRAM
97
# Do a whole file compile by textually including all C code.
99
@echo " Compiling whole program $3"
100
$(Q)printf '$(foreach i,$2,#include "../$i"\n)' > $3.tmp.c
101
$(Q)$(CC) $1 $(CFLAGSWHOLE) -c $3.tmp.c -o $3
105
@echo " Stripping $@"
106
$(Q)$(STRIP) $< -o $@
109
@echo " Compiling to assembler $@"
110
$(Q)$(CC) $(CFLAGS16) -S -c $< -o $@
112
$(OUT)%.o: %.c $(OUT)autoconf.h
113
@echo " Compile checking $@"
114
$(Q)$(CC) $(CFLAGS32FLAT) -c $< -o $@
117
@echo " Precompiling $@"
118
$(Q)$(CPP) -P -D__ASSEMBLY__ $< -o $@
121
################ Main BIOS build rules
123
$(OUT)asm-offsets.s: $(OUT)autoconf.h
125
$(OUT)asm-offsets.h: $(OUT)asm-offsets.s
126
@echo " Generating offset file $@"
127
$(Q)./tools/gen-offsets.sh $< $@
129
$(OUT)ccode16.o: $(OUT)autoconf.h $(patsubst %.c, out/%.o,$(SRC16)) ; $(call whole-compile, $(CFLAGS16), $(addprefix src/, $(SRC16)),$@)
131
$(OUT)code32seg.o: $(OUT)autoconf.h $(patsubst %.c, out/%.o,$(SRC32SEG)) ; $(call whole-compile, $(CFLAGS32SEG), $(addprefix src/, $(SRC32SEG)),$@)
133
$(OUT)ccode32flat.o: $(OUT)autoconf.h $(patsubst %.c, out/%.o,$(SRC32FLAT)) ; $(call whole-compile, $(CFLAGS32FLAT), $(addprefix src/, $(SRC32FLAT)),$@)
135
$(OUT)romlayout.o: romlayout.S $(OUT)asm-offsets.h
136
@echo " Compiling (16bit) $@"
137
$(Q)$(CC) $(CFLAGS16) -c -D__ASSEMBLY__ $< -o $@
139
$(OUT)romlayout16.lds: $(OUT)ccode32flat.o $(OUT)code32seg.o $(OUT)ccode16.o $(OUT)romlayout.o tools/layoutrom.py
140
@echo " Building ld scripts"
141
$(Q)./tools/buildversion.sh $(OUT)version.c
142
$(Q)$(CC) $(CFLAGS32FLAT) -c $(OUT)version.c -o $(OUT)version.o
143
$(Q)$(LD) -melf_i386 -r $(OUT)ccode32flat.o $(OUT)version.o -o $(OUT)code32flat.o
144
$(Q)$(LD) -melf_i386 -r $(OUT)ccode16.o $(OUT)romlayout.o -o $(OUT)code16.o
145
$(Q)$(OBJDUMP) -thr $(OUT)code32flat.o > $(OUT)code32flat.o.objdump
146
$(Q)$(OBJDUMP) -thr $(OUT)code32seg.o > $(OUT)code32seg.o.objdump
147
$(Q)$(OBJDUMP) -thr $(OUT)code16.o > $(OUT)code16.o.objdump
148
$(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
150
# These are actually built by tools/layoutrom.py above, but by pulling them
151
# into an extra rule we prevent make -j from spawning layoutrom.py 4 times.
152
$(OUT)romlayout32seg.lds $(OUT)romlayout32flat.lds $(OUT)code32flat.o $(OUT)code16.o: $(OUT)romlayout16.lds
154
$(OUT)rom16.o: $(OUT)code16.o $(OUT)romlayout16.lds
156
$(Q)$(LD) -T $(OUT)romlayout16.lds $< -o $@
158
$(OUT)rom32seg.o: $(OUT)code32seg.o $(OUT)romlayout32seg.lds
160
$(Q)$(LD) -T $(OUT)romlayout32seg.lds $< -o $@
162
$(OUT)rom.o: $(OUT)rom16.strip.o $(OUT)rom32seg.strip.o $(OUT)code32flat.o $(OUT)romlayout32flat.lds
164
$(Q)$(LD) -T $(OUT)romlayout32flat.lds $(OUT)rom16.strip.o $(OUT)rom32seg.strip.o $(OUT)code32flat.o -o $@
166
$(OUT)bios.bin.elf $(OUT)bios.bin: $(OUT)rom.o tools/checkrom.py
168
$(Q)$(OBJDUMP) -thr $< > $<.objdump
169
$(Q)$(OBJCOPY) -O binary $< $(OUT)bios.bin.raw
170
$(Q)$(PYTHON) ./tools/checkrom.py $<.objdump $(OUT)bios.bin.raw $(OUT)bios.bin
171
$(Q)$(STRIP) -R .comment $< -o $(OUT)bios.bin.elf
174
################ VGA build rules
177
SRCVGA=src/output.c src/util.c src/pci.c \
178
vgasrc/vgabios.c vgasrc/vgafb.c vgasrc/vgafonts.c vgasrc/vbe.c \
179
vgasrc/stdvga.c vgasrc/stdvgamodes.c vgasrc/stdvgaio.c \
180
vgasrc/clext.c vgasrc/bochsvga.c vgasrc/geodevga.c
182
CFLAGS16VGA = $(CFLAGS16INC) -Isrc
184
$(OUT)vgaccode16.raw.s: $(OUT)autoconf.h ; $(call whole-compile, $(CFLAGS16VGA) -S, $(SRCVGA),$@)
186
$(OUT)vgaccode16.o: $(OUT)vgaccode16.raw.s
187
@echo " Fixup VGA rom assembler"
188
$(Q)$(PYTHON) ./tools/vgafixup.py $< $(OUT)vgaccode16.s
189
$(Q)$(AS) --32 src/code16gcc.s $(OUT)vgaccode16.s -o $@
191
$(OUT)vgaentry.o: vgaentry.S $(OUT)autoconf.h
192
@echo " Compiling (16bit) $@"
193
$(Q)$(CC) $(CFLAGS16VGA) -c -D__ASSEMBLY__ $< -o $@
195
$(OUT)vgarom.o: $(OUT)vgaccode16.o $(OUT)vgaentry.o $(OUT)vgalayout.lds
197
$(Q)./tools/buildversion.sh $(OUT)vgaversion.c VAR16
198
$(Q)$(CC) $(CFLAGS16VGA) -c $(OUT)vgaversion.c -o $(OUT)vgaversion.o
199
$(Q)$(LD) --gc-sections -T $(OUT)vgalayout.lds $(OUT)vgaccode16.o $(OUT)vgaentry.o $(OUT)vgaversion.o -o $@
201
$(OUT)vgabios.bin.raw: $(OUT)vgarom.o
202
@echo " Extracting binary $@"
203
$(Q)$(OBJCOPY) -O binary $< $@
205
$(OUT)vgabios.bin: $(OUT)vgabios.bin.raw tools/buildrom.py
206
@echo " Finalizing rom $@"
207
$(Q)$(PYTHON) ./tools/buildrom.py $< $@
210
################ DSDT build rules
212
iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
213
; then echo "$(2)"; else echo "$(3)"; fi ;)
215
$(OUT)%.hex: src/%.dsl ./tools/acpi_extract_preprocess.py ./tools/acpi_extract.py
216
@echo " Compiling IASL $@"
217
$(Q)cpp -P $< > $(OUT)$*.dsl.i.orig
218
$(Q)$(PYTHON) ./tools/acpi_extract_preprocess.py $(OUT)$*.dsl.i.orig > $(OUT)$*.dsl.i
219
$(Q)$(IASL) $(call iasl-option,$(IASL),-Pn,) -vs -l -tc -p $(OUT)$* $(OUT)$*.dsl.i
220
$(Q)$(PYTHON) ./tools/acpi_extract.py $(OUT)$*.lst > $(OUT)$*.off
221
$(Q)cat $(OUT)$*.off > $@
223
$(OUT)acpi.o: $(OUT)acpi-dsdt.hex $(OUT)ssdt-proc.hex $(OUT)ssdt-pcihp.hex $(OUT)ssdt-susp.hex $(OUT)q35-acpi-dsdt.hex
225
################ Kconfig rules
228
$(Q)mkdir -p $(OUT)/tools/kconfig/lxdialog
229
$(Q)mkdir -p $(OUT)/include/config
230
$(Q)$(MAKE) -C $(OUT) -f $(CURDIR)/tools/kconfig/Makefile srctree=$(CURDIR) src=tools/kconfig obj=tools/kconfig Q=$(Q) Kconfig=$(CURDIR)/src/Kconfig $1
233
$(OUT)autoconf.h : $(KCONFIG_CONFIG) ; $(call do-kconfig, silentoldconfig)
234
$(KCONFIG_CONFIG): ; $(call do-kconfig, defconfig)
235
%onfig: ; $(call do-kconfig, $@)
236
help: ; $(call do-kconfig, $@)
239
################ Generic rules
245
$(Q)rm -f .config .config.old