home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sources.misc
- From: chris@sterling.com (Chris Olson)
- Subject: v38i055: fixdepend - Fix dependencies from makedepend to reference library objects, Part01/01
- Message-ID: <1993Jul14.143655.25340@sparky.sterling.com>
- X-Md4-Signature: dd1c7202c78ee1f306d0ea3eab4485b6
- Sender: kent@sparky.sterling.com (Kent Landfield)
- Organization: Sterling Software
- Date: Wed, 14 Jul 1993 14:36:55 GMT
- Approved: kent@sparky.sterling.com
-
- Submitted-by: chris@sterling.com (Chris Olson)
- Posting-number: Volume 38, Issue 55
- Archive-name: fixdepend/part01
- Environment: UNIX
-
- fixdepend takes the Makefile generated by makedepend and produces a new
- Makefile which has the library .o's depending on the .h files rather than
- on the .c's. This allows a makefile to be easily constructed which generates
- libraries without having to keep .o files around outside of the library.
- This saves space and is avoids clutter in the makefile itself.
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then feed it
- # into a shell via "sh file" or similar. To overwrite existing files,
- # type "sh file -c".
- # Contents: README Makefile fixdepend.c fixdepend.l
- # Wrapped by kent@sparky on Sun Jul 11 19:21:59 1993
- PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
- echo If this archive is complete, you will see the following message:
- echo ' "shar: End of archive 1 (of 1)."'
- if test -f 'README' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'README'\"
- else
- echo shar: Extracting \"'README'\" \(668 characters\)
- sed "s/^X//" >'README' <<'END_OF_FILE'
- Xa) To paraphrase the man page:
- X
- X fixdepend takes the Makefile generated by makedepend and produces a new
- X Makefile which has the library .o's depending on the .h files rather than on
- X the .c's. This allows a makefile to be easily constructed which generates
- X libraries without having to keep .o files around outside of the library.
- X This, understandably, saves space and is avoids clutter in the makefile
- X itself.
- X
- X -- Chris Olson
- X
- Xb) To build fixdepend, just edit the makefile and set the bindir and mandir's,
- X then type 'make install'.
- X
- X This program has been tested on Dec and Sun platform's, using the GNU make
- X program.
- X
- X Good Luck!
- END_OF_FILE
- if test 668 -ne `wc -c <'README'`; then
- echo shar: \"'README'\" unpacked with wrong size!
- fi
- # end of 'README'
- fi
- if test -f 'Makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'Makefile'\"
- else
- echo shar: Extracting \"'Makefile'\" \(320 characters\)
- sed "s/^X//" >'Makefile' <<'END_OF_FILE'
- XCFLAGS=-O
- XBINDIR=/usr/local/bin
- XMANDIR=/usr/local/man/manl
- X
- Xfixdepend: fixdepend.o
- X $(CC) -o fixdepend fixdepend.o
- X
- Xfixdepend.o: fixdepend.c
- X
- Xinstall: fixdepend
- X mv fixdepend $(BINDIR)
- X chmod 775 $(BINDIR)/fixdepend
- X cp fixdepend.l $(MANDIR)
- X chmod 664 $(MANDIR)
- X
- X# DO NOT DELETE THIS LINE -- make depend depends on it.
- END_OF_FILE
- if test 320 -ne `wc -c <'Makefile'`; then
- echo shar: \"'Makefile'\" unpacked with wrong size!
- fi
- # end of 'Makefile'
- fi
- if test -f 'fixdepend.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'fixdepend.c'\"
- else
- echo shar: Extracting \"'fixdepend.c'\" \(5161 characters\)
- sed "s/^X//" >'fixdepend.c' <<'END_OF_FILE'
- X/*
- X * fixdepend - Fixup the dpendency list generated by makedepend to properly
- X * reference library members.
- X *
- X * This program and source is copyright 1993 by Chris Olson, All Rights
- X * Reserved. Permission is granted for personal use, and it may be
- X * distributed by any means as long as no more than a fair duplication
- X * and media costs are charged. If this program is going to be sold as
- X * part of a larger product, please contact the author at the following
- X * electronic address:
- X *
- X * chris@Sterling.COM
- X *
- X * fixdepend -l library [-f Makefile] [-s "marker-line"] object ...
- X *
- X * Chris Olson
- X * v1.0
- X * 06/10/93
- X */
- X#include <stdio.h>
- X#include <string.h>
- X#include <sys/param.h>
- X
- Xstatic char *File = "Makefile";
- Xstatic char *Lib = "";
- Xstatic char *Start = "# DO NOT DELETE THIS LINE -- make depend depends on it.";
- X
- X/*
- X * Tear apart the command line and fill in all of the variables. Used instead
- X * of 'getarg' because I could not guarentee a 'getarg' on all systems this
- X * program might be ported to.
- X */
- Xstatic int parse_args (argc, argv)
- X int argc; /* Number of arguments on the command line. */
- X char **argv; /* The argument list */
- X{
- X int i; /* Simple loop counter. */
- X
- X for (i = 1; i < argc; i++)
- X if (argv[i][0] != '-')
- X return i;
- X else
- X switch (argv[i][1]) {
- X case 'f':
- X if (argv[i][2] == '\0')
- X File = argv[++i];
- X else
- X File = &argv[i][2];
- X break;
- X case 'l':
- X if (argv[i][2] == '\0')
- X Lib = argv[++i];
- X else
- X Lib = &argv[i][2];
- X break;
- X case 's':
- X if (argv[i][2] == '\0')
- X Start = argv[++i];
- X else
- X Start = &argv[i][2];
- X break;
- X default:
- X fprintf(stderr, "Bad option '%s'.\n", argv[i]);
- X exit(-1);
- X }
- X return i;
- X} /* parse_args */
- X
- X/*
- X * Rename a file. Does NOT work across volumes, but does not need to for this
- X * program.
- X */
- Xstatic int mv(init, new)
- X char *init; /* Initial name of the file. */
- X char *new; /* New name for the file. */
- X{
- X unlink(new); /* Don't care if this fails... */
- X if (link(init, new))
- X return -1;
- X return unlink(init);
- X} /* mv */
- X
- X/*
- X * Main part of the code.
- X */
- Xint main (argc, argv)
- X int argc; /* Number of command line arguments. */
- X char **argv; /* Command line arguments. */
- X{
- X FILE *fp_in; /* Stream reading from (Makefile.bak). */
- X FILE *fp_out; /* Stream writing too (new Makefile) */
- X char *colon; /* Position of the colon in the string. */
- X char line[BUFSIZ]; /* IO buffer. */
- X char save_file[MAXPATHLEN]; /* Orginal filename. */
- X int i; /* Loop counter. */
- X int start; /* Where in the argument list the files are. */
- X
- X /*
- X * Parse the command line.
- X */
- X start = parse_args(argc, argv);
- X if (!strlen(Lib)) {
- X fprintf(stderr, "You must specify a library name!\n");
- X exit(-1);
- X }
- X
- X /*
- X * Make a backup copy of the makefile, and open up the files.
- X */
- X sprintf(save_file, "%s.bak", File);
- X if (mv(File, save_file) == -1) {
- X fprintf(stderr, "Unable to make backup file '%s'\n", save_file);
- X exit(-1);
- X }
- X if ((fp_out = fopen(File, "w")) == NULL) {
- X fprintf(stderr, "Unable to open new '%s'.\n", File);
- X if (mv(save_file, File))
- X fprintf(stderr, "Unable to recover '%s', origional in '%s'.\n",
- X File, save_file);
- X exit(-1);
- X }
- X if ((fp_in = fopen(save_file, "r")) == NULL) {
- X fprintf(stderr, "Can't open '%s' for reading.\n", File);
- X if (mv(save_file, File))
- X fprintf(stderr, "Unable to recover '%s', origional in '%s'.\n",
- X File, save_file);
- X exit(-1);
- X }
- X
- X /*
- X * Copy the file unchanged until we find the line of code where
- X * makedepend left the do-not-edit-beyond-this-point comment.
- X */
- X while (fgets(line, BUFSIZ, fp_in)) {
- X fputs(line, fp_out);
- X if (!strncmp(Start, line, strlen(Start)))
- X break;
- X }
- X
- X /*
- X * Now adjust the lines for the objects requested.
- X */
- X while (fgets(line, BUFSIZ, fp_in)) {
- X if ((colon = strchr(line, ':')) == NULL) {
- X /*
- X * Not a dependency intro, just copy it out.
- X */
- X fputs(line, fp_out);
- X continue;
- X }
- X
- X /*
- X * Terminate the item, and mark the rest of line.
- X */
- X *(colon++) = '\0';
- X for (i = start; i < argc; i++)
- X if (!strcmp(line, argv[i])) {
- X /*
- X * Adjust the reference to refer to a library.
- X */
- X *strchr(line, '.') = '\0';
- X fputs(Lib, fp_out);
- X fprintf(fp_out, "(%s.o):", Lib, line);
- X fputs(colon, fp_out);
- X break;
- X }
- X if (i == argc)
- X /*
- X * Not one of the ones we where looking for, just output it.
- X */
- X fprintf(fp_out, "%s:%s", line, colon);
- X }
- X
- X /*
- X * Close all of the files and exit...
- X */
- X fclose(fp_in);
- X fclose(fp_out);
- X exit(0);
- X} /* main */
- END_OF_FILE
- if test 5161 -ne `wc -c <'fixdepend.c'`; then
- echo shar: \"'fixdepend.c'\" unpacked with wrong size!
- fi
- # end of 'fixdepend.c'
- fi
- if test -f 'fixdepend.l' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'fixdepend.l'\"
- else
- echo shar: Extracting \"'fixdepend.l'\" \(1051 characters\)
- sed "s/^X//" >'fixdepend.l' <<'END_OF_FILE'
- X.TH fixdepend 1 LOCAL
- X.SH NAME
- Xfixdepend \- Fix dependencies generated by makedepend to reference library members
- X.SH SYNOPSIS
- X.B fixdepend
- X.B\-l libname
- X[
- X.B\-f Makefile
- X] [
- X.B\-s <makedepend-separator-line>
- X]
- X.B object ...
- X
- X.SH DESCRIPTION
- X.I fixdepend
- Xtakes the Makefile generated by
- X.I makedepend
- Xand produces a new Makefile which has the library .o's depending on the .h
- Xfiles rather than on the .c's. This allows a makefile to be easily constructed
- Xwhich generates libraries without having to keep .o files around outside of
- Xthe library. This, understandably, saves space and is avoids clutter in the
- Xmakefile itself.
- X
- X.SH OPTIONS
- X.IP "-l <library>" 4
- XSpecifies the library name to use in the dependency line.
- X.IP "-f <Makefile>"
- XAllows the use of varied makefile names, the default is
- X.I Makefile.
- X.IP "-s <makedepend-separator-line>"
- XAllows the use of non-standard separator lines. the default is
- X
- X # DO NOT DELETE THIS LINE -- make depend depends on it.
- X.SH AUTHOR
- XChris Olson <chris@Sterling.COM>
- X.SH "SEE ALSO"
- Xmake(1), makedepend(1)
- END_OF_FILE
- if test 1051 -ne `wc -c <'fixdepend.l'`; then
- echo shar: \"'fixdepend.l'\" unpacked with wrong size!
- fi
- # end of 'fixdepend.l'
- fi
- echo shar: End of archive 1 \(of 1\).
- cp /dev/null ark1isdone
- MISSING=""
- for I in 1 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have the archive.
- rm -f ark[1-9]isdone
- else
- echo You still must unpack the following archives:
- echo " " ${MISSING}
- fi
- exit 0
- exit 0 # Just in case...
-