help-make
[Top][All Lists]
Advanced

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

paths and included makefiles


From: Ross Boylan
Subject: paths and included makefiles
Date: Fri, 3 Sep 2004 14:30:54 -0700
User-agent: Mutt/1.5.6+20040722i

I would like my snippets of makefiles able to find out the directory
in which they reside, even if they are included from another
directory.  As far as I can tell, this facility is not directly
available.  I'd appreciate any suggestions about the best way to
proceed.

Here's a simplified version of my setup
/src
/src/test
/src/debugtest
/src/libtest

/src has my main code, and test/ has test code and data files for the
tests.

debugtest/ and libtest/ are two different places I will build and run
the source and test code.

In either src/ or src/test I want to put a little snippet that,
depending on options, creates a variable holding arguments to pass to
the test program.  The options control how many arguments there are.
The arguments are paths to the test data files (in src/test/).

If, for example, the snippet is under test/, it seems natural to say
CMDARGS = $(CURDIR)/data1 $(CURDIR)/data2.

The problem is that if I include that snippet from another directory,
CURDIR isn't pointing at the right place.

Here are some ways I've thought of solving this:

1. Since everything will be driven by a makefile in src/, I could
define TOPDIR := $(CURDIR) their and export TOPDIR, using it in my
other files.

2. I could (perhaps) rely on the snippets always being invoked from
similar positions in the hierarchy (i.e, one level down), and define
paths like "../test/data1".

3. I could process CURDIR with some function that knew how to strip
out the lower parts to get something like TOPDIR.

4. I could do the conditional processing where I make the rules, so
I'd have
test: $(ALLOBJS) data1
or
test: $(ALLOBJS) data1 data2
depending on the value.
I would use this with VPATH, and then manipulate $< to get the
prerequisites with paths, and manipulate it to strip out the object
files, passing the rest to the command line.

1. Looks easiest, 4 hardest (if it could work at all).

By crude analogy, CURDIR is dynamically scoped, and I'm looking for
something like it that's lexically scoped.

I am planning to have separate Makefiles in each directory, and invoke
them recursively.

Or, perhaps, this isn't a good way to structure the directories and
makefiles.  I'm open to suggestions.

Thanks.




reply via email to

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