home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pccts1.zip / SUPPORT / GENMK.C
C/C++ Source or Header  |  1993-09-01  |  3KB  |  122 lines

  1. /*
  2.  * genmk -- a program to make makefiles for PCCTS
  3.  *
  4.  * genmk project f1.g f2.g f3.g ...
  5.  *
  6.  * where fi.g are the grammar files you want a makefile for
  7.  *
  8.  * ANTLR 1.10
  9.  * Terence John Parr 1989 - 1993
  10.  * Purdue University
  11.  */
  12. #include <stdio.h>
  13.  
  14. char *dlg = "parser.dlg";
  15. char *err = "err.c";
  16. char *hdr = "stdpccts.h";
  17. char *tok = "tokens.h";
  18. char *mode = "mode.h";
  19.  
  20. main(argc, argv)
  21. int argc;
  22. char **argv;
  23. {
  24.     char *project;
  25.     char **files;
  26.  
  27.     if ( argc < 3 )
  28.     {
  29.         fprintf(stderr, "genmk: genmk project f1.g f2.g f3.g ...\n");
  30.         exit(-1);
  31.     }
  32.     project = argv[1];
  33.     files = &argv[2];
  34.     mk(project, files, argc-2);
  35.     return 0;
  36. }
  37.  
  38. mk(project, files, n)
  39. char *project;
  40. char **files;
  41. int n;
  42. {
  43.     printf("#\n");
  44.     printf("# PCCTS makefile for: ");
  45.     pfiles(files, n, NULL);
  46.     printf("\n");
  47.     printf("# PCCTS release 1.10\n");
  48.     printf("#\n");
  49.     printf("DLG_FILE = %s\n", dlg);
  50.     printf("ERR_FILE = %s\n", err);
  51.     printf("HDR_FILE = %s\n", hdr);
  52.     printf("TOK_FILE = %s\n", tok);
  53.     printf("MOD_FILE = %s\n", mode);
  54.     printf("K = 1\n");
  55.     printf("ANTLR_H = .\n");
  56.     printf("BIN = .\n");
  57.     printf("ANTLR = $(BIN)/antlr\n");
  58.     printf("DLG = $(BIN)/dlg\n");
  59.     printf("CFLAGS = -I. -I$(ANTLR_H)\n");
  60.     printf("AFLAGS = -fe $(ERR_FILE) -fh $(HDR_FILE) -fl $(DLG_FILE) -ft $(TOK_FILE) \\\n         -fm $(MOD_FILE) -k $(K) -gk\n");
  61.     printf("DFLAGS = -C2 -i\n");
  62.     printf("GRM = ");
  63.     pfiles(files, n, NULL);
  64.     printf("\n");
  65.     printf("SRC = ");
  66.     pfiles(files, n, "c");
  67.     printf(" scan.c err.c\n");
  68.     printf("OBJ = ");
  69.     pfiles(files, n, "o");
  70.     printf(" scan.o err.o\n");
  71.     printf("\n%s: $(OBJ) $(SRC)\n", project);
  72.     printf("    cc -o %s $(CFLAGS) $(OBJ)\n", project);
  73.     printf("\n");
  74.     pfiles(files, n, "o");
  75.     printf(" : $(MOD_FILE) $(TOK_FILE) ");
  76.     pfiles(files, n, "c");
  77.     printf("\n\n");
  78.     pfiles(files, n, "c");
  79.     printf(" %s tokens.h : ", dlg);
  80.     pfiles(files, n, NULL);
  81.     printf("\n");
  82.     printf("    $(ANTLR) $(AFLAGS) ");
  83.     pfiles(files, n, NULL);
  84.     printf("\n");
  85.     printf("\n");
  86.     printf("scan.c mode.h : %s\n", dlg);
  87.     printf("    $(DLG) $(DFLAGS) %s scan.c\n", dlg);
  88.     printf("\n");
  89. }
  90.  
  91. pfiles(files, n, suffix)
  92. char **files;
  93. int n;
  94. char *suffix;
  95. {
  96.     int first=1;
  97.  
  98.     while ( n>0 )
  99.     {
  100.         char *p = &(*files)[strlen(*files)-1];
  101.         if ( !first ) putchar(' ');
  102.         first=0;
  103.         while ( p > *files && *p != '.' ) --p;
  104.         if ( p == *files )
  105.         {
  106.             fprintf(stderr,
  107.                     "genmk: filenames must be file.suffix format: %s\n",
  108.                     *files);
  109.             exit(-1);
  110.         }
  111.         if ( suffix == NULL ) printf("%s", *files);
  112.         else
  113.         {
  114.             *p = '\0';
  115.             printf("%s.%s", *files, suffix);
  116.             *p = '.';
  117.         }
  118.         files++;
  119.         --n;
  120.     }
  121. }
  122.