home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource5
/
312_01
/
cincdep.awk
< prev
next >
Wrap
Text File
|
1990-04-23
|
16KB
|
336 lines
# HEADER: ;
# TITLE: Makefile dependency generator;
# DATE: 09/28/1989;
# VERSION: 2.2;
# DESCRIPTION: "An AWK program which finds included files and
# builds a dependency list. This dependency list
# is a component of a make-file. The list consists
# of the source file name followed by a colon and
# then all of the files which it includes (and also
# those which are included by the included files, &c.)
# The last item is a compile-command.";
#
# KEYWORDS: Makefile, make, include, dependency generator;
# SYSTEM: MS-DOS, UNIX;
# WARNINGS: "Doesn't handle directory names embedded within
# #include <here>. Doesn't handle preprocessor #if.. blocks
# or #include statements which are "commented out."
# Only handles a single include-path.
# PolyAwk will generate false matches to lines
# beginning with non-ASCII (i.e. 128..256) chars."
# Filenames are case sensitive.";
# FILENAME: CINCDEP.AWK;
# SEE-ALSO: TLR2MAK.AWK, CF2MAK.AWK, AINCDEP.AWK, PINCDEP.AWK;
# AUTHORS: James Yehle;
# COMPILERS: PolyAWK, Mortice Kern AWK, Rob Duff's PC-AWK 2.0,
# In any case, must be 1985 awk (not 1977);
#
# ============================================================================
#
# cincdep.awk Last modified Sep 28, 1989 22:23
#
# Scans a C file for all "#include" dependencies
# This scanning process involves all nested include files, too.
#
# Jim Yehle 753 Left Fork Rd. #B/Sugarloaf Star Route/Boulder, CO 80302 9252
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
#
# Usage is:
# awk -f [path]cincdep.awk [path]src_file.c objname=[path]filename
# cc=compile_comd ccf=[p][n][e] [incpath=[pathname]] [>[path]outfile]
# Pathnames must contain trailing separator, e.g. "c:\inc\"
# Order of command-line parameters (save for "-f ..." and srcfile.c)
# is irrelevant, but identifiers must be in lower case.
# "src_file.c" may be replaced by special "__NOFILE__"
# cc is the compile command (no spaces allowed)
# ccf controls which components of the source file's name get
# included in the compile command line: p = directory path,
# n = name, e = extension.
#
# Output is:
# [path]src_file.obj: [path]src_file.c [path]included_file1 linecont
# [path]included_file2 [path]included_file3 ...
# <\t>comd [path]src_file[extenstion]
# <\n>
# For __NOFILE__, output is:
# [path]src_file.obj:
# <\n>
# <\n>
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
#
# Known limitations and anomalies:
# - Assumes that no directory paths are within the "file" or <file> strings
# - Doesn't make any attempt to switch out #if-#endif blocks.
# I don't see this as a serious problem. (The solution certainly isn't
# trivial.) It will mean only that your make-file may turn out to be a
# bit more "paranoid," including more dependencies than really exist
# if an #include directive is #iffed out. It could be a problem if
# nonexistent include-files appear in a make-file's dependency, and your
# make utility barfs when it doesn't find a file.
# - The same problem can be created by "commenting out" a line containing
# an include directive, such as:
# /*
# #include <stdio.h>
# */
# - File names are case- and directory-sensitive. Huh? If a file includes
# both blah.h and Blah.h, they'll both appear in the dependency list.
# Furthermore, if it includes "splunge.h" and <splunge.h>, and an instance
# appears in both the default directory and the include-file directory,
# you'll get two occurrences in the dependency list, one with the
# directory pathname tacked on the front and the other without.
# - So far it has been tested with Polytron and MKS awk interpreters, and
# Turbo C's make utility, all running under the MS-DOS operating system.
# - Your ability to specify complex compilation commands is really limited.
# There's also no way to set source-file-specific command-line options.
# - I don't know what will happen if your source file doesn't end with .c
# and your object files don't end with .obj. Try it!
# - Only one include-path is supported. For the form #include <file>, cincdep
# searches the include-path first, then the current directory for the
# given file. If your file says #include "file", the order is reversed.
#
# . . . Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . .
#
# Sep 28 89 -- Released for C User's Group distribution --
# 2.2 Sep 10 89 JRY Added legal-filename-char regular expression
# 2.1 Aug 17 89 JRY Added add_fnexist option (as internal directive)
# 2.0 Aug 10 89 JRY If an included file can't be found, cincdep now
# beeps and prints an error to CO, then continues
# without scanning the file for nested inclusions.
# (It adds it to the dependency list, without a
# directory path on the front of the filename.)
# Also added an optimization: if addfile() sees
# that a file is already in the list, then it has
# already been scanned, so it isn't done again.
# Added "verbose" CO output as debug level 1.
# 1.7 Jun 20 89 JRY Added "ccf=" command-line parameter
# 1.6 Jun 7 1989 JRY Added include-file pathnames to output,
# added objname= & cc= command-line parameters
# 1.5 May 31 1989 JRY Added primary source file at start of
# dependency list
# 1.4 Cinco di Mayo 89 JRY Cleaned output-line-too-long test
# 1.3 Apr 21 1989 JRY Added line-too-long continuation on next line,
# translation of primary file from .c to .obj.
# 1.2 Feb 22 1989 JRY Added incpath command-line option
# 1.1 Feb 21 1989 JRY Re-wrote to handle recursion internally.
# 1.0 Feb 15 1989 JRY Initial creation & debugging.. algorithm used
# recursive invocations of awk via system(awk)
# function, but ran out of memory (640k DOS)
# after three levels.
# ============================================================================
#
BEGIN {
co = "CON" # Console-out: MS-DOS "CON", iRMX ":co:", unix "/dev/tty"
linecont = " \\" # Line-continuation EOL char: snake " /", unix make "\\"
debug = 0 # 0=off, 1=verbose, 2=main-level debug, 3= adds functions
use_fnexist = 1 # Add nonexistent header files to dependency list?
fname_chars = "[^\\\\ :]" # Any single legal char in a file name.
# (Must exclude directory path separator character! (DOS \, UNIX /) )
printf( "cincdep.awk C #include dependency scanner v 2.2") > co
objfile = get_cl_param( "objname=", 0)
if (debug>1) printf( "objfile = '%s'\n", objfile) > co
cc = get_cl_param( "cc=", 0)
if (debug>1) printf( "cc = '%s'\n", cc) > co
ccf = get_cl_param( "ccf=", 0)
if (debug>1) printf( "ccf = '%s'\n", ccf) > co
# Omitting "incpath=xx" ok.. assume default directory for #include files
incpath = get_cl_param( "incpath=", 1)
if (debug>1) printf( "incpath = '%s'\n", incpath) > co
if (ARGV[1] == "__NOFILE__") {
if (debug)
printf( "\n__NOFILE__: Empty dependency list generated.\n") > co
else
printf( " (of __NOFILE__)\n") > co
exit # Hop to END; srcfile is still an empty string & flist is empty
}
# 1st in list of ARGV[]'s is sourc