forked from INFORMSJoC/2019.0000
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
53 lines (39 loc) · 1 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
CXX ?= g++
BUILD_DIR ?= build
SRC_DIR ?= src
SRCS := $(shell find $(SRC_DIR) -name '*.cpp')
OBJS := $(SRCS:$(SRC_DIR)/%.cpp=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)
INC_DIRS := $(shell find $(SRC_DIR) -type d)
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
SUM_TEST ?= false
CPPFLAGS ?= $(INC_FLAGS) -O2 -pedantic-errors -Wall -Wextra -Werror -MMD -MP
mult: $(OBJS)
@echo "Linking: $@"
@$(CXX) $(OBJS) -o $@ $(LDFLAGS)
sum: $(OBJS)
@echo "Linking: $@"
@$(CXX) $(OBJS) -o $@ -DSUM $(LDFLAGS)
# c source
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
@$(MKDIR_P) $(dir $@)
@echo "Compiling: $< -> $@"
@$(CXX) $(CPPFLAGS) -c $< -o $@
# c++ source
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp
@$(MKDIR_P) $(dir $@)
@echo "Compiling: $< -> $@"
@$(CXX) $(CPPFLAGS) -c $< -o $@
.PHONY: test
sum-test: sum
python3 scripts/test.py sum
mult-test: mult
python3 scripts/test.py mult
.PHONY: clean
clean:
@echo "Deleting build directory"
@$(RM) -r $(BUILD_DIR)
@echo "Deleting binary"
@$(RM) $(BIN_NAME)
-include $(DEPS)
MKDIR_P ?= mkdir -p