summaryrefslogtreecommitdiff
path: root/lib/make/make.thornlib
blob: 1690025a8b109ae108847e1f97aadebf1a8ac25a (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
# /*@@
#   @file      make.thornlib
#   @date      Sun Jan 17 22:20:45 1999
#   @author    Tom Goodale
#   @desc 
#   Creates the library for a particular thorn
#   @enddesc 
#   @version $Id$
# @@*/

# 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 main make definitions for this configuration
include $(CONFIG)/make.config.defn

BINDINGS_DIR=$(TOP)/bindings

# Include the configuration make.THORN_NAME.defn for the thorn
# if it is not CactusBindings
INC_DIRS = 
ifneq ($(THORN), CactusBindings)
-include $(BINDINGS_DIR)/Configuration/Thorns/make.$(THORN).defn
endif

# Add appropriate include lines
INC_DIRS += $(SYS_INC_DIRS) $(SRCDIR) $(SRCDIR)/include $(CONFIG) $(BINDINGS_DIR)/include $(CCTK_HOME)/src/include $(CCTK_HOME)/arrangements $(BINDINGS_DIR)/Configuration/Thorns $(BINDINGS_DIR)/include/$(THORN)

# Allow subdirectories to inherit these include directories
export INC_DIRS

# Define some make variables
PRE_WRAPPER = make.pre
POST_WRAPPER = make.post

CCTK_SRCS :=

# Include the thorn's local include data
include $(SRCDIR)/make.code.defn

# Some extra stuff to allow make to recurse into subdirectories
# Protect the value of SRCS and SUBDIRS of this directory

LOCAL_SUBDIRS := . $(SUBDIRS)

# Include all the make.code.defn files for the subdirectories
# These have to be wrapped to allow us to concatenate all the
# SRCS definitions, complete with subdirectory names.
# Using -include to prevent warnings the first time the make.identity files 
# need to be made.
ifneq ($(strip $(LOCAL_SUBDIRS)),)
-include $(foreach DIR,$(LOCAL_SUBDIRS), $(DIR)/make.identity $(MAKE_DIR)/$(PRE_WRAPPER) $(SRCDIR)/$(DIR)/make.code.defn $(MAKE_DIR)/$(POST_WRAPPER))
endif

# The CactusBindings pseudo-thorn doesn't need to define its own bindings 8-)

ifneq ($(THORN), CactusBindings)
THORNBINDINGS=cctk_Bindings
-include cctk_Bindings/make.identity $(MAKE_DIR)/$(PRE_WRAPPER) $(BINDINGS_DIR)/build/$(THORN)/make.code.defn $(MAKE_DIR)/$(POST_WRAPPER)
endif

# Restore the value of SRCS and SUBDIRS of this directory
SRCS = $(CCTK_SRCS)

SUBDIRS = $(LOCAL_SUBDIRS)

# Turn source file names into object file names
OBJS = $(SRCS:%=%.o)

$(NAME): $(addsuffix /make.checked, $(SUBDIRS) $(THORNBINDINGS))
	if [ -r $(NAME) ] ; then echo Updating $(NAME) ; else echo Creating $(NAME) ; fi
	if [ -r $@ ] ; then rm -f $@ ; fi
###	create an archive of the object files
#	
##	This naive method will fail on some machines (eg. IBM SP5)
##	when there are too many object files to be passed on the command line.
#	$(AR) $(ARFLAGS) $@ $(OBJS)
#
##	This creates a list of all object files and incrementally archives them
##	in batches not larger than $(OBJS-words-max) files at a time.
	$(MAKE) -f $(MAKE_DIR)/make.thornlib $(NAME).objectlist
	xargs -n $(OBJS-words-max) $(AR) $(ARFLAGS) $@ < $(NAME).objectlist
##	Alternatively, we could create a single object file from the object
##	files and put it into an archive.
#	ld -r -o $@.o $(OBJS)
#	$(AR) $(ARFLAGS) $@ $@.o
	if test "x$(USE_RANLIB)" = "xyes" ; then $(RANLIB) $(RANLIBFLAGS) $@ ; fi
##	Or we could create a dynamic library the object files.
##	to do: use a two-level namespace
##		(this requires knowing the dependencies of each thorn library)
#	libtool -dynamic -arch_only ppc -o $@ $(OBJS) -flat_namespace -undefined suppress -single_module
	$(NOTIFY_DIVIDER)

# Extra stuff for allowing make to recurse into directories

# This one makes the object files in the subdirectory
.PHONY: FORCE

$(addsuffix /make.checked, $(SUBDIRS)) : FORCE
	if [ ! -d $(dir $@) ] ; then $(MKDIR) $(MKDIRFLAGS) $(dir $@) ; fi
	cd $(dir $@) ; $(MAKE) CCTK_TARGET=make.checked TOP=$(TOP) CONFIG=$(CONFIG) SRCDIR=$(subst /*,,$(dir $(SRCDIR)/$@)*) THORN=$(THORN) USESTHORNS="$(USESTHORNS)" -f $(MAKE_DIR)/make.subdir

cctk_Bindings/make.checked: FORCE
	cd cctk_Bindings; $(MAKE) CCTK_TARGET=make.checked TOP=$(TOP) CONFIG=$(CONFIG) SRCDIR=$(BINDINGS_DIR)/build/$(THORN) THORN=$(THORN) USESTHORNS="$(USESTHORNS)" -f $(MAKE_DIR)/make.subdir

# This one puts a file containing identity info into the build subdirectory
$(addsuffix /make.identity, $(SUBDIRS) $(THORNBINDINGS)):
	if [ ! -d $(dir $@) ] ; then $(MKDIR) $(MKDIRFLAGS) $(dir $@) ; fi
	echo CCTK_THIS_SUBDIR := $(dir $@) > $@



# Create a file containing the names of all object files.

# Since the list may be too long to be passed to a shell, it is split
# into a set of rules which add lines to a file.  This file can later
# be used via xargs.

OBJS-words = $(words $(OBJS))

ifeq ($(shell uname),AIX)
# Be conservative about the maximum number of objects that can be
# handled at once.  AIX has a command line length limit of about
# 32000.  Each object's path name may be about 100 characters long.
OBJS-words-max = 200
else
# Assume that the system has no limit to speak of.
OBJS-words-max = 10000
endif

ifeq ($(shell test $(OBJS-words) -le $(OBJS-words-max) && echo 1), 1)

# The list is short.  Create the file directly, which is faster.

.PHONY: $(NAME).objectlist
$(NAME).objectlist:
	echo $(OBJS) > $(NAME).objectlist

else

# The list is long.  Create the file via a set of rules, one rule per
# object file.

OBJS-added = $(OBJS:%=%.added)

.PHONY: $(NAME).objectlist
$(NAME).objectlist: $(OBJS-added)

# Truncate the file
.PHONY: $(NAME).objectlist.create
$(NAME).objectlist.create:
	: > $(NAME).objectlist

# Add a line to the file
.PHONY: $(OBJS-added)
$(OBJS-added): $(NAME).objectlist.create
	echo $(@:%.added=%) >> $(NAME).objectlist

endif