summaryrefslogtreecommitdiff
path: root/Makefile
blob: 5c8a0ad7fa3ee6c1146fa0e5303cf9638c335581 (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
# /*@@
#   @file      Makefile
#   @date      Sun Jan 17 22:26:05 1999
#   @author    Tom Goodale
#   @desc 
#   gnu Makefile for the CCTK.
#
# WARNING: This makefile may not function with "make".  Errors like
# make: file `Makefile' line 36: Must be a separator (: or ::) for rules (bu39)
# mean you should have used gmake.  gmake is available free
# from ftp://prep.ai.mit.edu/ and should be installed on all production
# systems.
#
# For information on how to use this makefile, type
# gmake help.
#
#   
#   @enddesc 
#   @version $Id: Makefile,v 1.26 1999-04-28 09:06:44 allen Exp $
# @@*/

# Make quietly unless told not to
ifneq ($(strip $(SILENT)),no)
.SILENT:
endif

# Stuff for parallel makes
# TJOBS is the number of thorns to compile in parallel
ifeq ($(strip $(TJOBS)), )
TJOBS = 1
endif

# FJOBS is the number of files within a thorn to compile in parallel
ifeq ($(strip $(FJOBS)), )
FJOBS = 1
endif

export TJOBS FJOBS

# End of parallel make stuff


# Set the options to pass to the setup script
ifneq ($(strip $(options)),)
SETUP_OPTIONS = -config_file=$(options)
else
SETUP_OPTIONS = 
endif

# Various auxilary programs
PERL = perl
SETUP    = lib/make/setup_configuration.pl
NEWTHORN = lib/make/new_thorn.pl

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

# Work out where we are
export CCTK_HOME := $(shell pwd)

# Work out which configurations are available
CONFIGURATIONS = $(patsubst configs/%,%,$(wildcard configs/*))

# Default target does nothing. 
# In principle should set up a default based upon uname or something.
.PHONY:default 

default: new_setup
	@echo $(DIVIDER)
ifeq ($(words $(CONFIGURATIONS)), 1)
	@echo Please use $(MAKE) $(CONFIGURATIONS) 
else
	@echo Known configurations are: $(CONFIGURATIONS)
	@echo Please use $(MAKE) \<configuration\>
endif
	@echo $(DIVIDER)

# If there are no configurations, call the setup program.
.PHONY: new_setup

new_setup:
ifeq ($(strip $(CONFIGURATIONS)),)
	@echo $(DIVIDER)
	@echo Setting up cctk
	$(PERL) -s $(SETUP) $(SETUP_OPTIONS)
	@echo $(DIVIDER)
	@echo You are now ready to build the CCTK.
	@echo This is done by $(MAKE) \<configuration\>
	@echo
	@echo Please ignore the error below !
	@echo $(DIVIDER)
	exit 2
endif

# Target to build a configuration
.PHONY: $(CONFIGURATIONS)

$(CONFIGURATIONS):
	cd configs/$@ 
	$(MAKE) -f $(CCTK_HOME)/lib/make/make.configuration TOP=$(CCTK_HOME)/configs/$@ CCTK_HOME=$(CCTK_HOME) -j $(TJOBS)

# Clean target
.PHONY: distclean

distclean:
	@echo $(DIVIDER)
	@echo Deleting all your configurations !
	rm -rf configs
	@echo $(DIVIDER)

# Targets to make tags files

# Mark these targets phony to force an update when gmake TAGS is done.
.PHONY: TAGS tags

TAGS:
	@echo $(DIVIDER)
	@echo Updating the Emacs TAGS file
	find src packages \( -name '*.[chCF]' -o -name '*.F77' -o -name '*.cc' \) \
          -exec etags --append {} \;
#	find src packages \( -name '*.[cChF]' -o -name '*.F77' -o -name '*.cc'\) \
#          -exec etags --append --regex '/[a-z A-Z \t]*FORTRAN_NAME[^)]*/' {} \;
	perl -pi -e 's/(subroutine\s*)([a-zA-Z0-9_]+)/\1\L\2/g;' TAGS
	@echo $(DIVIDER)

tags:
	@echo $(DIVIDER)
	@echo Updating the vi tags file
	find src packages \( -name '*.[cChF]' -o -name '*.F77' -o '*.cc'\) \
          -exec ctags --append {} \;
	perl -pi -e 's/(subroutine\s*)([a-zA-Z0-9_]+)/\1\L\2/g;' tags
	@echo $(DIVIDER)

# Make a new configuration
.PHONY: config

config:
	@echo $(DIVIDER)
	@echo Running the configuration program
	$(PERL) -s $(SETUP) $(SETUP_OPTIONS)
	@echo $(DIVIDER)

# The help system.
.PHONY: help

help:
	@echo $(DIVIDER)
	@echo This is the main makefile for the Cactus Computational Toolkit
ifeq ($(strip $(CONFIGURATIONS)),)
	@echo There are no configurations currently specified.
	@echo $(MAKE) with no arguments will run a setup script.
else
	@echo The following configurations are currently specified
	@echo $(CONFIGURATIONS)
	@echo To build a configuration run $(MAKE) followed by the name of a configuration.
	@echo To clean a configuration run $(MAKE) followed by the name of a configuration suffixed by -clean e.g. Linux-clean.  This deletes all object and dependency files in the configuration.
	@echo To clean a configuration\'s dependency files run $(MAKE) followed by the name of a configuration suffixed by -cleandeps e.g. Linux-cleandeps.
	@echo To clean a configuration\'s object files run $(MAKE) followed by the name of a configuration suffixed by -cleanobjs e.g. Linux-cleanobjs.
	@echo To restore a configuration to almost a new state run $(MAKE) followed by the name of a configuration suffixed by -realclean e.g. Linux-realclean. This deletes all but the config-data directory and the ActiveThorns file.
	@echo To delete a configuration run $(MAKE) followed by the name of a configuration suffixed by -delete e.g. Linux-delete.
	@echo To rebuild a configuration run $(MAKE) followed by the name of a configuration suffixed by -rebuild e.g. Linux-rebuild. This forces the CST to be rerun.
	@echo To reconfigure a configuration run $(MAKE) followed by the name of a configuration suffixed by -reconfig e.g. Linux-reconfig.  This reruns the configuration scripts.
endif
	@echo $(DIVIDER)
	@echo $(MAKE) also knows the following targets
	@echo
	@echo       TAGS      - creates an Emacs TAGS file
	@echo       tags      - creates a Vi TAGS file
	@echo       config    - creates a new configuration
	@echo       newthorn  - creates a new thorn
	@echo       distclean - deletes all existing configurations
	@echo       testsuite - run the test program
	@echo       downsize  - remove non-essential files
	@echo       \<anything else\> prompts to create such a configuration.
	@echo $(DIVIDER)

# Clean a configuration

ifneq ($strip($(CONFIGURATIONS)),)
.PHONY $(addsuffix -clean,$(CONFIGURATIONS)):

$(addsuffix -clean,$(CONFIGURATIONS)):
	@echo $(DIVIDER)
	@echo Cleaning configuration $(@:%-clean=%)
	cd configs/$(@:%-clean=%)  
	$(MAKE) -f $(CCTK_HOME)/lib/make/make.configuration TOP=$(CCTK_HOME)/configs/$(@:%-clean=%) CCTK_HOME=$(CCTK_HOME) clean
	@echo $(DIVIDER)

endif

%-clean:
	@echo $(DIVIDER)
	@echo Configuration $(@:%-clean=%) does not exist.
	@echo Cleaning aborted.


# Clean just dependency files

ifneq ($strip($(CONFIGURATIONS)),)
.PHONY $(addsuffix -cleandeps,$(CONFIGURATIONS)):

$(addsuffix -cleandeps,$(CONFIGURATIONS)):
	@echo $(DIVIDER)
	@echo Cleaning configuration $(@:%-cleandeps=%)
	cd configs/$(@:%-cleandeps=%)  
	$(MAKE) -f $(CCTK_HOME)/lib/make/make.configuration TOP=$(CCTK_HOME)/configs/$(@:%-cleandeps=%) CCTK_HOME=$(CCTK_HOME) cleandeps
	@echo $(DIVIDER)

endif

%-cleandeps:
	@echo $(DIVIDER)
	@echo Configuration $(@:%-cleandeps=%) does not exist.
	@echo Cleaning dependencies aborted.

# Clean just object files

ifneq ($strip($(CONFIGURATIONS)),)
.PHONY $(addsuffix -cleanobjs,$(CONFIGURATIONS)):

$(addsuffix -cleanobjs,$(CONFIGURATIONS)):
	@echo $(DIVIDER)
	@echo Cleaning configuration $(@:%-cleanobjs=%)
	cd configs/$(@:%-cleanobjs=%)  
	$(MAKE) -f $(CCTK_HOME)/lib/make/make.configuration TOP=$(CCTK_HOME)/configs/$(@:%-cleanobjs=%) CCTK_HOME=$(CCTK_HOME) cleanobjs
	@echo $(DIVIDER)

endif

%-cleanobjs:
	@echo $(DIVIDER)
	@echo Configuration $(@:%-cleanobjs=%) does not exist.
	@echo Cleaning object files aborted.


# Clean away all produced files (doesn't delete ActiveThorns)

ifneq ($strip($(CONFIGURATIONS)),)
.PHONY $(addsuffix -realclean,$(CONFIGURATIONS)):

$(addsuffix -realclean,$(CONFIGURATIONS)):
	@echo $(DIVIDER)
	@echo Cleaning configuration $(@:%-realclean=%)
	cd configs/$(@:%-realclean=%)  
	$(MAKE) -f $(CCTK_HOME)/lib/make/make.configuration TOP=$(CCTK_HOME)/configs/$(@:%-realclean=%) CCTK_HOME=$(CCTK_HOME) realclean
	@echo $(DIVIDER)

endif

%-realclean:
	@echo $(DIVIDER)
	@echo Configuration $(@:%-cleanreal=%) does not exist.
	@echo Cleaning aborted.

# Delete a configuration

ifneq ($strip($(CONFIGURATIONS)),)
.PHONY $(addsuffix -delete,$(CONFIGURATIONS)):

$(addsuffix -delete,$(CONFIGURATIONS)):
	@echo $(DIVIDER)
	@echo Deleting configuration $(@:%-delete=%)
	cd configs ; rm -rf $(@:%-delete=%)  
	@echo $(DIVIDER)

endif

%-delete:
	@echo $(DIVIDER)
	@echo Configuration $(@:%-delete=%) does not exist.
	@echo Deletion aborted.

# Rebuild a configuration

ifneq ($strip($(CONFIGURATIONS)),)
.PHONY $(addsuffix -rebuild,$(CONFIGURATIONS)):

$(addsuffix -rebuild,$(CONFIGURATIONS)):
	@echo $(DIVIDER)
	@echo Rebuilding $(@:%-rebuild=%)
	if [ -r configs/$(@:%-rebuild=%)/config-data/make.thornlist ] ; then rm  configs/$(@:%-rebuild=%)/config-data/make.thornlist ; fi
	$(MAKE) $(@:%-rebuild=%)
endif

%-rebuild:
	@echo $(DIVIDER)
	@echo Configuration $(@:%-rebuild=%) does not exist.
	@echo Rebuild aborted.

# Regenerate the active thorns list

ifneq ($strip($(CONFIGURATIONS)),) 
.PHONY $(addsuffix -activethorns,$(CONFIGURATIONS)):

$(addsuffix -activethorns,$(CONFIGURATIONS)):
	@echo $(DIVIDER)
	@echo Regenerating ActiveThorn list $(@:%-activethorns=%)
	if [ -r configs/$(@:%-activethorns=%)/ActiveThorns ] ; then rm configs/$(@:%-activethorns=%)/ActiveThorns ; fi
	$(MAKE) $(@:%-activethorns=%)
endif

%-activethorns:
	@echo $(DIVIDER)
	@echo Configuration $(@:%-activethorns=%) does not exist.
	@echo Regeneration of ActiveThorns aborted.

# Rerun the configuration script

ifneq ($strip($(CONFIGURATIONS)),)
.PHONY $(addsuffix -reconfig,$(CONFIGURATIONS)):

$(addsuffix -reconfig,$(CONFIGURATIONS)):
	@echo $(DIVIDER)
	$(PERL) -s $(SETUP) -reconfig=1 $(SETUP_OPTIONS) $(@:%-reconfig=%); 
endif

%-reconfig:
	@echo $(DIVIDER)
	@echo Configuration $(@:%-reconfig=%) does not exist.
	@echo Reconfiguration aborted.

# Make a new thorn

.PHONY: newthorn
newthorn:
	@echo $(DIVIDER)
	@echo Creating a new thorn
	$(PERL) -s $(NEWTHORN);
	@echo $(DIVIDER)

# Run the testsuite

ifneq ($strip($(CONFIGURATIONS)),) 
.PHONY $(addsuffix -testsuite,$(CONFIGURATIONS)):

$(addsuffix -testsuite,$(CONFIGURATIONS)):
	@echo $(DIVIDER)
	@echo Running test suite $(@:%-activethorns=%)
	if [ -r configs/$(@:%-testsuite=%)/ActiveThorns ] ; then $(PERL) lib/sbin/Runtest.pl $(@:%-testsuite=%) ; fi
endif

%-testsuite:
	@echo $(DIVIDER)
	@echo Configuration $(@:%-testsuite=%) does not exist.
	@echo Test suite aborted.

# Remove non-essential files

.PHONY: downsize
downsize:
	@echo $(DIVIDER)
	@echo Remove flesh and thorn documentation \(\no\)?
	read yesno rest ;\
	if [ "x$$yesno" = "xyes" -o "x$$yesno" = "xy" -o "x$$yesno" = "xYES" -o "x$$yesno" = "xY" ] ;\
	then  \
	rm -rf doc; rm -rf packages/*/*/doc; \
	echo $(DIVIDER)   ;  \
	fi 
	@echo Remove thorn testsuites \(\no\)?
	read yesno rest ;\
	if [ "x$$yesno" = "xyes" -o "x$$yesno" = "xy" -o "x$$yesno" = "xYES" -o "x$$yesno" = "xY" ] ;\
	then  \
	rm -rf packages/*/*/test; \
	echo $(DIVIDER)   ;  \
	fi 
	@echo Remove all configurations \(\no\)?
	read yesno rest ;\
	if [ "x$$yesno" = "xyes" -o "x$$yesno" = "xy" -o "x$$yesno" = "xYES" -o "x$$yesno" = "xY" ] ;\
	then  \
	gmake distclean; \
	echo $(DIVIDER)   ;  \
	fi 

# Last resort rule.  Assume it is the name of a configuration

%::
	@echo $(DIVIDER)
	echo Setup configuration $@ \(no\)?
	read yesno rest ;\
	if [ "x$$yesno" = "xyes" -o "x$$yesno" = "xy" -o "x$$yesno" = "xYES" -o "x$$yesno" = "xY" ] ;\
	then  \
	echo Setting up new configuration $@; \
	$(PERL) -s $(SETUP) $(SETUP_OPTIONS) $@; \
	echo $(DIVIDER)   ;  \
	echo Use $(MAKE) $@ to build the configuration.; \
	else \
	echo Setup cancelled ;     \
	fi 
	@echo $(DIVIDER)