Solution to makefile problem (was : Makefiles -- .c and .h)

Doug Lee dgl292 at pallas.athenanet.com
Wed Nov 21 15:16:17 AEST 1990


In (several articles) (several people) have been writing:
[about the problem of maintaining dependency lists in makefiles in a portable
manner.]

I have written a PERL script which may help solve the problem of finding
file dependency relationships.  Given a list of C source files (one per line),
it generates a makefile-ready dependency list for each associated object file.
For instance, given the files a.c and b.c, it might produce

a.o:  a.c a.h global.h utils.h
b.o:  b.c b.h globals.h

>From the comments (which may become a doc file for efficiency):

# This PERL script takes a list of C source files and generates a list of
# dependencies for each corresponding object file in a format suitable for
# inclusion in a makefile.  Files listed as dependencies are also scanned for
# dependencies of their own, and any files found in this way are also listed as
# dependencies of the object file.  File inclusions of virtually unlimited
# depth are handled properly, and no file will be listed as a dependency more
# than once, regardless of how often it is referenced.  (This also protects
# against infinite loops, although no warnings of these will be produced.)
# 
# By default, a standard header file (one referenced via "#include <...>') is
# not listed as a dependency and is not scanned for dependencies of its own.
# See the -s option below.
#
# At this writing, conditionals are not recognized; thus, if a file is included
# conditionally, it WILL be listed as a dependency in all cases.
#
# Usage:  mkdep [ -d ] [ -s[<include_dir>] ] [ list_file ... ]
#   -d  Debugging output.  Sends a progress report to stderr.
#   -s  Consider standard header files in addition to "local" headers.  This
#       will also cause standard header files referenced to be scanned for
#       dependencies.  Probably not necessary unless your system is extremely
#       dynamic.  The directory containing standard header files (/usr/include
#       by default) may be given as an argument.
#   list_file
#       Use one or more list files rather than stdin for the list of source
#       files to check.  If multiple filenames are given, the final list will
#       be the concatenation of the file contents in the order given.

Send me a request if interested.  I could probably post it (it's only 156
lines, including comments), but I'm not so sure after the recent commotion
over the issue of posting the error-handling library.  In any case, I'll place
it in the public domain.

Doug Lee  (dgl292 at athenanet.com or uunet!pallas!dgl292)
(NOTE: that's "DGL" in lower case--there's no #1)



More information about the Comp.unix.programmer mailing list