-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
107 lines (92 loc) · 2.89 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
### Project specific variables
GPU_ARCHS ?= 70
CUDA_HOME ?= /usr/local/cuda
VERBOSE ?= 0
### Project specific variables
### Project specific constants
STD_CXX := c++11
SRC_DIR := src
EXE := cuda-template
TEST_DIR := tests
TEST_EXE := test-$(EXE)
CATCH2_DIR := catch2
LIBS :=
INCLUDES := -I$(CATCH2_DIR)/single_include \
-I$(CUDA_HOME)/include \
-I$(SRC_DIR)
### Project specific constants
######## Don't edit anything below this!
NVCC := nvcc
GENCODE := $(foreach arch,$(GPU_ARCHS),-gencode arch=compute_$(arch),code=sm_$(arch))
NVCCFLAGS := $(GENCODE) \
-std=$(STD_CXX) \
--expt-extended-lambda \
$(INCLUDES)
CXX := g++
CXXFLAGS := -std=$(STD_CXX) \
$(INCLUDES)
LD := nvcc
LDFLAGS := $(LIBS)
CU_SRCS := $(shell find $(SRC_DIR) -name "*.cu")
CXX_SRCS := $(shell find $(SRC_DIR) -name "*.cpp")
CU_OBJS := $(patsubst %.cu,%.cu.o,$(CU_SRCS))
CXX_OBJS := $(patsubst %.cpp,%.cpp.o,$(CXX_SRCS))
OBJS := $(CU_OBJS) $(CXX_OBJS)
TEST_CU_SRCS := $(shell find $(TEST_DIR) -name "*.cu")
TEST_CXX_SRCS := $(shell find $(TEST_DIR) -name "*.cpp")
TEST_CU_OBJS := $(patsubst %.cu,%.cu.o,$(TEST_CU_SRCS))
TEST_CXX_OBJS := $(patsubst %.cpp,%.cpp.o,$(TEST_CXX_SRCS))
TEST_OBJS := $(TEST_CU_OBJS) $(TEST_CXX_OBJS)
ifeq ($(VERBOSE),1)
PREFIX :=
else
PREFIX := @
endif
default:
@echo "make what? Available targets are:"
@echo " . clean - clean up built files"
@echo " . clean_all - clean up built files and other downloaded files"
@echo " . exe - build the executable"
@echo " . test - build and run the test exe"
@echo "Flags to customize behavior:"
@echo " . GPU_ARCHS - space-separated list of gpu-architectures to"
@echo " compile for [$(GPU_ARCHS)]"
debug:
@echo "TEST_OBJS=$(TEST_OBJS)"
@echo "TEST_CU_OBJS=$(TEST_CU_OBJS)"
@echo "TEST_CXX_OBJS=$(TEST_CXX_OBJS)"
@echo "TEST_CU_SRCS=$(TEST_CU_SRCS)"
@echo "TEST_CXX_SRCS=$(TEST_CXX_SRCS)"
.PHONY: exe
exe: $(EXE)
$(EXE): $(OBJS)
@if [ "$(VERBOSE)" = "0" ]; then \
echo "Building $@ ..."; \
fi
$(PREFIX)$(LD) $(LDLFAGS) -o $@ $^
.PHONY: test
test: $(CATCH2_DIR) $(TEST_EXE)
./$(TEST_EXE)
$(TEST_EXE): $(TEST_OBJS) $(OBJS)
@if [ "$(VERBOSE)" = "0" ]; then \
echo "Building $@ ..."; \
fi
$(PREFIX)$(LD) $(LDFLAGS) -o $@ $^
%.cu.o: %.cu
@if [ "$(VERBOSE)" = "0" ]; then \
echo "Compiling CUDA source $@ ..."; \
fi
$(PREFIX)$(NVCC) $(NVCCFLAGS) -c -o $@ $<
%.cpp.o: %.cpp
@if [ "$(VERBOSE)" = "0" ]; then \
echo "Compiling CXX source $@ ..."; \
fi
$(PREFIX)$(CXX) $(CXXFLAGS) -c -o $@ $<
$(CATCH2_DIR):
git clone https://github.com/catchorg/Catch2 $@
.PHONY: clean
clean:
rm -f $(EXE) $(OBJS) $(TEST_OBJS)
.PHONY: clean_all
clean_all: clean
rm -rf $(CATCH2_DIR)