[Top][All Lists]

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

Re: Problems with empty macros.

From: Paul D. Smith
Subject: Re: Problems with empty macros.
Date: Sun, 21 Sep 2003 21:35:01 -0400

%% "Malayambakkam, Ravi [IT]" <address@hidden> writes:

  mr> I am using the follwoing makefile.  What the makefile is trying to
  mr> do is to read the contents from the 2nd line of the file
  mr> filename.dat.  The file basically contains a list of file objects.
  mr> The install target is trying to move the files to the install
  mr> directory.  I am having a problem when the file filename.dat is
  mr> empty.  SRC_FILES macro now becomes null and the install target is
  mr> failing for the cp command.

This is a shell issue, not a make issue.  Most Bourne shells don't allow
the argument list in a for loop to be empty.

  mr> Could you pls tell me if there is any fix for this.  I cannot add
  mr> any dummy entry in the file filename.dat.

There are all kinds of ways to avoid this, depending on how portable you
want to be.

You can add a dummy file into your for-loop then check for it, like

  install_target1: $(SRC_FILES)
        $(INS) ...
        for i in / $(SRC_FILES) ; do \
          case $$i in /) continue ;; esac; \
          echo "Installing $$i"; \
            ...; \

Or, you can test before the for loop:

  install_target1: $(SRC_FILES)
        $(INS) ...
        if [ -n "$(SRC_FILES)" ]; then \
          for i in $(SRC_FILES) ; do \
            echo "Installing $$i"; \
              ...; \
          done; \

Or, if you switch to using GNU make you can just test for it in make
instead of the shell:

  install_target1: $(SRC_FILES)
        $(INS) ...
  ifdef SRC_FILES
        for i in $(SRC_FILES) ; do \
          echo "Installing $$i"; \

  mr> all install install_MtrxDDL get_files := SRC_FILES = $(FILES:sh)

The above is not GNU make syntax and will not work.

Please don't post questions about versions of make which aren't GNU make
to this list.  If you're using Solaris make, use the comp.unix.solaris
USENET newsgroup for example.

 Paul D. Smith <address@hidden>          Find some GNU make tips at:            
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist

reply via email to

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