Article View: comp.unix.programmer
Article #3691GNU Make question - referring to target in dependancy line
From: Roger Gonzalez
Date: Wed, 05 Jul 1995 00:00
Date: Wed, 05 Jul 1995 00:00
97 lines
3688 bytes
3688 bytes
* Executive summary: is it possible in GNU Make to refer to the target
* on the dependancy line?
First, some background:
In my development tree, I have libraries set up that look like the following:
/devel/src/lib/foo/foo.h
/devel/src/lib/foo/foo_local.h
/devel/src/lib/foo/foo_bar.c
/devel/src/lib/foo/foo_bleah.c
/devel/src/lib/foo/foo_xyzzy.c
where "foo.h" is the public header file for the library, and the .c files
will get built into the library "libfoo.a". The public header file and
the library are "installed" into the following directories:
/devel/include/foo.h
/devel/lib/linux/libfoo.a
When building an application that depends on "libfoo.a" and "foo.h", I want
to have the installed version of the public header file depend on the
source version of the header file back in the library source directory.
Assuming that I've gotten to the point where the application is depending
on /devel/include/foo.h. Then I'd like to have a rule:
/devel/include/foo.h : /devel/lib/foo/foo.h
cd /devel/lib/foo ; make /devel/include/foo.h
Or, generically:
INSTINCDIR = /devel/include
LIBSRCROOT = /devel/src/lib
$(INSTINCDIR)/%.h : $(LIBSRCROOT)/%/%.h
cd $(LIBSRCROOT)/$(*F) ; make $@
Note heavy use of GNU Make-isms.
The problem is that GNU Make doesn't seem to like to evaluate its pattern
matcher "%" more than once.
So, I tried the System-Vism $$@:
$(INSTINCDIR)/%.h : $(LIBSRCROOT)/$(basename $(notdir $$@))/$(notdir $$@)
cd $(LIBSRCROOT)/$(*F) ; make $@
This didn't work; from the GNU Make texinfo:
* In System V `make', the string `$$@' has the strange meaning that,
in the dependencies of a rule with multiple targets, it stands for
the particular target that is being processed.
This is not defined in GNU `make' because `$$' should always stand
for an ordinary `$'.
It is possible to get this functionality through the use of static
pattern rules (*See Static Pattern Rules: Static Pattern.). The
System V `make' rule:
$(targets): $$@.o lib.a
can be replaced with the GNU `make' static pattern rule:
$(targets): %: %.o lib.a
Unfortunately, in the actual dependancy portion, their example still only
uses a single %. (The %: is part of the static pattern, which seems to
be a different animal altogether.)
So, I seem to be stuck.
I've currently fallen back to merely depending on "%.h" by itself, and
setting VPATH to contain all the library source directories, but this
slows things down dramatically.
Can anyone think of any way I can do what I want?
Changing the directory tree is not an option.
Thanks in advance,
-Roger
Roger Gonzalez Net Info Corporation
rg@server.net 56 Rogers Street
home (617) 863-0705 Cambridge, MA 02142
mobile (617) 755-0635 work (617) 868-8600
60 09 3A EE FE 6A 1E CC -pgp- B7 F7 6B 0F 00 1D 01 C7
Technical Details
Message-ID:
<RG.95Jul5131908@caffeine.server.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11318c,bc6d5d7de1d72224,start X-Google-Attributes: gid11318c,public X-Google-Thread: fc89c,bc6d5d7de1d72224,start X-Google-Attributes: gidfc89c,public From: rg@server.net (Roger Gonzalez) Subject: GNU Make question - referring to target in dependancy line Date: 1995/07/05 Message-ID: <RG.95Jul5131908@caffeine.server.net> X-Deja-AN: 105732041 distribution: world x-disclaimer: Not an official NetInfo article organization: Net Info x-attribution: RG reply-to: rg@server.net newsgroups: comp.unix.programmer,gnu.gcc.help