-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
83 lines (73 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
73
74
75
76
77
78
79
80
81
82
83
CONFIG=config.txt
include $(CONFIG)
ifeq ($(patsubst %.c,,$(SOURCE)),)
TARGET := ./target
COMMAND := $(TARGET)
$(TARGET): $(SOURCE)
gcc -O3 -ansi -Wall $< -o $@ -lm
endif
ifeq ($(patsubst %.cpp,,$(SOURCE)),)
TARGET := ./target
COMMAND := $(TARGET)
$(TARGET): $(SOURCE)
g++ -std=c++11 -O3 -Wall $< -o $@ -lm
endif
ifeq ($(patsubst %.rs,,$(SOURCE)),)
TARGET := ./target
COMMAND := $(TARGET)
$(TARGET): $(SOURCE)
rustc --edition=2021 -C opt-level=3 -o $@ $<
endif
ifeq ($(patsubst %.java,,$(SOURCE)),)
TARGET := $(patsubst %.java, %.class, $(SOURCE))
COMMAND := java -Xss32m -Xmx256 -cp $$(dirname $(SOURCE)) $(patsubst %.java, %, $(SOURCE))
$(TARGET): $(SOURCE)
javac $<
endif
ifeq ($(patsubst %.py,,$(SOURCE)),)
TARGET :=
COMMAND := python $(SOURCE)
$(TARGET): $(SOURCE)
endif
ccred := \033[0;31m\033[1m
ccgreen := \033[0;32m\033[1m
ccend := \033[0m
TEST_FOLDER := tests/proj2
TESTS := $(sort $(shell find $(TEST_FOLDER) -type f -name '*.in'))
TESTS_NUM = $(shell find $(TEST_FOLDER) -type f -name '*.in' | wc -l)
TESTS_FAIL = $$(find $(TEST_FOLDER) -type f -name '*.diff' | wc -l)
.DEFAULT_GOAL := all
.PHONY: all clean force
all: clean_tests $(TARGET) $(TESTS)
@printf "\n\n"
@if [ $(TESTS_FAIL) -gt 0 ]; \
then \
printf "$(ccred)Failed Tests:$(ccend)\n"; \
cat failed_tests.txt; \
printf "Tests Passed $(ccred)[$$(($(TESTS_NUM) - $(TESTS_FAIL)))/$(TESTS_NUM)]$(ccend)\n"; \
else \
printf "Tests Passed $(ccgreen)[$$(($(TESTS_NUM) - $(TESTS_FAIL)))/$(TESTS_NUM)]$(ccend)\n"; \
fi
# Compare test results
tests/%.in: force tests/%.out
@-$(COMMAND) < tests/$*.in > tests/$*.outhyp
@-if (diff -iw -B --color tests/$*.outhyp tests/$*.out) > /dev/null; \
then \
printf "$* $(ccgreen)PASSED$(ccend).\n"; \
else \
printf "$* $(ccred)FAILED$(ccend).\n"; \
(diff -iwu -B --color tests/$*.outhyp tests/$*.out || touch tests/$*.diff) 2> /dev/null; \
(diff -iwu -B --color tests/$*.outhyp tests/$*.out > tests/$*.diff || touch tests/$*.diff) 2> /dev/null; \
echo $* >> failed_tests.txt; \
fi
@echo
clean: clean_tests
@$(RM) target
clean_tests:
@$(RM) $$(find tests -type f -name '*.diff')
@$(RM) $$(find tests -type f -name '*.outhyp')
@$(RM) failed_tests.txt
$(SOURCE):
$(error Could not find file in $(SOURCE))
# Force target to run
force: