[Top][All Lists]

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

Re: Paths above current/working directory don't work with suffix rules

From: Paul Smith
Subject: Re: Paths above current/working directory don't work with suffix rules
Date: Mon, 24 Jan 2022 14:12:44 -0500
User-agent: Evolution 3.36.5-0ubuntu1

On Mon, 2022-01-24 at 19:09 +0100, Adam Tuja wrote:
> It doesn't matter how with many levels above current directory the
> path has (../ ../../ ...), it's still the same.

Suffix rules are very limited: this is why pattern rules were invented.

As long as you're happy with creating the object file in the current
directory, AND you're happy with ensuring that no two directories ever
have the same source file name, then it's possible to use suffix rules
to build them.

However you can see from the rule:


that there's nothing here to tell make where the source file will be,
so clearly that cannot work by itself.  A suffix rule is identical to
the pattern rule:

  %.o : %.c

so, the prefix of the target and prerequisite MUST be identical
strings.  The string "c-1up" is not identical to the string "../c-1up", 
and so this rule cannot match.

You can use VPATH to give make a list of directories to use to search
for source files.  So, in your makefile if you add this:

  VPATH = .. ../..

when make wants to build c-1up.c it will look for ./c-1up.c, then
../c-1up.c, then ../../c-1up.c, and build the first one it finds.


> PS.
> Not to mention that if I don't specify target (all) then it only
> processes one file

Make has to choose SOME target to build by default, if you don't
specify one.  Make always chooses the first target in the makefile by
default.  So, move your "all" target to the top so it's the first
target and it will work as you expect.


reply via email to

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