-
Notifications
You must be signed in to change notification settings - Fork 65
/
Makefile
71 lines (56 loc) · 1.59 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
TARGET = mzcc
CFLAGS = -Wall -Werror -std=gnu99 -g -I.
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
CFLAGS += -no-pie
endif
SHELL_HACK := $(shell echo CBUILD=\"$(CC) $(CFLAGS)\" > .cbuild)
# Control the build verbosity
# `make V=1` is equal to `make VERBOSE=1`
ifeq ("$(origin V)", "command line")
VERBOSE = $(V)
endif
ifeq ("$(VERBOSE)","1")
Q :=
VECHO = @true
else
Q := @
VECHO = @printf
endif
OBJS = lexer.o codegen_x64.o parser.o verbose.o main.o
deps := $(OBJS:%.o=.%.o.d)
%.o: %.c
$(VECHO) " CC\t$@\n"
$(Q)$(CC) -o $@ $(CFLAGS) -c -MMD -MF [email protected] $<
$(TARGET): $(OBJS)
$(VECHO) " LD\t$@\n"
$(Q)$(CC) $(CFLAGS) -o $@ $^
TESTS := $(patsubst %.c,%.bin,$(wildcard tests/*.c))
PASS_COLOR = \e[32;01m
NO_COLOR = \e[0m
pass = printf "[ $(PASS_COLOR)Passed$(NO_COLOR) ]\n"
check: nqueen $(TESTS)
@echo
@for test in $(TESTS); do \
printf "*** verify $$test ***\n" ; \
head -n 1 `echo $$test | sed s/.bin/.c/`; \
./$$test; \
$(call pass,$$test); \
echo; \
done
tests/driver.sh
tests/%.s: tests/%.c $(TARGET)
./mzcc -o $@ $<
tests/%.bin: tests/%.s $(TARGET)
$(VECHO) " CC\t$@\n"
$(Q)$(CC) $(CFLAGS) -o $@ $<
nqueen: sample/nqueen.c $(TARGET)
$(VECHO) " MazuCC\t$<\n"
$(Q)./mzcc -o ${<:.c=.s} $<
$(VECHO) " AS+LD\t\t$@\n"
$(Q)$(CC) $(CFLAGS) -o sample/nqueen sample/nqueen.s
.PHONY: clean check
clean:
$(RM) $(TARGET) $(TESTS) $(OBJS) $(deps) .cbuild
$(RM) sample/*.o sample/nqueen.s sample/nqueen
-include $(deps)