From b48f5291779bc502b563d60c2ed9dbc4212834f7 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 26 Jan 1990 11:53:08 +0000 Subject: [PATCH] Added some mkdep features and fixed a bug --- util/cpp/Makefile | 1 + util/cpp/domacro.c | 4 ++-- util/cpp/main.c | 32 +++++++++++++++++++++++++++----- util/cpp/options.c | 12 ++++++++---- 4 files changed, 38 insertions(+), 11 deletions(-) diff --git a/util/cpp/Makefile b/util/cpp/Makefile index e4b2f5340..0c11debea 100644 --- a/util/cpp/Makefile +++ b/util/cpp/Makefile @@ -198,6 +198,7 @@ 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 diff --git a/util/cpp/domacro.c b/util/cpp/domacro.c index f0c0b2954..fb4b3ff0e 100644 --- a/util/cpp/domacro.c +++ b/util/cpp/domacro.c @@ -278,12 +278,12 @@ do_include() error("cannot find include file \"%s\"", filenm); #else warning("cannot find include file \"%s\"", filenm); - add_file(filenm); + add_dependency(filenm); #endif } else { #ifdef MKDEP - add_file(result); + add_dependency(result); #endif WorkingDir = getwdir(result); svnestlevel[++nestcount] = nestlevel; diff --git a/util/cpp/main.c b/util/cpp/main.c index 70852a383..e4494ecad 100644 --- a/util/cpp/main.c +++ b/util/cpp/main.c @@ -39,7 +39,7 @@ main(argc, argv) inctable = (char **) Malloc(10 * sizeof(char *)); inc_max = 10; - inc_total = 2; + inc_total = 3; inctable[0] = ""; inctable[1] = "/usr/include"; init_pp(); /* initialise the preprocessor macros */ @@ -90,25 +90,37 @@ compile(argc, argv) if (source) WorkingDir = getwdir(dummy); preprocess(source); #ifdef MKDEP - list_files(); + list_dependencies(source); #endif } #ifdef MKDEP struct idf *file_head; +extern char *strrindex(); -list_files() +list_dependencies(source) + char *source; { register struct idf *p = file_head; + if (source) { + register char *s = strrindex(source, '.'); + + if (s && *(s+1)) { + s++; + *s++ = 'o'; + *s = '\0'; + } + else source = 0; + } while (p) { assert(p->id_resmac == K_FILE); - print("%s\n", p->id_text); + dependency(p->id_text, source); p = p->id_file; } } -add_file(s) +add_dependency(s) char *s; { register struct idf *p = str2idf(s, 0); @@ -119,4 +131,14 @@ add_file(s) file_head = p; } } + +dependency(s, source) + char *s; +{ + if (options['s'] && !strncmp(s, "/usr/include/", 13)) { + return; + } + if (options['m'] && source) print("%s: ", source); + print("%s\n", s); +} #endif diff --git a/util/cpp/options.c b/util/cpp/options.c index 6df0df3f7..486a43717 100644 --- a/util/cpp/options.c +++ b/util/cpp/options.c @@ -10,6 +10,7 @@ #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 */ @@ -25,13 +26,19 @@ 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 */ - options['C'] = 1; + case 'P' : /* run preprocessor stand-alone, without #'s */ + options[*(text-1)] = 1; break; case 'D' : /* -Dname : predefine name */ { @@ -98,9 +105,6 @@ do_option(text) idfsize = 8; } break; - case 'P' : /* run preprocessor stand-alone, without #'s */ - options['P'] = 1; - break; case 'U' : /* -Uname : undefine predefined */ if (*text) { register struct idf *idef = findidf(text); -- 2.34.1