Xref: utzoo comp.sources.wanted:2788 comp.lang.c:5652
Path: utzoo!mnetor!uunet!husc6!cmcl2!rutgers!iuvax!silver!creps
From: creps@silver.bacs.indiana.edu (Steve Creps)
Newsgroups: comp.sources.wanted,comp.lang.c
Subject: Re: Desperately Seeking Makefile Maker
Message-ID: <538@silver.bacs.indiana.edu>
Date: 17 Dec 87 13:13:48 GMT
References: <1034@cpocd2.UUCP>
Reply-To: creps@silver.UUCP (Steve Creps)
Organization: Indiana University Computer Science Department
Lines: 39
Keywords: makefile

In article <1034@cpocd2.UUCP> nate@cpocd2.UUCP (Nathan Hess) writes:
>	Is there a program available that creates makefiles, preferrably
>	written in C?

   I thought this may be of general interest to the group, so I'm posting
it here.
   This problem sounds like something that could be easily done using the
standard Unix utilities. If your only file dependencies come from #include
lines in the files, then this should work pretty well. Use fgrep to
find all the #include's, and pipe it to awk for prettying up.
You could say something like this:
fgrep #include *.c *.h | awk -f makefile.awk >makefile

and makefile.awk might look something like this:
BEGIN { ORS = " "; filename = 0 }
{ if ($1 != filename) { filename = $1; print "\n" filename,":",$3 }
  else print " " $3 }
END { print "\n" }

What I'm hoping is that fgrep will output records of the form
file1: #include "foo.h"
file1: #include "bar.h"
file2: #include "foo.h"

and that for example $1 will get file2, and $3 will get "foo.h". Also, note
how I changed the output record separator (ORS) from newline to space,
and then print a newline with a file name every time the file name changes.
What I'm trying to get as output for the above example is this:
file1 : "foo.h" "bar.h"
file2 : "foo.h"

I'm writing this on the fly, so it may be a little buggy, but it should
work with little or no modification. I'll test it after I post this, and
see how it works.

-	-	-	-	-	-	-	-	-
Steve Creps on the VAX 8650 running Ultrix 2.0-1 at Indiana University.
	creps@silver.bacs.indiana.edu
"F-14 Tomcat! There IS no substitute."