-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExercise.mk
66 lines (57 loc) · 1.65 KB
/
Exercise.mk
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
CFILES=$(wildcard *.c)
TESTDIR=tests/
TESTS=$(wildcard $(TESTDIR)*.tin)
TEST_RESULTS=$(patsubst %.tin,%.res,$(TESTS))
CC=gcc
CFLAGS=-Wall -Wextra -Werror -ggdb -std=c89
ANSI_COLORS=$(shell tput colors 2>/dev/null)
ifeq ($(ANSI_COLORS),$(filter $(ANSI_COLORS),8 16 88 256))
ANSIRED="\033[31m"
ANSIGREEN="\033[32m"
ANSIYELLOW="\033[33m"
ANSIBOLD="\033[1m"
ANSIRST="\033[0m"
DIFFCOLOR="always"
else
ANSIRED=""
ANSIGREEN=""
ANSIYELLOW=""
ANSIBOLD=""
ANSIRST=""
DIFFCOLOR="never"
endif
ANSIGOK=" ["$(ANSIGREEN)"OK"$(ANSIRST)"] "
ANSIYBIN=$(ANSIYELLOW)$(BINARY)$(ANSIRST)
MAKEFLAGS+=--silent
all: $(BINARY)
$(BINARY): $(CFILES)
echo -n " - Building "$(ANSIYBIN)":"
$(CC) $(CFLAGS) -o $@ $^ $(LFLAGS)
echo $(ANSIGOK)
check: $(TEST_RESULTS)
echo "** "$(ANSIBOLD)$(ANSIYBIN)" test results:"$(ANSIBOLD)$(ANSIGOK)
%.res: TESTNAME=$(strip $(patsubst $(TESTDIR)%.tin,%,$?))
%.res: TESTARGS=$$(cat $(strip $(patsubst %.tin,%.targs,$?)) 2>/dev/null)
%.res: TESTOUT=$(strip $(patsubst %.tin,%.tout,$?))
%.res: TESTERR=$(strip $(patsubst %.tin,%.terr,$?))
%.res: %.tin
echo -n " - testing "$(ANSIBOLD)$(BINARY)$(ANSIRST)":" \
$(ANSIYELLOW)$(TESTNAME)$(ANSIRST)
ifeq (,$(wildcard $(BINARY)))
echo "\n"$(ANSIRED)"Error! "$(ANSIBOLD)"./"$(BINARY)$(ANSIRST)$(ANSIRED)" not found." \
"Please 'make'."$(ANSIRST)
false
else
./$(BINARY) $(TESTARGS) <$? >$@ult 2>$@ult_err || true
diff --color=$(DIFFCOLOR) --text $@ult $(TESTOUT)
if [ -f $(strip $(TESTERR)) ]; then \
diff --color=$(DIFFCOLOR) --text $@ult_err $(TESTERR); \
fi
echo $(ANSIGOK)
endif
clean:
echo -n " - Cleaning "$(ANSIYBIN)":"
rm -f $(BINARY)
rm -f $(TESTDIR)*.result
rm -f $(TESTDIR)*.result_err
echo $(ANSIGOK)