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 | 3b89719 | 2008-07-20 10:08:59 -0400 | [diff] [blame] | 12 | serial.c clock.c pic.c cdrom.c ps2port.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 | 0525d29 | 2008-07-04 06:18:30 -0400 | [diff] [blame] | 15 | acpi.c pirtable.c smm.c smpdetect.c mptable.c smbios.c pciinit.c |
Kevin O'Connor | 44c631d | 2008-03-02 11:24:36 -0500 | [diff] [blame] | 16 | TABLESRC=font.c cbt.c floppy_dbt.c |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 17 | |
Kevin O'Connor | 786502d | 2008-02-27 10:41:41 -0500 | [diff] [blame] | 18 | cc-option = $(shell if test -z "`$(1) $(2) -S -o /dev/null -xc \ |
| 19 | /dev/null 2>&1`"; then echo "$(2)"; else echo "$(3)"; fi ;) |
| 20 | |
Kevin O'Connor | bdce35f | 2008-02-26 21:33:14 -0500 | [diff] [blame] | 21 | # Default compiler flags |
Kevin O'Connor | ba2d0df | 2008-04-13 16:59:03 -0400 | [diff] [blame] | 22 | COMMONCFLAGS = -Wall -Os -MD -m32 -march=i386 -mregparm=3 \ |
| 23 | -mpreferred-stack-boundary=2 -mrtd \ |
Kevin O'Connor | bc28a2b | 2008-03-11 19:32:38 -0400 | [diff] [blame] | 24 | -ffreestanding -fwhole-program -fomit-frame-pointer \ |
| 25 | -fno-delete-null-pointer-checks |
Kevin O'Connor | 786502d | 2008-02-27 10:41:41 -0500 | [diff] [blame] | 26 | COMMONCFLAGS += $(call cc-option,$(CC),-nopie,) |
| 27 | COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector,) |
| 28 | COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,) |
| 29 | |
Kevin O'Connor | c43bcba | 2008-07-30 20:37:13 -0400 | [diff] [blame] | 30 | override CFLAGS = $(COMMONCFLAGS) -g -DMODE16=0 |
Kevin O'Connor | 7ab798f | 2008-07-13 11:08:36 -0400 | [diff] [blame] | 31 | CFLAGS16INC = $(COMMONCFLAGS) -DMODE16=1 -fno-jump-tables -fno-defer-pop \ |
Kevin O'Connor | a2d1692 | 2008-05-12 23:44:57 -0400 | [diff] [blame] | 32 | $(call cc-option,$(CC),--param large-stack-frame=8,) |
Kevin O'Connor | 410680b | 2008-03-02 20:48:35 -0500 | [diff] [blame] | 33 | CFLAGS16 = $(CFLAGS16INC) -g |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 34 | |
Kevin O'Connor | 44c631d | 2008-03-02 11:24:36 -0500 | [diff] [blame] | 35 | TABLETMP=$(addprefix $(OUT), $(patsubst %.c,%.16.s,$(TABLESRC))) |
Kevin O'Connor | 59fead6 | 2008-05-10 15:49:20 -0400 | [diff] [blame] | 36 | all: $(OUT) $(OUT)bios.bin $(TABLETMP) |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 37 | |
| 38 | # Run with "make V=1" to see the actual compile commands |
| 39 | ifdef V |
| 40 | Q= |
| 41 | else |
| 42 | Q=@ |
| 43 | endif |
| 44 | |
| 45 | .PHONY : all FORCE |
| 46 | |
| 47 | vpath %.c src |
| 48 | vpath %.S src |
| 49 | |
| 50 | ################ Build rules |
Kevin O'Connor | 410680b | 2008-03-02 20:48:35 -0500 | [diff] [blame] | 51 | |
| 52 | # Do a whole file compile - two methods are supported. The first |
| 53 | # involves including all the content textually via #include |
| 54 | # directives. The second method uses gcc's "-combine" option. |
| 55 | ifdef AVOIDCOMBINE |
| 56 | DEPHACK= |
| 57 | define whole-compile |
| 58 | @echo " Compiling whole program $3" |
| 59 | $(Q)/bin/echo -e '$(foreach i,$2,#include "../$i"\n)' > $3.tmp.c |
| 60 | $(Q)$(CC) $1 -c $3.tmp.c -o $3 |
| 61 | endef |
| 62 | else |
| 63 | # Ugly way to get gcc to generate .d files correctly. |
| 64 | DEPHACK=-combine src/null.c |
| 65 | define whole-compile |
| 66 | @echo " Compiling whole program $3" |
| 67 | $(Q)$(CC) $1 -combine -c $2 -o $3 |
| 68 | endef |
| 69 | endif |
| 70 | |
| 71 | |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 72 | $(OUT)%.proc.16.s: $(OUT)%.16.s |
| 73 | @echo " Moving data sections to text in $<" |
Kevin O'Connor | d5f1e84 | 2008-02-28 20:01:11 -0500 | [diff] [blame] | 74 | $(Q)sed 's/\t\.section\t\.rodata.*// ; s/\t\.data//' < $< > $@ |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 75 | |
| 76 | $(OUT)%.16.s: %.c |
| 77 | @echo " Generating assembler for $<" |
Kevin O'Connor | 410680b | 2008-03-02 20:48:35 -0500 | [diff] [blame] | 78 | $(Q)$(CC) $(CFLAGS16INC) $(DEPHACK) -S -c $< -o $@ |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 79 | |
| 80 | $(OUT)%.lds: %.lds.S |
| 81 | @echo " Precompiling $<" |
| 82 | $(Q)$(CPP) -P $< -o $@ |
| 83 | |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 84 | |
Kevin O'Connor | 410680b | 2008-03-02 20:48:35 -0500 | [diff] [blame] | 85 | $(OUT)blob.16.s: ; $(call whole-compile, $(CFLAGS16) -S, $(addprefix src/, $(SRC16)),$@) |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 86 | |
Kevin O'Connor | 44c631d | 2008-03-02 11:24:36 -0500 | [diff] [blame] | 87 | TABLEASM=$(addprefix $(OUT), $(patsubst %.c,%.proc.16.s,$(TABLESRC))) |
Kevin O'Connor | 7453453 | 2008-05-12 18:28:58 -0400 | [diff] [blame] | 88 | $(OUT)romlayout16.o: romlayout.S $(OUT)blob.16.s $(TABLEASM) |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 89 | @echo " Generating 16bit layout of $@" |
| 90 | $(Q)$(CC) $(CFLAGS16) -c $< -o $@ |
| 91 | |
Kevin O'Connor | 2fda7cb | 2008-07-05 20:41:53 -0400 | [diff] [blame] | 92 | $(OUT)romlayout32.o: ; $(call whole-compile, $(CFLAGS), $(addprefix src/, $(SRC32)),$@) |
| 93 | |
Kevin O'Connor | d289977 | 2008-07-06 09:56:14 -0400 | [diff] [blame] | 94 | $(OUT)rom32.o: $(OUT)romlayout32.o $(OUT)rombios32.lds |
Kevin O'Connor | 2fda7cb | 2008-07-05 20:41:53 -0400 | [diff] [blame] | 95 | @echo " Linking (no relocs) $@" |
Kevin O'Connor | d289977 | 2008-07-06 09:56:14 -0400 | [diff] [blame] | 96 | $(Q)ld -r -T $(OUT)rombios32.lds $< -o $@ |
Kevin O'Connor | 2fda7cb | 2008-07-05 20:41:53 -0400 | [diff] [blame] | 97 | |
Kevin O'Connor | d289977 | 2008-07-06 09:56:14 -0400 | [diff] [blame] | 98 | $(OUT)rom16.o: $(OUT)romlayout16.o $(OUT)rom32.o $(OUT)rombios16.lds |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 99 | @echo " Linking $@" |
Kevin O'Connor | d289977 | 2008-07-06 09:56:14 -0400 | [diff] [blame] | 100 | $(Q)objcopy --prefix-symbols=_code32_ $(OUT)rom32.o $(OUT)rom32.rename.o |
| 101 | $(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] | 102 | |
Kevin O'Connor | d289977 | 2008-07-06 09:56:14 -0400 | [diff] [blame] | 103 | $(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] | 104 | @echo " Linking $@" |
Kevin O'Connor | d289977 | 2008-07-06 09:56:14 -0400 | [diff] [blame] | 105 | $(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] | 106 | |
Kevin O'Connor | d289977 | 2008-07-06 09:56:14 -0400 | [diff] [blame] | 107 | $(OUT)bios.bin.elf: $(OUT)rom.o |
Kevin O'Connor | 9bcc527 | 2008-07-05 21:08:56 -0400 | [diff] [blame] | 108 | @echo " Prepping $@" |
| 109 | $(Q)nm $< | ./tools/checkrom.py |
Kevin O'Connor | 2fda7cb | 2008-07-05 20:41:53 -0400 | [diff] [blame] | 110 | $(Q)strip $< -o $@ |
| 111 | |
| 112 | $(OUT)bios.bin: $(OUT)bios.bin.elf |
| 113 | @echo " Extracting binary $@" |
| 114 | $(Q)objcopy -O binary $< $@ |
| 115 | |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 116 | |
| 117 | ####### Generic rules |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 118 | clean: |
| 119 | rm -rf $(OUT) |
| 120 | |
| 121 | $(OUT): |
| 122 | mkdir $@ |
| 123 | |
| 124 | -include $(OUT)*.d |