-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
147 lines (123 loc) · 3.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
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
145
146
147
GCC_CXX := g++
CLANG_CXX := clang++
COV := gcov
CXXFLAGS := -std=c++11 -fmessage-length=0 -ftemplate-backtrace-limit=0
# AVX instructions are problematic with GCC 64 bit on Windows due to its lack of support for 32 byte stack alignment.
GCC_CXXFLAGS := $(CXXFLAGS) -Wno-ignored-attributes -fopenmp
GCC_CUDA_CXXFLAGS := $(GCC_CXXFLAGS) -DCATTL3_USE_CUDA
# Clang does not actually utilize OpenMP on Windows; no libomp or libiomp5.
CLANG_CXXFLAGS := $(CXXFLAGS) -march=native
CLANG_CUDA_CXXFLAGS := $(CLANG_CXXFLAGS) -DCATTL3_USE_CUDA
RELEASE_OPT_FLAGS := -O3 -DNDEBUG
# Without level 1 optimization, the object file is too big.
DEBUG_OPT_FLAGS := -O1 -g
# Support gcov/lcov.
COVERAGE_OPT_FLAGS := $(DEBUG_OPT_FLAGS) -fprofile-arcs -ftest-coverage
HEADER_DIR := C-ATTL3
HEADERS := $(shell find $(HEADER_DIR) -type f -name '*.hpp')
SOURCE_DIR := test
SOURCES := $(wildcard $(SOURCE_DIR)/*.cpp)
BUILD_DIR := build
OBJECTS := $(patsubst $(SOURCE_DIR)/%.cpp,$(BUILD_DIR)/%.o,$(SOURCES))
TARGET_DIR := bin
TARGET_NAME := cattle_test.exe
TARGET := $(TARGET_DIR)/$(TARGET_NAME)
COV_DIR := $(BUILD_DIR)/cov
GTEST_DIR := test/gtest
GTEST_MAKE_PATH := $(GTEST_DIR)/make
# For Clang on Windows, omp.h must be copied from GCC.
INCLUDES := -I$(HEADER_DIR) -IEigen -I$(GTEST_DIR)/include -I$(SOURCE_DIR)
CUDA_INCLUDES := -I"$(CUDA_INC_PATH)" $(INCLUDES)
LIBS := -lpthread
CUDA_LIBS := $(LIBS) -L"$(CUDA_LIB_PATH)" -lcudart -lcurand -lcublas -lcudnn
$(TARGET): $(OBJECTS)
@cd $(GTEST_MAKE_PATH) && $(MAKE) gtest.a && cd $(CURDIR)
@mkdir -p $(TARGET_DIR)
# Link the gtest static library directly as it is built by default without the 'lib' prefix.
$(CXX) $(CXXFLAGS) $(OPT_FLAGS) -o $@ $? $(GTEST_MAKE_PATH)/gtest.a $(LIBS)
$(OBJECTS): $(SOURCES) $(HEADERS)
$(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.cpp
@cd $(GTEST_MAKE_PATH) && $(MAKE) gtest-all.o && cd $(CURDIR)
@mkdir -p $(BUILD_DIR)
$(CXX) $(CXXFLAGS) $(OPT_FLAGS) $(INCLUDES) -c -o $@ $<
.DEFAULT_GOAL := all
.PHONY: all
all:
$(MAKE) $(TARGET) \
CXX='$(GCC_CXX)' \
CXXFLAGS='$(GCC_CXXFLAGS)' \
OPT_FLAGS='$(RELEASE_OPT_FLAGS)'
.PHONY: debug
debug:
$(MAKE) $(TARGET) \
CXX='$(GCC_CXX)' \
CXXFLAGS='$(GCC_CXXFLAGS)' \
OPT_FLAGS='$(DEBUG_OPT_FLAGS)'
.PHONY: coverage
coverage:
$(MAKE) $(TARGET) \
CXX='$(GCC_CXX)' \
CXXFLAGS='$(GCC_CXXFLAGS)' \
OPT_FLAGS='$(COVERAGE_OPT_FLAGS)'
.PHONY: cuda_all
cuda_all:
$(MAKE) $(TARGET) \
CXX='$(GCC_CXX)' \
CXXFLAGS='$(GCC_CUDA_CXXFLAGS)' \
OPT_FLAGS='$(RELEASE_OPT_FLAGS)' \
INCLUDES='$(CUDA_INCLUDES)' \
LIBS='$(CUDA_LIBS)'
.PHONY: cuda_debug
cuda_debug:
$(MAKE) $(TARGET) \
CXX='$(GCC_CXX)' \
CXXFLAGS='$(GCC_CUDA_CXXFLAGS)' \
OPT_FLAGS='$(DEBUG_OPT_FLAGS)' \
INCLUDES='$(CUDA_INCLUDES)' \
LIBS='$(CUDA_LIBS)'
.PHONY: clang_all
clang_all:
$(MAKE) $(TARGET) \
CXX='$(CLANG_CXX)' \
CXXFLAGS='$(CLANG_CXXFLAGS)' \
OPT_FLAGS='$(RELEASE_OPT_FLAGS)'
.PHONY: clang_debug
clang_debug:
$(MAKE) $(TARGET) \
CXX='$(CLANG_CXX)' \
CXXFLAGS='$(CLANG_CXXFLAGS)' \
OPT_FLAGS='$(DEBUG_OPT_FLAGS)'
.PHONY: clang_cuda_all
clang_cuda_all:
$(MAKE) $(TARGET) \
CXX='$(CLANG_CXX)' \
CXXFLAGS='$(CLANG_CUDA_CXXFLAGS)' \
OPT_FLAGS='$(RELEASE_OPT_FLAGS)' \
INCLUDES='$(CUDA_INCLUDES)' \
LIBS='$(CUDA_LIBS)'
.PHONY: clang_cuda_debug
clang_cuda_debug:
$(MAKE) $(TARGET) \
CXX='$(CLANG_CXX)' \
CXXFLAGS='$(CLANG_CUDA_CXXFLAGS)' \
OPT_FLAGS='$(DEBUG_OPT_FLAGS)' \
INCLUDES='$(CUDA_INCLUDES)' \
LIBS='$(CUDA_LIBS)'
.PHONY: check
check:
@bin/cattle_test.exe
.PHONY: report
report:
$(COV) -o $(BUILD_DIR) -r $(SOURCES)
@rm -rf $(COV_DIR)
@mkdir $(COV_DIR) && (mv -f -t $(COV_DIR) $(HEADERS:%=%.gcov) || true)
@rm -f *.gcov
.PHONY: clean
clean:
@rm -rf $(BUILD_DIR) $(TARGET_DIR)
@cd $(GTEST_MAKE_PATH) && $(MAKE) clean && cd $(CURDIR)
.PHONY: variables
variables:
@echo "Sources: " $(SOURCES)
@echo "Headers: " $(HEADERS)
@echo "Objects: " $(OBJECTS)