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_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 | vm_handler.o \ |
---|
26 | sys_handler.o \ |
---|
27 | giet.o \ |
---|
28 | switch.o \ |
---|
29 | common.o \ |
---|
30 | ctx_handler.o \ |
---|
31 | drivers.o \ |
---|
32 | exc_handler.o \ |
---|
33 | irq_handler.o \ |
---|
34 | kernel_init.o |
---|
35 | |
---|
36 | BOOT_OBJS_LIST = reset.o \ |
---|
37 | boot_handler.o |
---|
38 | |
---|
39 | #LIB_SRCS = $(wildcard $(LIB_NAME)/*.c) |
---|
40 | LIB_OBJS_LIST = stdio.o \ |
---|
41 | mwmr_channel.o \ |
---|
42 | barrier.o \ |
---|
43 | spin_lock.o \ |
---|
44 | common.o |
---|
45 | |
---|
46 | LIB_OBJS = $(patsubst %,$(LIB_NAME)/%,$(LIB_OBJS_LIST)) |
---|
47 | SYS_OBJS = $(patsubst %,$(SYS_NAME)/%,$(SYS_OBJS_LIST)) |
---|
48 | BOOT_OBJS = $(patsubst %,$(BOOT_NAME)/%,$(BOOT_OBJS_LIST)) |
---|
49 | |
---|
50 | |
---|
51 | CFLAGS=-Wall -ffreestanding -mno-gpopt -mips32 -g |
---|
52 | |
---|
53 | SYS_INCLUDE = -I$(SYS_PATH) -I$(MAP_PATH) -I$(LIB_PATH) -I. |
---|
54 | BOOT_INCLUDE = -I$(BOOT_PATH) -I$(MAP_PATH) -I$(LIB_PATH) -I. |
---|
55 | LIB_INCLUDE = -I$(LIB_PATH) -I$(MAP_PATH) |
---|
56 | INCLUDE = -I$(LIB_PATH) -I$(MAP_PATH) |
---|
57 | |
---|
58 | TRASH= /dev/null||true |
---|
59 | |
---|
60 | .PHONY: apps prepare |
---|
61 | |
---|
62 | all: prepare soft.elf |
---|
63 | |
---|
64 | ## merge all *.elf to soft.elf |
---|
65 | soft.elf: boot.elf sys.elf map.bin apps |
---|
66 | $(MAKE) -C memo |
---|
67 | memo/memo.x map.bin |
---|
68 | $(DU) -D $@ > $(BUILD_PATH)$@.txt |
---|
69 | |
---|
70 | ## prepare the environement |
---|
71 | prepare: |
---|
72 | @mkdir $(BUILD_PATH) 2>$(TRASH) |
---|
73 | @mkdir $(ELF_PATH) 2>$(TRASH) |
---|
74 | @mkdir $(BUILD_PATH)/$(BOOT_NAME) 2>$(TRASH) |
---|
75 | @mkdir $(BUILD_PATH)/$(LIB_NAME) 2>$(TRASH) |
---|
76 | @mkdir $(BUILD_PATH)/$(SYS_NAME) 2>$(TRASH) |
---|
77 | |
---|
78 | ## mapping compilation |
---|
79 | map.bin: map.xml |
---|
80 | $(MAKE) -C xml |
---|
81 | xml/xml2bin map.xml map.bin |
---|
82 | |
---|
83 | ## system compilation |
---|
84 | sys.elf: $(SYS_OBJS) $(SYS_PATH)/sys.ld |
---|
85 | (cd $(BUILD_PATH); $(LD) -o $@ -T $(SYS_PATH)/sys.ld $(SYS_OBJS) ) |
---|
86 | (cd $(BUILD_PATH); $(DU) -D $@ > $@.txt) |
---|
87 | |
---|
88 | $(SYS_NAME)/%.o: $(SYS_NAME)/%.c |
---|
89 | $(CC) $(SYS_INCLUDE) $(CFLAGS) -c -o $(BUILD_PATH)/$@ $< |
---|
90 | |
---|
91 | $(SYS_NAME)/%.o: $(SYS_NAME)/%.s |
---|
92 | $(CC) $(SYS_INCLUDE) $(CFLAGS) -c -o $(BUILD_PATH)/$@ $< |
---|
93 | |
---|
94 | $(SYS_NAME)/%.o: $(SYS_NAME)/%.S |
---|
95 | $(CC) $(SYS_INCLUDE) $(CFLAGS) -c -o $(BUILD_PATH)/$@ $< |
---|
96 | |
---|
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) |
---|
101 | |
---|
102 | $(BOOT_NAME)/%.o: $(BOOT_NAME)/%.c |
---|
103 | $(CC) $(BOOT_INCLUDE) $(CFLAGS) -c -o $(BUILD_PATH)/$@ $< |
---|
104 | |
---|
105 | $(BOOT_NAME)/%.o: $(BOOT_NAME)/%.s |
---|
106 | $(CC) $(BOOT_INCLUDE) $(CFLAGS) -c -o $(BUILD_PATH)/$@ $< |
---|
107 | |
---|
108 | $(BOOT_NAME)/%.o: $(BOOT_NAME)/%.S |
---|
109 | $(CC) $(BOOT_INCLUDE) $(CFLAGS) -c -o $(BUILD_PATH)/$@ $< |
---|
110 | |
---|
111 | ##libs compilation |
---|
112 | $(LIB_NAME)/%.o: $(LIB_NAME)/%.c |
---|
113 | $(CC) $(CFLAGS) $(LIB_INCLUDE) -c -o $(BUILD_PATH)/$@ $< |
---|
114 | |
---|
115 | ## applications |
---|
116 | apps: $(LIB_OBJS) |
---|
117 | @echo "---------------------------------------------BUILDING APPS------------------------------------------------------" |
---|
118 | set -e; for d in $(APP_DIRS); do $(MAKE) -C $$d ; echo "Compiling $$d"; done |
---|
119 | |
---|
120 | ### special rules |
---|
121 | clean: |
---|
122 | rm -f *.o *.elf *.bin *.txt core *~ 2>$(TRASH) |
---|
123 | $(MAKE) -s clean -C xml/ 2>$(TRASH) |
---|
124 | $(MAKE) -s clean -C memo/ 2>$(TRASH) |
---|
125 | rm -r $(BUILD_PATH) 2>$(TRASH) |
---|
126 | set -e; for d in $(APP_DIRS); do $(MAKE) clean -C $$d ; done |
---|