summaryrefslogtreecommitdiff
path: root/lib/make/make.configuration
blob: 663a23d45803874ba35f44fd5bd07998e4078764 (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
#/*@@
#  @file      make.configuration
#  @date      Sun Jan 17 22:15:23 1999
#  @author    Tom Goodale
#  @desc
#  Makes the CCTK executable for a particular configuration
#  @enddesc
#  @version $Id$
# @@*/

# Some configuration variables
CONFIG = $(TOP)/config-data
BINDINGS_DIR = $(TOP)/bindings
FLESH_DIR = $(CCTK_HOME)/src


# Scratch build area - need this to make sure F90 module files end up all
# in one directory.
export SCRATCH_BUILD=$(TOP)/scratch


# Check if the user specified options which are only used at configure time
# We only check some obvious configuration options here.
ifneq ($(strip $(DEBUG)), )
  $(warning "You specified 'DEBUG=$(DEBUG)'. This option is evaluated only at configuration time and will be ignored at compile time.")
endif
ifneq ($(strip $(OPTIMISE)), )
  $(warning "You specified 'OPTIMISE=$(OPTIMISE)'. This option is evaluated only at configuration time and will be ignored at compile time.")
endif
ifneq ($(strip $(OPTIMIZE)), )
  $(warning "You specified 'OPTIMIZE=$(OPTIMIZE)'. This option is evaluated only at configuration time and will be ignored at compile time.")
endif
ifneq ($(strip $(PROFILE)), )
  $(warning "You specified 'PROFILE=$(PROFILE)'. This option is evaluated only at configuration time and will be ignored at compile time.")
endif

export MAKE_DIR  = $(CCTK_HOME)/lib/make

CCTK_LIBNAME_PREFIX=thorn_
FLESHLIB = Cactus
BINDINGSLIB= CactusBindings

CACTUSLIBS = $(FLESHLIB) $(BINDINGSLIB)

# Dividers to make the screen output slightly nicer
DIVEL   =  __________________
DIVIDER =  $(DIVEL)$(DIVEL)$(DIVEL)$(DIVEL)
ifeq ($(shell echo $(VERBOSE) | tr '[:upper:]' '[:lower:]'),yes)
define NOTIFY_DIVIDER
	echo $(DIVIDER)
endef
else
define NOTIFY_DIVIDER
	:
endef
endif

# Include the definitions for this configuration
include $(CONFIG)/make.config.defn

# Define the name of the source file which is the one object on the linkline

DATESTAMP = $(CCTK_HOME)/src/datestamp.c

export PERLINTERP = $(shell echo $(PERL) | sed 's,^/cygdrive/\(.\)/,\1:/,' | sed 's,^//\(.\)/,\1:/,' )

# Use a phony main target to make sure we print a nice ending message 8-)
.PHONY: main

main: $(EXEDIR)$(DIRSEP)$(EXE)
	@echo All done !
	$(NOTIFY_DIVIDER)


# Put this in temporarily to make sure that people with existing
# configurations aren't disturbed

ifeq ($(strip $(LIBNAME_PREFIX)),)
ifeq ($(strip $(LIBNAME_SUFFIX)),)
LIBNAME_PREFIX = lib#
LIBNAME_SUFFIX = .a
endif
endif

# Include the list of thorns to be built
# (Use -include to prevent warnings messages, as the file will be built if
# it is missing .)
# We don't want to include this file if doing something like a make clean
# because if the file didn't exist, it would first be made, which would be
# pretty confusing during a make clean !

ifeq ($(strip $(MAKECMDGOALS)),)
-include $(CONFIG)/make.thornlist
endif

ifeq ($(strip $(MAKECMDGOALS)), utils)
-include $(CONFIG)/make.thornlist
endif

ifeq ($(strip $(MAKECMDGOALS)), build)
-include $(CONFIG)/make.thornlist
endif

ifeq ($(suffix $(strip $(MAKECMDGOALS))), .custom)
-include $(CONFIG)/make.thornlist
endif

# When building utility programs, include makefile definitions
# generated from a thorn's configuration.ccl
ifeq ($(strip $(UTILS)),)
ifneq ($(strip $(THORN_LINKLIST)),)
-include $(THORN_LINKLIST:%=$(BINDINGS_DIR)/Configuration/Thorns/make.%.defn)
endif
endif

# Allow each thorn to include some global definitions
ifneq ($(strip $(THORNS)),)
-include $(THORNS:%=$(PACKAGE_DIR)/%/src/make.configuration.defn)
endif

ifeq ($(strip $(UTILS)),)
override UTILS = $(ALL_UTILS)
endif

UTIL_DIR=$(EXEDIR)$(DIRSEP)$(CONFIG_NAME)


# Build the list of all libraries
ifeq ($(strip $(BEGIN_WHOLE_ARCHIVE_FLAGS)),)
# Repeat Cactus only if --whole-archive is not used
ALLCACTUSLIBS_BASE = $(notdir $(CACTUSLIBS) $(THORN_LINKLIST) $(CACTUSLIBS))
else
ALLCACTUSLIBS_BASE = $(notdir $(THORNS) $(CACTUSLIBS))
endif

ALLCACTUSLIBS = $(ALLCACTUSLIBS_BASE:%=$(CCTK_LIBNAME_PREFIX)%)

$(CCTK_LIBDIR)/LINKLIST: $(patsubst %,$(CCTK_LIBDIR)/$(LIBNAME_PREFIX)$(CCTK_LIBNAME_PREFIX)%$(LIBNAME_SUFFIX),$(notdir $(THORNS) $(CACTUSLIBS)))
	cd $(CCTK_LIBDIR); \
	for thorn in $(notdir $(THORNS) $(CACTUSLIBS)); do \
		$(XARGS) -n 1 -I :OBJFILE: echo $$thorn/:OBJFILE: <$(LIBNAME_PREFIX)$(CCTK_LIBNAME_PREFIX)$$thorn$(LIBNAME_SUFFIX).objectlist; \
	done >$@.tmp
	mv $@.tmp $@

# Build the executable
$(EXEDIR)$(DIRSEP)$(EXE): $(CONFIG)/make.thornlist $(CONFIG)/cctki_version.h $(patsubst %,$(CCTK_LIBDIR)/$(LIBNAME_PREFIX)$(CCTK_LIBNAME_PREFIX)%$(LIBNAME_SUFFIX),$(notdir $(THORNS) $(CACTUSLIBS))) $(CCTK_LIBDIR)/LINKLIST
	@echo Creating $(EXE) in $(EXEDIR) from $(THORNS)
	datetime=`/bin/date +'%Y-%m-%dT%H:%M:%S%z' 2>&1` ; \
	if [ $$? != 0 ]; then datetime=`/bin/date` ; fi ; \
	$(CC) $(CFLAGS) -DCCTK_COMPILE_DATETIME="$$datetime" $(CCOMPILEONLY)$(OPTIONSEP)"$(call TRANSFORM_DIRS,$(TOP)/datestamp.o)" -I"$(call TRANSFORM_DIRS,$(CCTK_HOME)/src/include)" -I"$(call TRANSFORM_DIRS,$(CONFIG))" "$(call TRANSFORM_DIRS,$(DATESTAMP))"
	if [ ! -d $(EXEDIR) ]; then $(MKDIR) $(MKDIRFLAGS) $(EXEDIR) ; fi
	$(LD) $(CREATEEXE)$(OPTIONSEP)"$(call TRANSFORM_DIRS,$@)" $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) $(EXTRAFLAGS) "$(call TRANSFORM_DIRS,$(TOP)/datestamp.o)" $(BEGIN_WHOLE_ARCHIVE_FLAGS) $(CACTUSLIBLINKLINE) $(END_WHOLE_ARCHIVE_FLAGS) $(GENERAL_LIBRARIES)
	@echo Done creating $(EXE).
	$(NOTIFY_DIVIDER)

# Version file
$(CONFIG)/cctki_version.h: $(CCTK_HOME)/Makefile
	echo "#ifndef _CCTKI_VERSION_H_" > $@
	echo "#define _CCTKI_VERSION_H_" >> $@
	echo "#define CCTK_VERSION_MAJOR $(CCTK_VERSION_MAJOR)" >> $@
	echo "#define CCTK_VERSION_MINOR $(CCTK_VERSION_MINOR)" >> $@
	echo "#define CCTK_VERSION_OTHER $(CCTK_VERSION_OTHER)" >> $@
	echo "#define CCTK_VERSION       $(CCTK_VERSION)" >> $@
	echo "#endif /* _CCTKI_VERSION_H_ */" >> $@

# Build a thorn library
# Libraries go into the appropriate library directory
# Each thorn's object files go into $(BUILD_DIR)/<thorn>
# This makes sure the appropriate build directories exist
# Also checks for the existance of Makefile in the thorn's
# src directory, and calls that rather than the default makefile
# used for making thorn libraries.
#
# Checks if the library is Cactus, in which case it uses the main source
# directory.

$(CCTK_LIBDIR)/$(LIBNAME_PREFIX)$(CCTK_LIBNAME_PREFIX)%$(LIBNAME_SUFFIX): update
        # (the mkdir below is protected against parallel makes)
	@thorn_name=$(@:$(CCTK_LIBDIR)/$(LIBNAME_PREFIX)$(CCTK_LIBNAME_PREFIX)%$(LIBNAME_SUFFIX)=%) ; \
	echo "Checking status of thorn $$thorn_name" ; \
	if [ ! -d $(SCRATCH_BUILD) ] ; \
	then \
		msg=`$(MKDIR) $(MKDIRFLAGS) $(SCRATCH_BUILD) 2>&1` ; \
		if [ ! -d $(SCRATCH_BUILD) ] ; \
		then \
			echo "$$msg" ; \
			exit 1 ; \
		fi ; \
	fi ; \
	if [ ! -d $(BUILD_DIR) ] ; \
	then \
		msg=`$(MKDIR) $(MKDIRFLAGS) $(BUILD_DIR) 2>&1` ; \
		if [ ! -d $(BUILD_DIR) ] ; \
		then \
			echo "$$msg" ; \
			exit 1 ; \
		fi ; \
	fi ; \
	if [ "$$thorn_name" = "Cactus" ] ; \
	then \
		src_dir=$(CCTK_HOME)/src ; \
	else \
		if [ "$$thorn_name" = "CactusBindings" ] ; \
		then \
			src_dir=$(BINDINGS_DIR) ; \
		else \
			src_dir=$(PACKAGE_DIR)/$(@:$(CCTK_LIBDIR)/$(LIBNAME_PREFIX)$(CCTK_LIBNAME_PREFIX)%$(LIBNAME_SUFFIX)=$(filter %/$(@:$(CCTK_LIBDIR)/$(LIBNAME_PREFIX)$(CCTK_LIBNAME_PREFIX)%$(LIBNAME_SUFFIX)=%), $(THORNS)))/src ; \
		fi ; \
	fi ; \
	if [ ! -d $(BUILD_DIR)/$$thorn_name ]; \
	then \
		$(MKDIR) $(MKDIRFLAGS) $(BUILD_DIR)/$$thorn_name ; \
	fi ; \
	cd $(BUILD_DIR)/$$thorn_name ; \
	$(NOTIFY_DIVIDER) ; \
	if [ -r "$$src_dir/Makefile" ] ; \
	then \
		make_file=$$src_dir/Makefile ; \
	else \
		make_file=$(MAKE_DIR)/make.thornlib ; \
	fi ; \
	$(MAKE) TOP=$(TOP) SRCDIR=$$src_dir CONFIG=$(CONFIG) NAME=$@ THORN=$$thorn_name USESTHORNS="$(USESTHORNS_$(@:$(CCTK_LIBDIR)/$(LIBNAME_PREFIX)$(CCTK_LIBNAME_PREFIX)%$(LIBNAME_SUFFIX)=%))" -f $$make_file $(FPARFLAGS)
	$(NOTIFY_DIVIDER)


# Include any extra dependencies

include $(CONFIG)/make.config.deps

# Rule to build the make.thornlist file from the ThornList file

rebuild: $(CONFIG)/make.thornlist

$(CONFIG)/make.thornlist: $(TOP)/ThornList $(foreach lib, $(CCTK_HOME)/src $(THORNS:%=$(PACKAGE_DIR)/%), $(lib)/param.ccl $(lib)/interface.ccl $(lib)/schedule.ccl) $(CCTK_HOME)/src/configuration.ccl $(CONFIG_THORNS:%=$(PACKAGE_DIR)/%/configuration.ccl) $(CCTK_HOME)/lib/make/force-rebuild
	if [ -r $@ ] ; then echo Reconfiguring thorns ; rm $@ ;\
	else echo Processing CCL files ; fi
	+$(PERL) -s $(CST) -config_dir=$(CONFIG) -cctk_home=$(CCTK_HOME) -top=$(TOP) $<

# Rule to build ThornList

$(TOP)/ThornList:
	@echo Creating compiled ThornList containing all thorns in the arrangements directory
	$(PERL) -s $(BUILD_ACTIVETHORNS) $(CCTK_HOME)/arrangements > $@
	if test "x$(PROMPT)" = "xyes" ; then \
	action="yes"; if [ "x$$EDITOR" = "x" ] ; then EDITOR=vi ; fi; \
	while [ "x$$action" = "xyes" -o "x$$action" = "xy" -o "x$$action" = "xYES" -o "x$$action" = "xY" ] ; \
	do \
	echo The thorn list is ; \
	$(NOTIFY_DIVIDER) ; \
	cat $@ ; \
	$(NOTIFY_DIVIDER) ; \
	echo Edit this list \(no\) \? ; \
	read action rest ; \
	if [ "x$$action" = "xyes" -o "x$$action" = "xy" -o "x$$action" = "xYES" -o "x$$action" = "xY" ] ; \
	then $$EDITOR $@ ; fi ; \
	done; \
	fi
	$(NOTIFY_DIVIDER)

# Allow each thorn to include some global dependencies
ifneq ($(strip $(THORNS)),)
-include $(THORNS:%=$(PACKAGE_DIR)/%/src/make.configuration.deps) $(THORNS:%=$(BINDINGS_DIR)/Configuration/Thorns/make.%.deps)
endif

# Catch the special case of a thorn being removed from the disk entirely.
$(foreach lib, $(CCTK_HOME)/src $(THORNS:%=$(PACKAGE_DIR)/%), $(lib)/param.ccl $(lib)/interface.ccl $(lib)/schedule.ccl) $(CCTK_HOME)/src/configuration.ccl $(CONFIG_THORNS:%=$(PACKAGE_DIR)/%/configuration.ccl):
	@echo "Missing file $@"
	@echo "Possibly from a thorn deleted from an arrangement"
	@echo "Deleting make.thornlist"
	rm  $(CONFIG)/make.thornlist
	@echo "Please try building again"
	exit 1


# Phony targets.

.PHONY:update editthorns clean cleandeps cleanobjs realclean build

# This phony target forces an update.
update:

editthorns:
	if test ! -r $(TOP)/ThornList ; then \
	echo "Creating compiled ThornList containing all thorns in the arrangements directory" \
	$(PERL) -s $(BUILD_ACTIVETHORNS) $(CCTK_HOME)/arrangements > $@ ; fi
	action="yes"; if [ "x$$EDITOR" = "x" ] ; then EDITOR=vi ; fi; \
	while [ "x$$action" = "xyes" -o "x$$action" = "xy" -o "x$$action" = "xYES" -o "x$$action" = "xY" ] ; \
	do \
	echo The thorn list is ; \
	$(NOTIFY_DIVIDER) ; \
	cat $(TOP)/ThornList ; \
	$(NOTIFY_DIVIDER) ; \
	echo Edit this list \(no\) \? ; \
	read action rest ; \
	if [ "x$$action" = "xyes" -o "x$$action" = "xy" -o "x$$action" = "xYES" -o "x$$action" = "xY" ] ; \
	then $$EDITOR $(TOP)/ThornList ; fi ; \
	done
	$(NOTIFY_DIVIDER)

clean:
	@echo Deleting all object and dependency files in $(TOP)
	find $(TOP) \( -name '*.[od]' -o -name '*.a' \) -exec rm {} \;
	rm -rf $(TOP)/scratch; $(MKDIR) $(MKDIRFLAGS) $(TOP)/scratch

cleandeps:
	@echo Deleting all dependency files in $(TOP)
	if test -d $(TOP)/build; then \
          find $(TOP)/build \( -name '*.[d]' -o -name '*.a' \) -exec rm {} \; ; \
        fi

cleanobjs:
	@echo Deleting all object files in $(TOP)
	find $(TOP) \( -name '*.[o]' -o -name '*.a' \) -exec rm {} \;
	rm -rf $(TOP)/scratch; $(MKDIR) $(MKDIRFLAGS) $(TOP)/scratch

realclean:
	@echo Deleting all built files in $(TOP)
	rm -rf $(TOP)/build
	rm -rf $(TOP)/bindings
	rm -rf $(TOP)/config-data/make.thornlist
	rm -rf $(TOP)/lib; $(MKDIR) $(MKDIRFLAGS) $(TOP)/lib
	rm -rf $(TOP)/scratch; $(MKDIR) $(MKDIRFLAGS) $(TOP)/scratch
	rm -f datestamp.o

# This target will build only a subset of the thorns for a given configuration.
# It also warns about thorns which don't exist.
THORN_BUILDLIST = $(filter $(ALLCACTUSLIBS_BASE), $(BUILDLIST))
UNKNOWN_THORNS = $(filter-out $(ALLCACTUSLIBS_BASE), $(BUILDLIST))

build: $(CONFIG)/make.thornlist $(CONFIG)/cctki_version.h $(patsubst %, $(CCTK_LIBDIR)/$(LIBNAME_PREFIX)$(CCTK_LIBNAME_PREFIX)%$(LIBNAME_SUFFIX), $(THORN_BUILDLIST))
	if test "x$(UNKNOWN_THORNS)" != "x"; then \
	  echo "WARNING: Don't know anything about '$(UNKNOWN_THORNS)' !"; \
	  $(NOTIFY_DIVIDER); \
	fi


# This target allows thorns to add to $(ALL_UTILS) and then
# have them built by a make utils

.PHONY: utils

utils: $(UTILS:%=$(UTIL_DIR)$(DIRSEP)%)