[comp.unix.questions] help with make needed

zap@front.se (Svante Lindahl) (04/25/89)

In article <459@front.se>,I wrote:
[ The target, a library, should be removed and rebuilt if the makefile
  has been updated. ]

> Makefile:	FRC
> 		-@if newer Makefile $(TARGET) ; then rm -f $(TARGET); fi
...

I got some good suggestions from Rich $alz on how to avoid the need
for the newer(1L) program. This is what it looks like:

Makefile:	FRC
	-@if echo "Makefile: $(TARGET) ; @/bin/false" | make -qf - ; \
	then rm -f $(TARGET) ; fi

Svante.Lindahl@front.se	    (!-net: ...!uunet!front.se!svante)
			    (non-mx: Svante.Lindahl%front.se@uunet.uu.net)

dpaulso@relay.nswc.navy.mil (04/26/89)

In several makefiles I've seen the prerequisite `FRC' used, as in

>Makefile:	FRC
>	-@if echo "Makefile: $(TARGET) ; @/bin/false" | make -qf - ; \
>	then rm -f $(TARGET) ; fi

I've also seen `FRC' used as the ultimate prerequisite for a group of
dependencies that are .RECURSIVE

but i've not seen any reference to `FRC' in TFM.  any hints as to what
it means and/or does?

/dave

---
Dave Paulson	dpaulso@relay.nswc.navy.mil	(703)663-2137
"I've upped my standards; now up yours" -- Pat Paulsen

rsalz@bbn.com (Rich Salz) (04/27/89)

In <19308@adm.BRL.MIL> dpaulso@relay.nswc.navy.mil writes:

>In several makefiles I've seen the prerequisite `FRC' used, as in
	Makefile:	FRC
		-@if echo "Makefile: $(TARGET) ; @/bin/false" | make -qf - ; \
		then rm -f $(TARGET) ; fi
>but i've not seen any reference to `FRC' in TFM.  any hints as to what
>it means and/or does?

What missing from the above example is this line in the Makefile.
	FRC:

What we're doing is saying the Makefile depends on FRC, a file that
(presumably) doesn't exist.  We tell make how to make FRC:  it has
no dependants, and you don't do anything.  This means, in essence, every
time make checks on Makefile, it checks on FRC, sees it doesn't exist,
does nothing to build it, but notes that everything that depends on it
is now out of date.

In short, it's a way of forcing something to always be rebuilt.  Sometimes
you see tricks like making "/tmp" be the dependant instead of FRC, since
/tmp is something that exists and, hopefully, getting modified often.
There's other tricks, too, but they basically come down to variations on
these two practices.

I first saw the FRC convention get widespread notice when ATT released the
SystemV "Augmented make" (the one that uses .c~ to represent SCCS files).

This isn't the clearest language in the world, sorry.
	/r$
-- 
Please send comp.sources.unix-related mail to rsalz@uunet.uu.net.

erikb@cs.vu.nl (Erik Baalbergen) (04/27/89)

In article <19308@adm.BRL.MIL> dpaulso@relay.nswc.navy.mil writes:
>In several makefiles I've seen the prerequisite `FRC' used, as in
>>Makefile:	FRC
>>	-@if echo "Makefile: $(TARGET) ; @/bin/false" | make -qf - ; \
>>	then rm -f $(TARGET) ; fi
>I've also seen `FRC' used as the ultimate prerequisite for a group of
>dependencies that are .RECURSIVE
>but i've not seen any reference to `FRC' in TFM.  any hints as to what
>it means and/or does?
>Dave Paulson	dpaulso@relay.nswc.navy.mil	(703)663-2137
>"I've upped my standards; now up yours" -- Pat Paulsen

``FRC'' stands for `Forced ReCompilation''.  It occurs as a dummy dependent
for the targets that need to be rebuilt in every ``make.''
FRC should be specified as a target, without dependents and command block,
in the make prelude or in the Makefile itself.
Be sure that no file FRC exists; ``make'' assumes any non-file target
be out-of-date.  The Makefile below demonstrates the use of FRC.

--8<------8<------8<------8<------8<------8<------8<------8<------8<------
	# Demonstrate the behavior of a fake target
	just-a-target: FRC
		touch just-a-target
	
	FRC:		# This is the fake target
--8<------8<------8<------8<------8<------8<------8<------8<------8<------

(Of course, the fake target may have another name!)  At every
``make (just-a-target)'', the touch command is executed.

Erik Baalbergen
-- 
Erik H. Baalbergen				    <erikb@cs.vu.nl>
Vrije Universiteit / Dept. of Maths. & Comp. Sc.
De Boelelaan 1081
1081 HV Amsterdam / The Netherlands		tel. +31 20 548 8080

rbj@dsys.icst.nbs.gov (Root Boy Jim) (05/02/89)

? From: Svante Lindahl <zap@front.se>

? I have a makefile in a directory were I keep the source files for a
? library. The makefile compiles a source file if it is newer than the
? corresponding archive member, replaces the archive member and deletes
? the newly compiled object file. In make notation:

? TARGET  = libfoo.a
? OBJECTS = $(TARGET)(a0.o) $(TARGET)(a1.o)

?  .c.a:
? 	$(CC) $(CFLAGS) -c $<
? 	ar rv $@ $*.o
? 	rm -f $*.o

? $(TARGET):	$(OBJECTS)
? 		ranlib $@

? (The .c.a rule is default in the make I use, but I am showing it here
? for clarity).
? This works fine, but there is one more thing I'd like to do; If the
? makefile is newer than the library, the library should be deleted and
? rebuilt from scratch. I can do this, by changing the last part of the
? makefile like this:

? $(TARGET):	Makefile $(OBJECTS)
? 		ranlib $@

? Makefile:	FRC
? 		-@if newer Makefile $(TARGET) ; then rm -f $(TARGET); fi

? FRC:

How about a double colon rule?

$(TARGET)::	Makefile
		rm -f $@

$(TARGET)::	$(OBJECTS)
		ranlib $@

Note: I have not tested this. I also don't believe in using the
construct "foo.a(bar.o)", but I suppose that's a personal aversion.

? Thanks,
? Svante.Lindahl@front.se	    (!-net: ...!uunet!front.se!svante)
? 			    (non-mx: Svante.Lindahl%front.se@uunet.uu.net)

	Root Boy Jim is what I am
	Are you what you are or what?