home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / rmake.cc < prev   
Encoding:
C/C++ Source or Header  |  1995-12-23  |  1.6 KB  |  85 lines

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <glob.h>
  6. #include <process.h>
  7. #include <unistd.h>
  8.  
  9. int
  10. main(int argc, char **argv)
  11. {
  12.   int i;
  13.   char cwd[200];
  14.   char path[200], *pathp;
  15.   char file[200];
  16.   FILE *oi = fopen("makefile.oi", "w");
  17.   FILE *rf = fopen("makefile.rf2", "w");
  18.  
  19.   getcwd(cwd, 200);
  20.  
  21.   argv[0] = "make";
  22.  
  23.   glob_t makefile_list;
  24.   glob(".../makefile", 0, 0, &makefile_list);
  25.  
  26.   for (i = 0; i<makefile_list.gl_pathc; i++)
  27.   {
  28.     char *mf = makefile_list.gl_pathv[i];
  29.     strcpy(path, mf);
  30.     char *lsl = strrchr(path, '/');
  31.     if (lsl) *lsl = 0;
  32.  
  33.     if (strcmp(mf, "makefile") == 0)
  34.       continue;
  35.  
  36.     printf("--------------------------------------- Making in %s\n", path);
  37.  
  38.     sprintf(file, "%s/%s", cwd, path);
  39.     if (chdir(file))
  40.     {
  41.       printf("Cannot chdir to %s\n", file);
  42.       continue;
  43.     }
  44.     if (spawnvp(P_WAIT, "make", argv))
  45.       exit(1);
  46.  
  47.     FILE *oh = fopen("makefile.oh", "r");
  48.     if (oh)
  49.     {
  50.       int last_was_nl = 1;
  51.       int ch;
  52.  
  53.       while ((ch = fgetc(oh)) != EOF)
  54.       {
  55.     if (ch != '\n' && last_was_nl)
  56.       fprintf(oi, "OBJS += ");
  57.     last_was_nl = (ch == '\n');
  58.     if (ch == '&')
  59.     {
  60.       fprintf(oi, "%s", path);
  61.       fprintf(rf, "%s", path);
  62.     }
  63.     else
  64.     {
  65.       fputc(ch, oi);
  66.       fputc(ch, rf);
  67.     }
  68.       }
  69.       fclose(oh);
  70.     }
  71.   }
  72.   fclose(rf);
  73.   fclose(oi);
  74.  
  75.   chdir(cwd);
  76.  
  77.   spawnlp(P_WAIT, "update", "update", "makefile.rf2", "makefile.rf", 0);
  78.   remove("makefile.rf2");
  79.  
  80.   if (spawnvp(P_WAIT, "make", argv))
  81.     exit(1);
  82.  
  83.   return 0;
  84. }
  85.