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