-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
117 lines (94 loc) · 3.99 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
PROG = p3
CFLAGS = -Werror -Wall -O0 -g -std=c11
C_FILES=${wildcard *.c}
O_FILES=${subst .c,.o,${C_FILES}}
FUN_FILES=${sort ${wildcard *.fun}}
TEST_NAMES=${subst .fun,,${FUN_FILES}}
TEST_S=${addsuffix .s,${TEST_NAMES}}
TEST_RUNS=${addsuffix .run,${TEST_NAMES}}
TEST_OUTS=${addsuffix .out,${TEST_NAMES}}
TEST_DIFFS=${addsuffix .diff,${TEST_NAMES}}
TEST_RESULTS=${addsuffix .result,${TEST_NAMES}}
TEST_TESTS=${addsuffix .test,${TEST_NAMES}}
all : ${PROG};
${PROG} : Makefile ${O_FILES}
@-rm -f $*
-gcc ${CFLAGS} -o $@ ${O_FILES}
${O_FILES} : %.o : Makefile %.c
@-rm -f $*.o
-gcc ${CFLAGS} -c -MMD -o $*.o $*.c
${TEST_S} : %.s : Makefile ${PROG} %.fun
./p3 < $*.fun > $*.s
${TEST_RUNS} : %.run : Makefile %.s
gcc -g -o $*.run -static $*.s
${TEST_OUTS} : %.out : Makefile %.run
@echo "failed to run" > $*.out
@rm -f $*.err
(/usr/bin/time --quiet -o $*.time -f "%E" timeout 7 ./$*.run > $*.out 2> $*.err); if [ $$? -eq 124 ]; then echo "timeout" > $*.time; fi
${TEST_DIFFS} : %.diff : Makefile %.out %.ok
@echo "failed to diff" > $*.diff
-diff -a $*.out $*.ok > $*.diff 2>&1 || true
${TEST_RESULTS} : %.result : Makefile %.diff
@echo "fail" > $*.result
(test \! -s $*.diff && echo "pass" > $*.result) || true
${TEST_TESTS} : %.test : Makefile %.result
@echo "$* ... `cat $*.result` [`cat $*.time`]"
test : ${TEST_TESTS};
clean:
-rm -rf ${PROG} *.out *.diff *.result *.d *.o *.time *.err
-include *.d
######### remote things ##########
ORIGIN_URL ?= ${shell git config --get remote.origin.url}
ORIGIN_REPO = ${shell echo ${ORIGIN_URL} | sed -e 's/.*://'}
STUDENT_NAME = ${shell echo ${ORIGIN_REPO} | sed -e 's/.*_//'}
PROJECT_NAME = ${shell echo ${ORIGIN_REPO} | sed -e 's/_${STUDENT_NAME}$$//'}
GIT_SERVER = ${shell echo ${ORIGIN_URL} | sed -e 's/:.*//'}
origin:
@echo "repo : ${ORIGIN_REPO}"
@echo "project : ${PROJECT_NAME}"
@echo "students : ${STUDENT_NAME}"
@echo "server : ${GIT_SERVER}"
get_tests:
test -d all_tests || git clone ${GIT_SERVER}:${PROJECT_NAME}__tests all_tests
(cd all_tests ; git pull)
@echo ""
@echo "Tests copied to all_tests (cd all_tests)"
@echo " Please don't add the all_tests directory to git"
@echo ""
get_summary:
test -d all_results || git clone ${GIT_SERVER}:${PROJECT_NAME}__results all_results
(cd all_results ; git pull)
python tools/summarize.py all_results
get_results:
test -d my_results || git clone ${GIT_SERVER}:${PROJECT_NAME}_${STUDENT_NAME}_results my_results
(cd my_results ; git pull)
@(cd my_results; \
for i in *.result; do \
name=$$(echo $$i | sed -e 's/\..*//'); \
echo "$$name `cat $$name.result` `cat $$name.time`"; \
done; \
echo ""; \
echo "`grep pass *.result | wc -l` / `ls *.result | wc -l`"; \
)
@echo ""
@echo "More details in my_results (cd my_results)"
@echo " Please don't add my_results directory to git"
@echo ""
get_submission:
test -d my_submission || git clone ${GIT_SERVER}:${PROJECT_NAME}_${STUDENT_NAME} my_submission
(cd my_submission && git pull)
@echo ""
@echo "A fresh copy of your submission is in my_submissions"
@echo " Please don't add my_submission to git"
@echo " Please don't do any development in my_submission"
@echo " It is here to help you view what you've submitted"
@echo ""
diff_submission: clean get_submission
@echo "======================================================================"
@echo "Here are the differences between what you have and what the server has"
@echo " More details in my_submission "
@echo " Please remember that the server will replace some of your files "
@echo " before running your code. Those changes are not shown here. "
@echo "======================================================================"
@diff -rqyl . my_submission --exclude=.git --exclude=my_submission || true
@echo ""