delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2001/06/22/17:56:09

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
Message-ID: <2C08D4EECBDED41184BB00D0B747334202FB44BE@exchanger.cacheflow.com>
From: "Karr, David" <david DOT karr AT cacheflow DOT com>
To: "'cygwin AT cygwin DOT com'" <cygwin AT cygwin DOT com>
Subject: Make: Adding ";" after dependency causes "$<" to not refer to whe
re it was found in "vpath"
Date: Fri, 22 Jun 2001 14:41:37 -0700
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.5.2653.19)

I'm confused by some behavior I'm seeing from GNU make.  It's certainly
possible I'm doing something wrong, but I'm at a loss to understand what is
going on here.

Following this is "Makefile" and "foo.c", which is just a "Hello, world"
program.  I have the source file in a "src" subdirectory, but I refer to the
source file name without the directory name, and use "vpath %.c src" so Make
knows where to find it.  My rule for compiling the source file uses "$<" to
specify the source file name.

These two lines from the Makefile are what concern me.

  #% :: dist ; echo bar
  % :: dist

If I do a "make all" with it in this state, I get the following (assume I
always do a "make clean" before doing anything):

  gcc -o foo.o -c src/foo.c
  gcc -o target.exe foo.o

This works fine.  Notice that "$<" expanded to "src/foo.c".

Now, if in the two lines of "concern" from above, if you comment back in the
first line and comment out the second line, and then do "make all" again,
you get:

  echo bar
  bar
  gcc -o foo.o -c foo.c
  gcc: foo.c: No such file or directory
  gcc: No input files
  make: *** [foo.o] Error 1

So, just by adding a command ("echo bar") after the catchall dependency on
"dist", it caused the value of "$<" for the "%.o" rule to be "foo.c" instead
of "src/foo.c".  It turns out it doesn't matter if I do "; echo bar", or if
I just put a "\techo bar" line after "% :: dist".

Then, I noticed that if I change "%.o : %.c" to "%.o :: %.c", then it gives
me the correct behavior again, where "$<" is equal to "src/foo.c".

What is going on here?

Makefile:
-----------------------
vpath %.c src
all : target.exe
dist :
	if [ ! -d $@ ]; then mkdir -p $@; fi

target.exe : foo.o
	gcc -o $@ $^

#%.o :: %.c
%.o : %.c
	gcc -o $@ -c $<

% :: dist ; echo bar
#% :: dist

clean :
	-rm -f *.o target.exe
-----------------------

src/foo.c:
-----------------------
#include <stdio.h>
int main(int argc, char* argv[])
{
	printf("Hello, world.\n");
}
-----------------------


--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019