Unix Programming - make question relating foreach ?

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > May 2005 > make question relating foreach ?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author make question relating foreach ?
lothar.behrens@lollisoft.de

2005-05-12, 5:52 pm

Hi,

I create makefiles automatically based on existing source files over a
source
mask. Building the object files with the created makefile is no
problem.

But the problem overcomes when there are too many files (exeeding 500
characters)

OBJS = file1.obj file2.obj filen.obj ...

$(PROGRAM).dll.lnk: $(OBJS) makefile
@echo NAME $(PROGRAM).dll > $@
@echo FIL { $(OBJS) } >> $@

The problem may only be on Windows, but I am not sure.

How to solve this ?

Thanks, Lothar

Jens.Toerring@physik.fu-berlin.de

2005-05-12, 5:52 pm

lothar.behrens@lollisoft.de wrote:
> I create makefiles automatically based on existing source files over a
> source
> mask. Building the object files with the created makefile is no
> problem.


> But the problem overcomes when there are too many files (exeeding 500
> characters)


> OBJS = file1.obj file2.obj filen.obj ...


> $(PROGRAM).dll.lnk: $(OBJS) makefile
> @echo NAME $(PROGRAM).dll > $@
> @echo FIL { $(OBJS) } >> $@


> The problem may only be on Windows, but I am not sure.


I just cobbled together a Makefile where I put files with into OBJS,
so that it ended up with more than 2000 chars. GNU make seems to
have no problems with this. So it could be that arbitrary limits are
built into the make version you are using. If that's the case your
only option is probably using a different version of make. Another
possibility is that it's a problem with your shell, i.e. the shell
does not like lines that long. In that case you might try to echo
the file names separately into the output file instead of trying to
do it in a single command - just use your shells commands for doing
that - but don't forget to have the commands you want to be run in a
single instance of the shell on a single line. And that you need an
additional '$' in front of shell variables since make "eats" one of
the. I.e. try something like

$(PROGRAM).dll.lnk: $(OBJS) makefile
@echo NAME $(PROGRAM).dll > $@
@echo -n "FIL { " >> $@;
@for obj in $(OBJS); do \
echo -n "$$obj " >> $@; \
done
@echo "}" >> $@

or whoever your shell allows you to do that (the example should work
with [ba]sh).

Which make and shell are you using? And what kind of error messages
do you get?
Regards, Jens
--
\ Jens Thoms Toerring ___ Jens.Toerring@physik.fu-berlin.de
\__________________________ http://www.toerring.de
lothar.behrens@lollisoft.de

2005-05-12, 5:52 pm

I use GNU make and on windows the cmd shell. I do not exactly know
how make executes the echo command.

Simply said, if $(OBJS) has more than 500 characters, it gets wrapped
exactly at character 500.

Due to the fact, that I write the application that creates the makefile
I would
better write a special rule for the link info file. This is because the
app knows
about the object files.

The for loop in your sample is a bash or similar loop. I cannot use it
with
cmd. And the foreach keyword I asked here is not mentioned as
equivalent
yet. It would probably, but I don't know how.

Lothar

Lothar

Måns Rullgård

2005-05-12, 5:52 pm

lothar.behrens@lollisoft.de writes:

> I use GNU make and on windows the cmd shell.


Then you should probably not be asking in comp.UNIX.programmer.

--
Måns Rullgård
mru@inprovide.com
lothar.behrens@lollisoft.de

2005-05-12, 5:52 pm

Thank you.

Is there anywhere a group especially for make ?

Since I search for a solution. I know what's wrong :-)

Roger Leigh

2005-05-12, 5:52 pm

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

lothar.behrens@lollisoft.de writes:

> Is there anywhere a group especially for make ?


gnu.utils.help

Your problems are most likely due to using a rubbish shell (cmd.exe),
with a very limited command line length. On my system, bash has a
maximum of 32 KiB (or so libtool tells me).

There are ways of working around this (google should help; I don't
remember myself), the most practical being a POSIX layer such as
Cygwin, or getting make to use an alternative shell. (I'd also
suggest using a system other than Windows, which includes a proper
shell.)


Regards,
Roger

- --
Roger Leigh
Printing on GNU/Linux? http://gimp-print.sourceforge.net/
Debian GNU/Linux http://www.debian.org/
GPG Public Key: 0x25BFB848. Please sign and encrypt your mail.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>

iD8DBQFCg78hVcFcaSW/ uEgRAgADAJ9hNLUiYRyJH8UGqyLd4FBLSpdTfQCc
CxDx
FtVByyydI2b8R0dDLzwxXnw=
=1T2O
-----END PGP SIGNATURE-----
Jens.Toerring@physik.fu-berlin.de

2005-05-12, 5:52 pm

lothar.behrens@lollisoft.de wrote:
> I use GNU make and on windows the cmd shell. I do not exactly know
> how make executes the echo command.


It invokes a shell for that purpose. You can set which shell to use
by setting the SHELL environment or Makefile variable (and figure
out which shell gets used by inspecting that make variable). For
each line in the Makefile a new shell gets invoked, that's why you
have to have all commands that are to be executed in the context
of the same shell on a single line.

> Simply said, if $(OBJS) has more than 500 characters, it gets wrapped
> exactly at character 500.


What does "gets wrapped" mean? The OBJS variable can't get wrapped since
where should it get wrapped to? So as far as I understand you it will
mean "in the output file", so it probably can only happen due to some
quirk of the shell you use (assuming that 'echo' is a shell-builtin, if
you have a separate 'echo' command that would also have to be taken
into account). Perhaps you have to look into getting a real shell to
make it work...

Or perhaps you shouldn't use a makefile for this special purpose.
It looks as if according to your rule the $(PROGRAM).dll.lnk file
will get rewritten anyway whenever you create a new makefile, so
you could also create it while your script is creating the make-
file - so all the information needed must already be known to the
script...
Regards, Jens
--
\ Jens Thoms Toerring ___ Jens.Toerring@physik.fu-berlin.de
\__________________________ http://www.toerring.de
lothar.behrens@lollisoft.de

2005-05-12, 5:52 pm

Wrapped normally means line breaks at word end for text editors or the
like.
Echo does line breaks in the middle of any word. (At character 500)

The 'tool' that writes the makefile, indeed knows about all the object
files. So it
can also write a separate file.

My understanding of foreach would not to be a workaround for the
problem with
the poor builtin echo command - eg. change the code of my mkmk tool is
needed :-(

I have choosen GNU make as my make tool, because this normally would be
used
on Linux. This way I have one make system for Windows, Linux and now
also for
Mac OS X.

For me this is multiplatform programming - not only at source code
level :-)

However, I am happy about such free tools !

Lothar

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com