VirtualBox

Changeset 503 in kBuild for trunk/src/gmake/implicit.c


Ignore:
Timestamp:
Sep 15, 2006 5:09:38 AM (18 years ago)
Author:
bird
Message:

Untested merge with GNU Make v3.81 (vendor/gnumake/2005-05-16 -> vendor/gnumake/current).

File:
1 edited

Legend:

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

    r281 r503  
    11/* Implicit rule searching for GNU Make.
    2 Copyright (C) 1988,1989,1990,1991,1992,1993,1994,1997,2000,2004,2005 Free Software Foundation, Inc.
     2Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
     31998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
     4Foundation, Inc.
    35This file is part of GNU Make.
    46
    5 GNU Make is free software; you can redistribute it and/or modify
    6 it under the terms of the GNU General Public License as published by
    7 the Free Software Foundation; either version 2, or (at your option)
    8 any later version.
    9 
    10 GNU Make is distributed in the hope that it will be useful,
    11 but WITHOUT ANY WARRANTY; without even the implied warranty of
    12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13 GNU General Public License for more details.
    14 
    15 You should have received a copy of the GNU General Public License
    16 along with GNU Make; see the file COPYING.  If not, write to
    17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    18 Boston, MA 02111-1307, USA.  */
     7GNU Make is free software; you can redistribute it and/or modify it under the
     8terms of the GNU General Public License as published by the Free Software
     9Foundation; either version 2, or (at your option) any later version.
     10
     11GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
     12WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     13A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     14
     15You should have received a copy of the GNU General Public License along with
     16GNU Make; see the file COPYING.  If not, write to the Free Software
     17Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.  */
    1918
    2019#include "make.h"
     
    8180
    8281static void
    83 free_idep_chain (struct idep* p)
     82free_idep_chain (struct idep *p)
    8483{
    85   register struct idep* n;
    86   register struct file *f;
     84  struct idep *n;
    8785
    8886  for (; p != 0; p = n)
     
    9290      if (p->name)
    9391        {
     92          struct file *f = p->intermediate_file;
     93
     94          if (f != 0
     95              && (f->stem < f->name || f->stem > f->name + strlen (f->name)))
     96            free (f->stem);
     97
    9498          free (p->name);
    95 
    96           f = p->intermediate_file;
    97 
    98           if (f != 0
    99               && (f->stem < f->name
    100                   || f->stem > f->name + strlen (f->name)))
    101             free (f->stem);
    10299        }
    103100
     
    264261  int specific_rule_matched = 0;
    265262
    266   register unsigned int i = 0;  /* uninit checks OK */
    267   register struct rule *rule;
    268   register struct dep *dep, *expl_d;
     263  unsigned int i = 0;  /* uninit checks OK */
     264  struct rule *rule;
     265  struct dep *dep, *expl_d;
    269266
    270267  char *p, *vname;
     
    350347             prefix and the target pattern does not contain a slash.  */
    351348
     349          check_lastslash = 0;
     350          if (lastslash)
     351            {
    352352#ifdef VMS
    353           check_lastslash = lastslash != 0
    354                             && ((strchr (target, ']') == 0)
    355                                 && (strchr (target, ':') == 0));
     353              check_lastslash = (strchr (target, ']') == 0
     354                                 && strchr (target, ':') == 0);
    356355#else
    357           check_lastslash = lastslash != 0 && strchr (target, '/') == 0;
     356              check_lastslash = strchr (target, '/') == 0;
     357#ifdef HAVE_DOS_PATHS
     358              /* Didn't find it yet: check for DOS-type directories.  */
     359              if (check_lastslash)
     360                {
     361                  char *b = strchr (target, '\\');
     362                  check_lastslash = !(b || (target[0] && target[1] == ':'));
     363                }
    358364#endif
     365#endif
     366            }
    359367          if (check_lastslash)
    360368            {
    361               /* In that case, don't include the
    362                  directory prefix in STEM here.  */
     369              /* If so, don't include the directory prefix in STEM here.  */
    363370              unsigned int difference = lastslash - filename + 1;
    364371              if (difference > stemlen)
     
    437444          unsigned int failed = 0;
    438445          int check_lastslash;
     446          int file_variables_set = 0;
    439447
    440448          rule = tryrules[i];
     
    474482          stem_str[stemlen] = '\0';
    475483
    476           /* Temporary assign STEM to file->stem and set file variables. */
     484          /* Temporary assign STEM to file->stem (needed to set file
     485             variables below).   */
    477486          file->stem = stem_str;
    478           set_file_variables (file);
    479487
    480488          /* Try each dependency; see if it "exists".  */
    481 
    482           /* @@ There is always only one dep line for any given implicit
    483                 rule. So the loop is not necessary. Can rule->deps be 0?
    484 
    485                 Watch out for conversion of suffix rules to implicit rules.
    486           */
    487489
    488490          for (dep = rule->deps; dep != 0; dep = dep->next)
     
    493495
    494496              /* In an ideal world we would take the dependency line,
    495                  substitute the stem, re-expand the whole line and
    496                  chop it into individual prerequisites. Unfortunately
    497                  this won't work because of the "check_lastslash" twist.
    498                  Instead, we will have to go word by word, taking $()'s
    499                  into account, for each word we will substitute the stem,
    500                  re-expand, chop it up, and, if check_lastslash != 0,
    501                  add the directory part to each resulting prerequisite.  */
     497                 substitute the stem, re-expand the whole line and chop it
     498                 into individual prerequisites. Unfortunately this won't work
     499                 because of the "check_lastslash" twist.  Instead, we will
     500                 have to go word by word, taking $()'s into account, for each
     501                 word we will substitute the stem, re-expand, chop it up, and,
     502                 if check_lastslash != 0, add the directory part to each
     503                 resulting prerequisite.  */
    502504
    503505              p = get_next_word (dep->name, &len);
     
    511513                    break; /* No more words */
    512514
    513                   /* If the dependency name has %, substitute the stem.
    514                      Watch out, we are going to do something tricky here. If
    515                      we just replace % with the stem value, later, when we do
    516                      the second expansion, we will re-expand this stem value
    517                      once again. This is not good especially if you have
    518                      certain characters in your setm (like $).
    519 
    520                      Instead, we will replace % with $* and allow the second
    521                      expansion to take care of it for us. This way (since $*
    522                      is a simple variable) there won't be additional
    523                      re-expansion of the stem.  */
     515                  /* Is there a pattern in this prerequisite?  */
    524516
    525517                  for (p2 = p; p2 < p + len && *p2 != '%'; ++p2)
    526518                    ;
    527519
    528                   if (p2 < p + len)
     520                  if (dep->need_2nd_expansion)
    529521                    {
    530                       register unsigned int i = p2 - p;
    531                       bcopy (p, depname, i);
    532                       bcopy ("$*", depname + i, 2);
    533                       bcopy (p2 + 1, depname + i + 2, len - i - 1);
    534                       depname[len + 2 - 1] = '\0';
    535 
    536                       if (check_lastslash)
    537                         add_dir = 1;
    538 
    539                       had_stem = 1;
     522                      /* If the dependency name has %, substitute the stem.
     523
     524                         Watch out, we are going to do something tricky
     525                         here. If we just replace % with the stem value,
     526                         later, when we do the second expansion, we will
     527                         re-expand this stem value once again. This is not
     528                         good especially if you have certain characters in
     529                         your stem (like $).
     530
     531                         Instead, we will replace % with $* and allow the
     532                         second expansion to take care of it for us. This way
     533                         (since $* is a simple variable) there won't be
     534                         additional re-expansion of the stem.  */
     535
     536                      if (p2 < p + len)
     537                        {
     538                          register unsigned int i = p2 - p;
     539                          bcopy (p, depname, i);
     540                          bcopy ("$*", depname + i, 2);
     541                          bcopy (p2 + 1, depname + i + 2, len - i - 1);
     542                          depname[len + 2 - 1] = '\0';
     543
     544                          if (check_lastslash)
     545                            add_dir = 1;
     546
     547                          had_stem = 1;
     548                        }
     549                      else
     550                        {
     551                          bcopy (p, depname, len);
     552                          depname[len] = '\0';
     553                        }
     554
     555                      /* Set file variables. Note that we cannot do it once
     556                         at the beginning of the function because of the stem
     557                         value.  */
     558                      if (!file_variables_set)
     559                        {
     560                          set_file_variables (file);
     561                          file_variables_set = 1;
     562                        }
     563
     564                      p2 = variable_expand_for_file (depname, file);
    540565                    }
    541566                  else
    542567                    {
    543                       bcopy (p, depname, len);
    544                       depname[len] = '\0';
     568                       if (p2 < p + len)
     569                        {
     570                          register unsigned int i = p2 - p;
     571                          bcopy (p, depname, i);
     572                          bcopy (stem_str, depname + i, stemlen);
     573                          bcopy (p2 + 1, depname + i + stemlen, len - i - 1);
     574                          depname[len + stemlen - 1] = '\0';
     575
     576                          if (check_lastslash)
     577                            add_dir = 1;
     578
     579                          had_stem = 1;
     580                        }
     581                      else
     582                        {
     583                          bcopy (p, depname, len);
     584                          depname[len] = '\0';
     585                        }
     586
     587                       p2 = depname;
    545588                    }
    546 
    547                   p2 = variable_expand_for_file (depname, file);
    548589
    549590                  /* Parse the dependencies. */
     
    564605
    565606                      /* @@ It would be nice to teach parse_file_seq or
    566                          multi_glob to add prefix. This would save us
    567                          some reallocations. */
     607                         multi_glob to add prefix. This would save us some
     608                         reallocations. */
    568609
    569610                      if (order_only || add_dir || had_stem)
     
    621662              if (file_impossible_p (name))
    622663                {
    623                   /* If this dependency has already been ruled
    624                      "impossible", then the rule fails and don't
    625                      bother trying it on the second pass either
    626                      since we know that will fail too.  */
     664                  /* If this dependency has already been ruled "impossible",
     665                     then the rule fails and don't bother trying it on the
     666                     second pass either since we know that will fail too.  */
    627667                  DBS (DB_IMPLICIT,
    628668                       (d->had_stem
     
    641681                    : _("Trying rule prerequisite `%s'.\n"), name));
    642682
    643               /* If this prerequisite also happened to be explicitly
    644                  mentioned for FILE skip all the test below since it
    645                  it has to be built anyway, no matter which implicit
    646                  rule we choose. */
     683              /* If this prerequisite also happened to be explicitly mentioned
     684                 for FILE skip all the test below since it it has to be built
     685                 anyway, no matter which implicit rule we choose. */
    647686
    648687              for (expl_d = file->deps; expl_d != 0; expl_d = expl_d->next)
    649                 if (strcmp (dep_name (expl_d), name) == 0) break;
    650 
     688                if (streq (dep_name (expl_d), name))
     689                  break;
    651690              if (expl_d != 0)
    652691                continue;
    653 
    654 
    655692
    656693              /* The DEP->changed flag says that this dependency resides in a
     
    665702                  /*|| ((!dep->changed || check_lastslash) && */
    666703                  || file_exists_p (name))
    667                 {
    668                   continue;
    669                 }
     704                continue;
    670705
    671706              /* This code, given FILENAME = "lib/foo.o", dependency name
     
    684719
    685720
    686               /* We could not find the file in any place we should look.
    687                  Try to make this dependency as an intermediate file,
    688                  but only on the second pass.  */
     721              /* We could not find the file in any place we should look.  Try
     722                 to make this dependency as an intermediate file, but only on
     723                 the second pass.  */
    689724
    690725              if (intermed_ok)
     
    717752                     file and failed, mark that name as impossible
    718753                     so we won't go through the search again later.  */
     754                  if (intermediate_file->variables)
     755                    free_variable_set (intermediate_file->variables);
    719756                  file_impossible (name);
    720757                }
     
    777814        {
    778815          struct dep *next = dep->next;
    779           free (dep->name);
    780           free ((char *)dep);
     816          free_dep (dep);
    781817          dep = next;
    782818        }
     
    837873        }
    838874
    839       dep = (struct dep *) xmalloc (sizeof (struct dep));
     875      dep = alloc_dep ();
    840876      dep->ignore_mtime = d->ignore_mtime;
    841       dep->need_2nd_expansion = 0;
    842877      s = d->name; /* Hijacking the name. */
    843878      d->name = 0;
    844879      if (recursions == 0)
    845880        {
    846           dep->name = 0;
    847881          dep->file = lookup_file (s);
    848882          if (dep->file == 0)
     
    857891        {
    858892          dep->name = s;
    859           dep->file = 0;
    860           dep->changed = 0;
    861893        }
     894
    862895      if (d->intermediate_file == 0 && tryrules[foundrule]->terminal)
    863896        {
     
    902935  file->is_target = 1;
    903936
     937  /* Set precious flag. */
     938  {
     939    struct file *f = lookup_file (rule->targets[matches[foundrule]]);
     940    if (f && f->precious)
     941      file->precious = 1;
     942  }
     943
    904944  /* If this rule builds other targets, too, put the others into FILE's
    905945     `also_make' member.  */
     
    909949      if (i != matches[foundrule])
    910950        {
    911           struct dep *new = (struct dep *) xmalloc (sizeof (struct dep));
     951          struct file *f;
     952          struct dep *new = alloc_dep ();
     953
    912954          /* GKM FIMXE: handle '|' here too */
    913           new->ignore_mtime = 0;
    914           new->need_2nd_expansion = 0;
    915955          new->name = p = (char *) xmalloc (rule->lens[i] + fullstemlen + 1);
    916956          bcopy (rule->targets[i], p,
     
    923963          new->file = enter_file (new->name);
    924964          new->next = file->also_make;
     965
     966          /* Set precious flag. */
     967          f = lookup_file (rule->targets[i]);
     968          if (f && f->precious)
     969            new->file->precious = 1;
     970
     971          /* Set the is_target flag so that this file is not treated
     972             as intermediate by the pattern rule search algorithm and
     973             file_exists_p cannot pick it up yet.  */
     974          new->file->is_target = 1;
     975
    925976          file->also_make = new;
    926977        }
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