removed MKDEP; it is now a cpp option (-d)
authorceriel <none@none>
Mon, 12 Feb 1990 11:47:50 +0000 (11:47 +0000)
committerceriel <none@none>
Mon, 12 Feb 1990 11:47:50 +0000 (11:47 +0000)
util/cpp/Makefile
util/cpp/Parameters
util/cpp/cpp.6
util/cpp/domacro.c
util/cpp/main.c
util/cpp/options.c
util/cpp/preprocess.c

index 0c11deb..9662c71 100644 (file)
@@ -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
index 32ba2fd..5c84964 100644 (file)
                                */
 
 
-!File: mkdep.h
-#undef MKDEP           1       /* if defined, preprocessor only outputs
-                                  names of files included (not finished yet)
-                               */
-
-
 
index 14ca50d..95fb605 100644 (file)
@@ -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
index 76aa7ce..72300aa 100644 (file)
@@ -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;
index 6d83057..ef3fd79 100644 (file)
@@ -8,19 +8,20 @@
 #include <alloc.h>
 #include <em_arith.h>
 #include <assert.h>
+#include <system.h>
 #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
index 486a437..24b015a 100644 (file)
 #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;
index d3814b5..64ca97e 100644 (file)
 #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