Ignore:
Timestamp:
Sep 15, 2006, 4:30:32 AM (19 years ago)
Author:
bird
Message:

Load make-3.81/ into vendor/gnumake/current.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/gnumake/current/read.c

    r280 r501  
    11/* Reading and parsing of makefiles for GNU Make.
    22Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
    3 2002 Free Software Foundation, Inc.
     31998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
     4Foundation, Inc.
    45This file is part of GNU Make.
    56
    6 GNU Make is free software; you can redistribute it and/or modify
    7 it under the terms of the GNU General Public License as published by
    8 the Free Software Foundation; either version 2, or (at your option)
    9 any later version.
    10 
    11 GNU Make is distributed in the hope that it will be useful,
    12 but WITHOUT ANY WARRANTY; without even the implied warranty of
    13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14 GNU General Public License for more details.
    15 
    16 You should have received a copy of the GNU General Public License
    17 along with GNU Make; see the file COPYING.  If not, write to
    18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    19 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.  */
    2018
    2119#include "make.h"
     
    144142static enum make_word_type get_next_mword PARAMS ((char *buffer, char *delim,
    145143                        char **startp, unsigned int *length));
     144static void remove_comments PARAMS ((char *line));
     145static char *find_char_unquote PARAMS ((char *string, int stop1,
     146                                        int stop2, int blank, int ignorevars));
    146147
    147148
     
    187188        if (*p != '\0')
    188189          *p++ = '\0';
    189         name = xstrdup (name);
    190         if (eval_makefile (name,
    191                            RM_NO_DEFAULT_GOAL|RM_INCLUDED|RM_DONTCARE) < 2)
    192           free (name);
     190        eval_makefile (name, RM_NO_DEFAULT_GOAL|RM_INCLUDED|RM_DONTCARE);
    193191      }
    194192
     
    252250          for (p = default_makefiles; *p != 0; ++p)
    253251            {
    254               struct dep *d = (struct dep *) xmalloc (sizeof (struct dep));
    255               d->name = 0;
     252              struct dep *d = alloc_dep ();
    256253              d->file = enter_file (*p);
    257254              d->file->dontcare = 1;
    258               d->ignore_mtime = 0;
    259               d->need_2nd_expansion = 0;
    260255              /* Tell update_goal_chain to bail out as soon as this file is
    261256                 made, and main not to die if we can't make this file.  */
     
    311306  struct ebuffer ebuf;
    312307  const struct floc *curfile;
     308  char *expanded = 0;
     309  char *included = 0;
    313310  int makefile_errno;
    314311  int r;
    315312
    316   ebuf.floc.filenm = filename;
     313  ebuf.floc.filenm = strcache_add (filename);
    317314  ebuf.floc.lineno = 1;
    318315
     
    337334  if (!(flags & RM_NO_TILDE) && filename[0] == '~')
    338335    {
    339       char *expanded = tilde_expand (filename);
     336      expanded = tilde_expand (filename);
    340337      if (expanded != 0)
    341338        filename = expanded;
     
    354351      for (i = 0; include_directories[i] != 0; ++i)
    355352        {
    356           char *name = concat (include_directories[i], "/", filename);
    357           ebuf.fp = fopen (name, "r");
    358           if (ebuf.fp == 0)
    359             free (name);
    360           else
     353          included = concat (include_directories[i], "/", filename);
     354          ebuf.fp = fopen (included, "r");
     355          if (ebuf.fp)
    361356            {
    362               filename = name;
     357              filename = included;
    363358              break;
    364359            }
    365         }
     360          free (included);
     361        }
     362      /* If we're not using it, we already freed it above.  */
     363      if (filename != included)
     364        included = 0;
    366365    }
    367366
    368367  /* Add FILENAME to the chain of read makefiles.  */
    369   deps = (struct dep *) xmalloc (sizeof (struct dep));
     368  deps = alloc_dep ();
    370369  deps->next = read_makefiles;
    371370  read_makefiles = deps;
    372   deps->name = 0;
    373371  deps->file = lookup_file (filename);
    374372  if (deps->file == 0)
    375373    deps->file = enter_file (xstrdup (filename));
    376   if (filename != ebuf.floc.filenm)
    377     free (filename);
    378374  filename = deps->file->name;
    379375  deps->changed = flags;
    380   deps->ignore_mtime = 0;
    381   deps->need_2nd_expansion = 0;
    382376  if (flags & RM_DONTCARE)
    383377    deps->file->dontcare = 1;
     378
     379  if (expanded)
     380    free (expanded);
     381  if (included)
     382    free (included);
    384383
    385384  /* If the makefile can't be found at all, give up entirely.  */
     
    802801
    803802          p = allocated_variable_expand (p2);
     803
     804          /* If no filenames, it's a no-op.  */
    804805          if (*p == '\0')
    805             {
    806               error (fstart,
    807                      _("no file name for `%sinclude'"), noerror ? "-" : "");
    808               continue;
    809             }
     806            {
     807              free (p);
     808              continue;
     809            }
    810810
    811811          /* Parse the list of file names.  */
     
    837837              r = eval_makefile (name, (RM_INCLUDED | RM_NO_TILDE
    838838                                        | (noerror ? RM_DONTCARE : 0)));
    839               if (!r)
    840                 {
    841                   if (!noerror)
    842                     error (fstart, "%s: %s", name, strerror (errno));
    843                   free (name);
    844                 }
     839              if (!r && !noerror)
     840                error (fstart, "%s: %s", name, strerror (errno));
     841              free (name);
    845842            }
    846843
     
    887884        /* Search the line for an unquoted ; that is not after an
    888885           unquoted #.  */
    889         cmdleft = find_char_unquote (line, ';', '#', 0);
     886        cmdleft = find_char_unquote (line, ';', '#', 0, 1);
    890887        if (cmdleft != 0 && *cmdleft == '#')
    891888          {
     
    934931              {
    935932                /* Look for a semicolon in the expanded line.  */
    936                 cmdleft = find_char_unquote (p2, ';', 0, 0);
     933                cmdleft = find_char_unquote (p2, ';', 0, 0, 0);
    937934
    938935                if (cmdleft != 0)
     
    961958              }
    962959
    963             colonp = find_char_unquote(p2, ':', 0, 0);
     960            colonp = find_char_unquote(p2, ':', 0, 0, 0);
    964961#ifdef HAVE_DOS_PATHS
    965962            /* The drive spec brain-damage strikes again...  */
     
    970967                   colonp > p2 && isalpha ((unsigned char)colonp[-1]) &&
    971968                   (colonp == p2 + 1 || strchr (" \t(", colonp[-2]) != 0))
    972               colonp = find_char_unquote(colonp + 1, ':', 0, 0);
     969              colonp = find_char_unquote(colonp + 1, ':', 0, 0, 0);
    973970#endif
    974971            if (colonp != 0)
     
    10841081        /* This is a normal target, _not_ a target-specific variable.
    10851082           Unquote any = in the dependency list.  */
    1086         find_char_unquote (lb_next, '=', 0, 0);
     1083        find_char_unquote (lb_next, '=', 0, 0, 0);
    10871084
    10881085        /* We have some targets, so don't ignore the following commands.  */
     
    10991096            if (cmdleft == 0)
    11001097              {
    1101                 cmdleft = find_char_unquote (p2, ';', 0, 0);
     1098                cmdleft = find_char_unquote (p2, ';', 0, 0, 0);
    11021099                if (cmdleft != 0)
    11031100                  *(cmdleft++) = '\0';
     
    11641161            if (pattern_percent == 0)
    11651162              fatal (fstart, _("target pattern contains no `%%'"));
    1166             free((char *)target);
     1163            free ((char *)target);
    11671164          }
    11681165        else
     
    11761173        if (beg <= end && *beg != '\0')
    11771174          {
    1178             char *top;
    1179             const char *fromp = beg;
    1180 
    1181             /* Make a copy of the dependency string.  Note if we find '$'.  */
    1182             deps = (struct dep*) xmalloc (sizeof (struct dep));
    1183             deps->next = 0;
    1184             deps->name = top = (char *) xmalloc (end - beg + 2);
    1185             deps->need_2nd_expansion = 0;
    1186             while (fromp <= end)
    1187               {
    1188                 if (*fromp == '$')
    1189                   deps->need_2nd_expansion = 1;
    1190                 *(top++) = *(fromp++);
    1191               }
    1192             *top = '\0';
    1193             deps->file = 0;
     1175            /* Put all the prerequisites here; they'll be parsed later.  */
     1176            deps = alloc_dep ();
     1177            deps->name = savestring (beg, end - beg + 1);
    11941178          }
    11951179        else
     
    13181302
    13191303
     1304/* Remove comments from LINE.
     1305   This is done by copying the text at LINE onto itself.  */
     1306
     1307static void
     1308remove_comments (char *line)
     1309{
     1310  char *comment;
     1311
     1312  comment = find_char_unquote (line, '#', 0, 0, 0);
     1313
     1314  if (comment != 0)
     1315    /* Cut off the line at the #.  */
     1316    *comment = '\0';
     1317}
     1318
    13201319/* Execute a `define' directive.
    13211320   The first line has already been read, and NAME is the name of
     
    18381837      v->origin = origin;
    18391838      v->per_target = 1;
    1840       if (exported)
    1841         v->export = v_export;
     1839      v->export = exported ? v_export : v_default;
    18421840
    18431841      /* If it's not an override, check to see if there was a command-line
     
    19121910      char *name = filenames->name;
    19131911      struct file *f;
    1914       struct dep *d;
    1915       struct dep *this;
     1912      struct dep *this = 0;
    19161913      char *implicit_percent;
    19171914
     
    19191916      free (filenames);
    19201917
    1921       /* Check for .POSIX.  We used to do this in snap_deps() but that's not
    1922          good enough: it doesn't happen until after the makefile is read,
    1923          which means we cannot use its value during parsing.  */
     1918      /* Check for special targets.  Do it here instead of, say, snap_deps()
     1919         so that we can immediately use the value.  */
    19241920
    19251921      if (streq (name, ".POSIX"))
    19261922        posix_pedantic = 1;
     1923      else if (streq (name, ".SECONDEXPANSION"))
     1924        second_expansion = 1;
    19271925
    19281926      implicit_percent = find_percent (name);
     
    19591957        }
    19601958
    1961       /* If there are multiple filenames, copy the chain DEPS
    1962          for all but the last one.  It is not safe for the same deps
    1963          to go in more than one place in the database.  */
    1964       this = nextf != 0 ? copy_dep_chain (deps) : deps;
    1965 
    1966       if (pattern != 0)
    1967         {
    1968           /* If this is an extended static rule:
    1969              `targets: target%pattern: dep%pattern; cmds',
    1970              translate each dependency pattern into a plain filename
    1971              using the target pattern and this target's name.  */
    1972           if (!pattern_matches (pattern, pattern_percent, name))
    1973             {
    1974               /* Give a warning if the rule is meaningless.  */
    1975               error (flocp,
    1976                      _("target `%s' doesn't match the target pattern"), name);
    1977               this = 0;
    1978             }
    1979           else
    1980             /* We use subst_expand to do the work of translating % to $* in
    1981                the dependency line.  */
    1982 
    1983             if (this != 0 && find_percent (this->name) != 0)
    1984               {
    1985                 char *o;
    1986                 char *buffer = variable_expand ("");
    1987 
    1988                 o = subst_expand (buffer, this->name, "%", "$*", 1, 2, 0);
    1989 
    1990                 free (this->name);
    1991                 this->name = savestring (buffer, o - buffer);
    1992                 this->need_2nd_expansion = 1;
    1993               }
    1994         }
     1959      /* If this is a static pattern rule:
     1960         `targets: target%pattern: dep%pattern; cmds',
     1961         make sure the pattern matches this target name.  */
     1962      if (pattern && !pattern_matches (pattern, pattern_percent, name))
     1963        error (flocp, _("target `%s' doesn't match the target pattern"), name);
     1964      else if (deps)
     1965        {
     1966          /* If there are multiple filenames, copy the chain DEPS for all but
     1967             the last one.  It is not safe for the same deps to go in more
     1968             than one place in the database.  */
     1969          this = nextf != 0 ? copy_dep_chain (deps) : deps;
     1970          this->need_2nd_expansion = (second_expansion
     1971                                      && strchr (this->name, '$'));
     1972        }
    19951973
    19961974      if (!two_colon)
     
    20322010            f->cmds = cmds;
    20332011
    2034           /* Defining .SUFFIXES with no dependencies
    2035              clears out the list of suffixes.  */
     2012          /* Defining .SUFFIXES with no dependencies clears out the list of
     2013             suffixes.  */
    20362014          if (f == suffix_file && this == 0)
    20372015            {
    2038               d = f->deps;
    2039               while (d != 0)
    2040                 {
    2041                   struct dep *nextd = d->next;
    2042                   free (d->name);
    2043                   free ((char *)d);
    2044                   d = nextd;
    2045                 }
     2016              free_dep_chain (f->deps);
    20462017              f->deps = 0;
    20472018            }
     
    20582029
    20592030                  if (cmds != 0)
    2060                     {
    2061                       /* This is the rule with commands, so put its deps
    2062                          last. The rationale behind this is that $< expands
    2063                          to the first dep in the chain, and commands use $<
    2064                          expecting to get the dep that rule specifies.
    2065                          However the second expansion algorithm reverses
    2066                          the order thus we need to make it last here.  */
    2067 
    2068                       (*d_ptr)->next = this;
    2069                     }
     2031                    /* This is the rule with commands, so put its deps
     2032                       last. The rationale behind this is that $< expands to
     2033                       the first dep in the chain, and commands use $<
     2034                       expecting to get the dep that rule specifies.  However
     2035                       the second expansion algorithm reverses the order thus
     2036                       we need to make it last here.  */
     2037                    (*d_ptr)->next = this;
    20702038                  else
    20712039                    {
    20722040                      /* This is the rule without commands. Put its
    2073                          dependencies at the end but before dependencies
    2074                          from the rule with commands (if any). This way
    2075                          everything appears in makefile order.  */
     2041                         dependencies at the end but before dependencies from
     2042                         the rule with commands (if any). This way everything
     2043                         appears in makefile order.  */
    20762044
    20772045                      if (f->cmds != 0)
     
    21032071                f->updating = 1;
    21042072            }
    2105 
    2106           /* If this is a static pattern rule, set the file's stem to
    2107              the part of its name that matched the `%' in the pattern,
    2108              so you can use $* in the commands.  */
    2109           if (pattern != 0)
    2110             {
    2111               static char *percent = "%";
    2112               char *buffer = variable_expand ("");
    2113               char *o = patsubst_expand (buffer, name, pattern, percent,
    2114                                          pattern_percent+1, percent+1);
    2115               f->stem = savestring (buffer, o - buffer);
    2116             }
    21172073        }
    21182074      else
    21192075        {
    2120           /* Double-colon.  Make a new record
    2121              even if the file already has one.  */
     2076          /* Double-colon.  Make a new record even if there already is one.  */
    21222077          f = lookup_file (name);
     2078
    21232079          /* Check for both : and :: rules.  Check is_target so
    21242080             we don't lose on default suffix rules or makefiles.  */
     
    21272083                   _("target file `%s' has both : and :: entries"), f->name);
    21282084          f = enter_file (name);
    2129           /* If there was an existing entry and it was a double-colon
    2130              entry, enter_file will have returned a new one, making it the
    2131              prev pointer of the old one, and setting its double_colon
    2132              pointer to the first one.  */
     2085          /* If there was an existing entry and it was a double-colon entry,
     2086             enter_file will have returned a new one, making it the prev
     2087             pointer of the old one, and setting its double_colon pointer to
     2088             the first one.  */
    21332089          if (f->double_colon == 0)
    2134             /* This is the first entry for this name, so we must
    2135                set its double_colon pointer to itself.  */
     2090            /* This is the first entry for this name, so we must set its
     2091               double_colon pointer to itself.  */
    21362092            f->double_colon = f;
    21372093          f->is_target = 1;
     
    21402096        }
    21412097
     2098      /* If this is a static pattern rule, set the stem to the part of its
     2099         name that matched the `%' in the pattern, so you can use $* in the
     2100         commands.  */
     2101      if (pattern)
     2102        {
     2103          static char *percent = "%";
     2104          char *buffer = variable_expand ("");
     2105          char *o = patsubst_expand (buffer, name, pattern, percent,
     2106                                     pattern_percent+1, percent+1);
     2107          f->stem = savestring (buffer, o - buffer);
     2108          if (this)
     2109            {
     2110              this->staticpattern = 1;
     2111              this->stem = xstrdup (f->stem);
     2112            }
     2113        }
     2114
    21422115      /* Free name if not needed further.  */
    21432116      if (f != 0 && name != f->name
     
    21492122
    21502123      /* If this target is a default target, update DEFAULT_GOAL_FILE.  */
    2151       if (strcmp (*default_goal_name, name) == 0
     2124      if (streq (*default_goal_name, name)
    21522125          && (default_goal_file == 0
    2153               || strcmp (default_goal_file->name, name) != 0))
     2126              || ! streq (default_goal_file->name, name)))
    21542127        default_goal_file = f;
    21552128    }
     
    21592132      targets[target_idx] = 0;
    21602133      target_percents[target_idx] = 0;
     2134      if (deps)
     2135        deps->need_2nd_expansion = second_expansion;
    21612136      create_pattern_rule (targets, target_percents, two_colon, deps, cmds, 1);
    21622137      free ((char *) target_percents);
     
    21692144   Quoting backslashes are removed from STRING by compacting it into
    21702145   itself.  Returns a pointer to the first unquoted STOPCHAR if there is
    2171    one, or nil if there are none.  */
    2172 
    2173 char *
    2174 find_char_unquote (char *string, int stop1, int stop2, int blank)
     2146   one, or nil if there are none.  STOPCHARs inside variable references are
     2147   ignored if IGNOREVARS is true.
     2148
     2149   STOPCHAR _cannot_ be '$' if IGNOREVARS is true.  */
     2150
     2151static char *
     2152find_char_unquote (char *string, int stop1, int stop2, int blank,
     2153                   int ignorevars)
    21752154{
    21762155  unsigned int string_len = 0;
    21772156  register char *p = string;
    21782157
     2158  if (ignorevars)
     2159    ignorevars = '$';
     2160
    21792161  while (1)
    21802162    {
    21812163      if (stop2 && blank)
    2182         while (*p != '\0' && *p != stop1 && *p != stop2
     2164        while (*p != '\0' && *p != ignorevars && *p != stop1 && *p != stop2
    21832165               && ! isblank ((unsigned char) *p))
    21842166          ++p;
    21852167      else if (stop2)
    2186         while (*p != '\0' && *p != stop1 && *p != stop2)
     2168        while (*p != '\0' && *p != ignorevars && *p != stop1 && *p != stop2)
    21872169          ++p;
    21882170      else if (blank)
    2189         while (*p != '\0' && *p != stop1
     2171        while (*p != '\0' && *p != ignorevars && *p != stop1
    21902172               && ! isblank ((unsigned char) *p))
    21912173          ++p;
    21922174      else
    2193         while (*p != '\0' && *p != stop1)
     2175        while (*p != '\0' && *p != ignorevars && *p != stop1)
    21942176          ++p;
    21952177
    21962178      if (*p == '\0')
    21972179        break;
     2180
     2181      /* If we stopped due to a variable reference, skip over its contents.  */
     2182      if (*p == ignorevars)
     2183        {
     2184          char openparen = p[1];
     2185
     2186          p += 2;
     2187
     2188          /* Skip the contents of a non-quoted, multi-char variable ref.  */
     2189          if (openparen == '(' || openparen == '{')
     2190            {
     2191              unsigned int pcount = 1;
     2192              char closeparen = (openparen == '(' ? ')' : '}');
     2193
     2194              while (*p)
     2195                {
     2196                  if (*p == openparen)
     2197                    ++pcount;
     2198                  else if (*p == closeparen)
     2199                    if (--pcount == 0)
     2200                      {
     2201                        ++p;
     2202                        break;
     2203                      }
     2204                  ++p;
     2205                }
     2206            }
     2207
     2208          /* Skipped the variable reference: look for STOPCHARS again.  */
     2209          continue;
     2210        }
    21982211
    21992212      if (p > string && p[-1] == '\\')
     
    22322245find_percent (char *pattern)
    22332246{
    2234   return find_char_unquote (pattern, '%', 0, 0);
     2247  return find_char_unquote (pattern, '%', 0, 0, 0);
    22352248}
    22362249
     
    22522265parse_file_seq (char **stringp, int stopchar, unsigned int size, int strip)
    22532266{
    2254   register struct nameseq *new = 0;
    2255   register struct nameseq *new1, *lastnew1;
    2256   register char *p = *stringp;
     2267  struct nameseq *new = 0;
     2268  struct nameseq *new1, *lastnew1;
     2269  char *p = *stringp;
    22572270  char *q;
    22582271  char *name;
     
    22752288      /* Yes, find end of next name.  */
    22762289      q = p;
    2277       p = find_char_unquote (q, stopchar, VMS_COMMA, 1);
     2290      p = find_char_unquote (q, stopchar, VMS_COMMA, 1, 0);
    22782291#ifdef VMS
    22792292        /* convert comma separated list to space separated */
     
    22862299               || isspace ((unsigned char)p[-1])))
    22872300      {
    2288         p = find_char_unquote (p+1, stopchar, VMS_COMMA, 1);
     2301        p = find_char_unquote (p+1, stopchar, VMS_COMMA, 1, 0);
    22892302      }
    22902303#endif
     
    22972310      while (p != 0 && !isspace ((unsigned char)*p) &&
    22982311             (p[1] == '\\' || p[1] == '/') && isalpha ((unsigned char)p[-1]))
    2299         p = find_char_unquote (p + 1, stopchar, VMS_COMMA, 1);
     2312        p = find_char_unquote (p + 1, stopchar, VMS_COMMA, 1, 0);
    23002313#endif
    23012314      if (p == 0)
     
    29072920  dirs[idx] = 0;
    29082921
    2909   /* Now compute the maximum length of any name in it.  */
     2922  /* Now compute the maximum length of any name in it. Also add each
     2923     dir to the .INCLUDE_DIRS variable.  */
    29102924
    29112925  max_incl_len = 0;
     
    29202934      if (len > max_incl_len)
    29212935        max_incl_len = len;
     2936
     2937      /* Append to .INCLUDE_DIRS.   */
     2938      do_variable_definition (NILF, ".INCLUDE_DIRS", dirs[i],
     2939                              o_default, f_append, 0);
    29222940    }
    29232941
Note: See TracChangeset for help on using the changeset viewer.