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