[comp.unix.questions] make removed my source file

david@wubios.wustl.edu (David J. Camp) (02/18/90)

I am using SunOS 4.0.3 on a Sun 3/260.  Here is my Makefile:
# Unix Makefile for xxencode and xxdecode
# This is my first unix makefile, so be kind...

all: xxencode.c
	cc -o xxencode xxencode.c
	/bin/rm -f xxdecode
	ln xxencode xxdecode

Here is are the filenames on my directory:
Makefile README xxdecode xxencode xxencode.c xxencode.l xxencode.man

Here is what it did when I typed 'make':
rm -f xxencode.c
lex  -t xxencode.l > xxencode.c
(lex diagnostics)
*** Error code 1
make: Fatal error: Command failed for target `xxencode.c'

I was lucky that I had recently backed up my files, so not many changes
were lost.  I do not understand why these commands were executed instead
of the ones I specified in my Makefile.

Bitnet:   david@wubios.wustl                ^      Mr. David J. Camp
Internet: david%wubios@wugate.wustl.edu   < * >    Box 8067, Biostatistics
uucp:     uunet!wugate!wubios!david         v      660 South Euclid
Washington University (314) 36-23635               Saint Louis, MO 63110

guy@auspex.auspex.com (Guy Harris) (02/19/90)

>I was lucky that I had recently backed up my files, so not many changes
>were lost.  I do not understand why these commands were executed instead
>of the ones I specified in my Makefile.

"make" has a big list of built-in rules (or, in the case of the SunPro
"make", which is the default "make" in SunOS 4.x, rules in
"/usr/include/make/default.mk").  "make" does not, unless you give it
the "-r" flag, confine itself to the rules you explicitly specify in
your Makefile.

Since Time Immemorial, the default rules have included rules for "lex". 
Since Time Immemorial, the suffix for "lex" files has been ".l".  If
your ".l" file is really a "lex" file, you should either rename
"xxencode.l" to something else ending with a ".l" or rename "xxencode.c"
to something else ending with a ".c".

If the ".l" file is something else, choose another suffix.  I suspect
that "xxencode.l" is supposed to be the manual page for "xxencode" and
"xxdecode".  You made the mistake of thinking that the convention that
manual pages for "local" things should end with ".l" actually had merit.
It has none whatsoever:

	1) local software comes in the form of commands, library
	   routines, device drivers, etc. just like "standard" software,
	   and as such its manual pages should be broken up into
	   different categories just like system manual pages;

	2) ".l", as a suffix, is already spoken for - it means "lex
	   file" (I'm willing to be slightly merciful to the inventor of
	   the ".l" convention if they'd done so before "lex" was
	   available in UNIX).

If the ".l" file is supposed to be a local manual page, don't follow the
stupid ".l" convention for local manual pages - call it ".1", instead,
since it appears to be a command.

cpcahil@virtech.uucp (Conor P. Cahill) (02/19/90)

In article <1025@wubios.wustl.edu>, david@wubios.wustl.edu (David J. Camp) writes:
> all: xxencode.c
> 	cc -o xxencode xxencode.c
> 	/bin/rm -f xxdecode
> 	ln xxencode xxdecode
> 
> Here is are the filenames on my directory:
> Makefile README xxdecode xxencode xxencode.c xxencode.l xxencode.man

The problem is that the xxencode.l file is newer then the xxencode.c file
and make has a built in rule for making a *.c file from a *.l file (using
lex).

A quick fix is to rename xxencode.l to xxencode.something_else

Or you could turn off the .l.c built in rule for make, or you 
could turn off make's understanding of the .l suffix.

PS: I would change the makefile to appear as:

	xxdecode:	xxencode
		rm -f xxdecode
		ln...

That way xxencode would only be rebuilt if xxencode.c is out of date (using
makes .c to executable built in rull) and xxdecode would only be linked
to xxencode if xxencode was newer than xxdecode.


-- 
+-----------------------------------------------------------------------+
| Conor P. Cahill     uunet!virtech!cpcahil      	703-430-9247	!
| Virtual Technologies Inc.,    P. O. Box 876,   Sterling, VA 22170     |
+-----------------------------------------------------------------------+

gwyn@smoke.BRL.MIL (Doug Gwyn) (02/20/90)

In article <1025@wubios.wustl.edu> david@wubios.UUCP (David J. Camp) writes:
>Here is what it did when I typed 'make':
>rm -f xxencode.c
>lex  -t xxencode.l > xxencode.c
>I do not understand why these commands were executed instead
>of the ones I specified in my Makefile.

"make" contains a built-in list of default rules (just which rules
varies from one implementation to another).  It appears in your case
that these was a built-in rule for making a .c from a .l.  You must
have had an xxencode.l file with a more recent mod time that xxencode.c.