[162] | 1 | export # export all variable to sub-Makefile |
---|
[158] | 2 | CC=mipsel-unknown-elf-gcc |
---|
| 3 | AS=mipsel-unknown-elf-as |
---|
| 4 | LD=mipsel-unknown-elf-ld |
---|
| 5 | DU=mipsel-unknown-elf-objdump |
---|
| 6 | |
---|
[162] | 7 | #current directory absolute path |
---|
| 8 | SOFT_PATH = $(shell pwd)/ |
---|
| 9 | |
---|
| 10 | SYS_NAME = sys |
---|
| 11 | BOOT_NAME = boot |
---|
| 12 | LIB_NAME = libs |
---|
| 13 | |
---|
| 14 | SYS_PATH = $(SOFT_PATH)$(SYS_NAME) |
---|
| 15 | BOOT_PATH = $(SOFT_PATH)$(BOOT_NAME) |
---|
| 16 | LIB_PATH = $(SOFT_PATH)$(LIB_NAME) |
---|
| 17 | MAP_PATH = $(SOFT_PATH)xml/ |
---|
| 18 | BUILD_PATH = $(SOFT_PATH)build/ |
---|
| 19 | ELF_PATH = $(SOFT_PATH)build/ |
---|
| 20 | |
---|
| 21 | #list of all applications directory |
---|
| 22 | APP_DIRS = $(shell ls -d apps/*/ ) |
---|
| 23 | |
---|
| 24 | SYS_OBJS_LIST = \ |
---|
| 25 | sys_handler.o \ |
---|
| 26 | giet.o \ |
---|
[160] | 27 | switch.o \ |
---|
| 28 | common.o \ |
---|
| 29 | ctx_handler.o \ |
---|
| 30 | drivers.o \ |
---|
| 31 | exc_handler.o \ |
---|
| 32 | irq_handler.o \ |
---|
[165] | 33 | kernel_init.o |
---|
[158] | 34 | |
---|
[162] | 35 | BOOT_OBJS_LIST = reset.o \ |
---|
| 36 | boot_handler.o |
---|
[158] | 37 | |
---|
[162] | 38 | #LIB_SRCS = $(wildcard $(LIB_NAME)/*.c) |
---|
[165] | 39 | LIB_OBJS_LIST = stdio.o \ |
---|
| 40 | mwmr_channel.o \ |
---|
| 41 | barrier.o \ |
---|
| 42 | spin_lock.o \ |
---|
[162] | 43 | common.o |
---|
[158] | 44 | |
---|
[162] | 45 | LIB_OBJS = $(patsubst %,$(LIB_NAME)/%,$(LIB_OBJS_LIST)) |
---|
| 46 | SYS_OBJS = $(patsubst %,$(SYS_NAME)/%,$(SYS_OBJS_LIST)) |
---|
| 47 | BOOT_OBJS = $(patsubst %,$(BOOT_NAME)/%,$(BOOT_OBJS_LIST)) |
---|
| 48 | |
---|
| 49 | |
---|
[160] | 50 | CFLAGS=-Wall -ffreestanding -mno-gpopt -mips32 -g |
---|
[158] | 51 | |
---|
[162] | 52 | SYS_INCLUDE = -I$(SYS_PATH) -I$(MAP_PATH) -I$(LIB_PATH) -I. |
---|
[158] | 53 | |
---|
[162] | 54 | BOOT_INCLUDE = -I$(BOOT_PATH) -I$(MAP_PATH) -I$(LIB_PATH) -I. |
---|
[158] | 55 | |
---|
[162] | 56 | INCLUDE = -I$(LIB_PATH) -I$(SOFT_PATH) -I$(SYS_PATH) -I$(MAP_PATH) |
---|
[160] | 57 | |
---|
| 58 | TRASH= /dev/null||true |
---|
| 59 | |
---|
| 60 | .PHONY: apps prepare |
---|
| 61 | |
---|
[161] | 62 | all: prepare soft.elf |
---|
[160] | 63 | |
---|
[161] | 64 | ## merge all *.elf to soft.elf |
---|
| 65 | soft.elf: boot.elf sys.elf map.bin apps |
---|
[163] | 66 | $(MAKE) -C memo |
---|
| 67 | memo/memo.x map.bin |
---|
[162] | 68 | $(DU) -D $@ > $(BUILD_PATH)$@.txt |
---|
[160] | 69 | |
---|
| 70 | ## prepare the environement |
---|
| 71 | prepare: |
---|
[162] | 72 | @mkdir $(BUILD_PATH) 2>$(TRASH) |
---|
| 73 | @mkdir $(ELF_PATH) 2>$(TRASH) |
---|
[160] | 74 | |
---|
[158] | 75 | ## mapping compilation |
---|
| 76 | map.bin: map.xml |
---|
[162] | 77 | $(MAKE) -C xml |
---|
[158] | 78 | xml/xml2bin map.xml map.bin |
---|
| 79 | |
---|
| 80 | ## system compilation |
---|
[161] | 81 | sys.elf: $(SYS_OBJS) $(SYS_PATH)/sys.ld |
---|
[162] | 82 | (cd $(BUILD_PATH); $(LD) -o $@ -T $(SYS_PATH)/sys.ld $(SYS_OBJS) ) |
---|
| 83 | (cd $(BUILD_PATH); $(DU) -D $@ > $@.txt) |
---|
[158] | 84 | |
---|
[162] | 85 | $(SYS_NAME)/%.o: $(SYS_NAME)/%.c |
---|
| 86 | @mkdir $(BUILD_PATH)/$(SYS_NAME) 2>$(TRASH) |
---|
| 87 | $(CC) $(SYS_INCLUDE) $(CFLAGS) -c -o $(BUILD_PATH)/$@ $< |
---|
[158] | 88 | |
---|
[162] | 89 | $(SYS_NAME)/%.o: $(SYS_NAME)/%.s |
---|
| 90 | @mkdir $(BUILD_PATH)/$(SYS_NAME) 2>$(TRASH) |
---|
| 91 | $(CC) $(SYS_INCLUDE) $(CFLAGS) -c -o $(BUILD_PATH)/$@ $< |
---|
[158] | 92 | |
---|
[162] | 93 | $(SYS_NAME)/%.o: $(SYS_NAME)/%.S |
---|
| 94 | @mkdir $(BUILD_PATH)/$(SYS_NAME) 2>$(TRASH) |
---|
| 95 | $(CC) $(SYS_INCLUDE) $(CFLAGS) -c -o $(BUILD_PATH)/$@ $< |
---|
[158] | 96 | |
---|
[162] | 97 | ## boot compilation |
---|
| 98 | boot.elf: $(BOOT_OBJS) $(BOOT_PATH)/boot.ld |
---|
| 99 | (cd $(BUILD_PATH); $(LD) -o $@ -T $(BOOT_PATH)/boot.ld $(BOOT_OBJS) ) |
---|
| 100 | (cd $(BUILD_PATH); $(DU) -D $@ > $@.txt) |
---|
[158] | 101 | |
---|
[162] | 102 | $(BOOT_NAME)/%.o: $(BOOT_NAME)/%.c |
---|
| 103 | @mkdir $(BUILD_PATH)/$(BOOT_NAME) 2>$(TRASH) |
---|
| 104 | $(CC) $(BOOT_INCLUDE) $(CFLAGS) -c -o $(BUILD_PATH)/$@ $< |
---|
[158] | 105 | |
---|
[162] | 106 | $(BOOT_NAME)/%.o: $(BOOT_NAME)/%.s |
---|
| 107 | @mkdir $(BUILD_PATH)/$(BOOT_NAME) 2>$(TRASH) |
---|
| 108 | $(CC) $(BOOT_INCLUDE) $(CFLAGS) -c -o $(BUILD_PATH)/$@ $< |
---|
[158] | 109 | |
---|
[162] | 110 | $(BOOT_NAME)/%.o: $(BOOT_NAME)/%.S |
---|
| 111 | @mkdir $(BUILD_PATH)/$(BOOT_NAME) 2>$(TRASH) |
---|
| 112 | $(CC) $(BOOT_INCLUDE) $(CFLAGS) -c -o $(BUILD_PATH)/$@ $< |
---|
[158] | 113 | |
---|
[162] | 114 | ##libs compilation |
---|
| 115 | $(LIB_NAME)/%.o: $(LIB_NAME)/%.c |
---|
| 116 | @mkdir $(BUILD_PATH)/$(LIB_NAME) 2>$(TRASH) |
---|
| 117 | $(CC) $(CFLAGS) $(INCLUDE) -c -o $(BUILD_PATH)/$@ $< |
---|
[158] | 118 | |
---|
[162] | 119 | ## applications |
---|
| 120 | apps: $(LIB_OBJS) |
---|
[160] | 121 | @echo "---------------------------------------------BUILDING APPS------------------------------------------------------" |
---|
[162] | 122 | set -e; for d in $(APP_DIRS); do $(MAKE) -C $$d ; echo "Compiling $$d"; done |
---|
[158] | 123 | |
---|
| 124 | ### special rules |
---|
| 125 | clean: |
---|
[161] | 126 | rm -f *.o *.elf *.bin *.txt core *~ 2>$(TRASH) |
---|
[162] | 127 | $(MAKE) clean -C xml/ 2>$(TRASH) |
---|
[163] | 128 | $(MAKE) clean -C memo/ 2>$(TRASH) |
---|
[162] | 129 | rm -r $(BUILD_PATH) 2>$(TRASH) |
---|
| 130 | set -e; for d in $(APP_DIRS); do $(MAKE) clean -C $$d ; done |
---|