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

Diff of /make/file.c

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

revision 1.76 by psmith, Mon Feb 28 07:48:22 2005 UTC revision 1.77 by bosk, Tue Mar 15 15:31:47 2005 UTC
# Line 414  set_intermediate (const void *item) Line 414  set_intermediate (const void *item)
414    f->intermediate = 1;    f->intermediate = 1;
415  }  }
416    
417    /* Expand and parse each dependency line. */
418    static void
419    expand_deps (struct file *f)
420    {
421      register struct dep *d, *d1;
422      struct dep *new = 0;
423      struct dep *old = f->deps;
424      unsigned int last_dep_has_cmds = f->updating;
425    
426      f->updating = 0;
427      f->deps = 0;
428    
429      /* We are going to do second expansion so initialize file
430         variables for the file. */
431      initialize_file_variables (f, 0);
432    
433      for (d = old; d != 0; d = d->next)
434        {
435          if (d->name != 0)
436            {
437              char *p;
438              struct dep **d_ptr;
439    
440              set_file_variables (f);
441    
442              p = variable_expand_for_file (d->name, f);
443    
444              /* Parse the dependencies.  */
445              new = (struct dep *)
446                multi_glob (
447                  parse_file_seq (&p, '|', sizeof (struct dep), 1),
448                  sizeof (struct dep));
449    
450              if (*p)
451                {
452                  /* Files that follow '|' are special prerequisites that
453                     need only exist in order to satisfy the dependency.
454                     Their modification times are irrelevant.  */
455    
456                  struct dep *d;
457                  for (d_ptr = &new; *d_ptr; d_ptr = &(*d_ptr)->next)
458                    ;
459                  ++p;
460    
461                  *d_ptr = (struct dep *)
462                    multi_glob (
463                      parse_file_seq (&p, '\0', sizeof (struct dep), 1),
464                      sizeof (struct dep));
465    
466                  for (d = *d_ptr; d != 0; d = d->next)
467                    d->ignore_mtime = 1;
468                }
469    
470              /* Enter them as files. */
471              for (d1 = new; d1 != 0; d1 = d1->next)
472                {
473                  d1->file = lookup_file (d1->name);
474                  if (d1->file == 0)
475                    d1->file = enter_file (d1->name);
476                  else
477                    free (d1->name);
478                  d1->name = 0;
479                }
480    
481              /* Add newly parsed deps to f->deps. If this is the last
482                 dependency line and this target has commands then put
483                 it in front so the last dependency line (the one with
484                 commands) ends up being the first. This is important
485                 because people expect $< to hold first prerequisite
486                 from the rule with commands. If it is not the last
487                 dependency line or the rule does not have commands
488                 then link it at the end so it appears in makefile
489                 order.  */
490    
491              if (new != 0)
492                {
493                  if (d->next == 0 && last_dep_has_cmds)
494                    {
495                      for (d_ptr = &new; *d_ptr; d_ptr = &(*d_ptr)->next)
496                            ;
497    
498                      *d_ptr = f->deps;
499                      f->deps = new;
500                    }
501                  else
502                    {
503                      for (d_ptr = &(f->deps); *d_ptr; d_ptr = &(*d_ptr)->next)
504                        ;
505    
506                      *d_ptr = new;
507                    }
508                }
509            }
510        }
511    
512      free_ns_chain ((struct nameseq*)old);
513    }
514    
515  /* For each dependency of each file, make the `struct dep' point  /* For each dependency of each file, make the `struct dep' point
516     at the appropriate `struct file' (which may have to be created).     at the appropriate `struct file' (which may have to be created).
517    
# Line 425  snap_deps (void) Line 523  snap_deps (void)
523  {  {
524    register struct file *f;    register struct file *f;
525    register struct file *f2;    register struct file *f2;
526    register struct dep *d, *d1;    register struct dep *d;
527    register struct file **file_slot_0;    register struct file **file_slot_0;
528    register struct file **file_slot;    register struct file **file_slot;
529    register struct file **file_end;    register struct file **file_end;
# Line 433  snap_deps (void) Line 531  snap_deps (void)
531    /* Perform second expansion and enter each dependency    /* Perform second expansion and enter each dependency
532       name as a file. */       name as a file. */
533    
534      /* Expand .SUFFIXES first; it's dependencies are used for
535         $$* calculation. */
536      for (f = lookup_file (".SUFFIXES"); f != 0; f = f->prev)
537        expand_deps (f);
538    
539    /* We must use hash_dump (), because within this loop    /* We must use hash_dump (), because within this loop
540       we might add new files to the table, possibly causing       we might add new files to the table, possibly causing
541       an in-situ table expansion.  */       an in-situ table expansion.  */
542    file_slot_0 = (struct file **) hash_dump (&files, 0, 0);    file_slot_0 = (struct file **) hash_dump (&files, 0, 0);
543    file_end = file_slot_0 + files.ht_fill;    file_end = file_slot_0 + files.ht_fill;
544    for (file_slot = file_slot_0; file_slot < file_end; file_slot++)    for (file_slot = file_slot_0; file_slot < file_end; file_slot++)
545      for (f2 = *file_slot; f2 != 0; f2 = f2->prev)      for (f = *file_slot; f != 0; f = f->prev)
546        {        {
547          struct dep *new = 0;          if (strcmp (f->name, ".SUFFIXES") != 0)
548          struct dep *old = f2->deps;            expand_deps (f);
         unsigned int last_dep_has_cmds = f2->updating;  
   
         f2->updating = 0;  
         f2->deps = 0;  
   
         /* We are going to do second expansion so initialize file  
            variables for the file. */  
         initialize_file_variables (f2, 0);  
   
         for (d = old; d != 0; d = d->next)  
           {  
             if (d->name != 0)  
               {  
                 char *p;  
                 struct dep **d_ptr;  
   
                 set_file_variables (f2);  
   
                 p = variable_expand_for_file (d->name, f2);  
   
                 /* Parse the dependencies.  */  
                 new = (struct dep *)  
                   multi_glob (  
                     parse_file_seq (&p, '|', sizeof (struct dep), 1),  
                     sizeof (struct dep));  
   
                 if (*p)  
                   {  
                     /* Files that follow '|' are special prerequisites that  
                        need only exist in order to satisfy the dependency.  
                        Their modification times are irrelevant.  */  
   
                     struct dep *d;  
                     for (d_ptr = &new; *d_ptr; d_ptr = &(*d_ptr)->next)  
                       ;  
                     ++p;  
   
                     *d_ptr = (struct dep *)  
                       multi_glob (  
                         parse_file_seq (&p, '\0', sizeof (struct dep), 1),  
                         sizeof (struct dep));  
   
                     for (d = *d_ptr; d != 0; d = d->next)  
                       d->ignore_mtime = 1;  
                   }  
   
                 /* Enter them as files. */  
                 for (d1 = new; d1 != 0; d1 = d1->next)  
                   {  
                     d1->file = lookup_file (d1->name);  
                     if (d1->file == 0)  
                       d1->file = enter_file (d1->name);  
                     else  
                       free (d1->name);  
                     d1->name = 0;  
                   }  
   
                 /* Add newly parsed deps to f2->deps. If this is the last  
                    dependency line and this target has commands then put  
                    it in front so the last dependency line (the one with  
                    commands) ends up being the first. This is important  
                    because people expect $< to hold first prerequisite  
                    from the rule with commands. If it is not the last  
                    dependency line or the rule does not have commands  
                    then link it at the end so it appears in makefile  
                    order.  */  
   
                 if (new != 0)  
                   {  
                     if (d->next == 0 && last_dep_has_cmds)  
                     {  
                       for (d_ptr = &new; *d_ptr; d_ptr = &(*d_ptr)->next)  
                         ;  
   
                       *d_ptr = f2->deps;  
                       f2->deps = new;  
                     }  
                     else  
                     {  
                       for (d_ptr = &(f2->deps); *d_ptr; d_ptr = &(*d_ptr)->next)  
                         ;  
   
                       *d_ptr = new;  
                     }  
                   }  
               }  
           }  
   
         free_ns_chain ((struct nameseq*)old);  
549        }        }
550    free (file_slot_0);    free (file_slot_0);
551    

Legend:
Removed from v.1.76  
changed lines
  Added in v.1.77

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