2009-05-24 00:21:18 +02:00
|
|
|
# SeaBIOS build system
|
2008-02-26 04:25:15 +01:00
|
|
|
#
|
2009-05-24 00:21:18 +02:00
|
|
|
# Copyright (C) 2008,2009 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
|
2009-12-19 16:51:29 +01:00
|
|
|
VERSION=pre-0.5.1-$(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
|
2009-12-13 17:25:25 +01:00
|
|
|
SRCBOTH=misc.c pmm.c stacks.c output.c util.c block.c floppy.c ata.c mouse.c \
|
2009-11-04 01:50:52 +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 \
|
2009-10-12 16:09:15 +02:00
|
|
|
usb.c usb-uhci.c usb-ohci.c usb-hid.c paravirt.c
|
2009-07-20 00:52:46 +02:00
|
|
|
SRC16=$(SRCBOTH) system.c disk.c apm.c pcibios.c font.c
|
2009-02-08 21:44:08 +01:00
|
|
|
SRC32=$(SRCBOTH) post.c shadow.c memmap.c coreboot.c boot.c \
|
2009-04-27 05:17:49 +02:00
|
|
|
acpi.c smm.c mptable.c smbios.c pciinit.c optionroms.c mtrr.c \
|
|
|
|
lzmadecode.c
|
2008-02-26 04:25:15 +01:00
|
|
|
|
2008-02-27 16:41:41 +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 03:33:14 +01:00
|
|
|
# Default compiler flags
|
2008-04-13 22:59:03 +02:00
|
|
|
COMMONCFLAGS = -Wall -Os -MD -m32 -march=i386 -mregparm=3 \
|
2009-03-27 01:45:36 +01:00
|
|
|
-mpreferred-stack-boundary=2 -mrtd -freg-struct-return \
|
2009-06-11 04:44:06 +02:00
|
|
|
-ffreestanding -fomit-frame-pointer \
|
2009-04-20 05:18:54 +02:00
|
|
|
-fno-delete-null-pointer-checks -Wno-strict-aliasing \
|
2009-06-16 04:27:01 +02:00
|
|
|
-ffunction-sections -fdata-sections -fno-common \
|
2009-04-20 05:18:54 +02:00
|
|
|
-minline-all-stringops
|
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,)
|
|
|
|
|
2008-07-31 02:37:13 +02:00
|
|
|
override CFLAGS = $(COMMONCFLAGS) -g -DMODE16=0
|
2009-06-11 04:44:06 +02:00
|
|
|
CFLAGS16INC = $(COMMONCFLAGS) -DMODE16=1 -fno-defer-pop \
|
|
|
|
$(call cc-option,$(CC),-fno-jump-tables,-DMANUAL_NO_JUMP_TABLE) \
|
2009-04-09 03:25:00 +02:00
|
|
|
$(call cc-option,$(CC),-fno-tree-switch-conversion,) \
|
2009-01-01 23:54:16 +01:00
|
|
|
$(call cc-option,$(CC),--param large-stack-frame=4,)
|
2008-03-03 02:48:35 +01:00
|
|
|
CFLAGS16 = $(CFLAGS16INC) -g
|
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=@
|
|
|
|
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
|
|
|
|
|
2008-02-26 04:25:15 +01:00
|
|
|
.PHONY : all FORCE
|
|
|
|
|
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.
|
2009-03-27 01:45:36 +01:00
|
|
|
TESTGCC:=$(shell CC=$(CC) tools/test-gcc.sh)
|
|
|
|
ifeq "$(TESTGCC)" "-1"
|
|
|
|
$(error "Please upgrade GCC")
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2008-12-07 00:56:19 +01:00
|
|
|
$(OUT)ccode.16.s: ; $(call whole-compile, $(CFLAGS16) -S, $(addprefix src/, $(SRC16)),$@)
|
2008-02-26 04:25:15 +01:00
|
|
|
|
2009-09-21 01:47:45 +02:00
|
|
|
$(OUT)ccode32.o: ; $(call whole-compile, $(CFLAGS), $(addprefix src/, $(SRC32)),$@)
|
|
|
|
|
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
|
|
|
|
2009-09-21 01:47:45 +02:00
|
|
|
$(OUT)romlayout16.lds $(OUT)romlayout32.lds $(OUT)code32.o: $(OUT)ccode32.o $(OUT)code16.o tools/layoutrom.py
|
|
|
|
@echo " Building ld scripts (version \"$(VERSION)\")"
|
|
|
|
$(Q)echo 'const char VERSION[] = "$(VERSION)";' > $(OUT)version.c
|
|
|
|
$(Q)$(CC) $(CFLAGS) -c $(OUT)version.c -o $(OUT)version.o
|
|
|
|
$(Q)$(LD) -melf_i386 -r $(OUT)ccode32.o $(OUT)version.o -o $(OUT)code32.o
|
2009-07-14 02:31:35 +02:00
|
|
|
$(Q)$(OBJDUMP) -thr $(OUT)code32.o > $(OUT)code32.o.objdump
|
|
|
|
$(Q)$(OBJDUMP) -thr $(OUT)code16.o > $(OUT)code16.o.objdump
|
|
|
|
$(Q)./tools/layoutrom.py $(OUT)code16.o.objdump $(OUT)code32.o.objdump $(OUT)romlayout16.lds $(OUT)romlayout32.lds
|
2009-01-17 16:41:28 +01:00
|
|
|
|
2009-07-14 02:31:35 +02:00
|
|
|
|
2009-09-21 01:47:45 +02:00
|
|
|
$(OUT)rom16.o: $(OUT)code16.o $(OUT)rom32.o $(OUT)romlayout16.lds
|
2009-05-24 00:21:18 +02:00
|
|
|
@echo " Linking (no relocs) $@"
|
2009-09-21 01:47:45 +02:00
|
|
|
$(Q)$(LD) -r -T $(OUT)romlayout16.lds $< -o $@
|
2008-02-26 04:25:15 +01:00
|
|
|
|
2009-09-21 01:47:45 +02:00
|
|
|
$(OUT)rom32.o: $(OUT)code32.o $(OUT)romlayout32.lds
|
2009-07-14 02:31:35 +02:00
|
|
|
@echo " Linking (no relocs) $@"
|
2009-09-21 01:47:45 +02:00
|
|
|
$(Q)$(LD) -r -T $(OUT)romlayout32.lds $< -o $@
|
2009-07-14 02:31:35 +02:00
|
|
|
|
2009-05-24 00:21:18 +02:00
|
|
|
$(OUT)rom.o: $(OUT)rom16.o $(OUT)rom32.o $(OUT)rombios16.lds $(OUT)rombios.lds
|
2009-09-29 03:32:08 +02:00
|
|
|
@echo " Linking $@"
|
2009-05-28 04:23:33 +02:00
|
|
|
$(Q)$(LD) -T $(OUT)rombios16.lds $(OUT)rom16.o -R $(OUT)rom32.o -o $(OUT)rom16.reloc.o
|
|
|
|
$(Q)$(STRIP) $(OUT)rom16.reloc.o -o $(OUT)rom16.final.o
|
2009-06-23 02:05:56 +02:00
|
|
|
$(Q)$(OBJCOPY) --adjust-vma 0xf0000 $(OUT)rom16.o $(OUT)rom16.moved.o
|
2009-09-21 01:47:45 +02:00
|
|
|
$(Q)$(LD) -T $(OUT)rombios.lds $(OUT)rom16.final.o $(OUT)rom32.o -R $(OUT)rom16.moved.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
|
2009-05-18 03:14:46 +02:00
|
|
|
SRCVGA=src/output.c src/util.c vgasrc/vga.c vgasrc/vgafb.c vgasrc/vgaio.c \
|
|
|
|
vgasrc/vgatables.c vgasrc/vgafonts.c vgasrc/clext.c
|
2009-05-07 05:35:59 +02:00
|
|
|
|
|
|
|
$(OUT)vgaccode.16.s: ; $(call whole-compile, $(CFLAGS16) -S -Isrc, $(SRCVGA),$@)
|
|
|
|
|
|
|
|
$(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
|
|
|
|
src/acpi-dsdt.hex: src/acpi-dsdt.dsl
|
|
|
|
@echo "Compiling DSDT"
|
|
|
|
$(Q)cpp -P $< > $(OUT)acpi-dsdt.dsl.i
|
|
|
|
$(Q)iasl -tc -p $@ $(OUT)acpi-dsdt.dsl.i
|
|
|
|
$(Q)rm $(OUT)acpi-dsdt.dsl.i
|
|
|
|
|
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
|
|
|
|
|
|
|
$(OUT):
|
2008-11-07 00:57:10 +01:00
|
|
|
$(Q)mkdir $@
|
2008-02-26 04:25:15 +01:00
|
|
|
|
|
|
|
-include $(OUT)*.d
|