-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
236 lines (152 loc) · 4.39 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# vim:comments=
#
# I don't like the Cuda SDK makefiles. Here's my own! This makefile should
# allow you to build Cuda programs independent of the NVidia Cuda SDK. Its
# simplicity makes it easy for you to put objects, binaries, etc where you want
# them. There is even some boiler-plate Makefile magic that you can copy
# into other Makefiles.
#
# Mark Murphy 2008
#
# http://www.eecs.berkeley.edu/~mjmurphy/makefile
#
# PJR Modified extensively for fev.
# PJR Modified again for 582
HOSTTYPE = $(shell uname -m)
BITS := $(if $(filter x86_64 x86_64-linux , $(HOSTTYPE)),64,32)
# Fill in the name of the output binary here
target := project
#build cuda lib directory name
ifeq ($(BITS),64)
CUDALIB := lib64
else
CUDALIB := lib
endif
# List of sources with .c, .cu, and .cc extensions
# PLEASE INCLUDE the target source file (e.g. Server.cpp)
sources := \
fileUtil.c\
hw1.cu\
hw1funs.c\
linkedList.c\
main.c\
timing.c\
words.c\
# Other things that need to be built, e.g. .cubin files
extradeps :=
# Flags common to all compilers. You can set these on the comamnd line, e.g:
# $ make opt="" dbg="-g" warn="-Wno-deptrcated-declarations -Wall -Werror"
opt ?= -m$(BITS)
dbg ?= -g -O0
cuda_dbg ?= -G $(dbg)
warn ?= -Wall -Werror
# This is where the cuda runtime libraries and includes can be found
cudaroot := /usr/local/cuda-7.0
# Tony: location of NVIDIA SDK
nv_sdk := $(cudaroot)
#----- C compilation options ------
gcc := /usr/bin/gcc
cflags += $(opt) $(dbg) $(warn)
clib_paths :=
cinc_paths := -I $(cudaroot)/samples/common/inc
clibraries :=
#----- C++ compilation options ------
gpp := /usr/bin/g++
ccflags += $(opt) $(dbg) $(warn)
cclib_paths :=
ccinc_paths := -I$(cudaroot)/samples/common/inc -I$(nv_sdk)/samples/common/inc
cclibraries :=
#----- CUDA compilation options -----
nvcc := $(cudaroot)/bin/nvcc
cuflags += $(opt) $(cuda_dbg)
culib_paths := -L$(cudaroot)/$(CUDALIB) -L$(nv_sdk)/C/lib -L$(nv_sdk)/samples/common/lib/$(OSTYPE)
cuinc_paths := -I$(cudaroot)/include -I$(nv_sdk)/samples/common/inc
culibraries := -lcuda -lcudart
lib_paths := $(culib_paths) $(cclib_paths) $(clib_paths)
libraries := $(culibraries) $(cclibraries) $(clibraries)
#----- Generate source file and object file lists
# This code separates the source files by filename extension into C, C++,
# and Cuda files.
csources := $(filter %.c ,$(sources))
ccsources := $(filter %.cc,$(sources))
cppsources := $(filter %.cpp,$(sources))
cusources := $(filter %.cu,$(sources))
# This code generates a list of object files by replacing filename extensions
objects := $(patsubst %.c,%.o ,$(csources)) \
$(patsubst %.cu,%.o,$(cusources)) \
$(patsubst %.cc,%.o,$(ccsources)) \
$(patsubst %.cpp,%.o,$(cppsources))
#----- Build rules ------
# foo:
# echo $(CUDALIB)
all: $(target)
$(target): $(objects)
$(gpp) -o $@ $(objects) $(ccflags) $(lib_paths) $(libraries)
%.o: %.cu
$(nvcc) -c $< $(cuflags) $(cuinc_paths) -o $@
%.cubin: %.cu
$(nvcc) -cubin $(cuflags) $(cuinc_paths) $^
%.o: %.cc
$(gpp) -c $< $(ccflags) $(ccinc_paths) -o $@
%.o: %.cpp
$(gpp) -c $< $(ccflags) $(ccinc_paths) -o $@
%.o: %.c
$(gcc) -c $< $(cflags) $(cinc_paths) -o $@
clean:
rm -f $(target) $(objects) *.mk *.combine *.vcg *.sibling
#----- Dependency Generation -----
#
# If a particular set of sources is non-empty, then have rules for
# generating the necessary dep files.
#
ccdep := ccdep.mk
cdep := cdep.mk
cudep := cudep.mk
cppdep := cppdep.mk
depfiles =
ifneq ($(ccsources),)
depfiles += $(ccdep)
$(ccdep): $(ccsources)
$(gpp) -MM $(ccsources) > $(ccdep)
else
$(ccdep):
endif
ifneq ($(cusources),)
depfiles += $(cudep)
$(cudep):
$(gpp) -MM -x c++ $(cuinc_paths) $(ccinc_paths) $(cusources) > $(cudep)
else
$(cudep):
endif
ifneq ($(csources),)
depfiles += $(cdep)
$(cdep): $(csources)
$(gcc) -MM -x c $(csources) > $(cdep)
else
$(cdep):
endif
ifneq ($(cppsources),)
depfiles += $(cppdep)
$(cppdep): $(cppsources)
$(gpp) -MM -x c++ $(ccinc_paths) $(cppsources) > $(cppdep)
else
$(cppdep):
endif
.PHONY: dep
dep: $(depfiles)
ifneq ($(MAKECMDGOALS),dep)
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(ccsources),)
include $(ccdep)
endif
ifneq ($(cusources),)
include $(cudep)
endif
ifneq ($(csources),)
include $(cdep)
endif
ifneq ($(cppsources),)
include $(cppdep)
endif
endif
endif