[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 \ |
---|
| 45 | spin_lock.o \ |
---|
[162] | 46 | common.o |
---|
[158] | 47 | |
---|
[177] | 48 | LIB_OBJS = $(patsubst %,$(LIB_DIR)/%,$(LIB_OBJS_LIST)) |
---|
| 49 | SYS_OBJS = $(patsubst %,$(SYS_DIR)/%,$(SYS_OBJS_LIST)) |
---|
| 50 | BOOT_OBJS = $(patsubst %,$(BOOT_DIR)/%,$(BOOT_OBJS_LIST)) |
---|
[162] | 51 | |
---|
| 52 | |
---|
[160] | 53 | CFLAGS=-Wall -ffreestanding -mno-gpopt -mips32 -g |
---|
[158] | 54 | |
---|
[177] | 55 | SYS_INCLUDE = -I$(SYS_PATH) -I$(XML_PATH) -I$(LIB_PATH) -I. |
---|
| 56 | BOOT_INCLUDE = -I$(BOOT_PATH) -I$(XML_PATH) -I$(LIB_PATH) -I. |
---|
| 57 | LIB_INCLUDE = -I$(LIB_PATH) -I$(XML_PATH) -I. |
---|
| 58 | APP_INCLUDE = -I$(LIB_PATH) -I$(XML_PATH) -I$(SOFT_PATH) |
---|
[158] | 59 | |
---|
[160] | 60 | TRASH= /dev/null||true |
---|
| 61 | |
---|
| 62 | .PHONY: apps prepare |
---|
| 63 | |
---|
[161] | 64 | all: prepare soft.elf |
---|
[160] | 65 | |
---|
[161] | 66 | ## merge all *.elf to soft.elf |
---|
| 67 | soft.elf: boot.elf sys.elf map.bin apps |
---|
[177] | 68 | $(MAKE) -C $(MEMO_PATH) |
---|
| 69 | $(MEMO_PATH)/memo.x map.bin |
---|
[162] | 70 | $(DU) -D $@ > $(BUILD_PATH)$@.txt |
---|
[160] | 71 | |
---|
| 72 | ## prepare the environement |
---|
| 73 | prepare: |
---|
[175] | 74 | @mkdir $(BUILD_PATH) 2>$(TRASH) |
---|
| 75 | @mkdir $(ELF_PATH) 2>$(TRASH) |
---|
[177] | 76 | @mkdir $(BUILD_PATH)/$(BOOT_DIR) 2>$(TRASH) |
---|
| 77 | @mkdir $(BUILD_PATH)/$(LIB_DIR) 2>$(TRASH) |
---|
| 78 | @mkdir $(BUILD_PATH)/$(SYS_DIR) 2>$(TRASH) |
---|
[160] | 79 | |
---|
[177] | 80 | ### mapping compilation |
---|
[158] | 81 | map.bin: map.xml |
---|
[177] | 82 | $(MAKE) -C $(XML_PATH) |
---|
| 83 | $(XML_PATH)/xml2bin $(SOFT_PATH)map.xml $(SOFT_PATH)map.bin |
---|
[158] | 84 | |
---|
[177] | 85 | ### system compilation |
---|
[161] | 86 | sys.elf: $(SYS_OBJS) $(SYS_PATH)/sys.ld |
---|
[162] | 87 | (cd $(BUILD_PATH); $(LD) -o $@ -T $(SYS_PATH)/sys.ld $(SYS_OBJS) ) |
---|
| 88 | (cd $(BUILD_PATH); $(DU) -D $@ > $@.txt) |
---|
[158] | 89 | |
---|
[177] | 90 | $(SYS_DIR)/%.o: $(SYS_DIR)/%.c |
---|
[162] | 91 | $(CC) $(SYS_INCLUDE) $(CFLAGS) -c -o $(BUILD_PATH)/$@ $< |
---|
[158] | 92 | |
---|
[177] | 93 | $(SYS_DIR)/%.o: $(SYS_DIR)/%.s |
---|
[162] | 94 | $(CC) $(SYS_INCLUDE) $(CFLAGS) -c -o $(BUILD_PATH)/$@ $< |
---|
[158] | 95 | |
---|
[177] | 96 | $(SYS_DIR)/%.o: $(SYS_DIR)/%.S |
---|
[162] | 97 | $(CC) $(SYS_INCLUDE) $(CFLAGS) -c -o $(BUILD_PATH)/$@ $< |
---|
[158] | 98 | |
---|
[177] | 99 | ### boot compilation |
---|
[162] | 100 | boot.elf: $(BOOT_OBJS) $(BOOT_PATH)/boot.ld |
---|
| 101 | (cd $(BUILD_PATH); $(LD) -o $@ -T $(BOOT_PATH)/boot.ld $(BOOT_OBJS) ) |
---|
| 102 | (cd $(BUILD_PATH); $(DU) -D $@ > $@.txt) |
---|
[158] | 103 | |
---|
[177] | 104 | $(BOOT_DIR)/%.o: $(BOOT_DIR)/%.c |
---|
[162] | 105 | $(CC) $(BOOT_INCLUDE) $(CFLAGS) -c -o $(BUILD_PATH)/$@ $< |
---|
[158] | 106 | |
---|
[177] | 107 | $(BOOT_DIR)/%.o: $(BOOT_DIR)/%.s |
---|
[162] | 108 | $(CC) $(BOOT_INCLUDE) $(CFLAGS) -c -o $(BUILD_PATH)/$@ $< |
---|
[158] | 109 | |
---|
[177] | 110 | $(BOOT_DIR)/%.o: $(BOOT_DIR)/%.S |
---|
[162] | 111 | $(CC) $(BOOT_INCLUDE) $(CFLAGS) -c -o $(BUILD_PATH)/$@ $< |
---|
[158] | 112 | |
---|
[177] | 113 | ### libs compilation |
---|
| 114 | $(LIB_DIR)/%.o: $(LIB_DIR)/%.c |
---|
[175] | 115 | $(CC) $(CFLAGS) $(LIB_INCLUDE) -c -o $(BUILD_PATH)/$@ $< |
---|
[158] | 116 | |
---|
[177] | 117 | ### applications |
---|
[162] | 118 | apps: $(LIB_OBJS) |
---|
[177] | 119 | @echo "---------------------------------------------- BUILDING APPS ---------------------------------------------------------" |
---|
| 120 | set -e; for d in $(APP_DIRS); do $(MAKE) -f config.mk -C $$d ; echo "Compiling $$d"; done |
---|
[158] | 121 | |
---|
[177] | 122 | ### clean |
---|
[158] | 123 | clean: |
---|
[177] | 124 | rm -f *.o *.elf *.bin *.txt core *~ 2>$(TRASH) |
---|
| 125 | $(MAKE) -s clean -C $(XML_PATH) 2>$(TRASH) |
---|
| 126 | $(MAKE) -s clean -C $(MEMO_PATH) 2>$(TRASH) |
---|
| 127 | rm -r $(BUILD_PATH) 2>$(TRASH) |
---|
| 128 | rm -r $(ELF_PATH) 2>$(TRASH) |
---|
| 129 | set -e; for d in $(APP_DIRS); do $(MAKE) clean -f config.mk -C $$d ; done |
---|