Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 1 | # Legacy Bios build system |
| 2 | # |
| 3 | # Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net> |
| 4 | # |
| 5 | # This file may be distributed under the terms of the GNU GPLv3 license. |
| 6 | |
| 7 | # Output directory |
| 8 | OUT=out/ |
| 9 | |
| 10 | # Source files |
Kevin O'Connor | 44eeaf1 | 2008-07-06 10:14:49 -0400 | [diff] [blame] | 11 | SRCBOTH=output.c util.c floppy.c ata.c system.c mouse.c kbd.c pci.c \ |
Kevin O'Connor | 18e38b2 | 2008-12-10 20:40:13 -0500 | [diff] [blame] | 12 | serial.c clock.c pic.c cdrom.c ps2port.c smpdetect.c resume.c |
Kevin O'Connor | cbffa8e | 2008-08-17 11:11:07 -0400 | [diff] [blame] | 13 | SRC16=$(SRCBOTH) disk.c apm.c pcibios.c vgahooks.c |
Kevin O'Connor | 44eeaf1 | 2008-07-06 10:14:49 -0400 | [diff] [blame] | 14 | SRC32=$(SRCBOTH) post.c shadow.c post_menu.c memmap.c coreboot.c boot.c \ |
Kevin O'Connor | a06bfb6 | 2008-12-06 19:37:56 -0500 | [diff] [blame] | 15 | acpi.c pirtable.c smm.c mptable.c smbios.c pciinit.c \ |
Kevin O'Connor | 714325c | 2008-11-01 20:32:27 -0400 | [diff] [blame] | 16 | optionroms.c |
Kevin O'Connor | 44c631d | 2008-03-02 11:24:36 -0500 | [diff] [blame] | 17 | TABLESRC=font.c cbt.c floppy_dbt.c |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 18 | |
Kevin O'Connor | 786502d | 2008-02-27 10:41:41 -0500 | [diff] [blame] | 19 | cc-option = $(shell if test -z "`$(1) $(2) -S -o /dev/null -xc \ |
| 20 | /dev/null 2>&1`"; then echo "$(2)"; else echo "$(3)"; fi ;) |
| 21 | |
Kevin O'Connor | bdce35f | 2008-02-26 21:33:14 -0500 | [diff] [blame] | 22 | # Default compiler flags |
Kevin O'Connor | ba2d0df | 2008-04-13 16:59:03 -0400 | [diff] [blame] | 23 | COMMONCFLAGS = -Wall -Os -MD -m32 -march=i386 -mregparm=3 \ |
| 24 | -mpreferred-stack-boundary=2 -mrtd \ |
Kevin O'Connor | bc28a2b | 2008-03-11 19:32:38 -0400 | [diff] [blame] | 25 | -ffreestanding -fwhole-program -fomit-frame-pointer \ |
| 26 | -fno-delete-null-pointer-checks |
Kevin O'Connor | 786502d | 2008-02-27 10:41:41 -0500 | [diff] [blame] | 27 | COMMONCFLAGS += $(call cc-option,$(CC),-nopie,) |
| 28 | COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector,) |
| 29 | COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,) |
| 30 | |
Kevin O'Connor | c43bcba | 2008-07-30 20:37:13 -0400 | [diff] [blame] | 31 | override CFLAGS = $(COMMONCFLAGS) -g -DMODE16=0 |
Kevin O'Connor | 7ab798f | 2008-07-13 11:08:36 -0400 | [diff] [blame] | 32 | CFLAGS16INC = $(COMMONCFLAGS) -DMODE16=1 -fno-jump-tables -fno-defer-pop \ |
Kevin O'Connor | a2d1692 | 2008-05-12 23:44:57 -0400 | [diff] [blame] | 33 | $(call cc-option,$(CC),--param large-stack-frame=8,) |
Kevin O'Connor | 410680b | 2008-03-02 20:48:35 -0500 | [diff] [blame] | 34 | CFLAGS16 = $(CFLAGS16INC) -g |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 35 | |
Kevin O'Connor | 44c631d | 2008-03-02 11:24:36 -0500 | [diff] [blame] | 36 | TABLETMP=$(addprefix $(OUT), $(patsubst %.c,%.16.s,$(TABLESRC))) |
Kevin O'Connor | 59fead6 | 2008-05-10 15:49:20 -0400 | [diff] [blame] | 37 | all: $(OUT) $(OUT)bios.bin $(TABLETMP) |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 38 | |
| 39 | # Run with "make V=1" to see the actual compile commands |
| 40 | ifdef V |
| 41 | Q= |
| 42 | else |
| 43 | Q=@ |
| 44 | endif |
| 45 | |
Kevin O'Connor | 2fc90bd | 2008-11-07 21:42:00 -0500 | [diff] [blame] | 46 | OBJCOPY=objcopy |
| 47 | NM=nm |
| 48 | STRIP=strip |
| 49 | |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 50 | .PHONY : all FORCE |
| 51 | |
| 52 | vpath %.c src |
| 53 | vpath %.S src |
| 54 | |
| 55 | ################ Build rules |
Kevin O'Connor | 410680b | 2008-03-02 20:48:35 -0500 | [diff] [blame] | 56 | |
| 57 | # Do a whole file compile - two methods are supported. The first |
| 58 | # involves including all the content textually via #include |
| 59 | # directives. The second method uses gcc's "-combine" option. |
| 60 | ifdef AVOIDCOMBINE |
| 61 | DEPHACK= |
| 62 | define whole-compile |
| 63 | @echo " Compiling whole program $3" |
Kevin O'Connor | 86cebee | 2008-11-06 18:57:10 -0500 | [diff] [blame] | 64 | $(Q)printf '$(foreach i,$2,#include "../$i"\n)' > $3.tmp.c |
Kevin O'Connor | 410680b | 2008-03-02 20:48:35 -0500 | [diff] [blame] | 65 | $(Q)$(CC) $1 -c $3.tmp.c -o $3 |
| 66 | endef |
| 67 | else |
| 68 | # Ugly way to get gcc to generate .d files correctly. |
| 69 | DEPHACK=-combine src/null.c |
| 70 | define whole-compile |
| 71 | @echo " Compiling whole program $3" |
| 72 | $(Q)$(CC) $1 -combine -c $2 -o $3 |
| 73 | endef |
| 74 | endif |
| 75 | |
| 76 | |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 77 | $(OUT)%.proc.16.s: $(OUT)%.16.s |
Kevin O'Connor | 9e82122 | 2008-12-06 18:56:19 -0500 | [diff] [blame] | 78 | @echo " Moving data sections to text in $@" |
Kevin O'Connor | d5f1e84 | 2008-02-28 20:01:11 -0500 | [diff] [blame] | 79 | $(Q)sed 's/\t\.section\t\.rodata.*// ; s/\t\.data//' < $< > $@ |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 80 | |
| 81 | $(OUT)%.16.s: %.c |
Kevin O'Connor | 9e82122 | 2008-12-06 18:56:19 -0500 | [diff] [blame] | 82 | @echo " Compiling to assembler $@" |
Kevin O'Connor | 410680b | 2008-03-02 20:48:35 -0500 | [diff] [blame] | 83 | $(Q)$(CC) $(CFLAGS16INC) $(DEPHACK) -S -c $< -o $@ |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 84 | |
| 85 | $(OUT)%.lds: %.lds.S |
Kevin O'Connor | 9e82122 | 2008-12-06 18:56:19 -0500 | [diff] [blame] | 86 | @echo " Precompiling $@" |
Kevin O'Connor | d9a8b2d | 2008-11-16 09:17:02 -0500 | [diff] [blame] | 87 | $(Q)$(CPP) -P -D__ASSEMBLY__ $< -o $@ |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 88 | |
Kevin O'Connor | 952974e | 2008-11-16 18:14:33 -0500 | [diff] [blame] | 89 | $(OUT)asm-offsets.h: $(OUT)asm-offsets.16.s |
| 90 | @echo " Generating offset file $@" |
| 91 | $(Q)./tools/gen-offsets.sh $< $@ |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 92 | |
Kevin O'Connor | 9e82122 | 2008-12-06 18:56:19 -0500 | [diff] [blame] | 93 | $(OUT)ccode.16.s: ; $(call whole-compile, $(CFLAGS16) -S, $(addprefix src/, $(SRC16)),$@) |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 94 | |
Kevin O'Connor | 44c631d | 2008-03-02 11:24:36 -0500 | [diff] [blame] | 95 | TABLEASM=$(addprefix $(OUT), $(patsubst %.c,%.proc.16.s,$(TABLESRC))) |
Kevin O'Connor | 9e82122 | 2008-12-06 18:56:19 -0500 | [diff] [blame] | 96 | $(OUT)romlayout16.o: romlayout.S $(OUT)ccode.16.s $(OUT)asm-offsets.h $(TABLEASM) |
| 97 | @echo " Compiling (16bit) $@" |
| 98 | $(Q)$(CC) $(CFLAGS16INC) -c -D__ASSEMBLY__ $< -o $@ |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 99 | |
Kevin O'Connor | 9e82122 | 2008-12-06 18:56:19 -0500 | [diff] [blame] | 100 | $(OUT)ccode32.o: ; $(call whole-compile, $(CFLAGS), $(addprefix src/, $(SRC32)),$@) |
Kevin O'Connor | 2fda7cb | 2008-07-05 20:41:53 -0400 | [diff] [blame] | 101 | |
Kevin O'Connor | 9e82122 | 2008-12-06 18:56:19 -0500 | [diff] [blame] | 102 | $(OUT)rom32.o: $(OUT)ccode32.o $(OUT)rombios32.lds |
Kevin O'Connor | 2fda7cb | 2008-07-05 20:41:53 -0400 | [diff] [blame] | 103 | @echo " Linking (no relocs) $@" |
Kevin O'Connor | 1b7d884 | 2008-11-08 10:36:16 -0500 | [diff] [blame] | 104 | $(Q)$(LD) -r -d -T $(OUT)rombios32.lds $< -o $@ |
Kevin O'Connor | 2fda7cb | 2008-07-05 20:41:53 -0400 | [diff] [blame] | 105 | |
Kevin O'Connor | d289977 | 2008-07-06 09:56:14 -0400 | [diff] [blame] | 106 | $(OUT)rom16.o: $(OUT)romlayout16.o $(OUT)rom32.o $(OUT)rombios16.lds |
Kevin O'Connor | 9e82122 | 2008-12-06 18:56:19 -0500 | [diff] [blame] | 107 | @echo " Linking (16bit) $@" |
Kevin O'Connor | 86cebee | 2008-11-06 18:57:10 -0500 | [diff] [blame] | 108 | $(Q)$(OBJCOPY) --prefix-symbols=_code32_ $(OUT)rom32.o $(OUT)rom32.rename.o |
| 109 | $(Q)$(LD) -T $(OUT)rombios16.lds -R $(OUT)rom32.rename.o $< -o $@ |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 110 | |
Kevin O'Connor | d289977 | 2008-07-06 09:56:14 -0400 | [diff] [blame] | 111 | $(OUT)rom.o: $(OUT)rom16.o $(OUT)rom32.o $(OUT)rombios.lds |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 112 | @echo " Linking $@" |
Kevin O'Connor | 86cebee | 2008-11-06 18:57:10 -0500 | [diff] [blame] | 113 | $(Q)$(LD) -T $(OUT)rombios.lds $(OUT)rom16.o $(OUT)rom32.o -o $@ |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 114 | |
Kevin O'Connor | d289977 | 2008-07-06 09:56:14 -0400 | [diff] [blame] | 115 | $(OUT)bios.bin.elf: $(OUT)rom.o |
Kevin O'Connor | 9bcc527 | 2008-07-05 21:08:56 -0400 | [diff] [blame] | 116 | @echo " Prepping $@" |
Kevin O'Connor | 86cebee | 2008-11-06 18:57:10 -0500 | [diff] [blame] | 117 | $(Q)$(NM) $< | ./tools/checkrom.py |
| 118 | $(Q)$(STRIP) $< -o $@ |
Kevin O'Connor | 2fda7cb | 2008-07-05 20:41:53 -0400 | [diff] [blame] | 119 | |
| 120 | $(OUT)bios.bin: $(OUT)bios.bin.elf |
| 121 | @echo " Extracting binary $@" |
Kevin O'Connor | 86cebee | 2008-11-06 18:57:10 -0500 | [diff] [blame] | 122 | $(Q)$(OBJCOPY) -O binary $< $@ |
Kevin O'Connor | 2fda7cb | 2008-07-05 20:41:53 -0400 | [diff] [blame] | 123 | |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 124 | |
| 125 | ####### Generic rules |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 126 | clean: |
Kevin O'Connor | 86cebee | 2008-11-06 18:57:10 -0500 | [diff] [blame] | 127 | $(Q)rm -rf $(OUT) |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 128 | |
| 129 | $(OUT): |
Kevin O'Connor | 86cebee | 2008-11-06 18:57:10 -0500 | [diff] [blame] | 130 | $(Q)mkdir $@ |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 131 | |
| 132 | -include $(OUT)*.d |