VirtualBox

Changeset 287 in kBuild for trunk/src/gmake/file.c


Ignore:
Timestamp:
May 16, 2005 11:34:55 PM (20 years ago)
Author:
bird
Message:

join + optimizations.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gmake/file.c

    r218 r287  
    3131#include "hash.h"
    3232
     33
     34/* Remember whether snap_deps has been invoked: we need this to be sure we
     35   don't add new rules (via $(eval ...)) afterwards.  In the future it would
     36   be nice to support this, but it means we'd need to re-run snap_deps() or
     37   at least its functionality... it might mean changing snap_deps() to be run
     38   per-file, so we can invoke it after the eval... or remembering which files
     39   in the hash have been snapped (a new boolean flag?) and having snap_deps()
     40   only work on files which have not yet been snapped. */
     41int snapped_deps = 0;
    3342
    3443/* Hash table of files the makefile knows how to make.  */
     
    345354      {
    346355        register struct file *f = *file_slot;
     356        /* Is this file eligible for automatic deletion?
     357           Yes, IFF: it's marked intermediate, it's not secondary, it wasn't
     358           given on the command-line, and it's either a -include makefile or
     359           it's not precious.  */
    347360        if (f->intermediate && (f->dontcare || !f->precious)
    348361            && !f->secondary && !f->cmd_target)
     
    405418}
    406419
     420/* Expand and parse each dependency line. */
     421static void
     422expand_deps (struct file *f)
     423{
     424  struct dep *d, *d1;
     425  struct dep *new = 0;
     426  struct dep *old = f->deps;
     427  unsigned int last_dep_has_cmds = f->updating;
     428  int initialized = 0;
     429
     430  f->updating = 0;
     431  f->deps = 0;
     432
     433  for (d = old; d != 0; d = d->next)
     434    {
     435      if (d->name != 0)
     436        {
     437          char *p;
     438
     439          /* If we need a second expansion on these, set up the file
     440             variables, etc.  It takes a lot of extra memory and processing
     441             to do this, so only do it if it's needed.  */
     442          if (! d->need_2nd_expansion)
     443            p = d->name;
     444          else
     445            {
     446              /* We are going to do second expansion so initialize file
     447                 variables for the file. */
     448              if (!initialized)
     449                {
     450                  initialize_file_variables (f, 0);
     451                  initialized = 1;
     452                }
     453
     454              set_file_variables (f);
     455
     456              p = variable_expand_for_file (d->name, f);
     457            }
     458
     459          /* Parse the dependencies.  */
     460          new = (struct dep *)
     461            multi_glob (
     462              parse_file_seq (&p, '|', sizeof (struct dep), 1),
     463              sizeof (struct dep));
     464
     465          if (*p)
     466            {
     467              /* Files that follow '|' are special prerequisites that
     468                 need only exist in order to satisfy the dependency.
     469                 Their modification times are irrelevant.  */
     470              struct dep **d_ptr;
     471
     472              for (d_ptr = &new; *d_ptr; d_ptr = &(*d_ptr)->next)
     473                ;
     474              ++p;
     475
     476              *d_ptr = (struct dep *)
     477                multi_glob (
     478                  parse_file_seq (&p, '\0', sizeof (struct dep), 1),
     479                  sizeof (struct dep));
     480
     481              for (d1 = *d_ptr; d1 != 0; d1 = d1->next)
     482                d1->ignore_mtime = 1;
     483            }
     484
     485          /* Enter them as files. */
     486          for (d1 = new; d1 != 0; d1 = d1->next)
     487            {
     488              d1->file = lookup_file (d1->name);
     489              if (d1->file == 0)
     490                d1->file = enter_file (d1->name);
     491              else
     492                free (d1->name);
     493              d1->name = 0;
     494              d1->need_2nd_expansion = 0;
     495            }
     496
     497          /* Add newly parsed deps to f->deps. If this is the last
     498             dependency line and this target has commands then put
     499             it in front so the last dependency line (the one with
     500             commands) ends up being the first. This is important
     501             because people expect $< to hold first prerequisite
     502             from the rule with commands. If it is not the last
     503             dependency line or the rule does not have commands
     504             then link it at the end so it appears in makefile
     505             order.  */
     506
     507          if (new != 0)
     508            {
     509              if (d->next == 0 && last_dep_has_cmds)
     510                {
     511                  struct dep **d_ptr;
     512                  for (d_ptr = &new; *d_ptr; d_ptr = &(*d_ptr)->next)
     513                    ;
     514
     515                  *d_ptr = f->deps;
     516                  f->deps = new;
     517                }
     518              else
     519                {
     520                  struct dep **d_ptr;
     521                  for (d_ptr = &f->deps; *d_ptr; d_ptr = &(*d_ptr)->next)
     522                    ;
     523
     524                  *d_ptr = new;
     525                }
     526            }
     527        }
     528    }
     529
     530  free_ns_chain ((struct nameseq *) old);
     531}
     532
    407533/* For each dependency of each file, make the `struct dep' point
    408534   at the appropriate `struct file' (which may have to be created).
     
    414540snap_deps (void)
    415541{
    416   register struct file *f;
    417   register struct file *f2;
    418   register struct dep *d;
    419   register struct file **file_slot_0;
    420   register struct file **file_slot;
    421   register struct file **file_end;
    422 
    423   /* Enter each dependency name as a file.  */
     542  struct file *f;
     543  struct file *f2;
     544  struct dep *d;
     545  struct file **file_slot_0;
     546  struct file **file_slot;
     547  struct file **file_end;
     548
     549  /* Perform second expansion and enter each dependency
     550     name as a file. */
     551
     552  /* Expand .SUFFIXES first; it's dependencies are used for
     553     $$* calculation. */
     554  for (f = lookup_file (".SUFFIXES"); f != 0; f = f->prev)
     555    expand_deps (f);
     556
    424557  /* We must use hash_dump (), because within this loop
    425558     we might add new files to the table, possibly causing
     
    428561  file_end = file_slot_0 + files.ht_fill;
    429562  for (file_slot = file_slot_0; file_slot < file_end; file_slot++)
    430     for (f2 = *file_slot; f2 != 0; f2 = f2->prev)
    431       for (d = f2->deps; d != 0; d = d->next)
    432         if (d->name != 0)
    433           {
    434             d->file = lookup_file (d->name);
    435             if (d->file == 0)
    436               d->file = enter_file (d->name);
    437             else
    438               free (d->name);
    439             d->name = 0;
    440           }
     563    for (f = *file_slot; f != 0; f = f->prev)
     564      {
     565        if (strcmp (f->name, ".SUFFIXES") != 0)
     566          expand_deps (f);
     567      }
    441568  free (file_slot_0);
    442569
     
    455582      for (f2 = d->file; f2 != 0; f2 = f2->prev)
    456583        {
    457           /* Mark this file as phony and nonexistent.  */
     584          /* Mark this file as phony nonexistent target.  */
    458585          f2->phony = 1;
     586          f2->is_target = 1;
    459587          f2->last_mtime = NONEXISTENT_MTIME;
    460588          f2->mtime_before_update = NONEXISTENT_MTIME;
     
    537665    }
    538666
     667  /* Remember that we've done this. */
     668  snapped_deps = 1;
    539669}
    540670
     
    699829    puts (_("#  Command-line target."));
    700830  if (f->dontcare)
    701     puts (_("#  A default or MAKEFILES makefile."));
     831    puts (_("#  A default, MAKEFILES, or -include/sinclude makefile."));
    702832  puts (f->tried_implicit
    703833        ? _("#  Implicit rule search has been done.")
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette