home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / makdep4d.zip / MAKDPWIN.ZIP / MAKEDEP2.TXT < prev    next >
Text File  |  1995-05-26  |  6KB  |  158 lines

  1. MakeDep2
  2. --------
  3. May 26, 1995 by David M. Miller
  4. Copyright (C) 1995, Business Visions, Inc.
  5.  
  6.  
  7. A makefile dependency generator for C and C++ based Windows programming.
  8. MakeDep2 takes a list of .C, .CPP, .CXX, .A, .ASM, or .RC files and
  9. generates a list of dependencies for each of them.  It knows that .C, .CPP,
  10. .CXX, .A, and .ASM files produce .OBJ files and that .RC files produce .RES
  11. files.
  12.  
  13. MakeDep2 ignores any "system" #includes (those that use angle brackets to
  14. delimit the name of the included file), focusing only on "local" #includes
  15. (which delimit the included file name with double quotes).  The output from
  16. MakeDep2 goes to stdout, wrapped to 78 columns with backslashes as line
  17. continuation characters.
  18.  
  19. Using a very simple mechanism with Microsoft's NMAKE, dependencies
  20. may be generated nearly automatically.
  21.  
  22. Why another dependency generator?  Why not use GNU Make or one of the
  23. commercial Make programs, such as MKS make, which are capable of
  24. automatically generating dependencies?
  25.  
  26. The fact is, I would love to standardize on Gnu Make or MKS Make, but as a
  27. contractor, I must work with what my clients already have. If they are using
  28. Microsoft C 8.0c (the command line compiler of VC++), then they are using
  29. NMAKE.  It's as simple as that.
  30.  
  31. So I wrote MakeDep2.  The name MakeDep2 was chosen so that would be no name
  32. conflicts with MakeDep, another similar freeware utility; I tried MakeDep
  33. first, but for me it had confusing command line syntax, it did not process
  34. .RC files, it expected .OBJ filenames (targets) instead of explicit source
  35. code filenames, and it did not word wrap the output to any reasonable
  36. column width.
  37.  
  38. Source code is included, and is hopefully modular enough that
  39. enhancements may be added reasonably and other languages could be
  40. accomodated.
  41.  
  42.  
  43. Syntax
  44. ------
  45.  
  46. Running MakeDep2 with the '-?' option produces this output:
  47.  
  48. usage: makedep2 [-options] {target | @respfile} [target ..]
  49. where:
  50.     -l             suppress logo
  51.     -ipath[;path]  include file search directories
  52.     -spath[;path]  source file search directories
  53.     target         specifies source file name (wildcards permitted)
  54.                    (examples: *.cpp file.c file.asm file.rc)
  55.     respfile       contains targets and/or options.
  56.     -?             this message
  57.  
  58. INCLUDE environment variable will be used to locate quoted include
  59. files not in the current directory. -I flag adds directories to search
  60.  
  61.  
  62. Specifying include file search directories widens the scope of the
  63. INCLUDE environment variable.  It does not change MakeDep2's behavior
  64. of ignoring angle-bracket files.  Only double-quoted include files
  65. will be used to generate dependencies.
  66.  
  67. Specifying source file search directories permits a structured source tree.
  68. I have not extensively tested this feature.
  69.  
  70. Target files may be specified in one or both of two ways: on the
  71. command line, or in a response file.  Wildcard expansion is supported
  72. on the command line, but not within response files. Output of the
  73. dependency list goes to stdout, and should be redirected.
  74.  
  75. The simplest use of MakeDeps2 is: "MakeDeps2 @filelist >makedeps" or
  76. "MakeDeps2 *.c > makedeps".  The latter is best used only if it is
  77. known that there are no unwanted .C files in the directory.
  78.  
  79.  
  80.  
  81. Dependency Generation using NMAKE
  82. ---------------------------------
  83.  
  84. A makefile variable can be defined, for example, MAKEDEPSRC, which
  85. contains the entire list of C and RC source files.  Substitution
  86. macros are useful for this.  For instance, if you have a macro, OBJS,
  87. defined as:
  88.  
  89. OBJS=file1.obj file2.obj file3.obj
  90.  
  91. and, if the Windows RC file is called resource.rc, MAKEDEPSRC may be
  92. defined using macro substitution as:
  93.  
  94. MAKEDEPSRC=$(OBJS:.obj=.c) resource.rc
  95.  
  96. Next, a psuedotarget, here called deps, can be defined, using NMAKE's
  97. inline file generation capability, as:
  98.  
  99. deps: $(MAKEDEPSRC)
  100.         makedep2 @<< >makedeps
  101. $(**)
  102. <<
  103.  
  104. which creates a file called makedeps by running MakeDep2 with an
  105. inline file created by NMAKE.  It is useful if the target deps is a
  106. psuedotarget, and does not refer to an actual file, since running the
  107. command, "nmake deps" at any time will always rebuld the makedeps
  108. file, without regard to real file dependencies between the files
  109. listed in MAKEDEPSRC and the target.
  110.  
  111. Finally, the makedeps file should be included in the makefile:
  112.  
  113. !if exist(makedeps)
  114. !include "makedeps"
  115. !endif
  116.  
  117. With this mechanism in place, regenerating the dependencies just
  118. requires running NMAKE with the command:
  119.  
  120. nmake deps
  121.  
  122.  
  123.  
  124. Automatic Dependency Generation using NMAKE
  125. -------------------------------------------
  126.  
  127. Only one additional step is required to enable automatic dependency
  128. generation using Microsoft's NMAKE.  This assumes that there is a
  129. makefile variable called MAKEDEPSRC, a psuedotarget called deps, and
  130. an include of the file called makedeps (as above).
  131.  
  132. The following lines, when added to a makefile, instruct the NMAKE
  133. preprocessor to run NMAKE recursively to build the makedeps file if
  134. it doesn't exist.  In order to prevent looping infinitely, a dummy
  135. makedeps file is created first.  These lines may be placed at the end
  136. of the makefile, or in a file to be included in a makefile, but they
  137. must PRECEED the line that says !include "makedeps":
  138.  
  139. !if !exist(makedeps)
  140. !if [echo. >makedeps]
  141. !endif
  142. !if [$(MAKE) deps]
  143. !endif
  144. !endif
  145.  
  146.  
  147. Included in the Zip file is a file called MAKEDEPS.INC, which
  148. implements all of this.  To use it, simply define the makefile
  149. variable, MAKEDEPSRC as the list of source files, and include
  150. MAKEDEPS.INC.  Just delete the makedeps file prior to running NMAKE
  151. and dependencies will automatically be generated.
  152.  
  153. Obviously, this is for Microsoft's NMAKE; I haven't used Watcom's,
  154. Symantec's or Borland's MAKE utilities recently, but I presume that
  155. they have similar preprocessing and macro substitution capabilities.
  156.  
  157. I am placing this utility in the Public Domain.
  158.