-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
144 lines (113 loc) · 3.37 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# Makefile for quick compile run
# call make DAY=x for a specific puzzle
# See 'make help' for a list of useful targets
# ==================================================
# Constants
# ===================================================
DAY = 12
YEAR = 2024
PART = 1
OCAMLC = ocamlopt -I +str str.cmxa -O2
RUSTC = rustc --cfg 'part="$(PART)"'
CARGO = cargo
DIR = $(YEAR)/$(DAY)
TARGET = $(DIR)/puzzle
EXE = $(TARGET).exe
DEBUG = on
TIME = time -f "Stats:\n Total time: %E\n CPU: %P\n Memory (kB): %M"
# set to ON/OFF to toggle ANSI escape sequences
COLOR = ON
# Uncomment to show commands
# VERBOSE = TRUE
# padding for help on targets
# should be > than the longest target
HELP_PADDING = 15
# ==================================================
# Make code and variable setting
# ==================================================
ifeq ($(DEBUG),on)
CARGO_TGT = ./target/debug/puzzle
CARGO_BUILD = $(CARGO) build
else
CARGO_TGT = ./target/release/puzzle
CARGO_BUILD = $(CARGO) build --release
endif
ifeq ($(COLOR),ON)
color_yellow = \033[93;1m
color_orange = \033[33m
color_red = \033[31m
color_green = \033[32m
color_blue = \033[34;1m
color_reset = \033[0m
endif
define print
@echo "$(color_yellow)$(1)$(color_reset)"
endef
# =================================================
# Default target
# =================================================
default: run-test
.PHONY: default
# =================================================
# Specific rules
# =================================================
ifeq ($(YEAR),2022)
EXT = ml
$(EXE): $(TARGET).ml
$(call print,Compiling $< with ocaml)
$(OCAMLC) $< -o $@
else
ifeq ($(YEAR),2023)
EXT = rs
$(EXE): $(CARGO_TGT)
cp "$(CARGO_TGT)" "$(EXE)"
$(CARGO_TGT): $(TARGET).rs cargo
$(call print,Compiling $< with rust)
$(CARGO_BUILD)
# $(EXE): $(TARGET).rs
# $(call print,Compiling $< with rust)
# $(RUSTC) $< -o $@
else
EXT = ml
$(EXE): $(TARGET).ml
$(call print,Compiling $< with ocaml)
$(OCAMLC) $< -o $@
endif
endif
# =================================================
# Special Targets
# =================================================
# No display of executed commands.
$(VERBOSE).SILENT:
.PHONY: cargo
cargo:
sed -i '8s#.*#path = "$(YEAR)/$(DAY)/puzzle.rs"#' Cargo.toml
.PHONY: compile
compile: $(EXE) ## Compile the given puzzle
.PHONY: run-test
run-test: $(EXE) ## Compile and run with test data
$(call print,Running $< with test data)
$(TIME) ./$(EXE) < $(TARGET)_test.txt
.PHONY: run
run: $(EXE) ## Compile and run with input data
$(call print,Running $< with input data)
$(TIME) ./$(EXE) < $(TARGET)_data.txt
.PHONY: clean
clean: ## Remove build files and executables
$(call print,Deleting build files and executables)
find . -type f -name '*.exe' -delete
find . -type f -name '*.cmo' -delete
find . -type f -name '*.cmi' -delete
find . -type f -name '*.o' -delete
find . -type f -name '*.cmx' -delete
.PHONY: help
help: ## Show this help
@echo "$(color_yellow)make:$(color_reset) list of useful targets:"
@egrep -h '\s##\s' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " $(color_blue)%-$(HELP_PADDING)s$(color_reset) %s\n", $$1, $$2}'
.PHONY: init
init: ## Create files for the new day
$(call print,Creating files for day $(DAY))
mkdir $(DIR)
echo "(* ==== Puzzle $(DAY) : https://adventofcode.com/$(YEAR)/day/$(DAY) ==== *)" > $(TARGET).$(EXT)
touch $(TARGET)_data.txt
touch $(TARGET)_test.txt