home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / make_1 / !make_c_Make < prev    next >
Encoding:
Text File  |  1992-12-07  |  4.8 KB  |  261 lines

  1. /* > C.Make
  2.  * Do the actual making for make
  3.  */
  4.  
  5. #include "h.h"
  6.  
  7.  
  8. /*
  9.  * Exec a shell that returns exit status correctly (/bin/esh).
  10.  * The standard EON shell returns the process number of the last
  11.  * async command, used by the debugger (ugg).
  12.  * [exec on eon is like a fork+exec on unix]
  13.  * As this is a 'single tasking' OS , I put it into a file which
  14.  * is EXEC'd MDJ
  15.  * RISC OS specific on how to get the ignore  .... 07-11-90 
  16.  
  17.  */
  18. int
  19. dosh(char *string,bool ignore)
  20. {
  21.   char ss[LZ];
  22.   strcpy(ss,string);
  23.   convertLine(ss); 
  24.   if (ignore)
  25.     fprintf(outfile,"%s\n",ss);
  26.   else
  27.     fprintf(outfile,"IF Sys$ReturnCode=0 THEN %s\n",ss);
  28.   return 0;
  29. }
  30.  
  31.  
  32.  
  33. /*
  34.  * Do commands to make a target
  35.  */
  36. void
  37. docmds1(struct name *np, struct line *lp)
  38.  
  39. {
  40.    bool     ssilent;
  41.    bool     signore;
  42.    register char *    q;
  43.    register char *    p;
  44.    register struct cmd *   cp;
  45.  
  46.  
  47.  
  48.    for (cp =(lp->l_cmd); cp!=NULL ; cp = (cp->c_next))
  49.    {
  50.  
  51.       strcpy(str1, cp->c_cmd);
  52. /*
  53.       printf("To do: %s\n",cp->c_cmd);
  54. */
  55.       expand(str1);
  56. /*
  57.       printf("Exp. : %s\n",str1);
  58. */
  59.       q = str1;
  60.       ssilent = silent;
  61.       signore = ignore;
  62.       while ((*q == '@') || (*q == '-'))
  63.       {
  64.     if (*q == '@')     /*  Specific silent  */
  65.        ssilent = TRUE;
  66.     else     /*  Specific ignore  */
  67.        signore = TRUE;
  68.     q++;     /*  Not part of the command  */
  69.       }
  70.  
  71.       if (!domake)
  72.     ssilent = 0;
  73.  
  74.       if (!ssilent)
  75.     fputs("Need to do: ", stdout);
  76.  
  77.       for (p=q; *p; p++)
  78.       {
  79.     if (*p == '\n' && p[1] != '\0')
  80.     {
  81.        *p = ' ';
  82.        if (!ssilent)
  83.           fputs("\\\n", stdout);
  84.     }
  85.     else if (!ssilent)
  86.        putchar(*p);
  87.       }
  88.       if (!ssilent)
  89.     putchar('\n');
  90.  
  91.       if (domake)
  92.       {        /*  Get the shell to execute it  */
  93.       dosh(q,signore );
  94.       }
  95.    }
  96. }
  97.  
  98. void
  99. docmds(struct name *np)
  100. {
  101.    register struct line *  lp;
  102.  
  103.  
  104.    for (lp = np->n_line; lp; lp = lp->l_next)
  105.       docmds1(np, lp);
  106. }
  107.  
  108.  
  109.  
  110. /*
  111.  * Get the modification time of a file.  If the first
  112.  * doesn't exist, it's modtime is set to 0.
  113.  */
  114. void
  115. modtime(struct name * np)
  116. {
  117.    int      mtime,stat;
  118.    mtime = getstamp(np->n_name,&stat);
  119.    if (stat != IS_FILE)
  120.      np->n_time = 0L;
  121.    else
  122.      np->n_time = mtime;
  123. }
  124.  
  125.  
  126. /*
  127.  * Update the mod time of a file to now.
  128.  */
  129. void
  130. touch(struct name *np)
  131. {
  132.  
  133.    if (!domake || !silent)
  134.       printf("    touch(%s)\n", np->n_name);
  135.  
  136.    if (domake)
  137.    {
  138.       stamp(np->n_name);
  139.    }
  140. }
  141.  
  142. void 
  143. make1(struct name *np, struct line * lp,struct depend * qdp);
  144.  
  145. /*
  146.  * Recursive routine to make a target.
  147.  */
  148. int
  149. make(struct name *np, int level)
  150.  
  151. {
  152.    register struct depend *   dp;
  153.    register struct line *     lp;
  154.    register struct depend *   qdp;
  155.  
  156.    time_t      dtime;
  157.    bool        didsomething;
  158.    didsomething = 0;
  159.    dtime = 1;
  160.  
  161. #ifdef debug
  162.    printf ("Make : %s\n",np->n_name);
  163. #endif
  164.  
  165.    if (np->n_flag & N_DONE)
  166.       return 0;
  167.  
  168.    if (!np->n_time)
  169.       /* finding out about  this file */
  170.       {
  171.       modtime(np);  /*  Gets modtime of this file  */
  172. /*
  173.       printf("when was %s  (%d)\n",np->n_name, np->n_time);
  174. */
  175.       }
  176.    if (rules)
  177.    {
  178.       for (lp = np->n_line; lp; lp = lp->l_next)
  179.     if (lp->l_cmd)
  180.        break;
  181.       if (!lp)
  182.     if (dyndep(np));
  183.    }
  184.  
  185.    if (!(np->n_flag & N_TARG) && np->n_time == 0L)
  186.       fatal("Don't know how to make %s", np->n_name);
  187.  
  188.    for (qdp = (struct depend *)0, lp = np->n_line; lp; lp = lp->l_next)
  189.      {
  190.      for (dp = lp->l_dep; dp; dp = dp->d_next)
  191.        {
  192. /*
  193.        printf("Look at %s\n",dp->d_name->n_name);
  194. */    
  195.        make(dp->d_name, level+1);
  196.        if (np->n_time < dp->d_name->n_time)
  197.          qdp = newdep(dp->d_name, qdp);
  198.        dtime = max(dtime, dp->d_name->n_time);
  199.        }
  200.        if (!quest && (np->n_flag & N_DOUBLE) && (np->n_time < dtime))
  201.          {
  202.          make1(np, lp, qdp);     /* free()'s qdp */
  203.          dtime = 1;
  204.          qdp = (struct depend *)0;
  205.          didsomething++;
  206.          }
  207.        }
  208.  
  209.    np->n_flag |= N_DONE;
  210.  
  211.    if (quest)
  212.      {
  213.      long  t;
  214.  
  215.      t = np->n_time;
  216.      time(&np->n_time);
  217.      return t < dtime;
  218.      }
  219.    else if (np->n_time < dtime && !(np->n_flag & N_DOUBLE))
  220.      {
  221.      make1(np, (struct line *)0, qdp);  /* free()'s qdp */
  222.      time(&np->n_time);
  223.      }
  224.    else if (level == 0 && !didsomething)
  225.      printf("%s: '%s' is up to date\n", myname, np->n_name);
  226.    return 0;
  227. }
  228.  
  229. void
  230. make1(struct name *np, struct line * lp,struct depend * qdp)
  231. {
  232.    register struct depend *   dp;
  233.  
  234.  
  235.    if (dotouch)
  236.       touch(np);
  237.    else
  238.      {
  239.      strcpy(str1, "");
  240.      for (dp = qdp; dp; dp = qdp)
  241.        {
  242.        if (strlen(str1))
  243.          strcat(str1, " ");
  244.        strcat(str1, dp->d_name->n_name);
  245.        qdp = dp->d_next;
  246.        free(dp);
  247.        }
  248.      setmacro("?", str1);
  249.      setmacro("@", np->n_name);
  250.  
  251. /*
  252.      printf("Set $(@) to %s\n",np->n_name);
  253. */
  254.      if (lp)    /* lp set if doing a :: rule */
  255.        docmds1(np, lp);
  256.      else
  257.        docmds(np);
  258.      }
  259. }
  260.  
  261.