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