-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile_generic
312 lines (232 loc) · 9.78 KB
/
Makefile_generic
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
#=======================================================================
# Targets
#=======================================================================
all: libs bins
BINS = generic_bins
ifneq ($(MATLAB),)
BINS = matlab_bins
endif
ifneq ($(PYTHON),)
BINS = python_bins
endif
bins: $(BINS)
#=======================================================================
# Mex file compilation
#=======================================================================
MEX =
ifneq ($(MATLAB_PATH),)
MEX := $(MATLAB_PATH)/bin/mex
endif
ifneq ($(MATLAB_PATH),)
CCINC += -I$(MATLAB_PATH)/extern/include
endif
#-----------------------------------------------------------------------
# List of mex files to compile. If no mex compiler is present, or the
# headers are not present, leave this blank
#-----------------------------------------------------------------------
MEXOBJ =
ifneq ($(MEX),)
ifneq ($(MATLAB_PATH),)
ifeq ($(MAC_OSX),0)
ifeq ($(COMPILE_FOR_64BIT),0)
MEXALLOBJ = $(patsubst %.cc,%.mexglx,$(wildcard $(BIN_PREFIX)Mat*.cc))
MEXOBJ = $(patsubst %.cc,%.mexglx,$(wildcard $(BIN_PREFIX)Mat*.cc))
else
MEXALLOBJ = $(patsubst %.cc,%.mexa64,$(wildcard $(BIN_PREFIX)Mat*.cc))
MEXOBJ = $(patsubst %.cc,%.mexa64,$(wildcard $(BIN_PREFIX)Mat*.cc))
endif
else
ifeq ($(COMPILE_FOR_64BIT),0)
MEXALLOBJ = $(patsubst %.cc,%.mexmac,$(wildcard $(BIN_PREFIX)Mat*.cc))
MEXOBJ = $(patsubst %.cc,%.mexmac,$(wildcard $(BIN_PREFIX)Mat*.cc))
else
MEXALLOBJ = $(patsubst %.cc,%.mexmaci64,$(wildcard $(BIN_PREFIX)Mat*.cc))
MEXOBJ = $(patsubst %.cc,%.mexmaci64,$(wildcard $(BIN_PREFIX)Mat*.cc))
endif
endif
endif
endif
matlab_bins: $(MEXOBJ)
#-----------------------------------------------------------------------
# Rule for making .mexglx files from .cc files
#-----------------------------------------------------------------------
$(BIN_EXE_PREFIX)%.mexglx: $(BIN_PREFIX)%.cc
$(MEX) $< $(MEXFLAGS) $(GENERIC_FLAGS) $(CCINC) $(LDPATH) $(MATLIBS) -output $(@)
#-----------------------------------------------------------------------
# Rule for making .mexa64 files from .cc files
#-----------------------------------------------------------------------
$(BIN_EXE_PREFIX)%.mexa64: $(BIN_PREFIX)%.cc
$(MEX) $< $(MEXFLAGS) $(GENERIC_FLAGS) $(CCINC) $(LDPATH) $(MATLIBS) -output $(@)
#-----------------------------------------------------------------------
# Rule for making .mexmac files from .cc files
#-----------------------------------------------------------------------
$(BIN_EXE_PREFIX)%.mexmac: $(BIN_PREFIX)%.cc
$(MEX) $< $(MEXFLAGS) $(GENERIC_FLAGS) $(CCINC) $(LDPATH) $(MATLIBS) -output $(@)
#-----------------------------------------------------------------------
# Rule for making .mexmaci64 files from .cc files
#-----------------------------------------------------------------------
$(BIN_EXE_PREFIX)%.mexmaci64: $(BIN_PREFIX)%.cc
$(MEX) $< $(MEXFLAGS) $(GENERIC_FLAGS) $(CCINC) $(MATLIBS) -output $(@)
#=======================================================================
# PYTHON file compilation
#=======================================================================
ifneq ($(PYTHON_INC_PATH),)
CCINC += -I$(PYTHON_INC_PATH)
endif
ifneq ($(NUMPY_INC_PATH),)
CCINC += -I$(NUMPY_INC_PATH)
endif
#-----------------------------------------------------------------------
# List of PY files to compile. If the PY headers are not present,
# this should be left blank
#-----------------------------------------------------------------------
PYOBJ =
ifneq ($(PYTHON_INC_PATH),)
PYALLOBJ = $(patsubst %.cc,%.pyso,$(wildcard $(BIN_PREFIX)Py*.cc))
PYOBJPYSO = $(subst $(BIN_PREFIX),$(BIN_EXE_PREFIX),$(PYALLOBJ))
endif
python_bins: $(PYOBJPYSO)
#-----------------------------------------------------------------------
# Rule for making .pyso files from .cc files
#-----------------------------------------------------------------------
PYFLAGS = -fPIC
# This rule
$(BIN_EXE_PREFIX)%.pyso: $(BIN_PREFIX)%.cc
$(TOP)/bin/$(BIN_EXE_PREFIX)PythonGenerator file=$< dir=$(TOP)/python \
suffix=pycc prefix=$(BIN_EXE_PREFIX)$*
$(CC) $(CCFLAGS) $(PYFLAGS) $(CCINC) -x c++ -c -o $(BIN_EXE_PREFIX)$*.pyso $(BIN_EXE_PREFIX)$*.pycc
$(CC) $(LIBSO_FLAGS) -o $(BIN_EXE_PREFIX)$*.so $(PYLIBS) $(BIN_EXE_PREFIX)$*.pyso
\rm -f $(BIN_EXE_PREFIX)$*.pycc
#=======================================================================
# Generic rules
#=======================================================================
# Rule for making .o files from .cc files
%.o: %.cc
$(CC) $(CCFLAGS) $(CCINC) -DHOST="\"$(HOSTNAME)\"" -DNAMESERVER="\"$(HOSTNAME):4000\"" -DEVENTSERVER="\"$(HOSTNAME):4001\"" -DCALFILE="\"$(SZA)/array/conf/cal\"" -c -o $@ $<
%.o: %.c
$(CC) $(CCFLAGS) $(CCINC) -DHOST="\"$(HOSTNAME)\"" -DNAMESERVER="\"$(HOSTNAME):4000\"" -DEVENTSERVER="\"$(HOSTNAME):4001\"" -DCALFILE="\"$(SZA)/array/conf/cal\"" -c -o $@ $<
#=======================================================================
# Doxygen documentation
#=======================================================================
# We have to make a phony target so that make will proceed even if
# there is a file/dir under the current directory with the same name
.PHONY : dox
dox:
@echo ' ';echo 'Making Doxygen documentation'; echo ' '
doxygen Doxyfile.cfg
clean_dox:
@echo ' ';echo 'Removing dox directory'; echo ' '
/bin/rm -rf dox
#=======================================================================
# Library generation: including Makefile should just have to define
# variable LIBSO_PREFIX
#=======================================================================
# List the dependencies by substituting from the source directory.
# This will cause the .o files to be made if they do not already
# exist. Otherwise if .o files don't already exist, the library will
# be made without complaint with no targets
# In wildcard, we use only files beginning with capitals, since these
# are the class definitions. Otherwise, threadserver.o and
# threadclient.o would get built into the library
CCLIBOBJ = $(patsubst %.cc,%.o,$(wildcard [A-Z]*.cc))
CLIBOBJ = $(patsubst %.c,%.o,$(wildcard *.c))
ifndef LIBOBJ
LIBOBJ = $(CCLIBOBJ)
LIBOBJ += $(CLIBOBJ)
endif
# If this is a matlab library, and no mex compiler is present, reset
# the list of object files
ifneq ($(MATLAB),)
ifeq ($(MEX),)
LIBOBJ =
endif
ifeq ($(MATLAB_PATH),)
LIBOBJ =
endif
endif
LIBSO = $(LIBSO_PREFIX)$(LIBSO_SUFFIX)
$(LIBDIR)/$(LIBSO): $(LIBOBJ)
g++ $(LIBSO_FLAGS) -o $(LIBDIR)/$(LIBSO) $(LIBOBJ)
libs: depend $(LIBOBJ)
@if [ ! -d $(LIBDIR) ] ; then mkdir $(LIBDIR) ; fi ;
$(MAKE) $(LIBDIR)/$(LIBSO);
#=======================================================================
# Binary generation
#=======================================================================
BINALLOBJ = $(patsubst %.cc,%,$(wildcard $(BIN_PREFIX)*.cc))
BINOBJ = $(subst $(BINEXC),,$(BINALLOBJ))
EXEOBJ = $(subst $(BIN_PREFIX),$(BINDIR)/$(BIN_EXE_PREFIX),$(BINOBJ))
generic_bins: depend $(EXEOBJ)
@if [ ! -d $(BINDIR) ] ; then mkdir $(BINDIR) ; fi ;
# Rule for making binaries
$(BINDIR)/$(BIN_EXE_PREFIX)%: $(BIN_PREFIX)%.o
$(CC) -o $@ $(CCFLAGS) $< $(LDPATH) $(RPATH) $(LIBS)
#=======================================================================
# Directive for compiling test programs
#=======================================================================
TESTALLOBJ = $(patsubst %.cc,%,$(wildcard t*.cc))
TESTOBJ = $(filter-out $(BINEXC),$(TESTALLOBJ))
#t%: t%.o
# $(FC) $(FC_FLAGS) -o $@ $(LDPATH) $(RPATH) $(LIBS) $(PGLIB) $(PGLD) $(FC_PG_RPATH) $(X11LD) -lXmu -lpng $<
t%: t%.o
$(CC) -o $@ $(CCFLAGS) $< $(LDPATH) $(RPATH) $(LIBS)
generic_test: depend $(TESTOBJ)
test: generic_test
#=======================================================================
# Include the file in which automatic dependencies are deposited by
# make depend, above. But only if it exists. If not, the rule for
# depend, below, will make it. Don't include Makefile.rules until
# after the desired default target is defined, or Makefile.rules will
# determine the default target for you!
#=======================================================================
MAKERULES := $(wildcard Makefile.rules)
ifeq ($(MAKERULES), Makefile.rules)
RULES_EXISTS = y
include Makefile.rules
else
RULES_EXISTS = n
endif
#-----------------------------------------------------------------------
# Make dependencies, if they don't already exist
#-----------------------------------------------------------------------
ifndef RULESFILES
RULESFILES = $(wildcard [A-Z]*.cc)
RULESFILES += $(wildcard t*.cc)
RULESFILES += $(wildcard *.c)
RULESFILES += $(wildcard $(BIN_PREFIX)*.cc)
endif
# If Makefile.rules doesn't exist (see above), executing this rule
# will cause it to be made and sourced.
dependCheck:
ifeq ($(RULES_EXISTS),n)
$(CC) $(CCFLAGS) $(OPTIONS) $(CCINC) -MM $(RULESFILES) > Makefile.rules
@set -e; [ -s Makefile.rules ] ;
@echo $(RULESFILES) > Makefile.rules.fileList ;
\cp -f Makefile.rules.fileList Makefile.rules.fileList_old ;
else
@if [ -f Makefile.rules.fileList ] ; then \mv -f Makefile.rules.fileList Makefile.rules.fileList_old ; fi ;
@echo $(RULESFILES) > Makefile.rules.fileList ;
endif
depend: dependCheck
ifneq (,$(shell diff Makefile.rules.fileList Makefile.rules.fileList_old))
@set -e; [ -s Makefile.rules ] ;
endif
#=======================================================================
# Clean directives
#=======================================================================
clean_bins:
\rm -f $(EXEOBJ)
clean_test_bins:
\rm -f $(TESTOBJ)
clean_depend:
\rm -f Makefile.rules*
clean_files:
\rm -f *.o
\rm -f *.mex*
\rm -f *.pycc
\rm -f *.pyso
clean_libs:
\rm -f $(LIBDIR)/$(LIBSO)
\rm -f *.so
clean_test: clean_test_bins clean_files
clean: clean_bins clean_depend clean_files clean_libs