From 7761eecc34e843f277a4a5e69eca0b5d41c421d3 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 12 Feb 1990 11:47:50 +0000 Subject: [PATCH] removed MKDEP; it is now a cpp option (-d) --- util/cpp/Makefile | 6 +----- util/cpp/Parameters | 6 ------ util/cpp/cpp.6 | 20 +++++++++++++++++--- util/cpp/domacro.c | 11 +++-------- util/cpp/main.c | 27 +++++++++++++-------------- util/cpp/options.c | 17 ++++++++++++----- util/cpp/preprocess.c | 16 +++------------- 7 files changed, 49 insertions(+), 54 deletions(-) diff --git a/util/cpp/Makefile b/util/cpp/Makefile index 0c11debea..9662c719d 100644 --- a/util/cpp/Makefile +++ b/util/cpp/Makefile @@ -62,7 +62,7 @@ GSRC = char.c symbol2str.c GHSRC = errout.h idfsize.h ifdepth.h lapbuf.h \ nparams.h numsize.h obufsize.h \ parbufsize.h pathlength.h strsize.h textsize.h \ - botch_free.h debug.h inputtype.h dobits.h line_prefix.h mkdep.h + botch_free.h debug.h inputtype.h dobits.h line_prefix.h # Other generated files, for 'make clean' only GENERATED = tokenfile.g Lpars.h LLfiles LL.output lint.out \ @@ -172,7 +172,6 @@ domacro.o: input.h domacro.o: inputtype.h domacro.o: interface.h domacro.o: macro.h -domacro.o: mkdep.h domacro.o: nparams.h domacro.o: parbufsize.h domacro.o: textsize.h @@ -192,13 +191,11 @@ main.o: file_info.h main.o: idf.h main.o: idfsize.h main.o: macro.h -main.o: mkdep.h options.o: charoffset.h options.o: class.h options.o: idf.h options.o: idfsize.h options.o: macro.h -options.o: mkdep.h preprocess.o: LLlex.h preprocess.o: bits.h preprocess.o: charoffset.h @@ -210,7 +207,6 @@ preprocess.o: idfsize.h preprocess.o: input.h preprocess.o: inputtype.h preprocess.o: line_prefix.h -preprocess.o: mkdep.h preprocess.o: obufsize.h replace.o: LLlex.h replace.o: charoffset.h diff --git a/util/cpp/Parameters b/util/cpp/Parameters index 32ba2fd37..5c8496493 100644 --- a/util/cpp/Parameters +++ b/util/cpp/Parameters @@ -68,10 +68,4 @@ */ -!File: mkdep.h -#undef MKDEP 1 /* if defined, preprocessor only outputs - names of files included (not finished yet) - */ - - diff --git a/util/cpp/cpp.6 b/util/cpp/cpp.6 index 14ca50d85..95fb6056e 100644 --- a/util/cpp/cpp.6 +++ b/util/cpp/cpp.6 @@ -30,7 +30,6 @@ as a macro with as its replacement text. .IP -\fBD\fIname\fR the same as -\fBD\fIname\fR=1. -.IP .IP -\fBU\fIname\fR .br undefine the macro name @@ -42,9 +41,25 @@ do not generate line directives .IP -\fBM\fIn\fR set maximum identifier length to .IR n . +.IP -\fBd\fR[\fIfile\fR] +.br +if \fIfile\fR is not given, do not preprocess, but instead generate a list +of makefile dependencies and write them to the standard output. +If \fIfile\fP is given, generate preprocessor output on standard output, +and generate the list of makefile dependencies on file \fIfile\fP. +.IP -\fBxs\fR +when generating makefile dependencies, do not include files from +/usr/include. +.IP -\fBxm\fR +when generating makefile dependencies, generate them in the following format: +.RS +.IP "file.o: file1.h" +.RE +.IP "" +where "file.o" is derived from the source file name. Normally, only a list +of files included is generated. .PP The following names are always available unless undefined: -.RS .IP __FILE__ The input (or #include) file being compiled (as a quoted string). @@ -53,4 +68,3 @@ The line number being compiled. .IP __DATE__ The date and time of compilation as a Unix ctime quoted string (the trailing newline is removed). -.RE diff --git a/util/cpp/domacro.c b/util/cpp/domacro.c index 76aa7cedf..72300aa8e 100644 --- a/util/cpp/domacro.c +++ b/util/cpp/domacro.c @@ -23,7 +23,6 @@ #include "class.h" #include "macro.h" #include "bits.h" -#include "mkdep.h" IMPORT char **inctable; /* list of include directories */ IMPORT char *getwdir(); @@ -34,6 +33,7 @@ PRIVATE char ifstack[IFDEPTH]; /* if-stack: the content of an entry is */ int nestlevel = -1; int svnestlevel[30] = {-1}; int nestcount; +extern int do_preprocess; char * GetIdentifier() @@ -274,17 +274,12 @@ do_include() inctable[0] = WorkingDir; if (filenm) { if (!InsertFile(filenm, &inctable[tok==FILESPECIFIER],&result)){ -#ifndef MKDEP - error("cannot find include file \"%s\"", filenm); -#else - warning("cannot find include file \"%s\"", filenm); + if (do_preprocess) error("cannot find include file \"%s\"", filenm); + else warning("cannot find include file \"%s\"", filenm); add_dependency(filenm); -#endif } else { -#ifdef MKDEP add_dependency(result); -#endif WorkingDir = getwdir(result); svnestlevel[++nestcount] = nestlevel; FileName = result; diff --git a/util/cpp/main.c b/util/cpp/main.c index 6d8305753..ef3fd796e 100644 --- a/util/cpp/main.c +++ b/util/cpp/main.c @@ -8,19 +8,20 @@ #include #include #include +#include #include "file_info.h" #include "idfsize.h" -#include "mkdep.h" -#ifdef MKDEP #include "idf.h" #include "macro.h" -#endif extern char *symbol2str(); extern char *getwdir(); extern int err_occurred; +extern int do_dependencies; +extern char *dep_file; int idfsize = IDFSIZE; extern char options[]; +static File *dep_fd = STDOUT; arith ifval; @@ -56,9 +57,6 @@ main(argc, argv) do_option(par); argc--, argv++; } -#ifdef MKDEP - options['P'] = 1; -#endif compile(argc - 1, &argv[1]); exit(err_occurred); } @@ -89,12 +87,9 @@ compile(argc, argv) source ? source : "stdin"); if (source) WorkingDir = getwdir(dummy); preprocess(source); -#ifdef MKDEP - list_dependencies(source); -#endif + if (do_dependencies) list_dependencies(source); } -#ifdef MKDEP struct idf *file_head; extern char *strrindex(); @@ -120,6 +115,9 @@ list_dependencies(source) } else source = 0; } + if (dep_file && !sys_open(dep_file, OP_WRITE, &dep_fd)) { + fatal("could not open %s", dep_file); + } while (p) { assert(p->id_resmac == K_FILE); dependency(p->id_text, source); @@ -140,12 +138,13 @@ add_dependency(s) } dependency(s, source) - char *s; + char *s, *source; { if (options['s'] && !strncmp(s, "/usr/include/", 13)) { return; } - if (options['m'] && source) print("%s: ", source); - print("%s\n", s); + if (options['m'] && source) { + fprint(dep_fd, "%s: %s\n", source, s); + } + else fprint(dep_fd, "%s\n", s); } -#endif diff --git a/util/cpp/options.c b/util/cpp/options.c index 486a43717..24b015ae5 100644 --- a/util/cpp/options.c +++ b/util/cpp/options.c @@ -10,13 +10,15 @@ #include "class.h" #include "macro.h" #include "idf.h" -#include "mkdep.h" char options[128]; /* one for every char */ int inc_pos = 1; /* place where next -I goes */ int inc_max; int inc_total; +int do_preprocess = 1; +int do_dependencies = 0; char **inctable; +char *dep_file = 0; extern int idfsize; int txt2int(); @@ -26,20 +28,25 @@ do_option(text) { switch(*text++) { case '-': -#ifdef MKDEP case 'x': -#endif options[*text] = 1; break; default: -#ifndef MKDEP error("illegal option: %c", text[-1]); -#endif break; case 'C' : /* comment output */ case 'P' : /* run preprocessor stand-alone, without #'s */ options[*(text-1)] = 1; break; + case 'd' : /* dependency generation */ + do_dependencies = 1; + if (*text) { + dep_file = text; + } + else { + do_preprocess = 0; + } + break; case 'D' : /* -Dname : predefine name */ { register char *cp = text, *name, *mactext; diff --git a/util/cpp/preprocess.c b/util/cpp/preprocess.c index d3814b51a..64ca97e83 100644 --- a/util/cpp/preprocess.c +++ b/util/cpp/preprocess.c @@ -14,42 +14,32 @@ #include "idfsize.h" #include "bits.h" #include "line_prefix.h" -#include "mkdep.h" #ifdef DOBITS char bits[128]; #endif -#ifndef MKDEP char _obuf[OBUFSIZE]; +extern int do_preprocess; Xflush() { - sys_write(STDOUT, _obuf, OBUFSIZE); + if (do_preprocess) sys_write(STDOUT, _obuf, OBUFSIZE); } -#endif preprocess(fn) char *fn; { register int c; -#ifndef MKDEP register char *op = _obuf; register char *ob = &_obuf[OBUFSIZE]; -#endif char Xbuf[256]; int lineno = 0; extern char options[]; -#ifndef MKDEP -#define flush(X) (sys_write(STDOUT,_obuf,X)) +#define flush(X) (! do_preprocess || sys_write(STDOUT,_obuf,X)) #define echo(ch) if (op == ob) { Xflush(); op = _obuf; } *op++ = (ch); #define newline() echo('\n') -#else -#define flush(X) -#define echo(ch) (ch) -#define newline() -#endif if (! options['P']) { /* Generate a line directive communicating the