Add tool for generating assembler offset definition file.
[seabios.git] / Makefile
index 70b0a3efae6c21e842b4fc3da46732ecfbc0c018..2c309453effc8ea45f50d30d5263712c721ff813 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -8,11 +8,12 @@
 OUT=out/
 
 # Source files
-SRCBOTH=output.c util.c floppy.c ata.c system.c mouse.c kbd.c pci.c boot.c \
-        serial.c clock.c pic.c
-SRC16=$(SRCBOTH) disk.c cdrom.c apm.c pcibios.c
-SRC32=$(SRCBOTH) post.c shadow.c post_menu.c memmap.c coreboot.c \
-      acpi.c pirtable.c smm.c smpdetect.c mptable.c smbios.c pciinit.c
+SRCBOTH=output.c util.c floppy.c ata.c system.c mouse.c kbd.c pci.c \
+        serial.c clock.c pic.c cdrom.c ps2port.c
+SRC16=$(SRCBOTH) disk.c apm.c pcibios.c vgahooks.c
+SRC32=$(SRCBOTH) post.c shadow.c post_menu.c memmap.c coreboot.c boot.c \
+      acpi.c pirtable.c smm.c smpdetect.c mptable.c smbios.c pciinit.c \
+      optionroms.c
 TABLESRC=font.c cbt.c floppy_dbt.c
 
 cc-option = $(shell if test -z "`$(1) $(2) -S -o /dev/null -xc \
@@ -27,8 +28,8 @@ COMMONCFLAGS += $(call cc-option,$(CC),-nopie,)
 COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
 COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,)
 
-CFLAGS = $(COMMONCFLAGS) -g
-CFLAGS16INC = $(COMMONCFLAGS) -DMODE16 -fno-jump-tables -fno-defer-pop \
+override CFLAGS = $(COMMONCFLAGS) -g -DMODE16=0
+CFLAGS16INC = $(COMMONCFLAGS) -DMODE16=1 -fno-jump-tables -fno-defer-pop \
               $(call cc-option,$(CC),--param large-stack-frame=8,)
 CFLAGS16 = $(CFLAGS16INC) -g
 
@@ -42,6 +43,10 @@ else
 Q=@
 endif
 
+OBJCOPY=objcopy
+NM=nm
+STRIP=strip
+
 .PHONY : all FORCE
 
 vpath %.c src
@@ -56,7 +61,7 @@ ifdef AVOIDCOMBINE
 DEPHACK=
 define whole-compile
 @echo "  Compiling whole program $3"
-$(Q)/bin/echo -e '$(foreach i,$2,#include "../$i"\n)' > $3.tmp.c
+$(Q)printf '$(foreach i,$2,#include "../$i"\n)' > $3.tmp.c
 $(Q)$(CC) $1 -c $3.tmp.c -o $3
 endef
 else
@@ -79,46 +84,49 @@ $(OUT)%.16.s: %.c
 
 $(OUT)%.lds: %.lds.S
        @echo "  Precompiling $<"
-       $(Q)$(CPP) -P $< -o $@
+       $(Q)$(CPP) -P -D__ASSEMBLY__ $< -o $@
 
+$(OUT)asm-offsets.h: $(OUT)asm-offsets.16.s
+       @echo "  Generating offset file $@"
+       $(Q)./tools/gen-offsets.sh $< $@
 
 $(OUT)blob.16.s: ; $(call whole-compile, $(CFLAGS16) -S, $(addprefix src/, $(SRC16)),$@)
 
 TABLEASM=$(addprefix $(OUT), $(patsubst %.c,%.proc.16.s,$(TABLESRC)))
-$(OUT)romlayout16.o: romlayout.S $(OUT)blob.16.s $(TABLEASM)
+$(OUT)romlayout16.o: romlayout.S $(OUT)blob.16.s $(OUT)asm-offsets.h $(TABLEASM)
        @echo "  Generating 16bit layout of $@"
-       $(Q)$(CC) $(CFLAGS16) -c $< -o $@
+       $(Q)$(CC) $(CFLAGS16) -c -D__ASSEMBLY__ $< -o $@
 
 $(OUT)romlayout32.o: ; $(call whole-compile, $(CFLAGS), $(addprefix src/, $(SRC32)),$@)
 
-$(OUT)rom32.notreloc.o: $(OUT)romlayout32.o $(OUT)rombios32.lds
+$(OUT)rom32.o: $(OUT)romlayout32.o $(OUT)rombios32.lds
        @echo "  Linking (no relocs) $@"
-       $(Q)ld -r -T $(OUT)rombios32.lds $< -o $@.raw
-       $(Q)objcopy --prefix-symbols=_code32_ $@.raw $@
+       $(Q)$(LD) -r -d -T $(OUT)rombios32.lds $< -o $@
 
-$(OUT)rom16.o: $(OUT)romlayout16.o $(OUT)rom32.notreloc.o $(OUT)rombios16.lds
+$(OUT)rom16.o: $(OUT)romlayout16.o $(OUT)rom32.o $(OUT)rombios16.lds
        @echo "  Linking $@"
-       $(Q)ld -T $(OUT)rombios16.lds -R $(OUT)rom32.notreloc.o $< -o $@
+       $(Q)$(OBJCOPY) --prefix-symbols=_code32_ $(OUT)rom32.o $(OUT)rom32.rename.o
+       $(Q)$(LD) -T $(OUT)rombios16.lds -R $(OUT)rom32.rename.o $< -o $@
 
-$(OUT)rom32.o: $(OUT)rom16.o $(OUT)romlayout32.o $(OUT)rombios32.lds
+$(OUT)rom.o: $(OUT)rom16.o $(OUT)rom32.o $(OUT)rombios.lds
        @echo "  Linking $@"
-       $(Q)ld -T $(OUT)rombios32.lds $(OUT)rom16.o $(OUT)romlayout32.o -o $@
+       $(Q)$(LD) -T $(OUT)rombios.lds $(OUT)rom16.o $(OUT)rom32.o -o $@
 
-$(OUT)bios.bin.elf: $(OUT)rom32.o
+$(OUT)bios.bin.elf: $(OUT)rom.o
        @echo "  Prepping $@"
-       $(Q)nm $< | ./tools/checkrom.py
-       $(Q)strip $< -o $@
+       $(Q)$(NM) $< | ./tools/checkrom.py
+       $(Q)$(STRIP) $< -o $@
 
 $(OUT)bios.bin: $(OUT)bios.bin.elf
        @echo "  Extracting binary $@"
-       $(Q)objcopy -O binary $< $@
+       $(Q)$(OBJCOPY) -O binary $< $@
 
 
 ####### Generic rules
 clean:
-       rm -rf $(OUT)
+       $(Q)rm -rf $(OUT)
 
 $(OUT):
-       mkdir $@
+       $(Q)mkdir $@
 
 -include $(OUT)*.d