summaryrefslogtreecommitdiff
path: root/lib/make/make.config.rules.in
blob: 0c633b4d94127176315cb418d74ae49e1e9e0131 (plain)
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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
# /*@@
#   @file    make.config.rules.in
#   @date    Sun Jan 17 22:31:16 1999
#   @author  Tom Goodale
#   @desc
#            Rules to generate object files from source files in another
#            directory.
#
#            Note that, due to the (IMHO) rather bizarre way in which Make
#            deals with directories in the target names, this will
#            not work if the target is in a subdirectory.
#
#            In order to accomodate Fortran 90 modules, the working directory
#            for each compilation is set to a scratch directory, so that
#            all module files end up there.
#   @enddesc
#   @version $Header$
# @@*/

# Dividers to make the screen output slightly nicer
DIVEL   =  __________________
DIVIDER =  $(DIVEL)$(DIVEL)$(DIVEL)$(DIVEL)

#####################################################################
# Shortcuts.

INCLUDE_LINE = $(patsubst %,-I"%",$(call TRANSFORM_DIRS,$(INC_DIRS)))

#####################################################################

ifeq ($(shell echo $(VERBOSE) | tr '[:upper:]' '[:lower:]'),yes)
define NOTIFY_PREPROCESSING
	echo Preprocessing $<
endef
define NOTIFY_COPYING
	echo Copying $<
endef
define NOTIFY_COMPILING
	echo Compiling $<
endef
define NOTIFY_POSTPROCESSING
	echo Postprocessing $<
endef
define NOTIFY_DIVIDER
	echo $(DIVIDER)
endef
else
define NOTIFY_PREPROCESSING
endef
define NOTIFY_COPYING
endef
define NOTIFY_COMPILING
	echo COMPILING $<
endef
define NOTIFY_POSTPROCESSING
endef
define NOTIFY_DIVIDER
endef
endif

# Define how to do dependencies.
# Correct the dependency target (i.e. the item on the LHS of a make
# rule). The name of the object file is wrong, and the dependency file
# (.d file) is missing. To simplify things, we don't try to match the
# object file name -- we assume that any file ending in .o is the
# object file.
ifeq ($(strip $(PERL_BACKUP_NECESSARY)),)
define DEPENDENCY_FIXER
	$(PERL) -pi -e 's{^\s*\Q$(basename $(basename $@)).o\E\s*:}{$(basename $@).o $(basename $@).d:};\
                        s{\s+\S*[/\\]($(DEP_EXCLUDE_FILES))\b}{}g' $@
endef
else
define DEPENDENCY_FIXER
	$(PERL) -pi.bak -e 's{^\Q$(basename $(basename $@)).o:\E}{$(basename $@).o $(basename $@).d:}\
                            s{\s+\S*[/\\]($(DEP_EXCLUDE_FILES))\b}{}g' $@
	rm $@.bak
endef
endif

define C_DEPENDENCIES
	$(C_DEPEND) $< $(INCLUDE_LINE) $(EXTRA_DEFINES:%=-D%) -DCCODE $(C_DEPEND_OUT)
	$(DEPENDENCY_FIXER)
endef

define CXX_DEPENDENCIES
	$(CXX_DEPEND) $< $(INCLUDE_LINE) $(EXTRA_DEFINES:%=-D%) -DCCODE $(CXX_DEPEND_OUT)
	$(DEPENDENCY_FIXER)
endef

define CUCC_DEPENDENCIES
        $(CUCC_DEPEND) $< $(INCLUDE_LINE) $(EXTRA_DEFINES:%=-D%) -DCCODE $(CUCC_DEPEND_OUT)
        $(DEPENDENCY_FIXER)
endef

define CL_DEPENDENCIES
# An OpenCL source file has no external dependencies
	$(CL_DEPEND) $< $(CL_DEPEND_OUT)
	$(DEPENDENCY_FIXER)
endef

define F77_DEPENDENCIES
	$(F77_DEPEND) $(INCLUDE_LINE) $(EXTRA_DEFINES:%=-D%) -DFCODE $< $(F77_DEPEND_OUT)
	$(DEPENDENCY_FIXER)
endef

define F_DEPENDENCIES
	$(F_DEPEND) $(INCLUDE_LINE) $(EXTRA_DEFINES:%=-D%) -DFCODE -DF90CODE $< $(F_DEPEND_OUT)
	$(DEPENDENCY_FIXER)
	current_wd=`$(GET_WD)` ; { if test $(F_LINE_DIRECTIVES) = 'yes'; then echo '#line 1 "'$<'"'; fi; cat $<; } | $(PERL) -p -e 's.//.CCTK_AUTOMATICALLY_GENERATED_CONCATENATION_PROTECTION.g' | $(FPP) $(FPPFLAGS) $(INCLUDE_LINE) $(EXTRA_DEFINES:%=-D%) -DFCODE -DF90CODE | $(PERL) -p -e 's.CCTK_AUTOMATICALLY_GENERATED_CONCATENATION_PROTECTION.//.g' | $(PERL) $(F_DEPEND_MODULES) $< $(basename $(notdir $<)).F.o $(SRCDIR) $(USESTHORNS:%=$$current_wd/../%) $(F_DEPEND_MODULES_OUT) || { rm $@; exit 1; }
endef

define F90_DEPENDENCIES
	$(F_DEPEND) $(INCLUDE_LINE) $(EXTRA_DEFINES:%=-D%) -DFCODE -DF90CODE $< $(F_DEPEND_OUT)
	$(DEPENDENCY_FIXER)
	current_wd=`$(GET_WD)` ; { if test $(F_LINE_DIRECTIVES) = 'yes'; then echo '#line 1 "'$<'"'; fi; cat $<; } | $(PERL) -p -e 's.//.CCTK_AUTOMATICALLY_GENERATED_CONCATENATION_PROTECTION.g' | $(FPP) $(FPPFLAGS) $(INCLUDE_LINE) $(EXTRA_DEFINES:%=-D%) -DFCODE -DF90CODE | $(PERL) -p -e 's.CCTK_AUTOMATICALLY_GENERATED_CONCATENATION_PROTECTION.//.g' | $(PERL) $(F_DEPEND_MODULES) $< $(basename $(notdir $<)).F90.o $(SRCDIR) $(USESTHORNS:%=$$current_wd/../%) $(F_DEPEND_MODULES_OUT) || { rm $@; exit 1; }
endef

# No preprocessing, just create empty dependency file
define f77_DEPENDENCIES
	echo "" > $@
	current_wd=`$(GET_WD)` ; cat $< | $(PERL) $(F_DEPEND_MODULES) $< $(basename $(notdir $<)).f77.o $(SRCDIR) $(USESTHORNS:%=$$current_wd/../%) $(F_DEPEND_MODULES_OUT) || { rm $@; exit 1; }
endef

define f_DEPENDENCIES
	echo "" > $@
	current_wd=`$(GET_WD)` ; cat $< | $(PERL) $(F_DEPEND_MODULES) $< $(basename $(notdir $<)).f.o $(SRCDIR) $(USESTHORNS:%=$$current_wd/../%) $(F_DEPEND_MODULES_OUT) || { rm $@; exit 1; }
endef

define f90_DEPENDENCIES
	echo "">  $@
	current_wd=`$(GET_WD)` ; cat $< | $(PERL) $(F_DEPEND_MODULES) $< $(basename $(notdir $<)).f90.o $(SRCDIR) $(USESTHORNS:%=$$current_wd/../%) $(F_DEPEND_MODULES_OUT) || { rm $@; exit 1; }
endef



# Define how to do a C compilation
define PREPROCESS_C
{ if test $(C_LINE_DIRECTIVES) = 'yes'; then echo '#line 1 "'$<'"'; fi; cat $<; } | $(PERL) -s $(C_FILE_PROCESSOR) -line_directives=$(C_LINE_DIRECTIVES) -source_file_name=$< $(CONFIG) > $(notdir $<)
endef

define COMPILE_C
current_wd=`$(GET_WD)` ; cd $(SCRATCH_BUILD) ; $(CC) $(CPPFLAGS) $(CFLAGS) $(CCOMPILEONLY)$(OPTIONSEP)$$current_wd$(DIRSEP)$@ $$current_wd$(DIRSEP)$(notdir $<) $(INCLUDE_LINE) $(EXTRA_DEFINES:%=-D%) -DCCODE
endef

define POSTPROCESS_C
$(C_POSTPROCESSING)
endef

# Define how to do a C++ compilation
define PREPROCESS_CXX
{ if test $(C_LINE_DIRECTIVES) = 'yes'; then echo '#line 1 "'$<'"'; fi; cat $<; } | $(PERL) -s $(C_FILE_PROCESSOR) -line_directives=$(C_LINE_DIRECTIVES) -source_file_name=$< $(CONFIG) > $(CXX_WORKING_NAME)
endef

define COMPILE_CXX
current_wd=`$(GET_WD)` ; cd $(SCRATCH_BUILD) ; $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(CCOMPILEONLY)$(OPTIONSEP)$$current_wd$(DIRSEP)$@ $$current_wd$(DIRSEP)$(CXX_WORKING_NAME) $(INCLUDE_LINE) $(EXTRA_DEFINES:%=-D%) -DCCODE
endef

define POSTPROCESS_CXX
$(CXX_POSTPROCESSING)
endef

# Define how to do an OpenCL compilation
define PREPROCESS_CL
# Wrap the OpenCL source code into a string, using the thorn name and
# file name to create a variable name, and create a C file
{								\
    echo 'char const *const OpenCL_source_$(THORN)_$* =';	\
    sed -e 's/\\/\\\\/g;s/"/\\"/g;s/\(.*\)/"\1\\n"/g';		\
    echo ';';							\
} < $^ > $(notdir $<).c
endef

define COMPILE_CL
# Basically a C compile, but with a different source file name
current_wd=`$(GET_WD)` ; cd $(SCRATCH_BUILD) ; $(CC) $(CPPFLAGS) $(CFLAGS) $(CCOMPILEONLY)$(OPTIONSEP)$$current_wd$(DIRSEP)$@ $$current_wd$(DIRSEP)$(notdir $<).c $(INCLUDE_LINE) $(EXTRA_DEFINES:%=-D%) -DCCODE
endef

define POSTPROCESS_CL
$(CL_POSTPROCESSING)
endef

# Define how to do a CUDA compilation
define PREPROCESS_CU
{ if test $(C_LINE_DIRECTIVES) = 'yes'; then echo '#line 1 "'$<'"'; fi; cat $<; } | $(PERL) -s $(C_FILE_PROCESSOR) -line_directives=$(C_LINE_DIRECTIVES) -source_file_name=$< $(CONFIG) > $(notdir $<)
endef

define COMPILE_CU
current_wd=`$(GET_WD)` ; cd $(SCRATCH_BUILD) ; $(CUCC) $(CUCCFLAGS) $(CCOMPILEONLY)$(OPTIONSEP)$$current_wd$(DIRSEP)$@ $$current_wd$(DIRSEP)$(notdir $<) $(INCLUDE_LINE) $(EXTRA_DEFINES:%=-D%) -DCCODE 
endef

define POSTPROCESS_CU
$(CUCC_POSTPROCESSING)
endef

# Define how to do a F77 compilation
define PREPROCESS_F77
{ if test $(F_LINE_DIRECTIVES) = 'yes'; then echo '#line 1 "'$<'"'; fi; cat $<; } | $(PERL) -p -e 's.//.CCTK_AUTOMATICALLY_GENERATED_CONCATENATION_PROTECTION.g' | $(FPP) $(FPPFLAGS) $(INCLUDE_LINE) $(EXTRA_DEFINES:%=-D%) -DFCODE | $(PERL) -p -e 's.CCTK_AUTOMATICALLY_GENERATED_CONCATENATION_PROTECTION.//.g' | $(PERL) -p -e 's/__FORTRANFILE__/\"$(basename $(notdir $<)).F77\"/g' | $(PERL) -s $(F_FILE_PROCESSOR) -line_directives=$(F_LINE_DIRECTIVES) -source_file_name=$< > $(basename $(notdir $<)).f
endef

define COMPILE_F77
if test "$(F77)" = "none" ; then echo "There is no Fortran 77 compiler available.  Aborting." ; exit 1 ; fi ; current_wd=`$(GET_WD)` ; cd $(SCRATCH_BUILD) ; $(F77) $(F77FLAGS) $(FCOMPILEONLY)$(OPTIONSEP)$$current_wd$(DIRSEP)$@ $$current_wd$(DIRSEP)$(basename $(notdir $<)).f
endef

define POSTPROCESS_F77
$(F77_POSTPROCESSING)
endef

# Define how to do a fixed-format F90 compilation
define PREPROCESS_F
{ if test $(F_LINE_DIRECTIVES) = 'yes'; then echo '#line 1 "'$<'"'; fi; cat $<; } | $(PERL) -p -e 's.//.CCTK_AUTOMATICALLY_GENERATED_CONCATENATION_PROTECTION.g' | $(FPP) $(FPPFLAGS) $(INCLUDE_LINE) $(EXTRA_DEFINES:%=-D%) -DFCODE -DF90CODE | $(PERL) -p -e 's.CCTK_AUTOMATICALLY_GENERATED_CONCATENATION_PROTECTION.//.g' | $(PERL) -p -e 's/__FORTRANFILE__/\"$(basename $(notdir $<)).F\"/g' | $(PERL) -s $(F_FILE_PROCESSOR) -line_directives=$(F_LINE_DIRECTIVES) -source_file_name=$< > $(basename $(notdir $<)).f
endef

define COMPILE_F
if test "$(F90)" = "none" ; then echo "There is no Fortran 90 compiler available.  Aborting." ; exit 1 ; fi ; current_wd=`$(GET_WD)` ; cd $(SCRATCH_BUILD) ; $(F90) $(F90FLAGS) $(INCLUDE_LINE) $(FCOMPILEONLY)$(OPTIONSEP)$$current_wd$(DIRSEP)$@ $$current_wd$(DIRSEP)$(basename $(notdir $<)).f
endef

define POSTPROCESS_F
$(F_POSTPROCESSING)
endef

# Define how to do a free-format F90 compilation
define PREPROCESS_F90
{ if test $(F_LINE_DIRECTIVES) = 'yes'; then echo '#line 1 "'$<'"'; fi; cat $<; } | $(PERL) -p -e 's.//.CCTK_AUTOMATICALLY_GENERATED_CONCATENATION_PROTECTION.g' | $(FPP) $(FPPFLAGS) $(INCLUDE_LINE) $(EXTRA_DEFINES:%=-D%) -DFCODE -DF90CODE | $(PERL) -p -e 's.CCTK_AUTOMATICALLY_GENERATED_CONCATENATION_PROTECTION.//.g' | $(PERL) -p -e 's/__FORTRANFILE__/\"$(basename $(notdir $<)).F90\"/g' | $(PERL) -s $(F_FILE_PROCESSOR) -free_format -line_directives=$(F_LINE_DIRECTIVES) -source_file_name=$< > $(basename $(notdir $<)).$(F90_SUFFIX)
endef

define COMPILE_F90
if test "$(F90)" = "none" ; then echo "There is no Fortran 90 compiler available.  Aborting." ; exit 1 ; fi ; current_wd=`$(GET_WD)` ; cd $(SCRATCH_BUILD) ; $(F90) $(F90FLAGS) $(INCLUDE_LINE) $(FCOMPILEONLY)$(OPTIONSEP)$$current_wd$(DIRSEP)$@ $$current_wd$(DIRSEP)$(basename $(notdir $<)).$(F90_SUFFIX)
endef

define POSTPROCESS_F90
$(F90_POSTPROCESSING)
endef

# Define how to do a f77 compilation
define PREPROCESS_f77
cat $< > $(basename $(notdir $<)).f
endef

# Define how to do a f compilation
define PREPROCESS_f
cat $< > $(basename $(notdir $<)).f
endef

# Define how to do a f90 compilation
define PREPROCESS_f90
cat $< > $(basename $(notdir $<)).$(F90_SUFFIX)
endef



# Build rules for C

%.asm.o: $(SRCDIR)/%.asm
	current_wd=`$(GET_WD)` ; cd $(SCRATCH_BUILD) ; yasm -f elf -m amd64 -g dwarf2 -o $$current_wd$(DIRSEP)$@ $<

%.c.o: $(SRCDIR)/%.c
	$(NOTIFY_PREPROCESSING)
	$(PREPROCESS_C)
	$(NOTIFY_COMPILING)
	$(COMPILE_C)
	$(NOTIFY_POSTPROCESSING)
	$(POSTPROCESS_C)
	$(NOTIFY_DIVIDER)

%.c.d: $(SRCDIR)/%.c
	$(C_DEPENDENCIES)

# Build rules for C++

%.cc.o: $(SRCDIR)/%.cc
	$(NOTIFY_PREPROCESSING)
	$(PREPROCESS_CXX)
	$(NOTIFY_COMPILING)
	$(COMPILE_CXX)
	$(NOTIFY_POSTPROCESSING)
	$(POSTPROCESS_CXX)
	$(NOTIFY_DIVIDER)

%.cc.d: $(SRCDIR)/%.cc
	$(CXX_DEPENDENCIES)

%.C.o: $(SRCDIR)/%.C
	$(NOTIFY_PREPROCESSING)
	$(PREPROCESS_CXX)
	$(NOTIFY_COMPILING)
	$(COMPILE_CXX)
	$(NOTIFY_POSTPROCESSING)
	$(POSTPROCESS_CXX)
	$(NOTIFY_DIVIDER)

%.C.d: $(SRCDIR)/%.C
	$(CXX_DEPENDENCIES)

%.cpp.o: $(SRCDIR)/%.cpp
	$(NOTIFY_PREPROCESSING)
	$(PREPROCESS_CXX)
	$(NOTIFY_COMPILING)
	$(COMPILE_CXX)
	$(NOTIFY_POSTPROCESSING)
	$(POSTPROCESS_CXX)
	$(NOTIFY_DIVIDER)


%.cpp.d: $(SRCDIR)/%.cpp
	$(CXX_DEPENDENCIES)

%.cxx.o: $(SRCDIR)/%.cxx
	$(NOTIFY_PREPROCESSING)
	$(PREPROCESS_CXX)
	$(NOTIFY_COMPILING)
	$(COMPILE_CXX)
	$(NOTIFY_POSTPROCESSING)
	$(POSTPROCESS_CXX)
	$(NOTIFY_DIVIDER)

%.cxx.d: $(SRCDIR)/%.cxx
	$(CXX_DEPENDENCIES)

# Build rules for OpenCL

%.cl.o: $(SRCDIR)/%.cl
	$(NOTIFY_PREPROCESSING)
	$(PREPROCESS_CL)
	$(NOTIFY_COMPILING)
	$(COMPILE_CL)
	$(NOTIFY_POSTPROCESSING)
	$(POSTPROCESS_CL)
	$(NOTIFY_DIVIDER)

%.cl.d: $(SRCDIR)/%.cl
	$(CL_DEPENDENCIES)

# Build rules for CUDA

%.cu.o: $(SRCDIR)/%.cu
	$(NOTIFY_PREPROCESSING)
	$(PREPROCESS_CU)
	$(NOTIFY_COMPILING)
	$(COMPILE_CU)
	$(NOTIFY_POSTPROCESSING)
	$(POSTPROCESS_CU)
	$(NOTIFY_DIVIDER)

%.cu.d: $(SRCDIR)/%.cu
	$(CUCC_DEPENDENCIES)

# Build rules for F77

%.F77.o: $(SRCDIR)/%.F77
	$(NOTIFY_PREPROCESSING)
	$(PREPROCESS_F77)
	$(NOTIFY_COMPILING)
	$(COMPILE_F77)
	$(NOTIFY_POSTPROCESSING)
	$(POSTPROCESS_F77)
	$(NOTIFY_DIVIDER)

%.f77.o: $(SRCDIR)/%.f77
	$(NOTIFY_COPYING)
	$(PREPROCESS_f77)
	$(NOTIFY_COMPILING)
	$(COMPILE_F77)
	$(NOTIFY_POSTPROCESSING)
	$(POSTPROCESS_F77)
	$(NOTIFY_DIVIDER)

%.F77.d: $(SRCDIR)/%.F77
	$(F77_DEPENDENCIES)

%.f77.d: $(SRCDIR)/%.f77
	$(f77_DEPENDENCIES)

# Build rules for F90

%.F.o: $(SRCDIR)/%.F
	$(NOTIFY_PREPROCESSING)
	$(PREPROCESS_F)
	$(NOTIFY_COMPILING)
	$(COMPILE_F)
	$(NOTIFY_POSTPROCESSING)
	$(POSTPROCESS_F)
	$(NOTIFY_DIVIDER)

%.f.o: $(SRCDIR)/%.f
	$(NOTIFY_COPYING)
	$(PREPROCESS_f)
	$(NOTIFY_COMPILING)
	$(COMPILE_F)
	$(NOTIFY_POSTPROCESSING)
	$(POSTPROCESS_F)
	$(NOTIFY_DIVIDER)

%.F.d: $(SRCDIR)/%.F
	$(F_DEPENDENCIES)

%.f.d: $(SRCDIR)/%.f
	$(f_DEPENDENCIES)

# Build rules for free-format F90

%.F90.o: $(SRCDIR)/%.F90
	$(NOTIFY_PREPROCESSING)
	$(PREPROCESS_F90)
	$(NOTIFY_COMPILING)
	$(COMPILE_F90)
	$(NOTIFY_POSTPROCESSING)
	$(POSTPROCESS_F90)
	$(NOTIFY_DIVIDER)

%.f90.o: $(SRCDIR)/%.f90
	$(NOTIFY_COPYING)
	$(PREPROCESS_f90)
	$(NOTIFY_COMPILING)
	$(COMPILE_F90)
	$(NOTIFY_POSTPROCESSING)
	$(POSTPROCESS_F90)
	$(NOTIFY_DIVIDER)

%.F90.d: $(SRCDIR)/%.F90
	$(F90_DEPENDENCIES)

%.f90.d: $(SRCDIR)/%.f90
	$(f90_DEPENDENCIES)