-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
232 lines (186 loc) · 7.65 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
VERSION = 0.95
TARGET_LIST = \
'arm/stm32f401_blackpill' 'arm/stm32f411_blackpill' \
'arm/stm32f407_discovery' 'arm/versatilepb' \
'avr/atmega32' 'avr/atmega328p' 'avr/atmega2560' \
'mips/hf-risc' 'riscv/hf-riscv' 'riscv/hf-riscv-e' \
'riscv/hf-riscv-llvm' 'riscv/riscv32-qemu' 'riscv/riscv32-qemu-llvm' \
'riscv/riscv64-qemu' 'riscv/riscv64-qemu-llvm'
#ARCH = none
SERIAL_BAUD=57600
SERIAL_DEVICE=/dev/ttyUSB0
SRC_DIR = .
BUILD_DIR = $(SRC_DIR)/build
BUILD_APP_DIR = $(BUILD_DIR)/app
BUILD_HAL_DIR = $(BUILD_DIR)/hal
BUILD_DRIVERS_DIR = $(BUILD_DIR)/drivers
BUILD_KERNEL_DIR = $(BUILD_DIR)/kernel
BUILD_TARGET_DIR = $(BUILD_DIR)/target
-include $(BUILD_TARGET_DIR)/target.mak
-include $(SRC_DIR)/arch/$(ARCH)/arch.mak
-include $(SRC_DIR)/drivers/drivers.mak
INC_DIRS += -I $(SRC_DIR)/include -I $(SRC_DIR)/include/lib \
-I $(SRC_DIR)/drivers/include -I $(SRC_DIR)/arch/common
CFLAGS += -D__VER__=\"$(VERSION)\"
incl:
ifeq ('$(ARCH)', 'none')
@echo "You must specify a target architecture (ARCH=arch/target)."
@echo "Supported targets are: $(TARGET_LIST)"
else
@echo "ARCH = $(ARCH)" > $(BUILD_TARGET_DIR)/target.mak
endif
serial:
stty ${SERIAL_BAUD} raw cs8 -parenb -crtscts clocal cread ignpar ignbrk -ixon -ixoff -ixany -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke -F ${SERIAL_DEVICE}
load: serial
cat image.bin > $(SERIAL_DEVICE)
debug: serial
cat ${SERIAL_DEVICE}
## kernel
ucx: incl hal libs ddrivers kernel
mv *.o $(SRC_DIR)/build/kernel
$(AR) $(ARFLAGS) $(BUILD_TARGET_DIR)/libucxos.a \
$(BUILD_KERNEL_DIR)/*.o
kernel: timer.o event.o message.o pipe.o semaphore.o ecodes.o syscall.o ucx.o main.o
main.o: $(SRC_DIR)/init/main.c
$(CC) $(CFLAGS) $(SRC_DIR)/init/main.c
ucx.o: $(SRC_DIR)/kernel/ucx.c
$(CC) $(CFLAGS) $(SRC_DIR)/kernel/ucx.c
syscall.o: $(SRC_DIR)/kernel/syscall.c
$(CC) $(CFLAGS) $(SRC_DIR)/kernel/syscall.c
ecodes.o: $(SRC_DIR)/kernel/ecodes.c
$(CC) $(CFLAGS) $(SRC_DIR)/kernel/ecodes.c
semaphore.o: $(SRC_DIR)/kernel/semaphore.c
$(CC) $(CFLAGS) $(SRC_DIR)/kernel/semaphore.c
pipe.o: $(SRC_DIR)/kernel/pipe.c
$(CC) $(CFLAGS) $(SRC_DIR)/kernel/pipe.c
message.o: $(SRC_DIR)/kernel/message.c
$(CC) $(CFLAGS) $(SRC_DIR)/kernel/message.c
event.o: $(SRC_DIR)/kernel/event.c
$(CC) $(CFLAGS) $(SRC_DIR)/kernel/event.c
timer.o: $(SRC_DIR)/kernel/timer.c
$(CC) $(CFLAGS) $(SRC_DIR)/kernel/timer.c
libs: console.o libc.o dump.o malloc.o list.o queue.o
queue.o: $(SRC_DIR)/lib/queue.c
$(CC) $(CFLAGS) $(SRC_DIR)/lib/queue.c
list.o: $(SRC_DIR)/lib/list.c
$(CC) $(CFLAGS) $(SRC_DIR)/lib/list.c
malloc.o: $(SRC_DIR)/lib/malloc.c
$(CC) $(CFLAGS) $(SRC_DIR)/lib/malloc.c
dump.o: $(SRC_DIR)/lib/dump.c
$(CC) $(CFLAGS) $(SRC_DIR)/lib/dump.c
libc.o: $(SRC_DIR)/lib/libc.c
$(CC) $(CFLAGS) $(SRC_DIR)/lib/libc.c
console.o: $(SRC_DIR)/lib/console.c
$(CC) $(CFLAGS) $(SRC_DIR)/lib/console.c
## kernel + application link
link:
ifeq ('$(ARCH)', 'avr/atmega32')
$(LD) $(LDFLAGS) -o $(BUILD_TARGET_DIR)/image.elf $(BUILD_APP_DIR)/*.o -L$(BUILD_TARGET_DIR) -lucxos
else ifeq ('$(ARCH)', 'avr/atmega328p')
$(LD) $(LDFLAGS) -o $(BUILD_TARGET_DIR)/image.elf $(BUILD_APP_DIR)/*.o -L$(BUILD_TARGET_DIR) -lucxos
else ifeq ('$(ARCH)', 'avr/atmega2560')
$(LD) $(LDFLAGS) -o $(BUILD_TARGET_DIR)/image.elf $(BUILD_APP_DIR)/*.o -L$(BUILD_TARGET_DIR) -lucxos
else
$(LD) $(LDFLAGS) -T$(LDSCRIPT) -Map $(BUILD_TARGET_DIR)/image.map -o $(BUILD_TARGET_DIR)/image.elf $(BUILD_APP_DIR)/*.o -L$(BUILD_TARGET_DIR) -lucxos
endif
$(DUMP) --disassemble --reloc $(BUILD_TARGET_DIR)/image.elf > $(BUILD_TARGET_DIR)/image.lst
$(DUMP) -h $(BUILD_TARGET_DIR)/image.elf > $(BUILD_TARGET_DIR)/image.sec
$(DUMP) -s $(BUILD_TARGET_DIR)/image.elf > $(BUILD_TARGET_DIR)/image.cnt
$(OBJ) -O binary $(BUILD_TARGET_DIR)/image.elf $(BUILD_TARGET_DIR)/image.bin
$(OBJ) -R .eeprom -O ihex $(BUILD_TARGET_DIR)/image.elf $(BUILD_TARGET_DIR)/image.hex
$(SIZE) $(BUILD_TARGET_DIR)/image.elf
hexdump -v -e '4/1 "%02x" "\n"' $(BUILD_TARGET_DIR)/image.bin > $(BUILD_TARGET_DIR)/code.txt
## applications
delay: rebuild
$(CC) $(CFLAGS) -o $(BUILD_APP_DIR)/delay.o app/delay.c
@$(MAKE) --no-print-directory link
driver: rebuild
$(CC) $(CFLAGS) -o $(BUILD_APP_DIR)/driver.o app/driver/driver.c
$(CC) $(CFLAGS) -o $(BUILD_APP_DIR)/app.o app/driver/app.c
@$(MAKE) --no-print-directory link
echo: rebuild
$(CC) $(CFLAGS) -o $(BUILD_APP_DIR)/echo.o app/echo.c
@$(MAKE) --no-print-directory link
events: rebuild
$(CC) $(CFLAGS) -o $(BUILD_APP_DIR)/events.o app/events.c
@$(MAKE) --no-print-directory link
hello: rebuild
$(CC) $(CFLAGS) -o $(BUILD_APP_DIR)/hello.o app/hello.c
@$(MAKE) --no-print-directory link
hello_p: rebuild
$(CC) $(CFLAGS) -o $(BUILD_APP_DIR)/hello_preempt.o app/hello_preempt.c
@$(MAKE) --no-print-directory link
i2c_master: rebuild
$(CC) $(CFLAGS) -o $(BUILD_APP_DIR)/i2c_master.o app/i2c_master.c
@$(MAKE) --no-print-directory link
messages: rebuild
$(CC) $(CFLAGS) -o $(BUILD_APP_DIR)/messages.o app/messages.c
@$(MAKE) --no-print-directory link
messages_alloc: rebuild
$(CC) $(CFLAGS) -o $(BUILD_APP_DIR)/messages_alloc.o app/messages_alloc.c
@$(MAKE) --no-print-directory link
messages_simple: rebuild
$(CC) $(CFLAGS) -o $(BUILD_APP_DIR)/messages_simple.o app/messages_simple.c
@$(MAKE) --no-print-directory link
mutex: rebuild
$(CC) $(CFLAGS) -o $(BUILD_APP_DIR)/mutex.o app/mutex.c
@$(MAKE) --no-print-directory link
pipes: rebuild
$(CC) $(CFLAGS) -o $(BUILD_APP_DIR)/pipes.o app/pipes.c
@$(MAKE) --no-print-directory link
pipes_s: rebuild
$(CC) $(CFLAGS) -o $(BUILD_APP_DIR)/pipes_small.o app/pipes_small.c
@$(MAKE) --no-print-directory link
pipes_struct: rebuild
$(CC) $(CFLAGS) -o $(BUILD_APP_DIR)/pipes_struct.o app/pipes_struct.c
@$(MAKE) --no-print-directory link
prodcons: rebuild
$(CC) $(CFLAGS) -o $(BUILD_APP_DIR)/prodcons.o app/prodcons.c
@$(MAKE) --no-print-directory link
progress: rebuild
$(CC) $(CFLAGS) -o $(BUILD_APP_DIR)/progress.o app/progress.c
@$(MAKE) --no-print-directory link
spi_master: rebuild
$(CC) $(CFLAGS) -o $(BUILD_APP_DIR)/spi_master.o app/spi_master.c
@$(MAKE) --no-print-directory link
spi_slave: rebuild
$(CC) $(CFLAGS) -o $(BUILD_APP_DIR)/spi_slave.o app/spi_slave.c
@$(MAKE) --no-print-directory link
suspend: rebuild
$(CC) $(CFLAGS) -o $(BUILD_APP_DIR)/suspend.o app/suspend.c
@$(MAKE) --no-print-directory link
test64: rebuild
$(CC) $(CFLAGS) -o $(BUILD_APP_DIR)/test64.o app/test64.c
@$(MAKE) --no-print-directory link
test_fixed: rebuild
$(CC) $(CFLAGS) -o $(BUILD_APP_DIR)/test_fixed.o app/test_fixed.c
@$(MAKE) --no-print-directory link
test_fp: rebuild
$(CC) $(CFLAGS) -o $(BUILD_APP_DIR)/test_fp.o app/test_fp.c
@$(MAKE) --no-print-directory link
timer: rebuild
$(CC) $(CFLAGS) -o $(BUILD_APP_DIR)/timer.o app/timer.c
@$(MAKE) --no-print-directory link
timer2: rebuild
$(CC) $(CFLAGS) -o $(BUILD_APP_DIR)/timer2.o app/timer2.c
@$(MAKE) --no-print-directory link
timer_kill: rebuild
$(CC) $(CFLAGS) -o $(BUILD_APP_DIR)/timer_kill.o app/timer_kill.c
@$(MAKE) --no-print-directory link
scall_suspend: rebuild
$(CC) $(CFLAGS) -o $(BUILD_APP_DIR)/scall_suspend.o app/scall_suspend.c
@$(MAKE) --no-print-directory link
vt100_term: rebuild
$(CC) $(CFLAGS) -o $(BUILD_APP_DIR)/vt100_term.o app/vt100_term.c
@$(MAKE) --no-print-directory link
# clean and rebuild rules
rebuild:
find '$(BUILD_APP_DIR)' -type f -name '*.o' -delete
clean:
find '$(BUILD_APP_DIR)' '$(BUILD_KERNEL_DIR)' -type f -name '*.o' -delete
find '$(BUILD_TARGET_DIR)' -type f -name '*.o' -delete -o -name '*~' \
-delete -o -name 'image.*' -delete -o -name 'code.*' -delete
find '$(SRC_DIR)' -type f -name '*.o' -delete
veryclean: clean
echo "ARCH = none" > $(BUILD_TARGET_DIR)/target.mak
find '$(BUILD_TARGET_DIR)' -type f -name '*.a' -delete