From 524f69acc59ac20955700c65d358490c383aa3a2 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sun, 4 Nov 2012 16:52:40 +0000 Subject: Support generation of dep files --- src/nsgenbind-ast.c | 12 ++++++++++++ src/nsgenbind.c | 41 ++++++++++++++++++++++++++++++++++++++--- src/options.h | 2 ++ 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/src/nsgenbind-ast.c b/src/nsgenbind-ast.c index c14f0df..52febaa 100644 --- a/src/nsgenbind-ast.c +++ b/src/nsgenbind-ast.c @@ -299,6 +299,10 @@ FILE *genbindopen(const char *filename) } prevfilepath = strndup(filename,fulllen); } + if (options->depfilehandle != NULL) { + fprintf(options->depfilehandle, " \\\n\t%s", + filename); + } return genfile; } @@ -315,6 +319,10 @@ FILE *genbindopen(const char *filename) if (options->verbose) { printf("Opened Genbind file %s\n", fullname); } + if (options->depfilehandle != NULL) { + fprintf(options->depfilehandle, " \\\n\t%s", + fullname); + } free(fullname); return genfile; } @@ -329,6 +337,10 @@ FILE *genbindopen(const char *filename) genfile = fopen(fullname, "r"); if ((genfile != NULL) && options->verbose) { printf("Opend Genbind file %s\n", fullname); + if (options->depfilehandle != NULL) { + fprintf(options->depfilehandle, " \\\n\t%s", + fullname); + } } free(fullname); diff --git a/src/nsgenbind.c b/src/nsgenbind.c index 14854ad..66292a9 100644 --- a/src/nsgenbind.c +++ b/src/nsgenbind.c @@ -30,7 +30,7 @@ static struct options* process_cmdline(int argc, char **argv) return NULL; } - while ((opt = getopt(argc, argv, "vdI:o:")) != -1) { + while ((opt = getopt(argc, argv, "vDd:I:o:")) != -1) { switch (opt) { case 'I': options->idlpath = strdup(optarg); @@ -40,17 +40,21 @@ static struct options* process_cmdline(int argc, char **argv) options->outfilename = strdup(optarg); break; + case 'd': + options->depfilename = strdup(optarg); + break; + case 'v': options->verbose = true; break; - case 'd': + case 'D': options->debug = true; break; default: /* '?' */ fprintf(stderr, - "Usage: %s [-I idlpath] [-o filename] inputfile\n", + "Usage: %s [-d depfilename] [-I idlpath] [-o filename] inputfile\n", argv[0]); free(options); return NULL; @@ -87,6 +91,32 @@ int main(int argc, char **argv) return 2; } + if (options->depfilename != NULL && + options->outfilename == NULL) { + fprintf(stderr, + "Error: output to stdout with dep generation would fail\n"); + return 3; + } + + if (options->depfilename != NULL && + options->infilename == NULL) { + fprintf(stderr, + "Error: input from stdin with dep generation would fail\n"); + return 3; + } + + if (options->depfilename != NULL) { + options->depfilehandle = fopen(options->depfilename, "w"); + if (options->depfilehandle == NULL) { + fprintf(stderr, + "Error: unable to open dep file\n"); + return 4; + } + fprintf(options->depfilehandle, + "%s %s :", options->depfilename, + options->outfilename); + } + res = genbind_parsefile(options->infilename, &genbind_root); if (res != 0) { fprintf(stderr, "Error: parse failed with code %d\n", res); @@ -104,5 +134,10 @@ int main(int argc, char **argv) return res; } + if (options->depfilehandle != NULL) { + fputc('\n', options->depfilehandle); + fclose(options->depfilehandle); + } + return 0; } diff --git a/src/options.h b/src/options.h index 696a907..ba43084 100644 --- a/src/options.h +++ b/src/options.h @@ -12,6 +12,8 @@ struct options { char *outfilename; char *infilename; + char *depfilename; + FILE *depfilehandle; char *idlpath; bool verbose; bool debug; -- cgit v1.2.3