forked from sysprog21/shecc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
73 lines (57 loc) · 1.79 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
CC ?= gcc
CFLAGS := -O -g \
-ansi -pedantic \
-Wall -Wextra
include mk/common.mk
include mk/arm.mk
STAGE0 := shecc
STAGE1 := shecc-stage1.elf
STAGE2 := shecc-stage2.elf
OUT ?= out
SRCDIR := $(shell find src -type d)
LIBDIR := $(shell find lib -type d)
SRCS := $(wildcard $(patsubst %,%/main.c, $(SRCDIR)))
OBJS := $(SRCS:%.c=$(OUT)/%.o)
deps := $(OBJS:%.o=%.o.d)
TESTS := $(wildcard tests/*.c)
TESTBINS := $(TESTS:%.c=$(OUT)/%.elf)
all: bootstrap
$(OUT)/tests/%.elf: tests/%.c $(OUT)/$(STAGE0)
$(VECHO) " SHECC\t$@\n"
$(Q)$(OUT)/$(STAGE0) --dump-ir -o $@ $< > $(basename $@).log ; \
chmod +x $@ ; $(PRINTF) "Running $@ ...\n"
$(Q)$(ARM_EXEC) $@ && $(call pass)
check: $(TESTBINS) tests/driver.sh
tests/driver.sh
$(OUT)/%.o: %.c
$(VECHO) " CC\t$@\n"
$(Q)$(CC) -o $@ $(CFLAGS) -c -MMD -MF [email protected] $<
SHELL_HACK := $(shell mkdir -p $(OUT) $(OUT)/$(SRCDIR) $(OUT)/tests)
$(OUT)/libc.inc: $(OUT)/inliner $(LIBDIR)/c.c
$(VECHO) " GEN\t$@\n"
$(Q)$(OUT)/inliner $(LIBDIR)/c.c $@
$(OUT)/inliner: tools/inliner.c
$(VECHO) " CC+LD\t$@\n"
$(Q)$(CC) $(CFLAGS) -o $@ $^
$(OUT)/$(STAGE0): $(OUT)/libc.inc $(OBJS)
$(VECHO) " LD\t$@\n"
$(Q)$(CC) $(OBJS) -o $@
$(OUT)/$(STAGE1): $(OUT)/$(STAGE0)
$(VECHO) " SHECC\t$@\n"
$(Q)$(OUT)/$(STAGE0) --dump-ir -o $@ $(SRCDIR)/main.c > $(OUT)/shecc-stage1.log
$(Q)chmod a+x $@
$(OUT)/$(STAGE2): $(OUT)/$(STAGE1)
$(VECHO) " SHECC\t$@\n"
$(Q)$(ARM_EXEC) $(OUT)/$(STAGE1) -o $@ $(SRCDIR)/main.c
bootstrap: $(OUT)/$(STAGE2)
$(Q)if ! diff -q $(OUT)/$(STAGE1) $(OUT)/$(STAGE2); then \
echo "Unable to bootstrap. Aborting"; false; \
fi
.PHONY: clean
clean:
-$(RM) $(OUT)/$(STAGE0) $(OUT)/$(STAGE1) $(OUT)/$(STAGE2)
-$(RM) $(OBJS) $(deps)
-$(RM) $(TESTBINS) $(OUT)/tests/*.log $(OUT)/tests/*.lst
-$(RM) $(OUT)/shecc*.log
-$(RM) $(OUT)/inliner $(OUT)/libc.inc
-include $(deps)