-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
77 lines (61 loc) · 2.08 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
ifeq ($(CC), cc)
CC := tools/clang
endif
ifeq ($(AS), as)
AS := tools/assembler
endif
ASFLAGS += --remove-unused
CPPFLAGS += -MP -MD
CFLAGS += -ccc-host-triple dcpu16 -Oz -Weverything -fcolor-diagnostics -std=c11 -I src -I include
rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
C_FILES := $(call rwildcard,src/,*.c)
DASM_FILES := src/kernel/scheduler/scheduler_switch.dasm \
src/kernel/interrupt_handler/interrupt_handler_asm.dasm
CASM_FILES := $(patsubst src/%,bin/%,$(C_FILES:.c=.s))
ASM_FILES := $(patsubst src/%,bin/%,$(DASM_FILES:.dasm=.s))
BIN ?= bin/FrOSt.bin
BIN_HEADER ?= bin/FrOSt_header.bin
TARGETS := $(BIN) $(BIN_HEADER)
all: $(CASM_FILES) $(TARGETS)
-include $(ASM_FILES:.s=.d)
tools/assembler tools/DCPU-Toolchain.jar:
@echo "Downloading the toolchain..."
@cd tools; ./download-toolchain.sh
$(BIN_HEADER): bin/FrOSt_header.s
$(BIN): bin/prelude.s bin/FrOSt.s $(ASM_FILES)
$(TARGETS): $(AS)
@mkdir -p $(@D)
@echo "AS $@"
@cat $(filter %.s,$^) > [email protected]
@$(COMPILE.s) [email protected] --symbols [email protected] $(OUTPUT_OPTION)
bin/prelude.s:
@mkdir -p bin
@echo -e "\tSET\tPC, main" > $@
bin/FrOSt.c: $(C_FILES)
@for file in $^; do echo "#include \"../$$file\""; done > bin/FrOSt.c
bin/FrOSt.s: bin/FrOSt.c Makefile $(CC)
@echo "CC $<"
@# No shadow since we cat all the c files in one file. That's why we also
@# build the individual .c files
@$(COMPILE.c) -Wno-shadow -o $@ -S $<
@sed -i -re 's/rfi/rfi 0/i' $@
@sed -i -re "s/_L/_$(shell echo $@ | sed -re 's|/|_|g')/" $@
@sed -i -re 's/\b(_[a-zA-Z0-9_]+\.s[A-Z]+[0-9]+_[0-9]+)/.\1/g' $@
bin/%.s: src/%.c Makefile $(CC)
@mkdir -p $(@D)
@echo "CC $@"
@$(COMPILE.c) -o $@ -S $<
@sed -i -re 's/rfi/rfi 0/i' $@
@sed -i -re "s/_L/_$(shell echo $@ | sed -re 's|/|_|g')/" $@
bin/%.s: src/%.dasm Makefile
@mkdir -p $(@D)
@cp -f $< $@
run: all tools/DCPU-Toolchain.jar
cd tools && ./run.sh
clean:
rm -rf bin/
cleanall:
rm -rf bin/ tools/assembler tools/emulator tools/DCPU-Toolchain* tools/native
format:
find src -name "*.c" -exec clang-format -i --style=file {} \;
.PHONY: all clean run