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

# Silence all but designated output
#.SILENT: 

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

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

DATESTAMP = $(CCTK_HOME)/src/datestamp.c
export MAKE_DIR  = $(CCTK_HOME)/lib/make

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

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

# Include the list of thorns to be built 
# (Use -include to prevent warnings messages, as the file will be built if
# it is missing .)
-include $(CONFIG)/make.thornlist

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

# Build the executable
$(EXE): $(CONFIG)/make.thornlist $(patsubst %,$(CCTK_LIBDIR)/lib%.a,$(notdir $(THORNS))) $(CCTK_LIBDIR)/libCactus.a $(CCTK_LIBDIR)/libCactusBindings.a
	@echo $(DIVIDER)
	@echo Creating $(EXE) from $(THORNS)
	$(CC) -c $(DATESTAMP) -o $(TOP)/datestamp.o
	$(LD) -o $@ $(LDFLAGS) $(TOP)/datestamp.o  -L$(CCTK_LIBDIR) -lCactus -lCactusBindings $(addprefix -l,$(notdir $(THORNS))) $(addprefix -l,$(notdir $(THORNS))) -lCactus $(LIBDIRS:%=-L%) $(LIBS:%=-l%)
	@echo $(DIVIDER)
	@echo All done !
	@echo $(DIVIDER)

# 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 
# directoryory.

$(CCTK_LIBDIR)/lib%.a: update
	@echo $(DIVIDER)
	@echo Checking status of $(notdir $@)
	if [ ! -d $(SCRATCH_BUILD) ]; then $(MKDIR) $(SCRATCH_BUILD) ; fi
	if [ ! -d $(BUILD_DIR) ]; then $(MKDIR) $(BUILD_DIR) ; fi
	thorn_name=$(@:$(CCTK_LIBDIR)/lib%.a=%); \
	if [ "$$thorn_name" = "Cactus" ] ; then src_dir=$(CCTK_HOME)/src ; \
	else if [ "$$thorn_name" = "CactusBindings" ] ; then src_dir=$(BINDINGS_DIR) ; \
	else src_dir=$(TOOLKIT_DIR)/$(@:$(CCTK_LIBDIR)/lib%.a=$(filter %/$(@:$(CCTK_LIBDIR)/lib%.a=%), $(THORNS)))/src ; fi ; fi ;\
	if [ ! -d $(BUILD_DIR)/$$thorn_name ]; then $(MKDIR) $(BUILD_DIR)/$$thorn_name ; fi ; \
	cd $(BUILD_DIR)/$$thorn_name ; \
	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 -f $$make_file 
	@echo $(DIVIDER)


# Include any extra dependencies

include $(CONFIG)/make.config.deps

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

$(CONFIG)/make.thornlist: $(TOP)/ActiveThorns $(foreach lib, $(CCTK_HOME)/src $(THORNS:%=$(TOOLKIT_DIR)/%), $(lib)/param.ccl $(lib)/interface.ccl $(lib)/schedule.ccl)
	@echo $(DIVIDER)
	if [ -r $@ ] ; then echo Reconfiguring thorns ; rm $@ ;\
	else echo Configuring thorns ; fi
	$(PERL) -s $(CST) -config_dir=$(CONFIG) -cctk_home=$(CCTK_HOME) -top=$(TOP) $< 

# Rule to build ActiveThorns

$(TOP)/ActiveThorns:
	@echo $(DIVIDER)
	@echo Creating ActiveThorn list containing all thorns in the toolkits directory
	$(PERL) -s $(BUILD_ACTIVETHORNS) $(CCTK_HOME)/toolkits > $@
	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 ; \
	echo $(DIVIDER) ; \
	cat $@ ; \
	echo $(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
	@echo $(DIVIDER)

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

# Phony targets.

.PHONY:update clean
update:

clean:
	@echo Deleting all object files in $(TOP)
	find $(TOP) \( -name '*.o' -o -name '*.a' \) -exec rm {} \;