-
Notifications
You must be signed in to change notification settings - Fork 100
/
Copy pathMakefile
51 lines (44 loc) · 1.29 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
SOURCES:=$(wildcard */*.c)
BINARIES:=$(SOURCES:.c=)
.PHONY: all clean test debug
all: $(BINARIES)
%: %.c
clang -g -DONLINE_JUDGE -Wall -std=c99 -pipe $< -lm -o $@
clean:
rm -f $(BINARIES)
test:
@mkdir -p temp; \
tracked_files=$$(git ls-tree --name-only HEAD PAT*/); \
for bin in $(BINARIES); do \
[ "$$tracked_files" = "$${tracked_files%$$bin*}" ] && continue; \
dir=$$(dirname "$$bin"); \
id=$$(basename "$$bin"); \
case "$$dir" in \
PATAdvanced) cat=a;; \
PATBasic) cat=b;; \
PATTop) cat=t;; \
esac; \
for sample in "samples/$$cat$$id-"*.in; do \
echo "testing $$bin, sample $$sample"; \
printf "%s" "$$("$$dir/$$id" < "$$sample" | tr -d '\0')" > temp/out; \
printf "%s" "$$(cat "$${sample%.in}.out")" > temp/ans; \
diff temp/out temp/ans || failed="$$failed$$bin $$sample\n"; \
done; \
done; \
rm -r temp
@str_check_output="Scroll back for answer and actuall output"; \
cred="\033[1;31m"; \
cgreen="\033[1;32m"; \
creset="\033[1;0m"; \
if [ -n "$$failed" ]; then \
printf "$$failed%s" | while read -r b s; do \
printf "$$cred%s failed for sample %s$$creset\n" "$$b" "$$s"; \
done; \
printf "$$cred%s$$creset\n" "$$str_check_output"; \
exit 1; \
else \
printf "$$cgreen%s$$creset\n" "All passed!"; \
fi
debug:
@echo $(SOURCES)
@echo $(BINARIES)