Xref: utzoo comp.sources.wanted:2800 comp.lang.c:5713 Path: utzoo!mnetor!uunet!husc6!hao!gatech!mcnc!rutgers!mtune!mtgzz!mtuxo!homxb!hropus!jgy From: jgy@hropus.UUCP (John Young) Newsgroups: comp.sources.wanted,comp.lang.c Subject: Re: Desperately Seeking Makefile Maker Message-ID: <1456@hropus.UUCP> Date: 19 Dec 87 03:22:06 GMT References: <1034@cpocd2.UUCP> <538@silver.bacs.indiana.edu> Organization: Bell Labs, Holmdel, NJ Lines: 43 > 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" } > > ....... > > - - - - - - - - - > 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." > The major issue here (for C programs) is #include files of course; As pointed out they may be nested and they also may have dependencies of the #ifdef, and -I (or #if) nature . Therefore the way to reliably determine include files is in the environment that the compilation is desired. Therefore: cc -Dwhatever -Dotherstuff -Iwhatever/path -E filename.c | sed -n -e 's/^# 1 .*"\(.*\)"/\1/p' | sort -u Is what you need to find the #include files necessary for a particular style of compilation. If you have a fairly recent version of a AT&T C compiler you can use the -H flag instead of the -E to just get desired info. john young