On 30 Jan 2004 at 09:55 PST, Daniel Shane wrote:
> I see,
>
> In that case, could we add a new text function that would work like
> filter-out, but simply faster? We could call it comm. The reason is quite
> simple, when strings become overwhelming, it is impossible to pass them to a
> shell script because of command line size limit. Therefore, they are not
> easy alternative to get the functionnality of filter-out at a reasonable
> speed.
>
> Daniel Shane

Hi Daniel,

If that is your problem, there is a work-around solution (suggested by Paul to
me 4 years back).

You can use make functions to echo (or rather printf) the elements of your
variable into a file.  Then you use xargs to process those values in sections
that will fit in your command line -- that is precisely the intended use of
xargs.

Make 3.80 allows you to call MAKE functions recursively.  This can be used to
loop through the list in chunks until you've extracted everything.

The full implementation of MAKE_LONG_LIST is attached below.

I needed this functionality to archive a library containing some 9000 objects.
I use it as follows:

AR_LIST := libfoo.list

include MakeLongList.mk

libfoo.a: $(AR_OBJS)
        $(call MAKE_LONG_LIST,$(AR_LIST),$(AR_OBJS))
        $(XARGS) $(AR) $(ARFLAGS) $@ < $(AR_LIST)

This is pretty fast, incidentally.

Ted        
-- 
 Ted Stern                                 Applications Group
 Cray Inc.                               office: 206-701-2182
 411 First Avenue South, Suite 600         cell: 206-383-1049
 Seattle, WA 98104-2860                     FAX: 206-701-2500

 Frango ut patefaciam -- I break that I may reveal
 (The Paleontological Society motto, equally apropos for debugging)

#
# MAKE_LONG_LIST:
#
# MAKE function to be called when a long variable list needs to be
# put into a file with one item on each line.
# Two arguments:
# $(1) = list name
# $(2) = MAKE variable to put into list
#
# The resulting list can be used in combination with xargs to get
# around shell command-line character-length restrictions.
#
# The current hack is encapsulated in a separate included Makefile
# to hide the confusing recursive function.
#
# RECURSIVE version is requires GNU make-3.80 or higher, but is shorter and
# will handle any size list.
#

# CALC:
# Math helper function -- Use shell to do simple operations.
# Relies on ksh/bash $(( )) syntax.
# If you don't like this or need something more portable, change to
# CALC = $(shell echo "$(1)" | bc)
CALC = $(shell echo $$(($(1))))

nextindx = $(call CALC,$(3)+1)
nextword = $(word $(nextindx),$(2))
nextlist = $(wordlist $(nextindx),$(words $(2)),$(2))

# ADD_TO_LIST:
# A recursive function definition to handle iteration
# ARG 1 = filename to contain list, one entry per line
# ARG 2 = variable containing a very long list
# ARG 3 = Increment
define ADD_TO_LIST
        @printf "%s\n" $(wordlist 1,$(3),$(2)) >> $(1)
        $(if $(nextword),$(call ADD_TO_LIST,$(1),$(nextlist),$(3)),@echo)
endef

# Actual MAKE_LONG_LIST definition is a wrapper around the recursive call.
# Note that the list file is first cleared out using Bourne/ksh/bash syntax.
# I just arbitrarily set the iteration size to 500, but you can make it
# smaller if the system environment length is still too large.
define MAKE_LONG_LIST
        : > $(1)
        $(call ADD_TO_LIST,$(1),$(2),500)
endef
_______________________________________________
Bug-make mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/bug-make

Reply via email to