MakeDep2 -------- May 26, 1995 by David M. Miller Copyright (C) 1995, Business Visions, Inc. A makefile dependency generator for C and C++ based Windows programming. MakeDep2 takes a list of .C, .CPP, .CXX, .A, .ASM, or .RC files and generates a list of dependencies for each of them. It knows that .C, .CPP, .CXX, .A, and .ASM files produce .OBJ files and that .RC files produce .RES files. MakeDep2 ignores any "system" #includes (those that use angle brackets to delimit the name of the included file), focusing only on "local" #includes (which delimit the included file name with double quotes). The output from MakeDep2 goes to stdout, wrapped to 78 columns with backslashes as line continuation characters. Using a very simple mechanism with Microsoft's NMAKE, dependencies may be generated nearly automatically. Why another dependency generator? Why not use GNU Make or one of the commercial Make programs, such as MKS make, which are capable of automatically generating dependencies? The fact is, I would love to standardize on Gnu Make or MKS Make, but as a contractor, I must work with what my clients already have. If they are using Microsoft C 8.0c (the command line compiler of VC++), then they are using NMAKE. It's as simple as that. So I wrote MakeDep2. The name MakeDep2 was chosen so that would be no name conflicts with MakeDep, another similar freeware utility; I tried MakeDep first, but for me it had confusing command line syntax, it did not process .RC files, it expected .OBJ filenames (targets) instead of explicit source code filenames, and it did not word wrap the output to any reasonable column width. Source code is included, and is hopefully modular enough that enhancements may be added reasonably and other languages could be accomodated. Syntax ------ Running MakeDep2 with the '-?' option produces this output: usage: makedep2 [-options] {target | @respfile} [target ..] where: -l suppress logo -ipath[;path] include file search directories -spath[;path] source file search directories target specifies source file name (wildcards permitted) (examples: *.cpp file.c file.asm file.rc) respfile contains targets and/or options. -? this message INCLUDE environment variable will be used to locate quoted include files not in the current directory. -I flag adds directories to search Specifying include file search directories widens the scope of the INCLUDE environment variable. It does not change MakeDep2's behavior of ignoring angle-bracket files. Only double-quoted include files will be used to generate dependencies. Specifying source file search directories permits a structured source tree. I have not extensively tested this feature. Target files may be specified in one or both of two ways: on the command line, or in a response file. Wildcard expansion is supported on the command line, but not within response files. Output of the dependency list goes to stdout, and should be redirected. The simplest use of MakeDeps2 is: "MakeDeps2 @filelist >makedeps" or "MakeDeps2 *.c > makedeps". The latter is best used only if it is known that there are no unwanted .C files in the directory. Dependency Generation using NMAKE --------------------------------- A makefile variable can be defined, for example, MAKEDEPSRC, which contains the entire list of C and RC source files. Substitution macros are useful for this. For instance, if you have a macro, OBJS, defined as: OBJS=file1.obj file2.obj file3.obj and, if the Windows RC file is called resource.rc, MAKEDEPSRC may be defined using macro substitution as: MAKEDEPSRC=$(OBJS:.obj=.c) resource.rc Next, a psuedotarget, here called deps, can be defined, using NMAKE's inline file generation capability, as: deps: $(MAKEDEPSRC) makedep2 @<< >makedeps $(**) << which creates a file called makedeps by running MakeDep2 with an inline file created by NMAKE. It is useful if the target deps is a psuedotarget, and does not refer to an actual file, since running the command, "nmake deps" at any time will always rebuld the makedeps file, without regard to real file dependencies between the files listed in MAKEDEPSRC and the target. Finally, the makedeps file should be included in the makefile: !if exist(makedeps) !include "makedeps" !endif With this mechanism in place, regenerating the dependencies just requires running NMAKE with the command: nmake deps Automatic Dependency Generation using NMAKE ------------------------------------------- Only one additional step is required to enable automatic dependency generation using Microsoft's NMAKE. This assumes that there is a makefile variable called MAKEDEPSRC, a psuedotarget called deps, and an include of the file called makedeps (as above). The following lines, when added to a makefile, instruct the NMAKE preprocessor to run NMAKE recursively to build the makedeps file if it doesn't exist. In order to prevent looping infinitely, a dummy makedeps file is created first. These lines may be placed at the end of the makefile, or in a file to be included in a makefile, but they must PRECEED the line that says !include "makedeps": !if !exist(makedeps) !if [echo. >makedeps] !endif !if [$(MAKE) deps] !endif !endif Included in the Zip file is a file called MAKEDEPS.INC, which implements all of this. To use it, simply define the makefile variable, MAKEDEPSRC as the list of source files, and include MAKEDEPS.INC. Just delete the makedeps file prior to running NMAKE and dependencies will automatically be generated. Obviously, this is for Microsoft's NMAKE; I haven't used Watcom's, Symantec's or Borland's MAKE utilities recently, but I presume that they have similar preprocessing and macro substitution capabilities. I am placing this utility in the Public Domain.