This repository has been archived by the owner on Jul 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
77 lines (58 loc) · 2.05 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
TARGET := ./bin/fortal
TEST_TARGET := ./bin/test
CXX := g++
CXXFLAGS := -std=c++17 -Wall -Wextra -pedantic -Wno-missing-field-initializers -g
LDFLAGS :=
ARGS := -D test/fortal/*.f
SRC_DIR := src
TEST_DIR := test
BIN_DIR := bin
OBJ_DIR := obj
DEP_DIR := deps
TMP_DIR := tmp
CPP_SRC_FILES := $(shell find $(SRC_DIR) -type f -name '*.cpp')
CPP_OBJ_FILES := $(patsubst %, $(OBJ_DIR)/%.o, $(CPP_SRC_FILES))
CPP_HEADERS := $(shell find $(SRC_DIR) -type f -name '*.h')
GTEST_LDFLAGS := -lgtest -pthread
TEST_SRC_FILES := $(shell find $(TEST_DIR) -type f -name '*.cpp')
TEST_OBJ_FILES := $(patsubst %, $(OBJ_DIR)/%.o, $(TEST_SRC_FILES))
all: $(TARGET) $(TEST_TARGET)
run: $(TARGET)
$(TARGET) $(ARGS)
test: $(TEST_TARGET)
$(TEST_TARGET)
format: $(CPP_SRC_FILES) $(TEST_SRC_FILES) $(CPP_HEADERS)
astyle --project=.astylerc $^
$(TARGET): $(CPP_OBJ_FILES)
@echo Linking $@
@mkdir -p $(dir $@)
@$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
$(TEST_TARGET): $(TEST_OBJ_FILES)
@echo Linking $@
@mkdir -p $(dir $@)
@$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) $(GTEST_LDFLAGS)
$(OBJ_DIR)/%.o: % $(DEP_DIR)/%.d
@echo Compiling $*
@mkdir -p $(dir $@)
@mkdir -p $(dir $(DEP_DIR)/$*.d)
@$(CXX) -MT $@ -MMD -MP -MF $(DEP_DIR)/$*.d $(CXXFLAGS) -c -o $@ $<
memcheck: $(TMP_DIR)/memcheck.out
grep -q "no leaks are possible" $<
rm $(TMP_DIR)/memcheck.out
$(TMP_DIR)/memcheck.out: $(TARGET)
@mkdir -p $(TMP_DIR)
valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --log-file=$(TMP_DIR)/memcheck.out $(TARGET) $(ARGS)
massif: $(TMP_DIR)/massif.out
$(TMP_DIR)/massif.out: $(TARGET)
@mkdir -p $(TMP_DIR)
valgrind --tool=massif --massif-out-file=$(TMP_DIR)/massif.out $(TARGET) $(ARGS)
ms_print: $(TMP_DIR)/ms_print.out
$(TMP_DIR)/ms_print.out: $(TMP_DIR)/massif.out
ms_print $(TMP_DIR)/massif.out > $(TMP_DIR)/ms_print.out
clean:
@echo Cleaning
@rm -rf $(BIN_DIR) $(OBJ_DIR) $(DEP_DIR) $(TMP_DIR)
@find . -type f -name '*.tmp' -exec rm -f {} \;
DEP_FILES := $(patsubst $(OBJ_DIR)/%.o, $(DEP_DIR)/%.d, $(CPP_OBJ_FILES) $(TEST_OBJ_FILES))
$(DEP_FILES):
include $(wildcard $(DEP_FILES))