home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume38 / fixdepnd / part01 < prev    next >
Encoding:
Text File  |  1993-07-13  |  10.4 KB  |  343 lines

  1. Newsgroups: comp.sources.misc
  2. From: chris@sterling.com (Chris Olson)
  3. Subject: v38i055:  fixdepend - Fix dependencies from makedepend to reference library objects, Part01/01
  4. Message-ID: <1993Jul14.143655.25340@sparky.sterling.com>
  5. X-Md4-Signature: dd1c7202c78ee1f306d0ea3eab4485b6
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Organization: Sterling Software
  8. Date: Wed, 14 Jul 1993 14:36:55 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: chris@sterling.com (Chris Olson)
  12. Posting-number: Volume 38, Issue 55
  13. Archive-name: fixdepend/part01
  14. Environment: UNIX
  15.  
  16. fixdepend takes the Makefile generated by makedepend and produces a new
  17. Makefile which has the library .o's depending on the .h files rather than 
  18. on the .c's.  This allows a makefile to be easily constructed which generates
  19. libraries without having to keep .o files around outside of the library.
  20. This saves space and is avoids clutter in the makefile itself.
  21.  
  22. #! /bin/sh
  23. # This is a shell archive.  Remove anything before this line, then feed it
  24. # into a shell via "sh file" or similar.  To overwrite existing files,
  25. # type "sh file -c".
  26. # Contents:  README Makefile fixdepend.c fixdepend.l
  27. # Wrapped by kent@sparky on Sun Jul 11 19:21:59 1993
  28. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  29. echo If this archive is complete, you will see the following message:
  30. echo '          "shar: End of archive 1 (of 1)."'
  31. if test -f 'README' -a "${1}" != "-c" ; then 
  32.   echo shar: Will not clobber existing file \"'README'\"
  33. else
  34.   echo shar: Extracting \"'README'\" \(668 characters\)
  35.   sed "s/^X//" >'README' <<'END_OF_FILE'
  36. Xa) To paraphrase the man page:
  37. X
  38. X   fixdepend takes the Makefile generated by makedepend and produces a new
  39. X   Makefile which has the library .o's depending on the .h files rather than on
  40. X   the .c's.  This allows a makefile to be easily constructed which generates
  41. X   libraries without having to keep .o files around outside of the library.
  42. X   This, understandably, saves space and is avoids clutter in the makefile
  43. X   itself.
  44. X
  45. X   -- Chris Olson
  46. X
  47. Xb) To build fixdepend, just edit the makefile and set the bindir and mandir's,
  48. X   then type 'make install'.
  49. X
  50. X   This program has been tested on Dec and Sun platform's, using the GNU make
  51. X   program.
  52. X
  53. X          Good Luck!
  54. END_OF_FILE
  55.   if test 668 -ne `wc -c <'README'`; then
  56.     echo shar: \"'README'\" unpacked with wrong size!
  57.   fi
  58.   # end of 'README'
  59. fi
  60. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  61.   echo shar: Will not clobber existing file \"'Makefile'\"
  62. else
  63.   echo shar: Extracting \"'Makefile'\" \(320 characters\)
  64.   sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  65. XCFLAGS=-O
  66. XBINDIR=/usr/local/bin
  67. XMANDIR=/usr/local/man/manl
  68. X
  69. Xfixdepend: fixdepend.o
  70. X    $(CC) -o fixdepend fixdepend.o
  71. X
  72. Xfixdepend.o: fixdepend.c
  73. X
  74. Xinstall: fixdepend
  75. X    mv fixdepend $(BINDIR)
  76. X    chmod 775 $(BINDIR)/fixdepend
  77. X    cp fixdepend.l $(MANDIR)
  78. X    chmod 664 $(MANDIR)
  79. X
  80. X# DO NOT DELETE THIS LINE -- make depend depends on it.
  81. END_OF_FILE
  82.   if test 320 -ne `wc -c <'Makefile'`; then
  83.     echo shar: \"'Makefile'\" unpacked with wrong size!
  84.   fi
  85.   # end of 'Makefile'
  86. fi
  87. if test -f 'fixdepend.c' -a "${1}" != "-c" ; then 
  88.   echo shar: Will not clobber existing file \"'fixdepend.c'\"
  89. else
  90.   echo shar: Extracting \"'fixdepend.c'\" \(5161 characters\)
  91.   sed "s/^X//" >'fixdepend.c' <<'END_OF_FILE'
  92. X/*
  93. X *  fixdepend - Fixup the dpendency list generated by makedepend to properly
  94. X *              reference library members.
  95. X *
  96. X *  This program and source is copyright 1993 by Chris Olson, All Rights
  97. X *  Reserved.  Permission is granted for personal use, and it may be
  98. X *  distributed by any means as long as no more than a fair duplication
  99. X *  and media costs are charged.  If this program is going to be sold as
  100. X *  part of a larger product, please contact the author at the following
  101. X *  electronic address:
  102. X *
  103. X *    chris@Sterling.COM
  104. X *
  105. X *  fixdepend -l library [-f Makefile] [-s "marker-line"] object ...
  106. X *
  107. X *  Chris Olson
  108. X *  v1.0
  109. X *  06/10/93
  110. X */
  111. X#include <stdio.h>
  112. X#include <string.h>
  113. X#include <sys/param.h>
  114. X
  115. Xstatic char *File = "Makefile";
  116. Xstatic char *Lib = "";
  117. Xstatic char *Start = "# DO NOT DELETE THIS LINE -- make depend depends on it.";
  118. X
  119. X/*
  120. X *  Tear apart the command line and fill in all of the variables.  Used instead
  121. X *  of 'getarg' because I could not guarentee a 'getarg' on all systems this
  122. X *  program might be ported to.
  123. X */
  124. Xstatic int parse_args (argc, argv)
  125. X   int argc;    /* Number of arguments on the command line. */
  126. X   char **argv;    /* The argument list */
  127. X{
  128. X   int i;    /* Simple loop counter. */
  129. X
  130. X   for (i = 1; i < argc; i++)
  131. X      if (argv[i][0] != '-')
  132. X         return i;
  133. X      else
  134. X         switch (argv[i][1]) {
  135. X         case 'f':
  136. X            if (argv[i][2] == '\0')
  137. X               File = argv[++i];
  138. X            else
  139. X               File = &argv[i][2];
  140. X            break;
  141. X         case 'l':
  142. X            if (argv[i][2] == '\0')
  143. X               Lib = argv[++i];
  144. X            else
  145. X               Lib = &argv[i][2];
  146. X            break;
  147. X         case 's':
  148. X            if (argv[i][2] == '\0')
  149. X               Start = argv[++i];
  150. X            else
  151. X               Start = &argv[i][2];
  152. X            break;
  153. X         default:
  154. X            fprintf(stderr, "Bad option '%s'.\n", argv[i]);
  155. X            exit(-1);
  156. X         }
  157. X   return i;
  158. X} /* parse_args */
  159. X
  160. X/*
  161. X *  Rename a file.  Does NOT work across volumes, but does not need to for this
  162. X *  program.
  163. X */
  164. Xstatic int mv(init, new)
  165. X   char *init;    /* Initial name of the file. */
  166. X   char *new;    /* New name for the file.    */
  167. X{
  168. X   unlink(new);    /* Don't care if this fails... */
  169. X   if (link(init, new))
  170. X      return -1;
  171. X   return unlink(init);
  172. X} /* mv */
  173. X
  174. X/*
  175. X *  Main part of the code.
  176. X */
  177. Xint main (argc, argv)
  178. X   int argc;    /* Number of command line arguments. */
  179. X   char **argv;    /* Command line arguments.           */
  180. X{
  181. X   FILE *fp_in;            /* Stream reading from (Makefile.bak).       */
  182. X   FILE *fp_out;        /* Stream writing too (new Makefile)         */
  183. X   char *colon;            /* Position of the colon in the string.      */
  184. X   char line[BUFSIZ];        /* IO buffer.                                */
  185. X   char save_file[MAXPATHLEN];    /* Orginal filename.                         */
  186. X   int i;            /* Loop counter.                             */
  187. X   int start;            /* Where in the argument list the files are. */
  188. X
  189. X   /*
  190. X    *  Parse the command line.
  191. X    */
  192. X   start = parse_args(argc, argv);
  193. X   if (!strlen(Lib)) {
  194. X      fprintf(stderr, "You must specify a library name!\n");
  195. X      exit(-1);
  196. X   }
  197. X
  198. X   /*
  199. X    *  Make a backup copy of the makefile, and open up the files.
  200. X    */
  201. X   sprintf(save_file, "%s.bak", File);
  202. X   if (mv(File, save_file) == -1) {
  203. X      fprintf(stderr, "Unable to make backup file '%s'\n", save_file);
  204. X      exit(-1);
  205. X   }
  206. X   if ((fp_out = fopen(File, "w")) == NULL) {
  207. X      fprintf(stderr, "Unable to open new '%s'.\n", File);
  208. X      if (mv(save_file, File))
  209. X         fprintf(stderr, "Unable to recover '%s', origional in '%s'.\n",
  210. X                 File, save_file);
  211. X      exit(-1);
  212. X   }
  213. X   if ((fp_in = fopen(save_file, "r")) == NULL) {
  214. X      fprintf(stderr, "Can't open '%s' for reading.\n", File);
  215. X      if (mv(save_file, File))
  216. X         fprintf(stderr, "Unable to recover '%s', origional in '%s'.\n",
  217. X                 File, save_file);
  218. X      exit(-1);
  219. X   }
  220. X
  221. X   /*
  222. X    *  Copy the file unchanged until we find the line of code where
  223. X    *  makedepend left the do-not-edit-beyond-this-point comment.
  224. X    */
  225. X   while (fgets(line, BUFSIZ, fp_in)) {
  226. X      fputs(line, fp_out);
  227. X      if (!strncmp(Start, line, strlen(Start)))
  228. X         break;
  229. X   }
  230. X
  231. X   /*
  232. X    *  Now adjust the lines for the objects requested.
  233. X    */
  234. X   while (fgets(line, BUFSIZ, fp_in)) {
  235. X      if ((colon = strchr(line, ':')) == NULL) {
  236. X     /*
  237. X      *  Not a dependency intro, just copy it out.
  238. X      */
  239. X         fputs(line, fp_out);
  240. X         continue;
  241. X      }
  242. X
  243. X      /*
  244. X       * Terminate the item, and mark the rest of line.
  245. X       */
  246. X      *(colon++) = '\0';
  247. X      for (i = start; i < argc; i++)
  248. X         if (!strcmp(line, argv[i])) {
  249. X        /*
  250. X         *  Adjust the reference to refer to a library.
  251. X         */
  252. X            *strchr(line, '.') = '\0';
  253. X        fputs(Lib, fp_out);
  254. X            fprintf(fp_out, "(%s.o):", Lib, line);
  255. X        fputs(colon, fp_out);
  256. X            break;
  257. X         }
  258. X      if (i == argc)
  259. X     /*
  260. X      *  Not one of the ones we where looking for, just output it.
  261. X      */
  262. X         fprintf(fp_out, "%s:%s", line, colon);
  263. X   }
  264. X
  265. X   /*
  266. X    *  Close all of the files and exit...
  267. X    */
  268. X   fclose(fp_in);
  269. X   fclose(fp_out);
  270. X   exit(0);
  271. X} /*  main */
  272. END_OF_FILE
  273.   if test 5161 -ne `wc -c <'fixdepend.c'`; then
  274.     echo shar: \"'fixdepend.c'\" unpacked with wrong size!
  275.   fi
  276.   # end of 'fixdepend.c'
  277. fi
  278. if test -f 'fixdepend.l' -a "${1}" != "-c" ; then 
  279.   echo shar: Will not clobber existing file \"'fixdepend.l'\"
  280. else
  281.   echo shar: Extracting \"'fixdepend.l'\" \(1051 characters\)
  282.   sed "s/^X//" >'fixdepend.l' <<'END_OF_FILE'
  283. X.TH fixdepend 1 LOCAL
  284. X.SH NAME
  285. Xfixdepend  \- Fix dependencies generated by makedepend to reference library members
  286. X.SH SYNOPSIS
  287. X.B fixdepend
  288. X.B\-l libname 
  289. X[
  290. X.B\-f Makefile
  291. X] [
  292. X.B\-s <makedepend-separator-line>
  293. X]
  294. X.B object ...
  295. X
  296. X.SH DESCRIPTION
  297. X.I fixdepend
  298. Xtakes the Makefile generated by
  299. X.I makedepend
  300. Xand produces a new Makefile which has the library .o's depending on the .h
  301. Xfiles rather than on the .c's.  This allows a makefile to be easily constructed
  302. Xwhich generates libraries without having to keep .o files around outside of
  303. Xthe library.  This, understandably, saves space and is avoids clutter in the
  304. Xmakefile itself.
  305. X
  306. X.SH OPTIONS
  307. X.IP "-l <library>" 4
  308. XSpecifies the library name to use in the dependency line.
  309. X.IP "-f <Makefile>"
  310. XAllows the use of varied makefile names, the default is
  311. X.I Makefile.
  312. X.IP "-s <makedepend-separator-line>"
  313. XAllows the use of non-standard separator lines.  the default is
  314. X # DO NOT DELETE THIS LINE -- make depend depends on it.
  315. X.SH AUTHOR
  316. XChris Olson <chris@Sterling.COM>
  317. X.SH "SEE ALSO"
  318. Xmake(1), makedepend(1)
  319. END_OF_FILE
  320.   if test 1051 -ne `wc -c <'fixdepend.l'`; then
  321.     echo shar: \"'fixdepend.l'\" unpacked with wrong size!
  322.   fi
  323.   # end of 'fixdepend.l'
  324. fi
  325. echo shar: End of archive 1 \(of 1\).
  326. cp /dev/null ark1isdone
  327. MISSING=""
  328. for I in 1 ; do
  329.     if test ! -f ark${I}isdone ; then
  330.     MISSING="${MISSING} ${I}"
  331.     fi
  332. done
  333. if test "${MISSING}" = "" ; then
  334.     echo You have the archive.
  335.     rm -f ark[1-9]isdone
  336. else
  337.     echo You still must unpack the following archives:
  338.     echo "        " ${MISSING}
  339. fi
  340. exit 0
  341. exit 0 # Just in case...
  342.