Xref: utzoo comp.sources.wanted:2822 comp.lang.c:5774 Path: utzoo!mnetor!uunet!husc6!yale!bunker!garys From: garys@bunker.UUCP (Gary M. Samuelson) Newsgroups: comp.sources.wanted,comp.lang.c Subject: Re: Desperately Seeking Makefile Maker Message-ID: <3133@bunker.UUCP> Date: 22 Dec 87 15:01:06 GMT References: <1034@cpocd2.UUCP> <538@silver.bacs.indiana.edu> Reply-To: garys@bunker.UUCP (Gary M. Samuelson) Organization: Bunker Ramo, an Olivetti Company, Shelton, Ct Lines: 54 Keywords: makefile In article <538@silver.bacs.indiana.edu> creps@silver.UUCP (Steve Creps) writes: >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" } Besides being buggy (for example, foo.c doesn't depend on bar.h, foo.o does), this doesn't cover several things which I would consider important in such a utility, (in roughly decreasing order of importance): 1. Header files in a directory other than the one containing the makefile. 2. Source files other than 'foo.c' -- such as lex or yacc source. 3. The possibility that one makefile makes several different programs, each of which depends on different (but overlapping) subsets of include files. 4. Nested includes. If bar.h includes baz.h, everything that depends on bar.h also depends on baz.h 5. The possibility of spaces or tabs between "#" and "include". Easy to fix if you don't use fgrep, but this would hurt performance. 6. "#include" appearing in a comment. 7. "#include" in a conditional compilation context (should such includes be, ah, included in the dependencies?) Of course, I don't know if the original poster considers these requirements, but I would. Such a script is bound to be slow. It will have to be run before make is run, every time a program is to be built, in case the actual dependencies have changed (includes added or deleted). We have a utility called 'gendepend' which generates a dependency list and appends it to a makefile. I don't know if it would be proper or even desirable to post it, and offhand I'm not sure it handles all of the cases I mentioned. I know it handles nested includes, and I am pretty sure it handles include files in other directories, but I am unsure of the others. (I personally don't use it that much.) If there is sufficient interest, I will look into it. Gary Samuelson