[net.unix] Problem with Make - dependencies on archives

peterc@ecr2.UUCP (Peter Curran) (07/20/85)

Some versions of 'make' allow you to specify dependencies on archive
files directly, but I've never managed to get it to work.  Here is
another approch:

1.  Write a program named (say) 'zero,' that takes a list of file names
and creates zero-length files with those names.  I don't have source
handy, but it is simple code - here is a description of the main loop:

	- do a stat() on the file name.
	- creat() the file.
	- if the file existed initially (i.e. the 'stat()' succeeded)
		reset the 'modified' time to its original value
		(using the 'utime()' system call.

The last step is not essential - skipping it only causes problems if
you start editing a source file after it has been compiled, but before
the object has been archived.  If you do, it can be fixed by "touching"
the object file.

(For this application, all files will exist.  However, a previous discussion
on the net demonstrated a lot of interest in a command to create a zero-
length file that does not exist, so for the sake of an 'if' statement,
this command might as well do it.)

2.  In your Makefile, make the source files depend on the object files
(as they would if you were not using the archive).  When you archive a
file, zero the object file instead of removing it.

To forestall one object - zero-length files only consume i-nodes, not
disk space (except for the dirsctory entry).  I have never seen a file
system for which i-nodes were the scarce resource.  No doubt they exist,
but that problem can be solved by re-configuring the file system.

One potential problem is your Makefile cannot be too naive about the
link commands it uses - it cannot just use (say) '*.o,' because that
will include the zero-length .o files, which the linker can't handle.
You have to identify your "real" object files more carefully.  The
technique I am describing here is a small part of the full development
environment we use - I am not going to get into describing it all,
so you will have to solve that aspect of the problem yourself.