1 /*
2 * genmms -- a program to make VMS makefiles for PCCTS
3 *
4 * ANTLR 1.33MR10
5 * Terence John Parr 1989 - 1998
6 * Purdue University
7 * U of MN
8 *
9 *
10 * VMS version from J.F. Pieronne
11 */
12
13 #include <stdio.h>
14 #include <ssdef.h>
15 #include "pcctscfg.h" /* be sensitive to what ANTLR/DLG call the files */
16
17 #define DIE return SS$_ABORT;
18 #define DONE return 1;
19
20 #ifndef require
21 #define require(expr, err) {if ( !(expr) ) fatal(err);}
22 #endif
23
24 #define MAX_FILES 50
25 #define MAX_CLASSES 50
26
27 char *RENAME_OBJ_FLAG="/obj=",
28 *RENAME_EXE_FLAG="/exe=";
29
30 char *dlg = "parser.dlg";
31 char *err = "err.c";
32 char *hdr = "stdpccts.h";
33 char *tok = "tokens.h";
34 char *mode = "mode.h";
35 char *scan = "scan";
36
37 char ATOKENBUFFER_O[100];
38 char APARSER_O[100];
39 char ASTBASE_O[100];
40 char PCCTSAST_O[100];
41 char LIST_O[100];
42 char DLEXERBASE_O[100];
43
44 /* Option flags */
45 static char *project="t", *files[MAX_FILES], *classes[MAX_CLASSES];
46 static int num_files = 0;
47 static int num_classes = 0;
48 static int user_lexer = 0;
49 static char *user_token_types = NULL;
50 static int gen_CPP = 0;
51 static char *outdir=".";
52 static char *dlg_class = "DLGLexer";
53 static int gen_trees = 0;
54 static int gen_hoist = 0;
55
56 typedef struct _Opt {
57 char *option;
58 int arg;
59 #ifdef __cplusplus
60 void (*process)(...);
61 #else
62 void (*process)();
63 #endif
64 char *descr;
65 } Opt;
66
67 #ifdef __STDC__
68 static void ProcessArgs(int, char **, Opt *);
69 #else
70 static void ProcessArgs();
71 #endif
72
73 static void
pProj(s,t)74 pProj( s, t )
75 char *s;
76 char *t;
77 {
78 project = t;
79 }
80
81 static void
pUL(s)82 pUL( s )
83 char *s;
84 {
85 user_lexer = 1;
86 }
87
88 static void
pCPP(s)89 pCPP( s )
90 char *s;
91 {
92 gen_CPP = 1;
93 }
94
95 static void
pUT(s,t)96 pUT( s, t )
97 char *s;
98 char *t;
99 {
100 user_token_types = t;
101 }
102
103 static void
pTrees(s)104 pTrees( s )
105 char *s;
106 {
107 gen_trees = 1;
108 }
109
110 static void
pHoist(s)111 pHoist( s )
112 char *s;
113 {
114 gen_hoist = 1;
115 }
116
117 static void
118 #ifdef __STDC__
pFile(char * s)119 pFile( char *s )
120 #else
121 pFile( s )
122 char *s;
123 #endif
124 {
125 if ( *s=='-' )
126 {
127 fprintf(stderr, "invalid option: '%s'; ignored...",s);
128 return;
129 }
130
131 require(num_files<MAX_FILES, "exceeded max # of input files");
132 files[num_files++] = s;
133 }
134
135 static void
136 #ifdef __STDC__
pClass(char * s,char * t)137 pClass( char *s, char *t )
138 #else
139 pClass( s, t )
140 char *s;
141 char *t;
142 #endif
143 {
144 require(num_classes<MAX_CLASSES, "exceeded max # of grammar classes");
145 classes[num_classes++] = t;
146 }
147
148 static void
149 #ifdef __STDC__
pDLGClass(char * s,char * t)150 pDLGClass( char *s, char *t )
151 #else
152 pDLGClass( s, t )
153 char *s;
154 char *t;
155 #endif
156 {
157 if ( !gen_CPP ) {
158 fprintf(stderr, "-dlg-class makes no sense without C++ mode; ignored...");
159 }
160 else dlg_class = t;
161 }
162
163 static void
164 #ifdef __STDC__
pOdir(char * s,char * t)165 pOdir( char *s, char *t )
166 #else
167 pOdir( s, t )
168 char *s;
169 char *t;
170 #endif
171 {
172 outdir = t;
173 }
174
175 static void
176 #ifdef __STDC__
pHdr(char * s,char * t)177 pHdr( char *s, char *t )
178 #else
179 pHdr( s, t )
180 char *s;
181 char *t;
182 #endif
183 {
184 hdr = t;
185 }
186
187 Opt options[] = {
188 { "-cc", 0, pCPP, "Generate C++ output"},
189 { "-class", 1, pClass, "Name of a grammar class defined in grammar (if C++)"},
190 { "-dlg-class", 1,pDLGClass,"Name of DLG lexer class (default=DLGLexer) (if C++)"},
191 { "-header", 1,pHdr, "Name of ANTLR standard header info (default=no file)"},
192 { "-o", 1, pOdir, "Directory where output files should go (default=\".\")"},
193 { "-project", 1, pProj, "Name of executable to create (default=t)"},
194 { "-token-types", 1, pUT, "Token types are in this file (don't use tokens.h)"},
195 { "-trees", 0, pTrees, "Generate ASTs"},
196 { "-user-lexer", 0, pUL, "Do not create a DLG-based scanner"},
197 { "-mrhoist",0,pHoist, "Maintenance release style hoisting"},
198 { "*", 0, pFile, "" }, /* anything else is a file */
199 { NULL, 0, NULL, NULL }
200 };
201
202 extern char *DIR();
203
main(argc,argv)204 main(argc, argv)
205 int argc;
206 char **argv;
207 {
208 if ( argc == 1 ) { help(); DIE; }
209 ProcessArgs(argc-1, &(argv[1]), options);
210
211 strcpy(ATOKENBUFFER_O, ATOKENBUFFER_C);
212 ATOKENBUFFER_O[strlen(ATOKENBUFFER_C)-strlen(CPP_FILE_SUFFIX)] = '\0';
213 strcat(ATOKENBUFFER_O, OBJ_FILE_SUFFIX);
214 strcpy(APARSER_O, APARSER_C);
215 APARSER_O[strlen(APARSER_O)-strlen(CPP_FILE_SUFFIX)] = '\0';
216 strcat(APARSER_O, OBJ_FILE_SUFFIX);
217
218 strcpy(ASTBASE_O, ASTBASE_C);
219 ASTBASE_O[strlen(ASTBASE_C)-strlen(CPP_FILE_SUFFIX)] = '\0';
220 strcat(ASTBASE_O, OBJ_FILE_SUFFIX);
221
222 strcpy(PCCTSAST_O, PCCTSAST_C);
223 PCCTSAST_O[strlen(PCCTSAST_C)-strlen(CPP_FILE_SUFFIX)] = '\0';
224 strcat(PCCTSAST_O, OBJ_FILE_SUFFIX);
225
226 strcpy(LIST_O, LIST_C);
227 LIST_O[strlen(LIST_C)-strlen(CPP_FILE_SUFFIX)] = '\0';
228 strcat(LIST_O, OBJ_FILE_SUFFIX);
229
230 strcpy(DLEXERBASE_O, DLEXERBASE_C);
231 DLEXERBASE_O[strlen(DLEXERBASE_C)-strlen(CPP_FILE_SUFFIX)] = '\0';
232 strcat(DLEXERBASE_O, OBJ_FILE_SUFFIX);
233
234 if ( num_files == 0 ) fatal("no grammar files specified; exiting...");
235 if ( !gen_CPP && num_classes>0 ) {
236 warn("can't define classes w/o C++ mode; turning on C++ mode...\n");
237 gen_CPP=1;
238 }
239 if ( gen_CPP && num_classes==0 ) {
240 fatal("must define classes >0 grammar classes in C++ mode\n");
241 }
242
243 mk(project, files, num_files, argc, argv);
244 DONE;
245 }
246
help()247 help()
248 {
249 Opt *p = options;
250 static char buf[1000+1];
251
252 fprintf(stderr, "genmk [options] f1.g ... fn.g\n");
253 while ( p->option!=NULL && *(p->option) != '*' )
254 {
255 buf[0]='\0';
256 if ( p->arg ) sprintf(buf, "%s ___", p->option);
257 else strcpy(buf, p->option);
258 fprintf(stderr, "\t%-16s %s\n", buf, p->descr);
259 p++;
260 }
261 }
262
mk(project,files,n,argc,argv)263 mk(project, files, n, argc, argv)
264 char *project;
265 char **files;
266 int n;
267 int argc;
268 char **argv;
269 {
270 int i;
271
272 printf("!\n");
273 printf("! PCCTS makefile for: ");
274 pfiles(files, n, NULL);
275 printf("\n");
276 printf("!\n");
277 printf("! Created from:");
278 for (i=0; i<argc; i++) printf(" %s", argv[i]);
279 printf("\n");
280 printf("!\n");
281 printf("! PCCTS release 1.33MR10\n");
282 printf("! Project: %s\n", project);
283 if ( gen_CPP ) printf("! C++ output\n");
284 else printf("! C output\n");
285 if ( user_lexer ) printf("! User-defined scanner\n");
286 else printf("! DLG scanner\n");
287 if ( user_token_types!=NULL ) printf("! User-defined token types in '%s'\n", user_token_types);
288 else printf("! ANTLR-defined token types\n");
289 printf("!\n");
290 if ( user_token_types!=NULL ) {
291 printf("! Make sure #tokdefs directive in ANTLR grammar lists this file:\n");
292 printf("TOKENS = %s", user_token_types);
293 }
294 else printf("TOKENS = %stokens.h", DIR());
295 printf("\n");
296 printf("!\n");
297 printf("! The following filenames must be consistent with ANTLR/DLG flags\n");
298 printf("DLG_FILE = %s%s\n", DIR(), dlg);
299 printf("ERR = %serr\n", DIR());
300 if ( strcmp(hdr,"stdpccts.h")!=0 ) printf("HDR_FILE = %s%s\n", DIR(), hdr);
301 else printf("HDR_FILE =\n");
302 if ( !gen_CPP ) printf("MOD_FILE = %s%s\n", DIR(), mode);
303 if ( !gen_CPP ) printf("SCAN = %s\n", scan);
304 else printf("SCAN = %s%s\n", DIR(), dlg_class);
305
306 printf("PCCTS = PCCTS_ROOT\n");
307 printf("ANTLR_H = $(PCCTS):[h]\n");
308 printf("BIN = $(PCCTS):[bin]\n");
309 printf("ANTLR = mcr $(BIN)antlr\n");
310 printf("DLG = mcr $(BIN)dlg\n");
311 printf("LNKFLAGS = /traceback\n");
312 if (gen_CPP)
313 printf("CFLAGS =/ASSUME=NOHEADER_TYPE_DEFAULT/define=(__STDC__)/include=($(ANTLR_H)");
314 else
315 printf("CFLAGS = /define=(__STDC__)/include=($(ANTLR_H)");
316 if ( strcmp(outdir, ".")!=0 ) printf(", %s", outdir);
317 printf(") $(COTHER)");
318 printf("\n");
319 printf("AFLAGS =");
320 if ( strcmp(outdir,".")!=0 ) printf(" -o %s", outdir);
321 if ( user_lexer ) printf(" -gx");
322 if ( gen_CPP ) printf(" -\"CC\"");
323 if ( strcmp(hdr,"stdpccts.h")!=0 ) printf(" -gh %s", hdr);
324 if ( gen_trees ) printf(" -gt");
325 if ( gen_hoist ) {
326 printf(" -mrhoist on") ;
327 } else {
328 printf(" -mrhoist off");
329 };
330 printf(" $(AOTHER)");
331 printf("\n");
332 printf("DFLAGS = -\"C2\" -i");
333 if ( gen_CPP ) printf(" -\"CC\"");
334 if ( strcmp(dlg_class,"DLGLexer")!=0 ) printf(" -cl %s", dlg_class);
335 if ( strcmp(outdir,".")!=0 ) printf(" -o %s", outdir);
336 printf(" $(DOTHER)");
337 printf("\n");
338 printf("GRM = ");
339 pfiles(files, n, NULL);
340 printf("\n");
341 printf("SRC = ");
342 if ( gen_CPP ) pfiles(files, n, CPP_FILE_SUFFIX_NO_DOT);
343 else pfiles(files, n, "c");
344 if ( gen_CPP ) {
345 printf(" ,-\n ");
346 printf(" ");
347 pclasses(classes, num_classes, CPP_FILE_SUFFIX_NO_DOT);
348 printf(" ,-\n ");
349 printf("$(ANTLR_H)%s", APARSER_C);
350 if ( !user_lexer ) printf(", $(ANTLR_H)%s", DLEXERBASE_C);
351 if ( gen_trees ) {
352 printf(" ,-\n ");
353 printf("$(ANTLR_H)%s,", ASTBASE_C);
354 printf(" $(ANTLR_H)%s", PCCTSAST_C);
355 /* printf(" $(ANTLR_H)%s%s", DirectorySymbol, LIST_C); */
356 }
357 printf(" ,-\n ");
358 printf(" $(ANTLR_H)%s", ATOKENBUFFER_C);
359 }
360 if ( !user_lexer ) {
361 if ( gen_CPP ) printf(", $(SCAN)%s", CPP_FILE_SUFFIX);
362 else printf(", %s$(SCAN).c", DIR());
363 }
364 if ( !gen_CPP ) printf(" $(ERR).c");
365 printf("\n");
366 printf("OBJ = ");
367 pfiles(files, n, "obj");
368 if ( gen_CPP ) {
369 printf(" ,-\n ");
370 printf(" ");
371 pclasses(classes, num_classes, "o");
372 printf(" ,-\n ");
373 printf(" %s%s", DIR(), APARSER_O);
374 if ( !user_lexer ) {
375 printf(", %s%s", DIR(), DLEXERBASE_O);
376 }
377 if ( gen_trees ) {
378 printf(" ,-\n ");
379 printf("%s%s", DIR(), ASTBASE_O);
380 printf(", %s%s", DIR(), PCCTSAST_O);
381 /* printf(" %s%s", DIR(), LIST_O); */
382 }
383 printf(", %s%s", DIR(), ATOKENBUFFER_O);
384 }
385 if ( !user_lexer ) {
386 if ( gen_CPP ) printf(", $(SCAN)%s", OBJ_FILE_SUFFIX);
387 else printf(", %s$(SCAN)%s", DIR(), OBJ_FILE_SUFFIX);
388 }
389 if ( !gen_CPP ) printf(", $(ERR)%s", OBJ_FILE_SUFFIX);
390 printf("\n");
391
392 printf("ANTLR_SPAWN = ");
393 if ( gen_CPP ) pfiles(files, n, CPP_FILE_SUFFIX_NO_DOT);
394 else pfiles(files, n, "c");
395 if ( gen_CPP ) {
396 printf(", ");
397 pclasses(classes, num_classes, CPP_FILE_SUFFIX_NO_DOT);
398 printf(" ,-\n ");
399 pclasses(classes, num_classes, "h");
400 if ( strcmp(hdr,"stdpccts.h")!=0 ) {
401 printf(" ,-\n ");
402 printf("$(HDR_FILE), stdpccts.h");
403 }
404 }
405 if ( user_lexer ) {
406 if ( !user_token_types ) printf(", $(TOKENS)");
407 }
408 else {
409 printf(", $(DLG_FILE)");
410 if ( !user_token_types ) printf(", $(TOKENS)");
411 }
412 if ( !gen_CPP ) printf(", $(ERR).c");
413 printf("\n");
414
415 if ( !user_lexer ) {
416 if ( gen_CPP ) printf("DLG_SPAWN = $(SCAN)%s", CPP_FILE_SUFFIX);
417 else printf("DLG_SPAWN = %s$(SCAN).c", DIR());
418 if ( gen_CPP ) printf(", $(SCAN).h");
419 else printf(", $(MOD_FILE)");
420 printf("\n");
421 }
422
423 printf("ANTLR_SPAWN_ALL_VERSIONS = ");
424 if ( gen_CPP ) pfiles(files, n, CPP_FILE_SUFFIX_NO_DOT);
425 else pfiles(files, n, "c");
426 if ( gen_CPP ) {
427 printf(";*, ");
428 pclasses(classes, num_classes, CPP_FILE_SUFFIX_NO_DOT);
429 printf(";* ,-\n ");
430 pclasses(classes, num_classes, "h");
431 printf(";*");
432 if ( strcmp(hdr,"stdpccts.h")!=0 ) {
433 printf(" ,-\n ");
434 printf("$(HDR_FILE);*, stdpccts.h;*");
435 }
436 }
437 if ( user_lexer ) {
438 if ( !user_token_types ) printf(", $(TOKENS);*");
439 }
440 else {
441 printf(", $(DLG_FILE);*");
442 if ( !user_token_types ) printf(", $(TOKENS);*");
443 }
444 if ( !gen_CPP ) printf(", $(ERR).c;*");
445 printf("\n");
446
447 if ( !user_lexer ) {
448 if ( gen_CPP ) printf("DLG_SPAWN_ALL_VERSIONS = $(SCAN)%s;*", CPP_FILE_SUFFIX);
449 else printf("DLG_SPAWN_ALL_VERSIONS = %s$(SCAN).c;*", DIR());
450 if ( gen_CPP ) printf(", $(SCAN).h;*");
451 else printf(", $(MOD_FILE);*");
452 printf("\n");
453 }
454
455 if ( gen_CPP ) {
456 printf("CCC=CXX\n");
457 printf("CC=$(CCC)\n");
458 }
459 else printf("CC=cc\n");
460
461 /* set up dependencies */
462 printf("\n%s.exe : $(OBJ), $(SRC)\n", project);
463 if (gen_CPP)
464 printf(" CXXLINK %s %s $(LNKFLAGS) $(OBJ)\n",
465 RENAME_EXE_FLAG,
466 project);
467 else
468 printf(" LINK %s %s $(LNKFLAGS) $(OBJ)\n",
469 RENAME_EXE_FLAG,
470 project);
471 printf("\n");
472
473 /* how to compile parser files */
474
475 for (i=0; i<num_files; i++)
476 {
477 pfiles(&files[i], 1, "obj");
478 if ( user_lexer ) {
479 printf(" : $(TOKENS)");
480 }
481 else {
482 if ( gen_CPP ) printf(" : $(TOKENS), $(SCAN).h");
483 else printf(" : $(MOD_FILE), $(TOKENS)");
484 }
485 printf(", ");
486 if ( gen_CPP ) pfiles(&files[i], 1, CPP_FILE_SUFFIX_NO_DOT);
487 else pfiles(&files[i], 1, "c");
488 if ( gen_CPP && strcmp(hdr,"stdpccts.h")!=0 ) printf(", $(HDR_FILE)");
489 printf("\n");
490 printf(" %s $(CFLAGS) %s ",gen_CPP?"$(CCC)":"$(CC)",RENAME_OBJ_FLAG);
491 pfiles(&files[i], 1, "obj");
492 printf(" ");
493 if ( gen_CPP ) pfiles(&files[i], 1, CPP_FILE_SUFFIX_NO_DOT);
494 else pfiles(&files[i], 1, "c");
495 printf("\n\n");
496 }
497
498 /* how to compile err.c */
499 if ( !gen_CPP ) {
500 printf("$(ERR)%s : $(ERR).c", OBJ_FILE_SUFFIX);
501 if ( !user_lexer ) printf(", $(TOKENS)");
502 printf("\n");
503 printf(" %s $(CFLAGS) %s $(ERR)%s $(ERR).c",
504 gen_CPP?"$(CCC)":"$(CC)",
505 RENAME_OBJ_FLAG,
506 OBJ_FILE_SUFFIX);
507 printf("\n\n");
508 }
509
510 /* how to compile Class.c */
511 for (i=0; i<num_classes; i++)
512 {
513 pclasses(&classes[i], 1, "obj");
514 if ( user_lexer ) {
515 printf(" : $(TOKENS)");
516 }
517 else {
518 printf(" : $(TOKENS), $(SCAN).h");
519 }
520 printf(", ");
521 pclasses(&classes[i], 1, CPP_FILE_SUFFIX_NO_DOT);
522 printf(", ");
523 pclasses(&classes[i], 1, "h");
524 if ( gen_CPP && strcmp(hdr,"stdpccts.h")!=0 ) printf(", $(HDR_FILE)");
525 printf("\n");
526 printf(" %s $(CFLAGS) %s ",
527 gen_CPP?"$(CCC)":"$(CC)",
528 RENAME_OBJ_FLAG);
529 pclasses(&classes[i], 1, "obj");
530 printf(" ");
531 pclasses(&classes[i], 1, CPP_FILE_SUFFIX_NO_DOT);
532 printf("\n\n");
533 }
534
535 /* how to compile scan.c */
536 if ( !user_lexer ) {
537 if ( gen_CPP ) printf("$(SCAN)%s : $(SCAN)%s", OBJ_FILE_SUFFIX, CPP_FILE_SUFFIX);
538 else printf("%s$(SCAN)%s : %s$(SCAN).c", DIR(), OBJ_FILE_SUFFIX, DIR());
539 if ( !user_lexer ) printf(", $(TOKENS)");
540 printf("\n");
541 if ( gen_CPP ) printf(" $(CCC) $(CFLAGS) %s $(SCAN)%s $(SCAN)%s",
542 RENAME_OBJ_FLAG,
543 OBJ_FILE_SUFFIX,
544 CPP_FILE_SUFFIX);
545 else printf(" $(CC) $(CFLAGS) %s %s$(SCAN)%s %s$(SCAN).c",
546 RENAME_OBJ_FLAG,
547 DIR(),
548 OBJ_FILE_SUFFIX,
549 DIR());
550 printf("\n\n");
551 }
552
553 printf("$(ANTLR_SPAWN) : $(GRM)\n");
554 printf(" $(ANTLR) $(AFLAGS) $(GRM)\n");
555
556 if ( !user_lexer )
557 {
558 printf("\n");
559 printf("$(DLG_SPAWN) : $(DLG_FILE)\n");
560 if ( gen_CPP ) printf(" $(DLG) $(DFLAGS) $(DLG_FILE)\n");
561 else printf(" $(DLG) $(DFLAGS) $(DLG_FILE) $(SCAN).c\n");
562 }
563
564 /* do the makes for ANTLR/DLG support */
565 if ( gen_CPP ) {
566 printf("\n");
567 printf("%s%s : $(ANTLR_H)%s\n", DIR(), APARSER_O, APARSER_C);
568 printf(" %s $(CFLAGS) %s ",
569 gen_CPP?"$(CCC)":"$(CC)",
570 RENAME_OBJ_FLAG);
571 printf("%s%s $(ANTLR_H)%s\n", DIR(), APARSER_O, APARSER_C);
572 printf("\n");
573 printf("%s%s : $(ANTLR_H)%s\n", DIR(), ATOKENBUFFER_O, ATOKENBUFFER_C);
574 printf(" %s $(CFLAGS) %s ",
575 gen_CPP?"$(CCC)":"$(CC)",
576 RENAME_OBJ_FLAG);
577 printf("%s%s $(ANTLR_H)%s\n", DIR(), ATOKENBUFFER_O, ATOKENBUFFER_C);
578 if ( !user_lexer ) {
579 printf("\n");
580 printf("%s%s : $(ANTLR_H)%s\n", DIR(), DLEXERBASE_O, DLEXERBASE_C);
581 printf(" %s $(CFLAGS) %s ",
582 gen_CPP?"$(CCC)":"$(CC)",
583 RENAME_OBJ_FLAG);
584 printf("%s%s $(ANTLR_H)%s\n", DIR(), DLEXERBASE_O, DLEXERBASE_C);
585 }
586 if ( gen_trees ) {
587 printf("\n");
588 printf("%s%s : $(ANTLR_H)%s\n", DIR(), ASTBASE_O, ASTBASE_C);
589 printf(" %s $(CFLAGS) %s ",
590 gen_CPP?"$(CCC)":"$(CC)",
591 RENAME_OBJ_FLAG);
592 printf("%s%s $(ANTLR_H)%s\n", DIR(), ASTBASE_O, ASTBASE_C);
593 printf("\n");
594 printf("%s%s : $(ANTLR_H)%s\n", DIR(), PCCTSAST_O, PCCTSAST_C);
595 printf(" %s $(CFLAGS) %s ",
596 gen_CPP?"$(CCC)":"$(CC)",
597 RENAME_OBJ_FLAG);
598 printf("%s%s $(ANTLR_H)%s\n", DIR(), PCCTSAST_O, PCCTSAST_C);
599 printf("\n");
600 /*
601 printf("%s%s : $(ANTLR_H)%s%s\n", DIR(), LIST_O, DirectorySymbol, LIST_C);
602 printf(" %s -c $(CFLAGS) %s ",
603 gen_CPP?"$(CCC)":"$(CC)",RENAME_OBJ_FLAG);
604 printf("%s%s $(ANTLR_H)%s%s\n", DIR(), LIST_O, DirectorySymbol, LIST_C);
605 */
606 }
607 }
608
609 /* clean and scrub targets */
610
611 printf("\nclean :\n");
612 printf(" delete *%s.*, %s.exe.*", OBJ_FILE_SUFFIX, project);
613 if ( strcmp(outdir, ".")!=0 ) printf(" %s*%s;*", DIR(), OBJ_FILE_SUFFIX);
614 printf("\n");
615
616 printf("\nscrub :\n");
617 printf(" delete *%s.*, %s.exe;*", OBJ_FILE_SUFFIX, project);
618 if ( strcmp(outdir, ".")!=0 ) printf(", %s*%s.*", DIR(), OBJ_FILE_SUFFIX);
619 printf(", $(ANTLR_SPAWN_ALL_VERSIONS)");
620 if ( !user_lexer ) printf(", $(DLG_SPAWN_ALL_VERSIONS)");
621 printf("\n");
622 }
623
pfiles(files,n,suffix)624 pfiles(files, n, suffix)
625 char **files;
626 int n;
627 char *suffix;
628 {
629 int first=1;
630
631 while ( n>0 )
632 {
633 char *p = &(*files)[strlen(*files)-1];
634 if ( !first ) putchar(' ');
635 first=0;
636 while ( p > *files && *p != '.' ) --p;
637 if ( p == *files )
638 {
639 fprintf(stderr,
640 "genmk: filenames must be file.suffix format: %s\n",
641 *files);
642 exit(-1);
643 }
644 if ( suffix == NULL ) printf("%s", *files);
645 else
646 {
647 *p = '\0';
648 printf("%s", DIR());
649 if ( strcmp(suffix, "o")==0 ) printf("%s%s", *files, OBJ_FILE_SUFFIX);
650 else printf("%s.%s", *files, suffix);
651 *p = '.';
652 }
653 files++;
654 --n;
655 }
656 }
657
pclasses(classes,n,suffix)658 pclasses(classes, n, suffix)
659 char **classes;
660 int n;
661 char *suffix;
662 {
663 int first=1;
664
665 while ( n>0 )
666 {
667 if ( !first ) putchar(' ');
668 first=0;
669 if ( suffix == NULL ) printf("%s", *classes);
670 else {
671 printf("%s", DIR());
672 if ( strcmp(suffix, "o")==0 ) printf("%s%s", *classes, OBJ_FILE_SUFFIX);
673 else printf("%s.%s", *classes, suffix);
674 }
675 classes++;
676 --n;
677 }
678 }
679
680 static void
681 #ifdef __STDC__
ProcessArgs(int argc,char ** argv,Opt * options)682 ProcessArgs( int argc, char **argv, Opt *options )
683 #else
684 ProcessArgs( argc, argv, options )
685 int argc;
686 char **argv;
687 Opt *options;
688 #endif
689 {
690 Opt *p;
691 require(argv!=NULL, "ProcessArgs: command line NULL");
692
693 while ( argc-- > 0 )
694 {
695 p = options;
696 while ( p->option != NULL )
697 {
698 if ( strcmp(p->option, "*") == 0 ||
699 strcmp(p->option, *argv) == 0 )
700 {
701 if ( p->arg )
702 {
703 (*p->process)( *argv, *(argv+1) );
704 argv++;
705 argc--;
706 }
707 else
708 (*p->process)( *argv );
709 break;
710 }
711 p++;
712 }
713 argv++;
714 }
715 }
716
fatal(err_)717 fatal( err_)
718 char *err_;
719 {
720 fprintf(stderr, "genmk: %s\n", err_);
721 exit(1);
722 }
723
warn(err_)724 warn( err_)
725 char *err_;
726 {
727 fprintf(stderr, "genmk: %s\n", err_);
728 }
729
DIR()730 char *DIR()
731 {
732 static char buf[200+1];
733
734 if ( strcmp(outdir,TopDirectory)==0 ) return "";
735 sprintf(buf, "%s", outdir);
736 return buf;
737 }
738