summaryrefslogtreecommitdiff
path: root/lib/make/make.configuration
blob: e89b73fe14b0eb3ca261faeb6d4a8e342ec10593 (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
#/*@@
#  @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$
# @@*/

# Silence all but designated output
#.SILENT: 

# 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

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

FLESHLIB = Cactus
BINDINGSLIB= CactusBindings

CACTUSLIBS = $(FLESHLIB) $(BINDINGSLIB)

export MAKE_DIR  = $(CCTK_HOME)/lib/make

ALLCACTUSLIBS = $(notdir $(CACTUSLIBS) $(THORNS) $(THORNS) $(CACTUSLIBS))

# 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 .)
# We don't want to include this file if doing something like a make clean
# as, 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

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

# Build the executable
$(EXE): $(CONFIG)/make.thornlist $(patsubst %,$(CCTK_LIBDIR)/lib%.a,$(notdir $(THORNS) $(CACTUSLIBS)))
	@echo $(DIVIDER)
	@echo Creating $(EXE) from $(THORNS)
	$(CC) $(CFLAGS) $(CCOMPILEONLY)$(OPTIONSEP)$(TOP)$(DIRSEP)datestamp.o $(DATESTAMP)
	$(LD) $(CREATEEXE)$(OPTIONSEP)$(subst /,$(DIRSEP),$@) $(LDFLAGS) $(EXTRAFLAGS) $(subst /,$(DIRSEP), $(TOP)/datestamp.o) $(CACTUSLIBLINKLINE) $(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 
# directory.

$(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=$(PACKAGE_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 -j $(FJOBS)
	@echo $(DIVIDER)


# Include any extra dependencies

include $(CONFIG)/make.config.deps

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

$(CONFIG)/make.thornlist: $(TOP)/ThornList $(foreach lib, $(CCTK_HOME)/src $(THORNS:%=$(PACKAGE_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 ThornList

$(TOP)/ThornList:
	@echo $(DIVIDER)
	@echo Creating compiled ThornList containing all thorns in the packages directory
	$(PERL) -s $(BUILD_ACTIVETHORNS) $(CCTK_HOME)/packages > $@
	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:%=$(PACKAGE_DIR)/%/src/make.configuration.deps)
endif

# Phony targets.

.PHONY:update clean cleandeps cleanobjs realclean
update:

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

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

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

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/*
	rm -f datestamp.o