Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/mkdep Add the following options with a view to using...
details: https://anonhg.NetBSD.org/src/rev/83c384be26e2
branches: trunk
changeset: 555171:83c384be26e2
user: dsl <dsl%NetBSD.org@localhost>
date: Mon Nov 10 17:56:38 2003 +0000
description:
Add the following options with a view to using 'cc -MD' to automatically
create dependency files:
-d process xxx.d files to generate .depend (don't run ${CC})
-o add .OPTIONAL: <headers> to output file
-q don't print warnins for missing files (with -d)
-s suf list of suffixes to replace ".o"
The -s suf should allow all the 'afterdepend' stuff to be killed.
(christos thought this might be a good idea...)
diffstat:
usr.bin/mkdep/Makefile | 3 +-
usr.bin/mkdep/mkdep.1 | 24 +++-
usr.bin/mkdep/mkdep.c | 307 +++++++++++++++++++++++++++++-------------------
3 files changed, 209 insertions(+), 125 deletions(-)
diffs (truncated from 459 to 300 lines):
diff -r 52a466be4c49 -r 83c384be26e2 usr.bin/mkdep/Makefile
--- a/usr.bin/mkdep/Makefile Mon Nov 10 16:13:05 2003 +0000
+++ b/usr.bin/mkdep/Makefile Mon Nov 10 17:56:38 2003 +0000
@@ -1,8 +1,9 @@
-# $NetBSD: Makefile,v 1.13 2003/05/18 07:57:35 lukem Exp $
+# $NetBSD: Makefile,v 1.14 2003/11/10 17:56:38 dsl Exp $
# @(#)Makefile 8.1 (Berkeley) 6/6/93
MAN= mkdep.1
PROG= mkdep
SRCS= mkdep.c findcc.c
+WARNS= 3
.include <bsd.prog.mk>
diff -r 52a466be4c49 -r 83c384be26e2 usr.bin/mkdep/mkdep.1
--- a/usr.bin/mkdep/mkdep.1 Mon Nov 10 16:13:05 2003 +0000
+++ b/usr.bin/mkdep/mkdep.1 Mon Nov 10 17:56:38 2003 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: mkdep.1,v 1.10 2003/08/07 11:15:12 agc Exp $
+.\" $NetBSD: mkdep.1,v 1.11 2003/11/10 17:56:38 dsl Exp $
.\"
.\" Copyright (c) 1987, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -29,7 +29,7 @@
.\"
.\" @(#)mkdep.1 8.1 (Berkeley) 6/6/93
.\"
-.Dd June 6, 1993
+.Dd November 9, 2003
.Dt MKDEP 1
.Os
.Sh NAME
@@ -37,9 +37,9 @@
.Nd construct Makefile dependency list
.Sh SYNOPSIS
.Nm
-.Op Fl a
-.Op Fl p
+.Op Fl adopq
.Op Fl f Ar file
+.Op Fl s Ar suffixes
.Op Ar flags
.Ar file ...
.Sh DESCRIPTION
@@ -66,10 +66,15 @@
so that multiple
.Nm Ns 's
may be run from a single Makefile.
+.It Fl d
+Post process and merge previously created (for example by 'cc -MD x.c') depend
+files into a single file.
.It Fl f
Write the include file dependencies to
.Ar file ,
instead of the default ``.depend''.
+.It Fl o
+Add an additional .OPTIONAL line for each dependant file.
.It Fl p
Cause
.Nm
@@ -85,6 +90,17 @@
module.
This is useful for programs whose source is contained in a single
module.
+.Fl p
+is equivalent to specifying a null suffix with
+.Fl s .
+.It Fl q
+Do not print a warning for inaccessible files when
+.Fl d
+is given.
+.It Fl s
+Replace the '.o' suffix of each target filename the suffixes from
+.Ar suffixes .
+The list of suffixes may be space or comma separated.
.El
.Sh FILES
.Bl -tag -width .depend -compact
diff -r 52a466be4c49 -r 83c384be26e2 usr.bin/mkdep/mkdep.c
--- a/usr.bin/mkdep/mkdep.c Mon Nov 10 16:13:05 2003 +0000
+++ b/usr.bin/mkdep/mkdep.c Mon Nov 10 17:56:38 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mkdep.c,v 1.17 2003/10/27 00:12:43 lukem Exp $ */
+/* $NetBSD: mkdep.c,v 1.18 2003/11/10 17:56:38 dsl Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -44,13 +44,15 @@
#if !defined(lint)
__COPYRIGHT("@(#) Copyright (c) 1999 The NetBSD Foundation, Inc.\n\
All rights reserved.\n");
-__RCSID("$NetBSD: mkdep.c,v 1.17 2003/10/27 00:12:43 lukem Exp $");
+__RCSID("$NetBSD: mkdep.c,v 1.18 2003/11/10 17:56:38 dsl Exp $");
#endif /* not lint */
+#include <sys/mman.h>
#include <sys/param.h>
#include <sys/wait.h>
#include <ctype.h>
#include <err.h>
+#include <fcntl.h>
#include <locale.h>
#include <paths.h>
#include <signal.h>
@@ -64,106 +66,56 @@
#define DEFAULT_PATH _PATH_DEFPATH
#define DEFAULT_FILENAME ".depend"
-int tmpfd;
-char tmpfilename[MAXPATHLEN];
-static void finish __P((int));
-static void usage __P((void));
-int main __P((int, char **));
+static inline void *
+deconst(const void *p)
+{
+ return (const char *)p - (const char *)0 + (char *)0;
+}
static void
-usage()
+usage(void)
{
(void)fprintf(stderr,
- "usage: %s [-a] [-p] [-f file] flags file ...\n",
+ "usage: %s [-acopq] [-f file] [-s suffix_list] flags file ...\n",
getprogname());
exit(EXIT_FAILURE);
}
-void
-finish(signo)
- int signo;
-{
-
- if (tmpfd != -1) {
- (void)close(tmpfd);
- (void)unlink(tmpfilename);
- }
- exit(EXIT_FAILURE);
-}
-
-int
-main(argc, argv)
- int argc;
- char **argv;
+static int
+run_cc(int argc, char **argv, const char **fname)
{
- /* LINTED local definition of index */
- int aflag, pflag, index, status;
- pid_t cpid, pid;
- char *filename, *CC, *pathname, **args;
- const char *tmpdir;
- /* LINTED local definition of tmpfile */
- FILE *tmpfile, *dependfile;
- char buffer[32768];
-
- setlocale(LC_ALL, "");
- setprogname(argv[0]);
-
- aflag = 0;
- pflag = 0;
- filename = DEFAULT_FILENAME;
-
- /* XXX should use getopt(). */
- for (index = 1; index < argc; index++) {
- if (strcmp(argv[index], "-a") == 0)
- aflag = 1;
- else if (strcmp(argv[index], "-f") == 0) {
- if (++index < argc)
- filename = argv[index];
- } else if (strcmp(argv[index], "-p") == 0)
- pflag = 1;
- else
- break;
- }
-
- argc -= index;
- argv += index;
- if (argc == 0)
- usage();
+ const char *CC, *pathname, *tmpdir;
+ static char tmpfilename[MAXPATHLEN];
+ char **args;
+ int tmpfd;
+ pid_t pid, cpid;
+ int status;
if ((CC = getenv("CC")) == NULL)
CC = DEFAULT_CC;
if ((pathname = findcc(CC)) == NULL)
if (!setenv("PATH", DEFAULT_PATH, 1))
pathname = findcc(CC);
- if (pathname == NULL) {
- (void)fprintf(stderr, "%s: %s: not found\n", getprogname(), CC);
- exit(EXIT_FAILURE);
- }
+ if (pathname == NULL)
+ err(EXIT_FAILURE, "%s: not found", CC);
+ if ((args = malloc((argc + 3) * sizeof(char *))) == NULL)
+ err(EXIT_FAILURE, "malloc");
- if ((args = malloc((argc + 3) * sizeof(char *))) == NULL) {
- perror(getprogname());
- exit(EXIT_FAILURE);
- }
- args[0] = CC;
- args[1] = "-M";
+ args[0] = deconst(CC);
+ args[1] = deconst("-M");
(void)memcpy(&args[2], argv, (argc + 1) * sizeof(char *));
if ((tmpdir = getenv("TMPDIR")) == NULL)
tmpdir = _PATH_TMP;
(void)snprintf(tmpfilename, sizeof (tmpfilename), "%s/%s", tmpdir,
"mkdepXXXXXX");
- /* set signal handler */
- tmpfd = -1;
- (void)signal(SIGINT, finish);
- (void)signal(SIGHUP, finish);
- (void)signal(SIGQUIT, finish);
- (void)signal(SIGPIPE, finish);
- (void)signal(SIGTERM, finish);
- if ((tmpfd = mkstemp (tmpfilename)) < 0) {
+ if ((tmpfd = mkstemp(tmpfilename)) < 0) {
warn("unable to create temporary file %s", tmpfilename);
exit(EXIT_FAILURE);
}
+ (void)unlink(tmpfilename);
+ *fname = tmpfilename;
switch (cpid = vfork()) {
case 0:
@@ -175,64 +127,179 @@
/* NOTREACHED */
case -1:
- (void)fprintf(stderr, "%s: unable to fork.\n", getprogname());
- (void)close(tmpfd);
- (void)unlink(tmpfilename);
- exit(EXIT_FAILURE);
+ err(EXIT_FAILURE, "unable to fork");
}
while (((pid = wait(&status)) != cpid) && (pid >= 0))
continue;
- if (status) {
- (void)fprintf(stderr, "%s: compile failed.\n", getprogname());
- (void)close(tmpfd);
- (void)unlink(tmpfilename);
- exit(EXIT_FAILURE);
- }
+ if (status)
+ errx(EXIT_FAILURE, "compile failed.");
+
+ return tmpfd;
+}
+
+int
+main(int argc, char **argv)
+{
+ int aflag, dflag, oflag, qflag;
+ const char *filename;
+ int dependfile;
+ char *buf, *ptr, *line, *suf, *colon, *eol;
+ int ok_ind, ch;
+ int sz;
+ int fd;
+ const char *fname;
+ const char *suffixes = NULL, *s, *s1;
+
+ setlocale(LC_ALL, "");
+ setprogname(argv[0]);
+
+ aflag = O_WRONLY | O_APPEND | O_CREAT | O_TRUNC;
+ dflag = 0;
+ oflag = 0;
+ qflag = 0;
+ filename = DEFAULT_FILENAME;
+ dependfile = -1;
- (void)lseek(tmpfd, (off_t)0, SEEK_SET);
- if ((tmpfile = fdopen(tmpfd, "r")) == NULL) {
- (void)fprintf(stderr, "%s: unable to read temporary file %s\n",
- getprogname(), tmpfilename);
- (void)close(tmpfd);
- (void)unlink(tmpfilename);
- exit(EXIT_FAILURE);
- }
-
- if ((dependfile = fopen(filename, aflag ? "a" : "w")) == NULL) {
- (void)fprintf(stderr, "%s: unable to %s to file %s\n",
- getprogname(), aflag ? "append" : "write", filename);
- (void)fclose(tmpfile);
- (void)unlink(tmpfilename);
- exit(EXIT_FAILURE);
+ opterr = 0; /* stop getopt() bleating about errors. */
Home |
Main Index |
Thread Index |
Old Index