-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
69 lines (58 loc) · 1.82 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
# Compiler
CXX = g++
# Executable names
exe = shock
test_exe = shocktest
# Directories
src_dir = src
bin_dir = bin
build_dir = build
test_dir = test
obj_dir = $(build_dir)/obj
test_obj_dir = $(test_dir)/obj
test_src_dir = $(test_dir)/src
# Files
test_src = $(wildcard $(test_src_dir)/*.cpp)
src = $(wildcard $(src_dir)/*.cpp)
obj = $(src:$(src_dir)/%.cpp=$(obj_dir)/%.o)
test_obj = $(test_src:$(test_src_dir)/%.cpp=$(test_obj_dir)/%.o)
# Paths to includes
include_paths = include lib/googletest/googletest/include lib/hdf5/include lib/hdf5/lib
# Compiler flags
warnings = -Wall -Wextra
flags = $(foreach dir, $(include_paths), -I$(dir)) -std=c++11 -g $(warnings)
# Libraries and locations
ldlibs = -Llib/googletest/lib -Llib/hdf5/lib -lgtest -lgtest_main -lpthread -lhdf5 -lhdf5_cpp -Wl,-rpath=lib/hdf5/lib
# Useful variables
empty =
test_suffix = _test
.PHONY: all
all: main test
.PHONY: main
main: directories $(bin_dir)/$(exe)
.PHONY: test
test: test_directories $(bin_dir)/$(test_exe)
# This is purely for testing purposes
.PHONY: print
print:
$(info $(patsubst $(test_obj_dir)/%_test.o,$(obj_dir)/%.o,$(test_obj)))
.PHONY: directories
directories:
if [ ! -d $(bin_dir) ]; then mkdir $(bin_dir); fi
if [ ! -d $(build_dir) ]; then mkdir $(build_dir); fi
if [ ! -d $(obj_dir) ]; then mkdir $(obj_dir); fi
.PHONY: test_directories
test_directories:
if [ ! -d $(test_dir) ]; then mkdir $(test_dir); fi
if [ ! -d $(test_obj_dir) ]; then mkdir $(test_obj_dir); fi
.PHONY: clean
clean:
rm -rf $(build_dir) $(bin_dir) $(test_obj_dir)
$(bin_dir)/$(exe): $(obj)
$(CXX) -o $@ $^ $(ldlibs)
$(obj_dir)/%.o: $(src_dir)/%.cpp
$(CXX) $(flags) -o $@ -c $<
$(bin_dir)/$(test_exe): $(patsubst $(test_obj_dir)/%_test.o,$(obj_dir)/%.o,$(test_obj)) $(test_obj)
$(CXX) -o $@ $^ $(ldlibs)
$(test_obj_dir)/%.o: $(test_src_dir)/%.cpp
$(CXX) $(flags) -o $@ -c $<