summaryrefslogtreecommitdiff
path: root/lib/make
diff options
context:
space:
mode:
authortradke <tradke@17b73243-c579-4c4c-a9d2-2d5706c11dac>2008-01-22 15:04:57 +0000
committertradke <tradke@17b73243-c579-4c4c-a9d2-2d5706c11dac>2008-01-22 15:04:57 +0000
commit205a037ee2e3f6fac27961121721eea9d87aed31 (patch)
tree0687160e4022f4c7ac0c9e9e3a5c559baa62a1e9 /lib/make
parentb4b8555712cb9acdfb32ab93fb7bc1f547e9d635 (diff)
patch from Erik Schnetter to work around an 'argument list too long' problem
during the generation of libCactusBindings.a on an IBM SP5 machine (see http://www.cactuscode.org/old/pipermail/developers/2007-December/005479.html as the corresponding email discussion thread) git-svn-id: http://svn.cactuscode.org/flesh/trunk@4446 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'lib/make')
-rw-r--r--lib/make/make.thornlib65
1 files changed, 62 insertions, 3 deletions
diff --git a/lib/make/make.thornlib b/lib/make/make.thornlib
index 6f1a9fd9..f54e0ca7 100644
--- a/lib/make/make.thornlib
+++ b/lib/make/make.thornlib
@@ -52,7 +52,7 @@ include $(SRCDIR)/make.code.defn
LOCAL_SUBDIRS := . $(SUBDIRS)
# Include all the make.code.defn files for the subdirectories
-# These have to be wrapped to allow us to concatanate all the
+# 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.
@@ -77,9 +77,27 @@ 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 $@ ; fi
- $(AR) $(ARFLAGS) $@ $(OBJS)
+ 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
+ $(RM) $(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
@echo $(DIVIDER)
# Extra stuff for allowing make to recurse into directories
@@ -98,3 +116,44 @@ cctk_Bindings/make.checked: FORCE
$(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))
+OBJS-words-max = 1000
+
+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