[comp.unix.questions] make

mickey@axis.UUCP (03/26/87)

Sorry about this going to the world but my email bounced.
The original question was how to get to make to update object file
archives (.a's containing .o's) from src aechives (.ar's containing .c's)

The standard version of make (AT&T make) does this, I think it has always
done it but the first time it was documented was with System 5 (perhaps 3
I can't remember the doc for system III).
Basically the trick is to define rules as normal except all objects
should be given as 'arguments' to the archive file - clear as mud eh?
here's an example with just the .o's in an archive:

libwotsit.a:	libwotsit.a(src1.o) libwotsit.a(src2.o)
		echo Done

this example is the simples because make has the default rules for
building archive members (of the .o type) from .c files.
Your example is of the form:


libobj.a:	libobj.a(a.o) libobj.a(b.o)
		echo Wow

libobj.a(a.o):	libsrc.ar(a.c)
		ar x libsrc.ar a.c
		cc -c $(CFLAGS) a.c
		ar r libobj.a a.o
		rm -f a.o

libobj.a(b.o):	libsrc.ar(b.c)
		ar x libsrc.ar b.c
		cc -c $(CFLAGS) b.c
		ar r libobj.a b.o
		rm -f b.o

ps this conforms to SVID VOL 2 pp 360 - 365 (the 'standard' make)
pps i tested this and it works ok, if you find a way of generalising
these rules please let me know as I failed to think of way
(I think that the .a suffix is special to make, .ar is thus not so
special and a rule of the form .a.a confuses me let alone make!

PAAAAAR%CALSTATE.BITNET@cunyvm.cuny.edu (06/09/88)

I have been having a long battle with the 'make' on our 2.9BSD PDP Unix
The documentation is dated August 1978 and most of the files haven't changed
since 1982. The Makefile is full of commands look as if the predate UNIX as
we know it today...

Qn 1.  Can anyone describe the later versions of 'make'

Qn 2.  Has anyone come up with a better way to do it?

Qn 3.  What I need to do is keep between 10 and 20 nrofd'ed files uptodate.
       They are typically named 'week??' and live in a special 'pub' directory
       where my students can print them, brouse thru them, grep words, und so on
       In my $HOME I have directories with the nroff files, I regularly need
       to make changes in two or thrre files and then genrate the printable
       public versions.  Often I archive the 'nroff' files to tape and then
       later reload them and edit again.
       In summary I need a 'makefile' that will 'nroff' new versions of files
       if the input files EXIST and have been changed more recently than the
       published version.
If I had a magic make (hum that's a nice name)
I could say things like this:
/usr/class/week\(??\) : ./week\1
        nroff -ms week\1 >$@; chmod 664 >$@
./week?? :
        # if not present, no problem
In other words with wild cards in targets plus the 'ed'/'sed'
convention for \(...\)  being saved and substituted for \n.
Dick Botting
PAAAAAR@CCS.CSUSCC.CALSTATE(doc-dick)
paaaaar@calstate.bitnet
PAAAAAR%CALSTATE.BITNET@{depends on the phase of the moon}.EDU
Dept Comp Sci., CSUSB, 5500 State Univ Pkway, San Bernardino CA 92407
Disclaimer: I am an only an egg
]

andrew@alice.UUCP (06/10/88)

you have my sympathies for trying to use an old make.
why not get a real substitute like mk? this costs $125
from AT&T Toolchest (commercial) or not much from Bell Labs
(educational). In the latter case, mail requests to research!andrew.
mk was described in the pheonix usenix proceedings. nmake is
also a possibility but is overkill. research v[89] make is
also much better than what you have

leo@philmds.UUCP (Leo de Wit) (06/17/88)

In article <16104@brl-adm.ARPA> PAAAAAR%CALSTATE.BITNET@cunyvm.cuny.edu writes:
>I have been having a long battle with the 'make' on our 2.9BSD PDP Unix
>The documentation is dated August 1978 and most of the files haven't changed
>since 1982. The Makefile is full of commands look as if the predate UNIX as
>we know it today...
>
>Qn 1.  Can anyone describe the later versions of 'make'

See the man pages. Too much to insert here. If you want copies please mail.

>Qn 2.  Has anyone come up with a better way to do it?

The Sys5 make is more elaborate; the Sun make also knows of header dependencies
but still I think the standard make is quite adequate.

>Qn 3.  What I need to do is keep between 10 and 20 nrofd'ed files uptodate.
   [stuff deleted...]

   I think your problem isn't that hard, but you shouldn't try to solve it
using make only. You have hinted to use sed yourself. What about this one:

1) Call your nroff files something like xxxxx.nrf, i.e. give them an extension.
And also for the formatted files, e.g. xxxxx.txt.
Now put in your makefile the following lines:

.SUFFIXES: .txt .nrf

.nrf.txt:
	nroff -ms $< >$@; chmod 664 $@
	rm -f /usr/class/$@; ln $@ /usr/class/$@

Now if you say: make week20.txt and it is not up to date, it will be made
(note the somewhat clumsy ln is needed because make expects files to reside
in the same directory for the suffix rules. You could also put the .nrf files
in the /usr/class directory).

But I assume you want to let make decide even what targets to be made?
Even this is possible: Have a first entry all in the makefile:

all:
	$(MAKE) dummy `ls *.nrf|sed 's/\.nrf/.txt/'`

dummy:

The dummy entry is needed to avoid problems when there are no .nrf files
(see for yourself what happens if you omit it!).
Hope this solves your problem - like to hear about it.

>Dick Botting
>PAAAAAR@CCS.CSUSCC.CALSTATE(doc-dick)
>paaaaar@calstate.bitnet
>PAAAAAR%CALSTATE.BITNET@{depends on the phase of the moon}.EDU
>Dept Comp Sci., CSUSB, 5500 State Univ Pkway, San Bernardino CA 92407
>Disclaimer: I am an only an egg

egg: chicken
	lay <$? >$@

chicken: egg
	brood <$? >$@

$ make egg

Make:$! nulled; predecessor circle.

Even make doesn't know which one was older 8-).

	Leo.

mm@chorus.fr (Marc Maathuis) (08/09/89)

Can anybody explain me why in the following typescript
'make -n' and 'make' want to recompile:

i/  Why does 'make -n' at command <9> say that prog.c has to be recompiled,
    and 'make' says <11> that prog is up to date ?

ii/ After having removed the file x.h at <12>, x.h in the makefile
    is just a target (make doesn't complain about not finding a file x.h).
    Why does 'make' recompile every time (<14>, <15>),
    altough the file y.h is older than prog.o ?

-------------------------------------------------
Script started on Wed Aug  9 11:41:18 1989
<1>  uname -a
java java 4.2BSD vm sun
<2>  echo $SHELL
/bin/ksh
<3>  type make
make is a tracked alias for /bin/make
<4>  cat prog.c
main () {return;}

<5>  cat makefile
prog:   prog.o
        cc -o prog prog.o

prog.o: x.h
        cc -c prog.c

x.h:    y.h

<6>  > x.h
<7>  > y.h
<8>  make
cc -c prog.c
cc -o prog prog.o
<9>  make -n
cc -c prog.c
cc -o prog prog.o
<10>  ls -l prog.o x.h
-rw-r-----  1 mm             74 Aug  9 11:43 prog.o
-rw-r-----  1 mm              0 Aug  9 11:41 x.h
<11>  make
`prog' is up to date.
<12>  rm x.h
<13>  make -n
cc -c prog.c
cc -o prog prog.o
<14>  make
cc -c prog.c
cc -o prog prog.o
<15>  make
cc -c prog.c
cc -o prog prog.o
<16>  exit

script done on Wed Aug  9 11:44:33 1989
------------------------------------------------

Thanks for sending answers by email.

Marc Maathuis
  Chorus systemes			Tel +33 (1) 30 57 00 22
  6, avenue Gustave Eiffel		Fax +33 (1) 30 57 00 66
  78182 St. Quentin en Yvelines Cedex	
  France

  E-mail: mm@chorus.fr                     	(Internet)
          {...,uunet}!mcvax!inria!chorus!mm	(UUCP)

gandalf@csli.Stanford.EDU (Juergen Wagner) (08/09/89)

In article <3019@chorus.fr> mm@chorus.fr (Marc Maathuis) writes:
>Can anybody explain me why in the following typescript
>'make -n' and 'make' want to recompile:
....
><5>  cat makefile
>prog:   prog.o
>        cc -o prog prog.o
>
>prog.o: x.h
>        cc -c prog.c
>
>x.h:    y.h
>
><6>  > x.h
><7>  > y.h

The problem here is that no matter how often you call 'make', the target
x.h is *ALWAYS* out of date with respect to y.h. Y.h is not being updated.
If there is no such update necessary, I don't see why you would have that
last rule in the Makefile. I'd prefer something like

	foo:	foo.o
		cc -o foo foo.o

	foo.o:	foo.c x.h y.h
		cc -c prog.c

Unless there is a special update for x.h which is necessary if y.h is newer,
the above lines should be sufficient.

Juergen Wagner		   			gandalf@csli.stanford.edu
						 wagner@arisia.xerox.com

net@tub.UUCP (Oliver Laumann) (08/14/90)

What is /bin/make supposed to do with the following Makefile (provided
that foo.c exists)?

% cat Makefile
.DEFAULT:
	echo Ouch.

all:	foo.o

foo.o:	foo.c
	cc -c foo.c
%

Note that the rule for "all" doesn't have commands.

Under all versions of UNIX where I have tested it (lots!), it only
compiles foo.c.  GNU make, on the other hand, compiles foo.c and then
executes the command under the .DEFAULT rule.

The 4.3BSD manual for make(1) says that if a target must be created and
there are neither any explicit commands nor a relevant built-in rule,
then the commands under the .DEFAULT are executed.  So GNU make seems
to be correct.  Is this true?

If so, how can I modify the above Makefile to suppress execution of the
.DEFAULT commands (provided the .DEFAULT rule must be there for other
reasons)?  Add a "dummy" echo command to the "all" rule?  Or an empty
command, i.e. just a tab character?  (We don't have GNU make here.)

Thanks,
--
Oliver Laumann     net@TUB.BITNET     net@tub.cs.tu-berlin.de     net@tub.UUCP