forked from jserv/amacc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
72 lines (63 loc) · 2.25 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
CFLAGS = -O0 -Wall -Wno-misleading-indentation
OBJ_DIR = elf
TEST_DIR = tests
TEST_SRC = $(wildcard $(TEST_DIR)/*.c)
TEST_OBJ = $(TEST_SRC:.c=.o)
BIN = amacc
EXEC = $(BIN) $(BIN)-native
include mk/arm.mk
include mk/common.mk
include mk/python.mk
## Build AMaCC
all: $(EXEC)
$(BIN): $(BIN).c
$(VECHO) " CC+LD\t\t$@\n"
$(Q)$(ARM_CC) $(CFLAGS) -o $@ $< -g -ldl
$(BIN)-native: $(BIN).c
$(VECHO) " CC+LD\t\t$@\n"
$(Q)$(CC) $(CFLAGS) -o $@ $< \
-Wno-pointer-to-int-cast -Wno-int-to-pointer-cast -Wno-format \
-ldl
## Run tests and show message
check: $(EXEC) $(TEST_OBJ)
$(VECHO) "[ C to IR translation ]"
$(Q)./$(BIN)-native -s tests/arginc.c | diff tests/arginc.list - \
&& $(call pass)
$(VECHO) "[ JIT compilation + execution ]"
$(Q)if [ "$(shell $(ARM_EXEC) ./$(BIN) tests/hello.c)" = "hello, world" ]; then \
$(call pass); \
fi
$(VECHO) "[ ELF generation ]"
$(Q)$(ARM_EXEC) ./$(BIN) -o $(OBJ_DIR)/hello tests/hello.c
$(Q)if [ "$(shell $(ARM_EXEC) $(OBJ_DIR)/hello)" = "hello, world" ]; then \
$(call pass); \
fi
$(VECHO) "[ nested/self compilation ]"
$(Q)if [ "$(shell $(ARM_EXEC) ./$(BIN) $(BIN).c tests/hello.c)" = "hello, world" ]; then \
$(call pass); \
fi
$(VECHO) "[ Compatibility with GCC/Arm ] "
$(Q)$(PYTHON) runtest.py || echo
$(OBJ_DIR)/$(BIN): $(BIN)
$(VECHO) " SelfCC\t$@\n"
$(Q)$(ARM_EXEC) ./$^ -o $@ $(BIN).c
SHELL_HACK := $(shell mkdir -p $(OBJ_DIR))
$(TEST_DIR)/%.o: $(TEST_DIR)/%.c $(BIN) $(OBJ_DIR)/$(BIN)
$(VECHO) "[*** verify $< <JIT> *******]\n"
$(Q)$(ARM_EXEC) ./$(BIN) $< 2 $(REDIR)
$(VECHO) "[*** verify $< <ELF> *******]\n"
$(Q)$(ARM_EXEC) ./$(BIN) -o $(OBJ_DIR)/$(notdir $(basename $<)) $< $(REDIR)
$(Q)$(ARM_EXEC) $(OBJ_DIR)/$(notdir $(basename $<)) 2 $(REDIR)
$(VECHO) "[*** verify $< <ELF-self> **]\n"
$(Q)$(ARM_EXEC) ./$(OBJ_DIR)/$(BIN) $< 2 $(REDIR)
$(Q)$(call pass,$<)
## Print available build targets
help:
@cat $(MAKEFILE_LIST) | \
awk '/^##.*$$/{l1=$$0;getline;l2=(l1 "##" $$0); print l2 $$0}' | awk -F"##" '{split($$3,t,":");printf "\033[36m%-11s\033[0m %s\n",t[1],$$2}'
## Dump assembly from source file. Usage: "make dump-ir FILE=tests/hello.c"
dump-ir: $(BIN)
@$(ARM_EXEC) $(BIN) -s $(FILE)
## Remove all generated files
clean:
$(RM) $(EXEC) $(OBJ_DIR)/* elf/* out-gcc/*