forked from burton-aad/adventofcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrules.mk
45 lines (34 loc) · 1.04 KB
/
rules.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
39
40
41
42
43
44
45
SRC_CPP := $(wildcard *.cpp)
BIN_CPP := $(basename $(SRC_CPP))
SRC_RS := $(wildcard *.rs)
BIN_RS := $(basename $(SRC_RS))
SRC_CARGO := $(wildcard */Cargo.toml)
CARGO_FOLDER := $(SRC_CARGO:/Cargo.toml=)
CXXFLAGS := -std=c++11
.DEFAULT_GOAL := all
define create_target_cpp
$(1): $(1).o
g++ -o $$@ $$< $$(LDFLAGS)
endef
define create_target_cargo
BIN_CARGO += $(addprefix $(1),$(addprefix /target/debug/,$(1)))
$$(lastword $$(BIN_CARGO)): $(wildcard $(1)/src/*.rs) $(1)/Cargo.toml
cargo build --manifest-path $$?
touch $$@
endef
define create_target_rs
$(1): $(1).rs
rustc $$<
endef
$(foreach jour, $(BIN_CPP), $(eval $(call create_target_cpp, $(jour))))
$(foreach jour, $(CARGO_FOLDER), $(eval $(call create_target_cargo, $(jour))))
$(foreach jour, $(BIN_RS), $(eval $(call create_target_rs, $(jour))))
.PHONY: all
all: $(BIN_CPP) $(BIN_CARGO) $(BIN_RS)
%.o: %.cpp
g++ $(CXXFLAGS) -o $@ -c $<
.PHONY: clean
clean:
rm -f $(BIN_CPP) $(SRC_CPP:.cpp=.o) $(BIN_RS) $(SRC_RS:.rs=.pdb)
rm -rf $(CARGO_FOLDER:%=%/target) $(SRC_CARGO:.toml=.lock)
FORCE: