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