2009-05-24 00:21:18 +02:00
|
|
|
# SeaBIOS build system
|
2008-02-26 04:25:15 +01:00
|
|
|
#
|
2010-09-16 03:48:16 +02:00
|
|
|
# Copyright (C) 2008-2010 Kevin O'Connor <kevin@koconnor.net>
|
2008-02-26 04:25:15 +01:00
|
|
|
#
|
2009-01-16 02:52:58 +01:00
|
|
|
# This file may be distributed under the terms of the GNU LGPLv3 license.
|
2008-02-26 04:25:15 +01:00
|
|
|
|
2009-07-30 02:41:39 +02:00
|
|
|
# Program version
|
2011-10-05 03:43:37 +02:00
|
|
|
VERSION=pre-1.6.4-$(shell date +"%Y%m%d_%H%M%S")-$(shell hostname)
|
2009-07-30 02:41:39 +02:00
|
|
|
|
2008-02-26 04:25:15 +01:00
|
|
|
# Output directory
|
|
|
|
OUT=out/
|
|
|
|
|
|
|
|
# Source files
|
2011-10-01 16:43:48 +02:00
|
|
|
SRCBOTH=misc.c stacks.c pmm.c output.c util.c block.c floppy.c ata.c mouse.c \
|
2011-12-18 16:48:44 +01:00
|
|
|
kbd.c pci.c serial.c clock.c pic.c cdrom.c ps2port.c smp.c resume.c \
|
|
|
|
pnpbios.c pirtable.c vgahooks.c ramdisk.c pcibios.c blockcmd.c \
|
|
|
|
usb.c usb-uhci.c usb-ohci.c usb-ehci.c usb-hid.c usb-msc.c \
|
|
|
|
virtio-ring.c virtio-pci.c virtio-blk.c apm.c ahci.c
|
2010-09-16 03:48:16 +02:00
|
|
|
SRC16=$(SRCBOTH) system.c disk.c font.c
|
2009-12-27 05:32:57 +01:00
|
|
|
SRC32FLAT=$(SRCBOTH) post.c shadow.c memmap.c coreboot.c boot.c \
|
2011-12-18 16:48:44 +01:00
|
|
|
acpi.c smm.c mptable.c smbios.c pciinit.c optionroms.c mtrr.c \
|
|
|
|
lzmadecode.c bootsplash.c jpeg.c usb-hub.c paravirt.c \
|
|
|
|
biostables.c xen.c bmp.c
|
2010-05-23 16:24:22 +02:00
|
|
|
SRC32SEG=util.c output.c pci.c pcibios.c apm.c stacks.c
|
2008-02-26 04:25:15 +01:00
|
|
|
|
2011-12-18 16:48:44 +01:00
|
|
|
cc-option=$(shell if test -z "`$(1) $(2) -S -o /dev/null -xc /dev/null 2>&1`" \
|
|
|
|
; then echo "$(2)"; else echo "$(3)"; fi ;)
|
2008-02-27 16:41:41 +01:00
|
|
|
|
2008-02-27 03:33:14 +01:00
|
|
|
# Default compiler flags
|
2011-01-29 17:26:54 +01:00
|
|
|
COMMONCFLAGS = -I$(OUT) -Os -MD \
|
2011-12-18 16:48:44 +01:00
|
|
|
-Wall -Wno-strict-aliasing -Wold-style-definition \
|
|
|
|
$(call cc-option,$(CC),-Wtype-limits,) \
|
|
|
|
-m32 -march=i386 -mregparm=3 -mpreferred-stack-boundary=2 \
|
|
|
|
-mrtd -minline-all-stringops \
|
2011-12-18 16:51:19 +01:00
|
|
|
-freg-struct-return -ffreestanding -fno-delete-null-pointer-checks \
|
2011-12-18 16:48:44 +01:00
|
|
|
-ffunction-sections -fdata-sections -fno-common
|
2008-02-27 16:41:41 +01:00
|
|
|
COMMONCFLAGS += $(call cc-option,$(CC),-nopie,)
|
|
|
|
COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
|
|
|
|
COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,)
|
|
|
|
|
2011-12-18 16:51:19 +01:00
|
|
|
CFLAGS32FLAT = $(COMMONCFLAGS) -DMODE16=0 -DMODESEGMENT=0 -g -fomit-frame-pointer
|
2009-12-30 18:14:53 +01:00
|
|
|
CFLAGSSEG = $(COMMONCFLAGS) -DMODESEGMENT=1 -fno-defer-pop \
|
2011-12-18 16:48:44 +01:00
|
|
|
$(call cc-option,$(CC),-fno-jump-tables,-DMANUAL_NO_JUMP_TABLE) \
|
|
|
|
$(call cc-option,$(CC),-fno-tree-switch-conversion,)
|
2011-12-18 16:51:19 +01:00
|
|
|
CFLAGS32SEG = $(CFLAGSSEG) -DMODE16=0 -g -fomit-frame-pointer
|
2009-12-30 18:14:53 +01:00
|
|
|
CFLAGS16INC = $(CFLAGSSEG) -DMODE16=1 \
|
2011-12-18 16:48:44 +01:00
|
|
|
$(call cc-option,$(CC),--param large-stack-frame=4,-fno-inline)
|
2011-12-18 16:51:19 +01:00
|
|
|
CFLAGS16 = $(CFLAGS16INC) -g -fomit-frame-pointer
|
2008-02-26 04:25:15 +01:00
|
|
|
|
2009-01-18 00:49:20 +01:00
|
|
|
all: $(OUT) $(OUT)bios.bin
|
2008-02-26 04:25:15 +01:00
|
|
|
|
|
|
|
# Run with "make V=1" to see the actual compile commands
|
|
|
|
ifdef V
|
|
|
|
Q=
|
|
|
|
else
|
|
|
|
Q=@
|
2011-01-27 03:14:59 +01:00
|
|
|
MAKEFLAGS += --no-print-directory
|
2008-02-26 04:25:15 +01:00
|
|
|
endif
|
|
|
|
|
2008-11-08 03:42:00 +01:00
|
|
|
OBJCOPY=objcopy
|
2009-01-17 16:41:28 +01:00
|
|
|
OBJDUMP=objdump
|
2008-11-08 03:42:00 +01:00
|
|
|
STRIP=strip
|
|
|
|
|
2011-01-27 03:14:59 +01:00
|
|
|
.PHONY : all clean distclean FORCE
|
2008-02-26 04:25:15 +01:00
|
|
|
|
2009-05-07 05:35:59 +02:00
|
|
|
vpath %.c src vgasrc
|
|
|
|
vpath %.S src vgasrc
|
2008-02-26 04:25:15 +01:00
|
|
|
|
|
|
|
################ Build rules
|
2008-03-03 02:48:35 +01:00
|
|
|
|
2009-06-16 04:27:01 +02:00
|
|
|
# Verify the gcc configuration and test if -fwhole-program works.
|
2011-05-22 03:05:04 +02:00
|
|
|
TESTGCC:=$(shell CC="$(CC)" LD="$(LD)" tools/test-gcc.sh)
|
2009-03-27 01:45:36 +01:00
|
|
|
ifeq "$(TESTGCC)" "-1"
|
2011-05-22 03:05:04 +02:00
|
|
|
$(error "Please upgrade GCC and/or binutils")
|
2009-03-27 01:45:36 +01:00
|
|
|
endif
|
|
|
|
|
2009-06-16 04:27:01 +02:00
|
|
|
ifndef COMPSTRAT
|
|
|
|
COMPSTRAT=$(TESTGCC)
|
2009-01-25 22:11:27 +01:00
|
|
|
endif
|
|
|
|
|
2009-06-16 04:27:01 +02:00
|
|
|
# Do a whole file compile - three methods are supported.
|
|
|
|
ifeq "$(COMPSTRAT)" "1"
|
|
|
|
# First method - use -fwhole-program without -combine.
|
|
|
|
define whole-compile
|
|
|
|
@echo " Compiling whole program $3"
|
|
|
|
$(Q)printf '$(foreach i,$2,#include "../$i"\n)' > $3.tmp.c
|
|
|
|
$(Q)$(CC) $1 -fwhole-program -DWHOLE_PROGRAM -c $3.tmp.c -o $3
|
|
|
|
endef
|
2009-06-18 02:33:41 +02:00
|
|
|
else
|
|
|
|
ifeq "$(COMPSTRAT)" "2"
|
2009-06-16 04:27:01 +02:00
|
|
|
# Second menthod - don't use -fwhole-program at all.
|
2008-03-03 02:48:35 +01:00
|
|
|
define whole-compile
|
|
|
|
@echo " Compiling whole program $3"
|
2008-11-07 00:57:10 +01:00
|
|
|
$(Q)printf '$(foreach i,$2,#include "../$i"\n)' > $3.tmp.c
|
2008-03-03 02:48:35 +01:00
|
|
|
$(Q)$(CC) $1 -c $3.tmp.c -o $3
|
|
|
|
endef
|
|
|
|
else
|
2009-06-16 04:27:01 +02:00
|
|
|
# Third (and preferred) method - use -fwhole-program with -combine
|
2008-03-03 02:48:35 +01:00
|
|
|
define whole-compile
|
|
|
|
@echo " Compiling whole program $3"
|
2009-06-16 04:27:01 +02:00
|
|
|
$(Q)$(CC) $1 -fwhole-program -DWHOLE_PROGRAM -combine -c $2 -o $3
|
2008-03-03 02:48:35 +01:00
|
|
|
endef
|
|
|
|
endif
|
2009-06-18 02:33:41 +02:00
|
|
|
endif
|
2008-03-03 02:48:35 +01:00
|
|
|
|
2010-05-01 15:50:13 +02:00
|
|
|
%.strip.o: %.o
|
|
|
|
@echo " Stripping $@"
|
|
|
|
$(Q)$(STRIP) $< -o $@
|
2008-03-03 02:48:35 +01:00
|
|
|
|
2009-01-18 00:49:20 +01:00
|
|
|
$(OUT)%.s: %.c
|
2008-12-07 00:56:19 +01:00
|
|
|
@echo " Compiling to assembler $@"
|
2009-01-18 00:49:20 +01:00
|
|
|
$(Q)$(CC) $(CFLAGS16INC) -S -c $< -o $@
|
2008-02-26 04:25:15 +01:00
|
|
|
|
|
|
|
$(OUT)%.lds: %.lds.S
|
2008-12-07 00:56:19 +01:00
|
|
|
@echo " Precompiling $@"
|
2008-11-16 15:17:02 +01:00
|
|
|
$(Q)$(CPP) -P -D__ASSEMBLY__ $< -o $@
|
2008-02-26 04:25:15 +01:00
|
|
|
|
2011-01-27 03:19:25 +01:00
|
|
|
$(OUT)asm-offsets.s: $(OUT)autoconf.h
|
|
|
|
|
2009-01-18 00:49:20 +01:00
|
|
|
$(OUT)asm-offsets.h: $(OUT)asm-offsets.s
|
2008-11-17 00:14:33 +01:00
|
|
|
@echo " Generating offset file $@"
|
|
|
|
$(Q)./tools/gen-offsets.sh $< $@
|
2008-02-26 04:25:15 +01:00
|
|
|
|
2009-07-14 02:31:35 +02:00
|
|
|
|
2011-01-27 03:19:25 +01:00
|
|
|
$(OUT)ccode.16.s: $(OUT)autoconf.h ; $(call whole-compile, $(CFLAGS16) -S, $(addprefix src/, $(SRC16)),$@)
|
2008-02-26 04:25:15 +01:00
|
|
|
|
2011-01-27 03:19:25 +01:00
|
|
|
$(OUT)code32seg.o: $(OUT)autoconf.h ; $(call whole-compile, $(CFLAGS32SEG), $(addprefix src/, $(SRC32SEG)),$@)
|
2009-12-30 18:14:53 +01:00
|
|
|
|
2011-01-27 03:19:25 +01:00
|
|
|
$(OUT)ccode32flat.o: $(OUT)autoconf.h ; $(call whole-compile, $(CFLAGS32FLAT), $(addprefix src/, $(SRC32FLAT)),$@)
|
2009-09-21 01:47:45 +02:00
|
|
|
|
2009-07-14 02:31:35 +02:00
|
|
|
$(OUT)code16.o: romlayout.S $(OUT)ccode.16.s $(OUT)asm-offsets.h
|
2008-12-07 00:56:19 +01:00
|
|
|
@echo " Compiling (16bit) $@"
|
|
|
|
$(Q)$(CC) $(CFLAGS16INC) -c -D__ASSEMBLY__ $< -o $@
|
2008-02-26 04:25:15 +01:00
|
|
|
|
2011-01-28 03:39:01 +01:00
|
|
|
$(OUT)romlayout16.lds: $(OUT)ccode32flat.o $(OUT)code32seg.o $(OUT)code16.o tools/layoutrom.py
|
2009-09-21 01:47:45 +02:00
|
|
|
@echo " Building ld scripts (version \"$(VERSION)\")"
|
|
|
|
$(Q)echo 'const char VERSION[] = "$(VERSION)";' > $(OUT)version.c
|
2009-12-30 18:14:53 +01:00
|
|
|
$(Q)$(CC) $(CFLAGS32FLAT) -c $(OUT)version.c -o $(OUT)version.o
|
2009-12-27 05:32:57 +01:00
|
|
|
$(Q)$(LD) -melf_i386 -r $(OUT)ccode32flat.o $(OUT)version.o -o $(OUT)code32flat.o
|
|
|
|
$(Q)$(OBJDUMP) -thr $(OUT)code32flat.o > $(OUT)code32flat.o.objdump
|
2009-12-30 18:14:53 +01:00
|
|
|
$(Q)$(OBJDUMP) -thr $(OUT)code32seg.o > $(OUT)code32seg.o.objdump
|
2009-07-14 02:31:35 +02:00
|
|
|
$(Q)$(OBJDUMP) -thr $(OUT)code16.o > $(OUT)code16.o.objdump
|
2009-12-30 18:14:53 +01:00
|
|
|
$(Q)./tools/layoutrom.py $(OUT)code16.o.objdump $(OUT)code32seg.o.objdump $(OUT)code32flat.o.objdump $(OUT)romlayout16.lds $(OUT)romlayout32seg.lds $(OUT)romlayout32flat.lds
|
2009-01-17 16:41:28 +01:00
|
|
|
|
2011-01-28 03:39:01 +01:00
|
|
|
# These are actually built by tools/layoutrom.py above, but by pulling them
|
|
|
|
# into an extra rule we prevent make -j from spawning layoutrom.py 4 times.
|
|
|
|
$(OUT)romlayout32seg.lds $(OUT)romlayout32flat.lds $(OUT)code32flat.o: $(OUT)romlayout16.lds
|
2009-07-14 02:31:35 +02:00
|
|
|
|
2010-05-01 15:50:13 +02:00
|
|
|
$(OUT)rom16.o: $(OUT)code16.o $(OUT)romlayout16.lds
|
|
|
|
@echo " Linking $@"
|
|
|
|
$(Q)$(LD) -T $(OUT)romlayout16.lds $< -o $@
|
2008-02-26 04:25:15 +01:00
|
|
|
|
2009-12-30 18:14:53 +01:00
|
|
|
$(OUT)rom32seg.o: $(OUT)code32seg.o $(OUT)romlayout32seg.lds
|
2010-05-01 15:50:13 +02:00
|
|
|
@echo " Linking $@"
|
|
|
|
$(Q)$(LD) -T $(OUT)romlayout32seg.lds $< -o $@
|
2009-07-14 02:31:35 +02:00
|
|
|
|
2010-05-01 15:50:13 +02:00
|
|
|
$(OUT)rom.o: $(OUT)rom16.strip.o $(OUT)rom32seg.strip.o $(OUT)code32flat.o $(OUT)romlayout32flat.lds
|
2009-09-29 03:32:08 +02:00
|
|
|
@echo " Linking $@"
|
2010-05-01 15:50:13 +02:00
|
|
|
$(Q)$(LD) -T $(OUT)romlayout32flat.lds $(OUT)rom16.strip.o $(OUT)rom32seg.strip.o $(OUT)code32flat.o -o $@
|
2008-07-06 02:41:53 +02:00
|
|
|
|
2009-09-21 01:47:45 +02:00
|
|
|
$(OUT)bios.bin.elf $(OUT)bios.bin: $(OUT)rom.o tools/checkrom.py
|
2008-07-06 03:08:56 +02:00
|
|
|
@echo " Prepping $@"
|
2009-09-21 01:47:45 +02:00
|
|
|
$(Q)$(OBJDUMP) -thr $< > $<.objdump
|
|
|
|
$(Q)$(OBJCOPY) -O binary $< $(OUT)bios.bin.raw
|
|
|
|
$(Q)./tools/checkrom.py $<.objdump $(OUT)bios.bin.raw $(OUT)bios.bin
|
2009-11-04 01:50:52 +01:00
|
|
|
$(Q)$(STRIP) -R .comment $< -o $(OUT)bios.bin.elf
|
2008-02-26 04:25:15 +01:00
|
|
|
|
|
|
|
|
2009-05-07 05:35:59 +02:00
|
|
|
################ VGA build rules
|
|
|
|
|
|
|
|
# VGA src files
|
2012-01-15 01:02:43 +01:00
|
|
|
SRCVGA=src/output.c src/util.c src/pci.c \
|
|
|
|
vgasrc/vgabios.c vgasrc/vgafb.c vgasrc/vgafonts.c vgasrc/vbe.c \
|
|
|
|
vgasrc/vgatables.c vgasrc/stdvga.c vgasrc/stdvgaio.c \
|
|
|
|
vgasrc/clext.c vgasrc/bochsvga.c vgasrc/geodevga.c
|
2009-05-07 05:35:59 +02:00
|
|
|
|
2011-12-18 16:51:19 +01:00
|
|
|
CFLAGS16VGA = $(CFLAGS16INC) -g -Isrc
|
|
|
|
|
|
|
|
$(OUT)vgaccode.16.s: $(OUT)autoconf.h ; $(call whole-compile, $(CFLAGS16VGA) -S, $(SRCVGA),$@)
|
2009-05-07 05:35:59 +02:00
|
|
|
|
|
|
|
$(OUT)vgalayout16.o: vgaentry.S $(OUT)vgaccode.16.s $(OUT)asm-offsets.h
|
|
|
|
@echo " Compiling (16bit) $@"
|
|
|
|
$(Q)$(CC) $(CFLAGS16INC) -c -D__ASSEMBLY__ -Isrc $< -o $@
|
|
|
|
|
|
|
|
$(OUT)vgarom.o: $(OUT)vgalayout16.o $(OUT)vgalayout.lds
|
|
|
|
@echo " Linking $@"
|
2009-06-11 03:56:01 +02:00
|
|
|
$(Q)$(LD) --gc-sections -T $(OUT)vgalayout.lds $(OUT)vgalayout16.o -o $@
|
2009-05-07 05:35:59 +02:00
|
|
|
|
|
|
|
$(OUT)vgabios.bin.raw: $(OUT)vgarom.o
|
|
|
|
@echo " Extracting binary $@"
|
|
|
|
$(Q)$(OBJCOPY) -O binary $< $@
|
|
|
|
|
2009-09-21 01:47:45 +02:00
|
|
|
$(OUT)vgabios.bin: $(OUT)vgabios.bin.raw tools/buildrom.py
|
2009-05-07 05:35:59 +02:00
|
|
|
@echo " Finalizing rom $@"
|
|
|
|
$(Q)./tools/buildrom.py $< $@
|
|
|
|
|
2009-10-09 03:57:15 +02:00
|
|
|
####### dsdt build rules
|
2011-10-04 15:26:01 +02:00
|
|
|
src/%.hex: src/%.dsl ./tools/acpi_extract_preprocess.py ./tools/acpi_extract.py
|
2009-10-09 03:57:15 +02:00
|
|
|
@echo "Compiling DSDT"
|
2011-10-04 15:26:01 +02:00
|
|
|
$(Q)cpp -P $< > $(OUT)$*.dsl.i.orig
|
|
|
|
$(Q)./tools/acpi_extract_preprocess.py $(OUT)$*.dsl.i.orig > $(OUT)$*.dsl.i
|
|
|
|
$(Q)iasl -l -tc -p $(OUT)$* $(OUT)$*.dsl.i
|
|
|
|
$(Q)./tools/acpi_extract.py $(OUT)$*.lst > $(OUT)$*.off
|
2011-10-26 23:28:02 +02:00
|
|
|
$(Q)cat $(OUT)$*.off > $@
|
2010-06-07 10:19:27 +02:00
|
|
|
|
2011-11-20 18:56:59 +01:00
|
|
|
$(OUT)ccode32flat.o: src/acpi-dsdt.hex src/ssdt-proc.hex src/ssdt-pcihp.hex
|
2009-10-09 03:57:15 +02:00
|
|
|
|
2011-01-27 03:14:59 +01:00
|
|
|
####### Kconfig rules
|
|
|
|
export HOSTCC := $(CC)
|
|
|
|
export CONFIG_SHELL := sh
|
|
|
|
export KCONFIG_AUTOHEADER := autoconf.h
|
|
|
|
export KCONFIG_CONFIG := $(CURDIR)/.config
|
|
|
|
|
2011-01-27 03:19:25 +01:00
|
|
|
$(OUT)autoconf.h : $(KCONFIG_CONFIG)
|
|
|
|
$(Q)$(MAKE) silentoldconfig
|
|
|
|
|
|
|
|
$(KCONFIG_CONFIG):
|
|
|
|
$(Q)$(MAKE) defconfig
|
|
|
|
|
2011-01-27 03:14:59 +01:00
|
|
|
%onfig:
|
|
|
|
$(Q)mkdir -p $(OUT)/tools/kconfig/lxdialog
|
|
|
|
$(Q)mkdir -p $(OUT)/include/config
|
|
|
|
$(Q)$(MAKE) -C $(OUT) -f $(CURDIR)/tools/kconfig/Makefile srctree=$(CURDIR) src=tools/kconfig obj=tools/kconfig Q=$(Q) Kconfig=$(CURDIR)/src/Kconfig $@
|
|
|
|
|
2011-11-24 17:20:36 +01:00
|
|
|
help:
|
|
|
|
$(Q)$(MAKE) -f $(CURDIR)/tools/kconfig/Makefile help
|
|
|
|
|
2008-02-26 04:25:15 +01:00
|
|
|
####### Generic rules
|
|
|
|
clean:
|
2008-11-07 00:57:10 +01:00
|
|
|
$(Q)rm -rf $(OUT)
|
2008-02-26 04:25:15 +01:00
|
|
|
|
2011-01-27 03:14:59 +01:00
|
|
|
distclean: clean
|
|
|
|
$(Q)rm -f .config .config.old
|
|
|
|
|
2008-02-26 04:25:15 +01:00
|
|
|
$(OUT):
|
2008-11-07 00:57:10 +01:00
|
|
|
$(Q)mkdir $@
|
2008-02-26 04:25:15 +01:00
|
|
|
|
|
|
|
-include $(OUT)*.d
|