Changeset 501 for vendor/gnumake/current/read.c
- Timestamp:
- Sep 15, 2006, 4:30:32 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/gnumake/current/read.c
r280 r501 1 1 /* Reading and parsing of makefiles for GNU Make. 2 2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 3 2002 Free Software Foundation, Inc. 3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software 4 Foundation, Inc. 4 5 This file is part of GNU Make. 5 6 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. */ 7 GNU Make is free software; you can redistribute it and/or modify it under the 8 terms of the GNU General Public License as published by the Free Software 9 Foundation; either version 2, or (at your option) any later version. 10 11 GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY 12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 13 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License along with 16 GNU Make; see the file COPYING. If not, write to the Free Software 17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ 20 18 21 19 #include "make.h" … … 144 142 static enum make_word_type get_next_mword PARAMS ((char *buffer, char *delim, 145 143 char **startp, unsigned int *length)); 144 static void remove_comments PARAMS ((char *line)); 145 static char *find_char_unquote PARAMS ((char *string, int stop1, 146 int stop2, int blank, int ignorevars)); 146 147 147 148 … … 187 188 if (*p != '\0') 188 189 *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); 193 191 } 194 192 … … 252 250 for (p = default_makefiles; *p != 0; ++p) 253 251 { 254 struct dep *d = (struct dep *) xmalloc (sizeof (struct dep)); 255 d->name = 0; 252 struct dep *d = alloc_dep (); 256 253 d->file = enter_file (*p); 257 254 d->file->dontcare = 1; 258 d->ignore_mtime = 0;259 d->need_2nd_expansion = 0;260 255 /* Tell update_goal_chain to bail out as soon as this file is 261 256 made, and main not to die if we can't make this file. */ … … 311 306 struct ebuffer ebuf; 312 307 const struct floc *curfile; 308 char *expanded = 0; 309 char *included = 0; 313 310 int makefile_errno; 314 311 int r; 315 312 316 ebuf.floc.filenm = filename;313 ebuf.floc.filenm = strcache_add (filename); 317 314 ebuf.floc.lineno = 1; 318 315 … … 337 334 if (!(flags & RM_NO_TILDE) && filename[0] == '~') 338 335 { 339 char *expanded = tilde_expand (filename);336 expanded = tilde_expand (filename); 340 337 if (expanded != 0) 341 338 filename = expanded; … … 354 351 for (i = 0; include_directories[i] != 0; ++i) 355 352 { 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) 361 356 { 362 filename = name;357 filename = included; 363 358 break; 364 359 } 365 } 360 free (included); 361 } 362 /* If we're not using it, we already freed it above. */ 363 if (filename != included) 364 included = 0; 366 365 } 367 366 368 367 /* Add FILENAME to the chain of read makefiles. */ 369 deps = (struct dep *) xmalloc (sizeof (struct dep));368 deps = alloc_dep (); 370 369 deps->next = read_makefiles; 371 370 read_makefiles = deps; 372 deps->name = 0;373 371 deps->file = lookup_file (filename); 374 372 if (deps->file == 0) 375 373 deps->file = enter_file (xstrdup (filename)); 376 if (filename != ebuf.floc.filenm)377 free (filename);378 374 filename = deps->file->name; 379 375 deps->changed = flags; 380 deps->ignore_mtime = 0;381 deps->need_2nd_expansion = 0;382 376 if (flags & RM_DONTCARE) 383 377 deps->file->dontcare = 1; 378 379 if (expanded) 380 free (expanded); 381 if (included) 382 free (included); 384 383 385 384 /* If the makefile can't be found at all, give up entirely. */ … … 802 801 803 802 p = allocated_variable_expand (p2); 803 804 /* If no filenames, it's a no-op. */ 804 805 if (*p == '\0') 805 { 806 error (fstart, 807 _("no file name for `%sinclude'"), noerror ? "-" : ""); 808 continue; 809 } 806 { 807 free (p); 808 continue; 809 } 810 810 811 811 /* Parse the list of file names. */ … … 837 837 r = eval_makefile (name, (RM_INCLUDED | RM_NO_TILDE 838 838 | (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); 845 842 } 846 843 … … 887 884 /* Search the line for an unquoted ; that is not after an 888 885 unquoted #. */ 889 cmdleft = find_char_unquote (line, ';', '#', 0 );886 cmdleft = find_char_unquote (line, ';', '#', 0, 1); 890 887 if (cmdleft != 0 && *cmdleft == '#') 891 888 { … … 934 931 { 935 932 /* 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); 937 934 938 935 if (cmdleft != 0) … … 961 958 } 962 959 963 colonp = find_char_unquote(p2, ':', 0, 0 );960 colonp = find_char_unquote(p2, ':', 0, 0, 0); 964 961 #ifdef HAVE_DOS_PATHS 965 962 /* The drive spec brain-damage strikes again... */ … … 970 967 colonp > p2 && isalpha ((unsigned char)colonp[-1]) && 971 968 (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); 973 970 #endif 974 971 if (colonp != 0) … … 1084 1081 /* This is a normal target, _not_ a target-specific variable. 1085 1082 Unquote any = in the dependency list. */ 1086 find_char_unquote (lb_next, '=', 0, 0 );1083 find_char_unquote (lb_next, '=', 0, 0, 0); 1087 1084 1088 1085 /* We have some targets, so don't ignore the following commands. */ … … 1099 1096 if (cmdleft == 0) 1100 1097 { 1101 cmdleft = find_char_unquote (p2, ';', 0, 0 );1098 cmdleft = find_char_unquote (p2, ';', 0, 0, 0); 1102 1099 if (cmdleft != 0) 1103 1100 *(cmdleft++) = '\0'; … … 1164 1161 if (pattern_percent == 0) 1165 1162 fatal (fstart, _("target pattern contains no `%%'")); 1166 free ((char *)target);1163 free ((char *)target); 1167 1164 } 1168 1165 else … … 1176 1173 if (beg <= end && *beg != '\0') 1177 1174 { 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); 1194 1178 } 1195 1179 else … … 1318 1302 1319 1303 1304 /* Remove comments from LINE. 1305 This is done by copying the text at LINE onto itself. */ 1306 1307 static void 1308 remove_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 1320 1319 /* Execute a `define' directive. 1321 1320 The first line has already been read, and NAME is the name of … … 1838 1837 v->origin = origin; 1839 1838 v->per_target = 1; 1840 if (exported) 1841 v->export = v_export; 1839 v->export = exported ? v_export : v_default; 1842 1840 1843 1841 /* If it's not an override, check to see if there was a command-line … … 1912 1910 char *name = filenames->name; 1913 1911 struct file *f; 1914 struct dep *d; 1915 struct dep *this; 1912 struct dep *this = 0; 1916 1913 char *implicit_percent; 1917 1914 … … 1919 1916 free (filenames); 1920 1917 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. */ 1924 1920 1925 1921 if (streq (name, ".POSIX")) 1926 1922 posix_pedantic = 1; 1923 else if (streq (name, ".SECONDEXPANSION")) 1924 second_expansion = 1; 1927 1925 1928 1926 implicit_percent = find_percent (name); … … 1959 1957 } 1960 1958 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 } 1995 1973 1996 1974 if (!two_colon) … … 2032 2010 f->cmds = cmds; 2033 2011 2034 /* Defining .SUFFIXES with no dependencies 2035 clears out the list ofsuffixes. */2012 /* Defining .SUFFIXES with no dependencies clears out the list of 2013 suffixes. */ 2036 2014 if (f == suffix_file && this == 0) 2037 2015 { 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); 2046 2017 f->deps = 0; 2047 2018 } … … 2058 2029 2059 2030 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; 2070 2038 else 2071 2039 { 2072 2040 /* 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 way2075 everythingappears 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. */ 2076 2044 2077 2045 if (f->cmds != 0) … … 2103 2071 f->updating = 1; 2104 2072 } 2105 2106 /* If this is a static pattern rule, set the file's stem to2107 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 }2117 2073 } 2118 2074 else 2119 2075 { 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. */ 2122 2077 f = lookup_file (name); 2078 2123 2079 /* Check for both : and :: rules. Check is_target so 2124 2080 we don't lose on default suffix rules or makefiles. */ … … 2127 2083 _("target file `%s' has both : and :: entries"), f->name); 2128 2084 f = enter_file (name); 2129 /* If there was an existing entry and it was a double-colon 2130 ent ry, enter_file will have returned a new one, making it the2131 p rev pointer of the old one, and setting its double_colon2132 pointer tothe 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. */ 2133 2089 if (f->double_colon == 0) 2134 /* This is the first entry for this name, so we must 2135 set itsdouble_colon pointer to itself. */2090 /* This is the first entry for this name, so we must set its 2091 double_colon pointer to itself. */ 2136 2092 f->double_colon = f; 2137 2093 f->is_target = 1; … … 2140 2096 } 2141 2097 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 2142 2115 /* Free name if not needed further. */ 2143 2116 if (f != 0 && name != f->name … … 2149 2122 2150 2123 /* If this target is a default target, update DEFAULT_GOAL_FILE. */ 2151 if (str cmp (*default_goal_name, name) == 02124 if (streq (*default_goal_name, name) 2152 2125 && (default_goal_file == 0 2153 || strcmp (default_goal_file->name, name) != 0))2126 || ! streq (default_goal_file->name, name))) 2154 2127 default_goal_file = f; 2155 2128 } … … 2159 2132 targets[target_idx] = 0; 2160 2133 target_percents[target_idx] = 0; 2134 if (deps) 2135 deps->need_2nd_expansion = second_expansion; 2161 2136 create_pattern_rule (targets, target_percents, two_colon, deps, cmds, 1); 2162 2137 free ((char *) target_percents); … … 2169 2144 Quoting backslashes are removed from STRING by compacting it into 2170 2145 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 2151 static char * 2152 find_char_unquote (char *string, int stop1, int stop2, int blank, 2153 int ignorevars) 2175 2154 { 2176 2155 unsigned int string_len = 0; 2177 2156 register char *p = string; 2178 2157 2158 if (ignorevars) 2159 ignorevars = '$'; 2160 2179 2161 while (1) 2180 2162 { 2181 2163 if (stop2 && blank) 2182 while (*p != '\0' && *p != stop1 && *p != stop22164 while (*p != '\0' && *p != ignorevars && *p != stop1 && *p != stop2 2183 2165 && ! isblank ((unsigned char) *p)) 2184 2166 ++p; 2185 2167 else if (stop2) 2186 while (*p != '\0' && *p != stop1 && *p != stop2)2168 while (*p != '\0' && *p != ignorevars && *p != stop1 && *p != stop2) 2187 2169 ++p; 2188 2170 else if (blank) 2189 while (*p != '\0' && *p != stop12171 while (*p != '\0' && *p != ignorevars && *p != stop1 2190 2172 && ! isblank ((unsigned char) *p)) 2191 2173 ++p; 2192 2174 else 2193 while (*p != '\0' && *p != stop1)2175 while (*p != '\0' && *p != ignorevars && *p != stop1) 2194 2176 ++p; 2195 2177 2196 2178 if (*p == '\0') 2197 2179 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 } 2198 2211 2199 2212 if (p > string && p[-1] == '\\') … … 2232 2245 find_percent (char *pattern) 2233 2246 { 2234 return find_char_unquote (pattern, '%', 0, 0 );2247 return find_char_unquote (pattern, '%', 0, 0, 0); 2235 2248 } 2236 2249 … … 2252 2265 parse_file_seq (char **stringp, int stopchar, unsigned int size, int strip) 2253 2266 { 2254 registerstruct nameseq *new = 0;2255 registerstruct nameseq *new1, *lastnew1;2256 registerchar *p = *stringp;2267 struct nameseq *new = 0; 2268 struct nameseq *new1, *lastnew1; 2269 char *p = *stringp; 2257 2270 char *q; 2258 2271 char *name; … … 2275 2288 /* Yes, find end of next name. */ 2276 2289 q = p; 2277 p = find_char_unquote (q, stopchar, VMS_COMMA, 1 );2290 p = find_char_unquote (q, stopchar, VMS_COMMA, 1, 0); 2278 2291 #ifdef VMS 2279 2292 /* convert comma separated list to space separated */ … … 2286 2299 || isspace ((unsigned char)p[-1]))) 2287 2300 { 2288 p = find_char_unquote (p+1, stopchar, VMS_COMMA, 1 );2301 p = find_char_unquote (p+1, stopchar, VMS_COMMA, 1, 0); 2289 2302 } 2290 2303 #endif … … 2297 2310 while (p != 0 && !isspace ((unsigned char)*p) && 2298 2311 (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); 2300 2313 #endif 2301 2314 if (p == 0) … … 2907 2920 dirs[idx] = 0; 2908 2921 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. */ 2910 2924 2911 2925 max_incl_len = 0; … … 2920 2934 if (len > max_incl_len) 2921 2935 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); 2922 2940 } 2923 2941
Note:
See TracChangeset
for help on using the changeset viewer.