|
Home > Archive > Unix Programming > February 2005 > Wildcard and Makefile Dependencies
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 |
Wildcard and Makefile Dependencies
|
|
| Tony George 2005-02-10, 5:58 pm |
| Hi,
I'm not quite sure if this is the appropriate newsgroup to post this to, but
I thought that someone in this audience may be able to help. If you know of
a better place to post this question, please let me know. I'm trying to use
ClearMake with the Sun compatibility mode, but I think it could qualify as a
generic "make" question.
I'm trying to write a particular makefile rule that will allow me to use the
"%" wildcard for pattern matching, but will also allow me to use the "+"
construct of Sun-make to be able to group a set of targets. In my case I
have a source file from which two other files are generated:
test.cc test.h: test.mdl
generate test.mdl
all: test.cc test.h
What I would like is to have the two targets grouped together with the "+"
so that they are treated as sibling DO's with ClearMake. This will ensure
that if I try to build all targets in parallel with ClearMake, the makefile
parser will recognize that the generate command will only need to be run
once instead of two times (one for the .cc and one for the .h).
I have many files in the directory that need to be built in this way, so I
was hoping to use something like this:
%.cc %.h: %.mdl
generate $<
However, I would like to get the "+" in there also. I've tried various
combinations, but I can't seem to find a rule or set of rules that will
handle all cases. For example, I can't put only the .cc files in the "all"
target, because if I were to remove a .h file, it wouldn't get regenerated.
If I keep the above rules with the % and then explicitly add an additional
rule like the following:
test.cc + test.h : test.mdl
then everything is fine. The only problem is having to explicitly put in
all these dependency rules for every mdl file. It starts to make the
makefile a little heavy (especially with at least 50 of these files to deal
with).
Does anyone have any suggestions?
Thanks in advance.
Tony
| |
| Nunya Bizness 2005-02-11, 2:51 am |
| Tony George wrote:
> Hi,
>
> I'm not quite sure if this is the appropriate newsgroup to post this to, but
> I thought that someone in this audience may be able to help. If you know of
> a better place to post this question, please let me know. I'm trying to use
> ClearMake with the Sun compatibility mode, but I think it could qualify as a
> generic "make" question.
>
> I'm trying to write a particular makefile rule that will allow me to use the
> "%" wildcard for pattern matching, but will also allow me to use the "+"
> construct of Sun-make to be able to group a set of targets. In my case I
> have a source file from which two other files are generated:
>
> test.cc test.h: test.mdl
> generate test.mdl
>
> all: test.cc test.h
>
> What I would like is to have the two targets grouped together with the "+"
> so that they are treated as sibling DO's with ClearMake. This will ensure
> that if I try to build all targets in parallel with ClearMake, the makefile
> parser will recognize that the generate command will only need to be run
> once instead of two times (one for the .cc and one for the .h).
>
> I have many files in the directory that need to be built in this way, so I
> was hoping to use something like this:
>
> %.cc %.h: %.mdl
> generate $<
>
> However, I would like to get the "+" in there also. I've tried various
> combinations, but I can't seem to find a rule or set of rules that will
> handle all cases. For example, I can't put only the .cc files in the "all"
> target, because if I were to remove a .h file, it wouldn't get regenerated.
>
> If I keep the above rules with the % and then explicitly add an additional
> rule like the following:
>
> test.cc + test.h : test.mdl
>
> then everything is fine. The only problem is having to explicitly put in
> all these dependency rules for every mdl file. It starts to make the
> makefile a little heavy (especially with at least 50 of these files to deal
> with).
>
> Does anyone have any suggestions?
>
> Thanks in advance.
>
> Tony
>
>
You should be able to just set up a 'suffix' rule like this:
..cc.mdl:
generate $<
..h.mdl:
generate $<
In order for this to work, though, you need to update your .SUFFIXES.
You can do this by clearing the built-in suffixes and redefining them by
adding two lines like this to the very beginning of your makefile:
..SUFFIXES
..SUFFIXES .mdl .c .h
(I'm too lazy to go check the man pages right now so my spelling/syntax
may be off a little, but you get the idea.)
Assuming you are dealing strictly with single module programs, you
shouldn't even need to set up any other dependencies in order to compile
since make should now have enough information to know how to compile
them all.
Check your man pages for make. There should be a command that you can
use to display all of the built-in rules that come with make. Depending
upon your needs, you can literally replace the built-in rules with your
own, although this is typically more trouble than it is worth.
| |
| Trent Buck 2005-02-11, 2:51 am |
| Up spake Nunya Bizness:
> .SUFFIXES:
> .SUFFIXES: .mdl .c .h
You missed the colon (added).
Note that the former line empties any existing suffixes -- rules like
..c.o are often provided by default.
--
-trent
God was my copilot, but we crashed into the mountains and I had to eat
him.
| |
| Nunya Bizness 2005-02-12, 2:48 am |
| Trent Buck wrote:
> Up spake Nunya Bizness:
>
>
>
> You missed the colon (added).
>
> Note that the former line empties any existing suffixes -- rules like
> .c.o are often provided by default.
>
Well, I did warn that it might be a little bit off....
I believe that I implied that the suffixes would be cleared, can't
remember if I stated it explicitly, and referred the reader to the man
pages so they could get a listing of them in case they wanted to add
any/all back. Personally, I usually clear them -- mainly because I've
never been able to get things to work quite right without doing so but
I'm pretty sure there is somebody lurking out there that is smarter than
me that can tell us all how to do it without clearing them.
| |
| Trent Buck 2005-02-12, 2:48 am |
| Up spake Nunya Bizness:
>
> Well, I did warn that it might be a little bit off....
I was simply providing clarification; no criticism was implied.
> Personally, I usually clear them -- mainly because I've never been
> able to get things to work quite right without doing so but I'm
> pretty sure there is somebody lurking out there that is smarter than
> me that can tell us all how to do it without clearing them.
Quite simply; omit the first line (of the original example). I advise
against doing this, since you might then rely on builtin rules that
aren't defined on the next system you port to.
--
-trent
When in doubt, make a fool of yourself. There is a microscopically thin
line between being brilliantly creative and acting like the most
gigantic idiot on earth. So what the hell, leap. -- Cynthia Heimel
| |
| Nunya Bizness 2005-02-22, 2:52 am |
| Trent Buck wrote:
> Up spake Nunya Bizness:
>
>
>
> I was simply providing clarification; no criticism was implied.
None taken.
>
>
>
>
> Quite simply; omit the first line (of the original example). I advise
> against doing this, since you might then rely on builtin rules that
> aren't defined on the next system you port to.
>
I would agree with you except for the fact that make evaluates the rules
in the order that the suffixes are defined. The suffixes I usually have
to deal with are 4gl suffixes that are pre-compiled into C so I usually
need to clear the suffixes and redefine the built-in rules to suit my
own situation. Since I don't port to different systems, porting is not
an issue for me but it may be for others.
|
|
|
|
|