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