-
Notifications
You must be signed in to change notification settings - Fork 0
/
After.mk
38 lines (27 loc) · 878 Bytes
/
After.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
PEG_CHALS_DIR := $(DIR)
ifndef SERVER
SERVER :=
endif
.PHONY: solve
#####
# solve_rule($1: challenge name)
#####
define _solve_rule
$1+PEG_FILES := $$(patsubst %.ear,%.peg,$$(wildcard $(PEG_CHALS_DIR)/$1/*.ear))
ifdef $(PEG_CHALS_DIR)/$1+DOCKER_PORTS
$1+PORT_ARG := PORT="$$($(PEG_CHALS_DIR)/$1+DOCKER_PORTS)"
else
$1+PORT_ARG :=
endif
.PHONY: solve[$1]
solve[$1]: $$($1+PEG_FILES)
$$(_v)cd $$(PEG_CHALS_DIR)/$1 && PATH="$$(PEG_PATH)" $$($1+PORT_ARG) SERVER="$$(SERVER)" ./solve | diff -w flag.txt - && echo 'SOLVE $1 PASS' || (echo 'SOLVE $1 FAIL'; cat solve.out)
solve: solve[$1]
.PHONY: clean[$1]
clean[$1]:
$(_v)rm -f $$($1+PEG_FILES)
clean:: clean[$1]
endef #_solve_rule
solve_rule = $(eval $(call _solve_rule,$1))
PEG_CHALS := $(patsubst $(PEG_CHALS_DIR)/%/solve,%,$(wildcard $(PEG_CHALS_DIR)/*/solve))
$(foreach chal,$(PEG_CHALS),$(call solve_rule,$(chal)))