forked from ccecka/fmmtl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.inc
147 lines (121 loc) · 4.17 KB
/
Makefile.inc
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
#########################
## Library Directories ##
########################
# External libraries
BOOST_DIR = /usr/include
# Optional libraries
# Only needed if using CUDA
CUDA_DIR = /usr/local/cuda-5.5
# This FMM library
FMMTL_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
KERNEL_DIR = $(FMMTL_DIR)kernel
####################
## Makefile Setup ##
####################
# Get the shell name to determine the OS
UNAME := $(shell uname)
# Define the C++ compiler to use
CXX := $(shell which g++) -std=c++11 -fPIC
# Check the version number of CXX
CXX_VERSION_LT_48 := $(shell expr `$(CXX) -dumpversion | cut -f1,2 -d.` \< 4.8)
ifeq ($(CXX_VERSION_LT_48),1)
$(error Makefile using g++ v$(shell $(CXX) -dumpversion), please use >= v4.8)
endif
# Check for CUDA compiler
NVCC := $(shell which nvcc)
# Dependency directory and flags
DEPSDIR := $(shell mkdir -p .deps; echo .deps)
# MD: Dependency as side-effect of compilation
# MF: File for output
# MP: Include phony targets
DEPSFILE = $(DEPSDIR)/$(notdir $*.d)
DEPSFLAGS = -MD -MF $(DEPSFILE) #-MP
# Define any directories containing header files
# To include directories use -Ipath/to/files
INCLUDES += -I. -I$(FMMTL_DIR) -I$(KERNEL_DIR)
INCLUDES += -I$(BOOST_DIR)
# Define cxx compile flags
CXXFLAGS = -fopenmp -funroll-loops -O3 -W -Wall -Wextra -Wno-unused-local-typedefs #-Wfatal-errors
# Define nvcc compile flags TODO: Detect and generate appropriate sm_XX
NVCCFLAGS := --compiler-options "$(CXXFLAGS)" -w -arch=sm_20 -O3 #-Xptxas="-v"
# Define any directories containing libraries
# To include directories use -Lpath/to/files
LDFLAGS +=
# Define any libraries to link into executable
# To link in libraries (libXXX.so or libXXX.a) use -lXXX
LDLIBS +=
######################
## Makefile Options ##
######################
ifeq ($(NDEBUG),1)
CXXFLAGS += -DFMMTL_NDEBUG
endif
ifeq ($(DEBUG),1)
CXXFLAGS += -DFMMTL_DEBUG -g -fno-inline
endif
ifeq ($(PROFILE),1)
CXXFLAGS += -g -pg
endif
ifeq ($(LOG),1)
CXXFLAGS += -DFMMTL_LOGGING
endif
ifeq ($(NO_CUDA),1)
NVCC :=
endif
# Set up for CUDA if available
ifeq ($(NVCC),) # NVCC is not available
else # NVCC is available
CXXFLAGS += -DFMMTL_WITH_CUDA
INCLUDES += -I$(CUDA_DIR)/include
LDFLAGS += -L$(CUDA_DIR)/lib64
LDLIBS += -lcudart
endif
####################
## Makefile Rules ##
####################
# Suffix replacement rules
# $^: the name of the prereqs of the rule
# $<: the name of the first prereq of the rule
# $@: the name of the target of the rule
.SUFFIXES: # Delete the default suffixes
.SUFFIXES: .hpp .cpp .kern .kern.cpp .kern.cu .o # Define our suffix list
# 'make' - default rule
all: $(EXEC)
# Default rule for creating an exec of $(EXEC) from a .o file
$(EXEC): % : %.o
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
# Default rule for creating a .o file from a .cpp file
%.o: %.cpp
$(CXX) $(CXXFLAGS) $(INCLUDES) $(DEPSFLAGS) -c -o $@ $<
# Default rule for creating a .o file from a .cu file
%.o: %.cu
$(NVCC) $(NVCCFLAGS) $(INCLUDES) -c -o $@ $<
@$(NVCC) $(NVCCFLAGS) $(INCLUDES) -M -o $(DEPSFILE) $<
@sed -i "1s,.*.o,$@," $(DEPSFILE) # Fix dep file file.o -> /path/file.o
# Default rule for creating a .o file from a .kern.cpp file
%.o: %.kern.cpp
$(CXX) -DFMMTL_KERNEL $(CXXFLAGS) $(INCLUDES) $(DEPSFLAGS) -c -o $@ $<
# Default rule for creating a .o file from a .kern.cu file
%.o: %.kern.cu
$(NVCC) -DFMMTL_KERNEL $(NVCCFLAGS) $(INCLUDES) -c -o $@ $<
@$(NVCC) -DFMMTL_KERNEL $(NVCCFLAGS) $(INCLUDES) -M -o $(DEPSFILE) $<
@sed -i "1s,.*.kern.o,$@," $(DEPSFILE) # Fix dep file file.o -> /path/file.o
# Default rule for creating a .o file from a .kern file
%.o: %.kern
ifeq ($(NVCC),) # NVCC isn't available
ln -s $< $(<:%.kern=%.kern.cpp)
@$(MAKE) --no-print-directory $@
else # NVCC is availble
ln -s $< $(<:%.kern=%.kern.cu)
@$(MAKE) --no-print-directory $@
endif
# 'make clean' - deletes all .o and temp files, exec, and dependency file
clean:
-$(RM) *.o $(KERNEL_DIR)/*.o
-$(RM) $(EXEC)
find $(KERNEL_DIR) -maxdepth 1 -type l -delete
$(RM) -r $(DEPSDIR)
# Define rules that do not actually generate the corresponding file
.PHONY: clean all
# Include the dependency files
-include $(wildcard $(DEPSDIR)/*.d)