make alternate dependency rules

make alternate dependency rules

Post by Patrick Rab » Wed, 17 Apr 2002 07:58:48



Can anyone give a simple example explaining the difference between
  : and :: in makefiles?

The make man page is not clear to me at all.

TIA

Patrick

 
 
 

make alternate dependency rules

Post by Reinier Po » Fri, 19 Apr 2002 19:23:31



>Can anyone give a simple example explaining the difference between
>  : and :: in makefiles?

Suppose you need to convert images to a common file format.

Let's say some of the images are bitmaps:

%.ps: %.pnm

%.pnm: %.gif

This is a dependency chain; if foo.ps is older than foo.gif,
make will regenerate it even if foo.gif doesn't exist.
(This is why I use % instead of *.)

Some images are xfig files:

%.ps: %.fig

If you put this together into one Makefile, make will complain:
it now has two ways to create foo.ps.

With standard : rules, like these, you can only provide one set
of commands to generate any given target.  Additional empty rules,
that just list dependencies, are fine:

%.ps: .remake-ps-files-please

but only one of the rules for .ps can specify commands to create them.

The :: rules is for cases in which we do have two different ways
to create the same type of target.  The following is a valid Makefile:

%.ps:: %.fig

%.ps:: %.pnm

%.pnm: %.gif

This will give make two different ways to create any .ps file.
Now, when you type

  make foo.ps

it will use the first rule if foo.fig exists,
and the second one if foo.pnm exists.

The problem is that we don't have the .pnm file, we have a .gif file,
so if foo.pnm is missing, 'make foo.ps' won't recreate it from foo.gif:
dependency chains aren't followed across :: rules, says the manpage.

Another problem is that GNU make and /usr/ccs/bin/make behave differently,
and I don't remember the details.

This makes sense in general: if it happened, it would be nontrivial
to find the chain to use.

Fortunately, :: and : rules can be mixed:

%.ps:: %.fig

%.ps: %.pnm

%.pnm: %.gif

This will make both makes do what we want.

--
Reinier

 
 
 

make alternate dependency rules

Post by Reinier Po » Fri, 19 Apr 2002 19:30:13



>Can anyone give a simple example explaining the difference between
>  : and :: in makefiles?

Suppose you need to convert images to a common file format.

Let's say some of the images are bitmaps:

%.ps: %.pnm

%.pnm: %.gif

This is a dependency chain; if foo.ps is older than foo.gif,
make will regenerate it even if foo.gif doesn't exist.
(This is why I use % instead of *.)

Some images are xfig files:

%.ps: %.fig

If you put this together into one Makefile, make will complain:
it now has two ways to create foo.ps.

With standard : rules, like these, you can only provide one set
of commands to generate any given target.  Additional empty rules,
that just list dependencies, are fine:

%.ps: .remake-ps-files-please

but only one of the rules for .ps can specify commands to create them.

The :: rules is for cases in which we do have two different ways
to create the same type of target.  The following is a valid Makefile:

%.ps:: %.fig

%.ps:: %.pnm

%.pnm: %.gif

This will give make two different ways to create any .ps file.
Now, when you type

  make foo.ps

it will use the first rule if foo.fig exists,
and the second one if foo.pnm exists.

The problem is that we don't have the .pnm file, we have a .gif file.
If foo.pnm is missing, '/usr/ccs/bin/make foo.ps' will recreate it
from foo.gif, but '/usr/gnu/bin/make foo.ps' will not, and I like
my Makefiles to be portable.

Fortunately, :: and : rules can be mixed:

%.ps:: %.fig

%.ps: %.pnm

%.pnm: %.gif

This will make even GNU make do what we want.

--
Reinier

 
 
 

1. Makefile - explicit dependencies & static pattern rules.

Hello.

I am trying to build a makefile for a small program, and have some
difficulties to make the right decisions about it.

Program have a following structure (all the files are in the same
directory):

LinkerBase.cc
    ||
    \/
 Linkers.cc
    ||
    \/
CmdParser.cc
    ||
    \/
  main.cc

where arrow means "used by".

Now, every source file except main.cc have a header with identical
name (Linkers.cc & Linkers.h), which is also included by files that
use .cc source file.

That means, that every .cc file depends on namesake .h file, and
every .cc file depends on header of .cc source file it uses.

In order to avoid a lot of typing, i tried to create a following
makefile:

######################################################################
BASE_NAME = CmdParser LinkerBase Linkers

HDR = $(addsuffix .h, $(BASE_NAME))
SRC = $(addsuffix .cc, $(BASE_NAME)) main.cc
OBG = $(addsuffix .o, $(BASE_NAME)) main.o

all: inst-link

$(SRC): %.cc: %.h
$(OBJ): %.o: %.cc

Linkers.o   : LinkerBase.h
CmdParser.o : Linkers.h
main.o      : $(HDR)

inst-link: $(OBG)
######################################################################

Static patterns were used to say that every .cc & .o file depends on
namesake .h & .cc file (respectively. for main.cc, which doesn't have
namesake header, main.h was 'touch'ed, in order not to disturb static
pattern), and an explicit rules are added to say that every .cc file
depends on header of .cc source file it uses.
As i want to use the same compile options for all source files,
i added command to the second static pattern in order for it to be
used to compile .o for all .cc files.

But there are two problems:

1) First of all, as there is an explicit rules, though all i intended
them for was to add dependencies, 'make' understands that those rules
have empty commands, and though they are empty, they revoke static
pattern's command, and 'make' uses implicit rules to satisfy dependencies.

2) There is no empty explicit rule to create Linkers.o, but
nontheless, 'make' uses implicit rule to compile it.

So, those are the questions:

1) How could i explicitly add dependencies without revoking by
that static pattern's commands.

2) Why implicit rule are used to compile Linkers.o when there is
a valid (not revoked) static pattern's command?

ddtl.

2. Xconfiguration broken : dead grey screen

3. Problem making alternate users.

4. installing the linux driver for md5620dt (newbie)

5. making a LPP -- dependency question

6. Imake: gcc instead of cc

7. making dependencies for non-C files with gmake - help needed

8. 2.2.3 and bridging (urgent)

9. Making kernel dependencies

10. Make: can rules be changed during making?

11. make - "No rule for making..."

12. manually making firewall rules for NAT

13. Missing rule while making fvwm2