summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2012-11-04 16:52:40 +0000
committerDaniel Silverstone <dsilvers@digital-scurf.org>2012-11-04 16:52:40 +0000
commit524f69acc59ac20955700c65d358490c383aa3a2 (patch)
tree1c4dccc21eb3bdbb0c639b5942aef1cf98990f05 /src
parenta59c3f3baa6bf13f74429d0946f4dc768be94e15 (diff)
downloadnsgenbind-524f69acc59ac20955700c65d358490c383aa3a2.tar.gz
nsgenbind-524f69acc59ac20955700c65d358490c383aa3a2.tar.bz2
Support generation of dep files
Diffstat (limited to 'src')
-rw-r--r--src/nsgenbind-ast.c12
-rw-r--r--src/nsgenbind.c41
-rw-r--r--src/options.h2
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;