/[make]/make/file.c
ViewVC logotype

Diff of /make/file.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.78 by psmith, Wed Apr 13 03:16:33 2005 UTC revision 1.79 by psmith, Mon Oct 24 13:01:39 2005 UTC
# Line 405  remove_intermediates (int sig) Line 405  remove_intermediates (int sig)
405      }      }
406  }  }
407    
408    struct dep *
409    parse_prereqs (char *p)
410    {
411      struct dep *new = (struct dep *)
412        multi_glob (parse_file_seq (&p, '|', sizeof (struct dep), 1),
413                    sizeof (struct dep));
414    
415      if (*p)
416        {
417          /* Files that follow '|' are "order-only" prerequisites that satisfy the
418             dependency by existing: their modification times are irrelevant.  */
419          struct dep *ood;
420    
421          ++p;
422          ood = (struct dep *)
423            multi_glob (parse_file_seq (&p, '\0', sizeof (struct dep), 1),
424                        sizeof (struct dep));
425    
426          if (! new)
427            new = ood;
428          else
429            {
430              struct dep *dp;
431              for (dp = new; dp->next != NULL; dp = dp->next)
432                ;
433              dp->next = ood;
434            }
435    
436          for (; ood != NULL; ood = ood->next)
437            ood->ignore_mtime = 1;
438        }
439    
440      return new;
441    }
442    
443    
444  /* Set the intermediate flag.  */  /* Set the intermediate flag.  */
445    
446  static void  static void
# Line 418  set_intermediate (const void *item) Line 454  set_intermediate (const void *item)
454  static void  static void
455  expand_deps (struct file *f)  expand_deps (struct file *f)
456  {  {
457    struct dep *d, *d1;    struct dep *d;
   struct dep *new = 0;  
458    struct dep *old = f->deps;    struct dep *old = f->deps;
459    unsigned int last_dep_has_cmds = f->updating;    unsigned int last_dep_has_cmds = f->updating;
460    int initialized = 0;    int initialized = 0;
# Line 429  expand_deps (struct file *f) Line 464  expand_deps (struct file *f)
464    
465    for (d = old; d != 0; d = d->next)    for (d = old; d != 0; d = d->next)
466      {      {
467        if (d->name != 0)        struct dep *new, *d1;
468          {        char *p;
           char *p;  
469    
470            /* If we need a second expansion on these, set up the file        if (! d->name)
471               variables, etc.  It takes a lot of extra memory and processing          continue;
472               to do this, so only do it if it's needed.  */  
473            if (! d->need_2nd_expansion)        /* Create the dependency list.
474              p = d->name;           If we're not doing 2nd expansion, then it's just the name.  */
475            else        if (! d->need_2nd_expansion)
476            p = d->name;
477          else
478            {
479              /* If it's from a static pattern rule, convert the patterns into
480                 "$*" so they'll expand properly.  */
481              if (d->staticpattern)
482              {              {
483                /* We are going to do second expansion so initialize file                char *o;
484                   variables for the file. */                char *buffer = variable_expand ("");
               if (!initialized)  
                 {  
                   initialize_file_variables (f, 0);  
                   initialized = 1;  
                 }  
485    
486                set_file_variables (f);                o = subst_expand (buffer, d->name, "%", "$*", 1, 2, 0);
487    
488                p = variable_expand_for_file (d->name, f);                free (d->name);
489                  d->name = savestring (buffer, o - buffer);
490                  d->staticpattern = 0;
491              }              }
492    
493            /* Parse the dependencies.  */            /* We are going to do second expansion so initialize file variables
494            new = (struct dep *)               for the file. */
495              multi_glob (            if (!initialized)
               parse_file_seq (&p, '|', sizeof (struct dep), 1),  
               sizeof (struct dep));  
   
           if (*p)  
496              {              {
497                /* Files that follow '|' are special prerequisites that                initialize_file_variables (f, 0);
498                   need only exist in order to satisfy the dependency.                initialized = 1;
499                   Their modification times are irrelevant.  */              }
               struct dep **d_ptr;  
500    
501                for (d_ptr = &new; *d_ptr; d_ptr = &(*d_ptr)->next)            set_file_variables (f);
502                  ;  
503                ++p;            p = variable_expand_for_file (d->name, f);
504            }
505    
506                *d_ptr = (struct dep *)        /* Parse the prerequisites.  */
507                  multi_glob (        new = parse_prereqs (p);
                   parse_file_seq (&p, '\0', sizeof (struct dep), 1),  
                   sizeof (struct dep));  
508    
509                for (d1 = *d_ptr; d1 != 0; d1 = d1->next)        /* If this dep list was from a static pattern rule, expand the %s.  We
510                  d1->ignore_mtime = 1;           use patsubst_expand to translate the prerequisites' patterns into
511              }           plain prerequisite names.  */
512          if (new && d->staticpattern)
513            {
514              char *pattern = "%";
515              char *buffer = variable_expand ("");
516              struct dep *dp = new, *dl = 0;
517    
518            /* Enter them as files. */            while (dp != 0)
           for (d1 = new; d1 != 0; d1 = d1->next)  
519              {              {
520                d1->file = lookup_file (d1->name);                char *percent = find_percent (dp->name);
521                if (d1->file == 0)                if (percent)
522                  d1->file = enter_file (d1->name);                  {
523                else                    /* We have to handle empty stems specially, because that
524                  free (d1->name);                       would be equivalent to $(patsubst %,dp->name,) which
525                d1->name = 0;                       will always be empty.  */
526                d1->need_2nd_expansion = 0;                    if (f->stem[0] == '\0')
527                        /* This needs memmove() in ISO C.  */
528                        bcopy (percent+1, percent, strlen (percent));
529                      else
530                        {
531                          char *o = patsubst_expand (buffer, f->stem, pattern,
532                                                     dp->name, pattern+1,
533                                                     percent+1);
534                          if (o == buffer)
535                            dp->name[0] = '\0';
536                          else
537                            {
538                              free (dp->name);
539                              dp->name = savestring (buffer, o - buffer);
540                            }
541                        }
542    
543                      /* If the name expanded to the empty string, ignore it.  */
544                      if (dp->name[0] == '\0')
545                        {
546                          struct dep *df = dp;
547                          if (dp == new)
548                            dp = new = new->next;
549                          else
550                            dp = dl->next = dp->next;
551                          free ((char *)df);
552                          continue;
553                        }
554                    }
555                  dl = dp;
556                  dp = dp->next;
557              }              }
558            }
559    
560            /* Add newly parsed deps to f->deps. If this is the last        /* Enter them as files. */
561               dependency line and this target has commands then put        for (d1 = new; d1 != 0; d1 = d1->next)
562               it in front so the last dependency line (the one with          {
563               commands) ends up being the first. This is important            d1->file = lookup_file (d1->name);
564               because people expect $< to hold first prerequisite            if (d1->file == 0)
565               from the rule with commands. If it is not the last              d1->file = enter_file (d1->name);
566               dependency line or the rule does not have commands            else
567               then link it at the end so it appears in makefile              free (d1->name);
568               order.  */            d1->name = 0;
569              d1->staticpattern = 0;
570              d1->need_2nd_expansion = 0;
571            }
572    
573            if (new != 0)        /* Add newly parsed deps to f->deps. If this is the last dependency
574             line and this target has commands then put it in front so the
575             last dependency line (the one with commands) ends up being the
576             first. This is important because people expect $< to hold first
577             prerequisite from the rule with commands. If it is not the last
578             dependency line or the rule does not have commands then link it
579             at the end so it appears in makefile order.  */
580    
581          if (new != 0)
582            {
583              if (d->next == 0 && last_dep_has_cmds)
584              {              {
585                if (d->next == 0 && last_dep_has_cmds)                struct dep **d_ptr;
586                  {                for (d_ptr = &new; *d_ptr; d_ptr = &(*d_ptr)->next)
587                    struct dep **d_ptr;                  ;
                   for (d_ptr = &new; *d_ptr; d_ptr = &(*d_ptr)->next)  
                     ;  
588    
589                    *d_ptr = f->deps;                *d_ptr = f->deps;
590                    f->deps = new;                f->deps = new;
591                  }              }
592                else            else
593                  {              {
594                    struct dep **d_ptr;                struct dep **d_ptr;
595                    for (d_ptr = &f->deps; *d_ptr; d_ptr = &(*d_ptr)->next)                for (d_ptr = &f->deps; *d_ptr; d_ptr = &(*d_ptr)->next)
596                      ;                  ;
597    
598                    *d_ptr = new;                *d_ptr = new;
                 }  
599              }              }
600          }          }
601      }      }

Legend:
Removed from v.1.78  
changed lines
  Added in v.1.79

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26