-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
92 lines (79 loc) · 3.58 KB
/
Copy pathMakefile
File metadata and controls
92 lines (79 loc) · 3.58 KB
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
# Competitive-programming task runner. See `make help`.
.DEFAULT_GOAL := help
.PHONY: help compile run clean contest list store add remove problems
PLATFORM ?= codeforces
CONTEST ?=
PROBLEMS ?=
PROBLEM ?=
# Also accept `make contest 2112` in addition to `make contest CONTEST=2112`.
contest_goal := $(word 2,$(MAKECMDGOALS))
ifeq ($(filter contest,$(MAKECMDGOALS)),contest)
ifeq ($(strip $(CONTEST)),)
CONTEST := $(contest_goal)
endif
ifneq ($(contest_goal),)
.PHONY: $(contest_goal)
$(contest_goal):
@:
endif
endif
help:
@printf '%s\n' \
'Competitive programming workspace' \
'' \
'Usage:' \
' make contest new # interactively create a contest' \
' make contest 2112' \
' make compile PROBLEM=contests/codeforces/2112/A' \
' make run # choose root or a contest problem' \
' make add # add a problem while in contest mode' \
' make remove # remove a problem while in contest mode' \
' make store # save the root Main.java as a named reference' \
'' \
'Targets:' \
' help Show this help.' \
' contest Create a contest with `new`, or enter an existing contest.' \
' compile Compile Main.java in PROBLEM to .build/.' \
' run Interactively compile and run; write output.txt.' \
' add Create a contest problem from boilerplate (contest mode only).' \
' remove Remove a contest problem after confirmation (contest mode only).' \
' problems List problem folders in the active contest (contest mode only).' \
' store Save the root Main.java under store/<PascalCaseName>.java.' \
' list List created problem directories.' \
' clean Remove builds and reset the root Main.java to boilerplate.' \
'' \
'Variables:' \
' PLATFORM Contest platform (default: codeforces).' \
' CONTEST Contest slug, such as 2112 (for contest mode or creation).' \
' PROBLEMS Comma-separated labels, such as A,B,C.' \
' PROBLEM Path to one problem directory.'
contest:
@if [ "$(CONTEST)" = "new" ]; then \
./scripts/new-contest.sh --platform "$(PLATFORM)"; \
else \
test -n "$(CONTEST)" || { echo 'Choose a contest, e.g. make contest 2112, or create one with make contest new'; exit 2; }; \
./scripts/contest-mode.sh --platform "$(PLATFORM)" --contest "$(CONTEST)"; \
fi
compile:
@test -n "$(PROBLEM)" || { echo 'Set PROBLEM, e.g. make compile PROBLEM=contests/codeforces/2112/A'; exit 2; }
@test -f "$(PROBLEM)/Main.java" || { echo "Missing $(PROBLEM)/Main.java"; exit 2; }
@mkdir -p "$(PROBLEM)/.build"
@javac -encoding UTF-8 -d "$(PROBLEM)/.build" "$(PROBLEM)/Main.java"
@echo "Compiled $(PROBLEM)/Main.java"
run:
@./scripts/run-problem.sh $(if $(PROBLEM),--problem "$(PROBLEM)",) $(if $(CP_CONTEST_DIR),--contest-dir "$(CP_CONTEST_DIR)",)
store:
@./scripts/store-solution.sh
add:
@./scripts/manage-problem.sh add $(if $(CP_CONTEST_DIR),--contest-dir "$(CP_CONTEST_DIR)",) $(if $(PROBLEM),--problem "$(PROBLEM)",)
remove:
@./scripts/manage-problem.sh remove $(if $(CP_CONTEST_DIR),--contest-dir "$(CP_CONTEST_DIR)",) $(if $(PROBLEM),--problem "$(PROBLEM)",) $(if $(FORCE),--force,)
problems:
@./scripts/manage-problem.sh list $(if $(CP_CONTEST_DIR),--contest-dir "$(CP_CONTEST_DIR)",)
list:
@if [ -d contests ]; then find contests -type f -name Main.java -print | sed 's|/Main.java$$||' | sort; else echo 'No contests created yet.'; fi
clean:
@find contests -type d -name .build -prune -exec rm -rf {} + 2>/dev/null || true
@rm -rf .build
@cp templates/java/boilerplate/Main.java Main.java
@echo 'Removed generated builds and reset Main.java from the boilerplate.'