make-w32
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: suggestion: new make function


From: Luke Shumaker
Subject: Re: suggestion: new make function
Date: Sun, 25 Sep 2011 13:41:30 -0400
User-agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (Goj┼Ź) APEL/10.8 Emacs/23.3 (i686-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO)

At Tue, 20 Sep 2011 12:09:42 -0700,
Lawrence Ibarria wrote:
> I have often hit problems with the limit of command line lengths
> many shells have (CMD.EXE in Windows in my case).
> This is a common case with few solutions, I have searched around:
> 
> http://www.makelinux.net/make3/make3-CHP-5-SECT-6
> 
> I would like to propose a couple new functions in make that can help
> work around this problem.
> 
> $(dumpOneLine filename, $(list))
> $(dumpOnePerLine filename, $(list))
> 
> The idea here is to ask make to dump into a file (either on a single
> line or each element of the list in a new line) all the contents of
> a list.
> This function specifically does not use the shell, I expect make to
> implement it with fopen directly. Once all the contents of a long
> list in make are in a file, programs (such as linker, or compiler)
> can use that file as input.
> 
> I do not know how to address specifics such as variable expansion on
> the list (I'd suggest no variable expansion at all, create a new
> list for that).
> 
> What do you think?
> 
>   -- Lawrence

I vote 'no'. This can easily be implemented in your
Makefile. (assuming no single list item breaks the limit)

dumpOneLine = $(foreach item,$(2),echo -n '$(item) ' >> '$(1)')
dumpOnePerLine = $(foreach item,$(2),echo '$(item)' >> '$(1)')

then use
  $(call dumpOnePerLine filename, $(list))

I don't know if '>>' works the same in CMD.EXE as it does in Bash
(concatentate stdout of the command on the left to the file on the
right), or if echo behaves similarly ('-n' to make it ommit the
trailing newline), but something like it should work.

Further, this is frequently the WRONG way to do it. The example on the
page you linked to is terrible (surprising, I've come to expect better
from O'Reilly). The proper way to do that in make is:

java_source_files = $(wildcard $(addsuffix /*.java,$(source_dirs)))
java_class_files = $(patsubst %.java,%.class,$(java_source_files))
compile_all: $(java_class_files)
%.class: %.java
         $(JAVAC) $<

I'm sure someone can find an example of when the command length is an
actuall problem, but generally, it means that you're doing it wrong.
You're trying to write your makefile like a scripting language,
defining functions for doing tasks.  Make is about defining
relationships between files.

~ Luke Shumaker
http://lukeshu.ath.cx



reply via email to

[Prev in Thread] Current Thread [Next in Thread]