Changeset 503 for trunk/src/gmake/read.c
- Timestamp:
- Sep 15, 2006, 7:09:38 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gmake/read.c
r466 r503 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 … … 253 251 for (p = default_makefiles; *p != 0; ++p) 254 252 { 255 struct dep *d = (struct dep *) xmalloc (sizeof (struct dep)); 256 d->name = 0; 253 struct dep *d = alloc_dep (); 257 254 d->file = enter_file (*p); 258 255 d->file->dontcare = 1; 259 d->ignore_mtime = 0;260 d->need_2nd_expansion = 0;261 256 /* Tell update_goal_chain to bail out as soon as this file is 262 257 made, and main not to die if we can't make this file. */ … … 312 307 struct ebuffer ebuf; 313 308 const struct floc *curfile; 309 char *expanded = 0; 310 char *included = 0; 314 311 int makefile_errno; 315 312 int r; 316 313 317 ebuf.floc.filenm = filename;314 ebuf.floc.filenm = strcache_add (filename); 318 315 ebuf.floc.lineno = 1; 319 316 … … 338 335 if (!(flags & RM_NO_TILDE) && filename[0] == '~') 339 336 { 340 char *expanded = tilde_expand (filename);337 expanded = tilde_expand (filename); 341 338 if (expanded != 0) 342 339 filename = expanded; … … 355 352 for (i = 0; include_directories[i] != 0; ++i) 356 353 { 357 char *name = concat (include_directories[i], "/", filename); 358 ebuf.fp = fopen (name, "r"); 359 if (ebuf.fp == 0) 360 free (name); 361 else 354 included = concat (include_directories[i], "/", filename); 355 ebuf.fp = fopen (included, "r"); 356 if (ebuf.fp) 362 357 { 363 filename = name;358 filename = included; 364 359 break; 365 360 } 366 } 361 free (included); 362 } 363 /* If we're not using it, we already freed it above. */ 364 if (filename != included) 365 included = 0; 367 366 } 368 367 369 368 /* Add FILENAME to the chain of read makefiles. */ 370 deps = (struct dep *) xmalloc (sizeof (struct dep));369 deps = alloc_dep (); 371 370 deps->next = read_makefiles; 372 371 read_makefiles = deps; 373 deps->name = 0;374 372 deps->file = lookup_file (filename); 375 373 if (deps->file == 0) 376 374 deps->file = enter_file (xstrdup (filename)); 377 if (filename != ebuf.floc.filenm)378 free (filename);379 375 filename = deps->file->name; 380 376 deps->changed = flags; 381 deps->ignore_mtime = 0;382 deps->need_2nd_expansion = 0;383 377 if (flags & RM_DONTCARE) 384 378 deps->file->dontcare = 1; 379 380 if (expanded) 381 free (expanded); 382 if (included) 383 free (included); 385 384 386 385 /* If the makefile can't be found at all, give up entirely. */ … … 803 802 804 803 p = allocated_variable_expand (p2); 804 805 /* If no filenames, it's a no-op. */ 805 806 if (*p == '\0') 806 { 807 error (fstart, 808 _("no file name for `%sinclude'"), noerror ? "-" : ""); 809 continue; 810 } 807 { 808 free (p); 809 continue; 810 } 811 811 812 812 /* Parse the list of file names. */ … … 838 838 r = eval_makefile (name, (RM_INCLUDED | RM_NO_TILDE 839 839 | (noerror ? RM_DONTCARE : 0))); 840 if (!r) 841 { 842 if (!noerror) 843 error (fstart, "%s: %s", name, strerror (errno)); 844 free (name); 845 } 840 if (!r && !noerror) 841 error (fstart, "%s: %s", name, strerror (errno)); 842 free (name); 846 843 } 847 844 … … 888 885 /* Search the line for an unquoted ; that is not after an 889 886 unquoted #. */ 890 cmdleft = find_char_unquote (line, ';', '#', 0 );887 cmdleft = find_char_unquote (line, ';', '#', 0, 1); 891 888 if (cmdleft != 0 && *cmdleft == '#') 892 889 { … … 935 932 { 936 933 /* Look for a semicolon in the expanded line. */ 937 cmdleft = find_char_unquote (p2, ';', 0, 0 );934 cmdleft = find_char_unquote (p2, ';', 0, 0, 0); 938 935 939 936 if (cmdleft != 0) … … 962 959 } 963 960 964 colonp = find_char_unquote(p2, ':', 0, 0 );961 colonp = find_char_unquote(p2, ':', 0, 0, 0); 965 962 #ifdef HAVE_DOS_PATHS 966 963 /* The drive spec brain-damage strikes again... */ … … 971 968 colonp > p2 && isalpha ((unsigned char)colonp[-1]) && 972 969 (colonp == p2 + 1 || strchr (" \t(", colonp[-2]) != 0)) 973 colonp = find_char_unquote(colonp + 1, ':', 0, 0 );970 colonp = find_char_unquote(colonp + 1, ':', 0, 0, 0); 974 971 #endif 975 972 if (colonp != 0) … … 1085 1082 /* This is a normal target, _not_ a target-specific variable. 1086 1083 Unquote any = in the dependency list. */ 1087 find_char_unquote (lb_next, '=', 0, 0 );1084 find_char_unquote (lb_next, '=', 0, 0, 0); 1088 1085 1089 1086 /* We have some targets, so don't ignore the following commands. */ … … 1100 1097 if (cmdleft == 0) 1101 1098 { 1102 cmdleft = find_char_unquote (p2, ';', 0, 0 );1099 cmdleft = find_char_unquote (p2, ';', 0, 0, 0); 1103 1100 if (cmdleft != 0) 1104 1101 *(cmdleft++) = '\0'; … … 1165 1162 if (pattern_percent == 0) 1166 1163 fatal (fstart, _("target pattern contains no `%%' (target `%s')"), target->name); 1167 free ((char *)target);1164 free ((char *)target); 1168 1165 } 1169 1166 else … … 1177 1174 if (beg <= end && *beg != '\0') 1178 1175 { 1179 char *top; 1180 const char *fromp = beg; 1181 1182 /* Make a copy of the dependency string. Note if we find '$'. */ 1183 deps = (struct dep*) xmalloc (sizeof (struct dep)); 1184 deps->next = 0; 1185 deps->name = top = (char *) xmalloc (end - beg + 2); 1186 deps->need_2nd_expansion = 0; 1187 while (fromp <= end) 1188 { 1189 if (*fromp == '$') 1190 deps->need_2nd_expansion = 1; 1191 *(top++) = *(fromp++); 1192 } 1193 *top = '\0'; 1194 deps->file = 0; 1176 /* Put all the prerequisites here; they'll be parsed later. */ 1177 deps = alloc_dep (); 1178 deps->name = savestring (beg, end - beg + 1); 1195 1179 } 1196 1180 else … … 1319 1303 1320 1304 1305 /* Remove comments from LINE. 1306 This is done by copying the text at LINE onto itself. */ 1307 1308 static void 1309 remove_comments (char *line) 1310 { 1311 char *comment; 1312 1313 comment = find_char_unquote (line, '#', 0, 0, 0); 1314 1315 if (comment != 0) 1316 /* Cut off the line at the #. */ 1317 *comment = '\0'; 1318 } 1319 1321 1320 /* Execute a `define' directive. 1322 1321 The first line has already been read, and NAME is the name of … … 1839 1838 v->origin = origin; 1840 1839 v->per_target = 1; 1841 if (exported) 1842 v->export = v_export; 1840 v->export = exported ? v_export : v_default; 1843 1841 1844 1842 /* If it's not an override, check to see if there was a command-line … … 1913 1911 char *name = filenames->name; 1914 1912 struct file *f; 1915 struct dep *d; 1916 struct dep *this; 1913 struct dep *this = 0; 1917 1914 char *implicit_percent; 1918 1915 … … 1920 1917 free (filenames); 1921 1918 1922 /* Check for .POSIX. We used to do this in snap_deps() but that's not 1923 good enough: it doesn't happen until after the makefile is read, 1924 which means we cannot use its value during parsing. */ 1919 /* Check for special targets. Do it here instead of, say, snap_deps() 1920 so that we can immediately use the value. */ 1925 1921 1926 1922 if (streq (name, ".POSIX")) 1927 1923 posix_pedantic = 1; 1924 else if (streq (name, ".SECONDEXPANSION")) 1925 second_expansion = 1; 1928 1926 1929 1927 implicit_percent = find_percent (name); … … 1960 1958 } 1961 1959 1962 /* If there are multiple filenames, copy the chain DEPS 1963 for all but the last one. It is not safe for the same deps 1964 to go in more than one place in the database. */ 1965 this = nextf != 0 ? copy_dep_chain (deps) : deps; 1966 1967 if (pattern != 0) 1968 { 1969 /* If this is an extended static rule: 1970 `targets: target%pattern: dep%pattern; cmds', 1971 translate each dependency pattern into a plain filename 1972 using the target pattern and this target's name. */ 1973 if (!pattern_matches (pattern, pattern_percent, name)) 1974 { 1975 /* Give a warning if the rule is meaningless. */ 1976 error (flocp, 1977 _("target `%s' doesn't match the target pattern"), name); 1978 this = 0; 1979 } 1980 else 1981 /* We use subst_expand to do the work of translating % to $* in 1982 the dependency line. */ 1983 1984 if (this != 0 && find_percent (this->name) != 0) 1985 { 1986 char *o; 1987 char *buffer = variable_expand (""); 1988 1989 o = subst_expand (buffer, this->name, "%", "$*", 1, 2, 0); 1990 1991 free (this->name); 1992 this->name = savestring (buffer, o - buffer); 1993 this->need_2nd_expansion = 1; 1994 } 1995 } 1960 /* If this is a static pattern rule: 1961 `targets: target%pattern: dep%pattern; cmds', 1962 make sure the pattern matches this target name. */ 1963 if (pattern && !pattern_matches (pattern, pattern_percent, name)) 1964 error (flocp, _("target `%s' doesn't match the target pattern"), name); 1965 else if (deps) 1966 { 1967 /* If there are multiple filenames, copy the chain DEPS for all but 1968 the last one. It is not safe for the same deps to go in more 1969 than one place in the database. */ 1970 this = nextf != 0 ? copy_dep_chain (deps) : deps; 1971 this->need_2nd_expansion = (second_expansion 1972 && strchr (this->name, '$')); 1973 } 1996 1974 1997 1975 if (!two_colon) … … 2033 2011 f->cmds = cmds; 2034 2012 2035 /* Defining .SUFFIXES with no dependencies 2036 clears out the list ofsuffixes. */2013 /* Defining .SUFFIXES with no dependencies clears out the list of 2014 suffixes. */ 2037 2015 if (f == suffix_file && this == 0) 2038 2016 { 2039 d = f->deps; 2040 while (d != 0) 2041 { 2042 struct dep *nextd = d->next; 2043 free (d->name); 2044 free ((char *)d); 2045 d = nextd; 2046 } 2017 free_dep_chain (f->deps); 2047 2018 f->deps = 0; 2048 2019 } … … 2059 2030 2060 2031 if (cmds != 0) 2061 { 2062 /* This is the rule with commands, so put its deps 2063 last. The rationale behind this is that $< expands 2064 to the first dep in the chain, and commands use $< 2065 expecting to get the dep that rule specifies. 2066 However the second expansion algorithm reverses 2067 the order thus we need to make it last here. */ 2068 2069 (*d_ptr)->next = this; 2070 } 2032 /* This is the rule with commands, so put its deps 2033 last. The rationale behind this is that $< expands to 2034 the first dep in the chain, and commands use $< 2035 expecting to get the dep that rule specifies. However 2036 the second expansion algorithm reverses the order thus 2037 we need to make it last here. */ 2038 (*d_ptr)->next = this; 2071 2039 else 2072 2040 { 2073 2041 /* This is the rule without commands. Put its 2074 dependencies at the end but before dependencies 2075 from the rule with commands (if any). This way2076 everythingappears in makefile order. */2042 dependencies at the end but before dependencies from 2043 the rule with commands (if any). This way everything 2044 appears in makefile order. */ 2077 2045 2078 2046 if (f->cmds != 0) … … 2104 2072 f->updating = 1; 2105 2073 } 2106 2107 /* If this is a static pattern rule, set the file's stem to2108 the part of its name that matched the `%' in the pattern,2109 so you can use $* in the commands. */2110 if (pattern != 0)2111 {2112 static char *percent = "%";2113 char *buffer = variable_expand ("");2114 char *o = patsubst_expand (buffer, name, pattern, percent,2115 pattern_percent+1, percent+1);2116 f->stem = savestring (buffer, o - buffer);2117 }2118 2074 } 2119 2075 else 2120 2076 { 2121 /* Double-colon. Make a new record 2122 even if the file already has one. */ 2077 /* Double-colon. Make a new record even if there already is one. */ 2123 2078 f = lookup_file (name); 2079 2124 2080 /* Check for both : and :: rules. Check is_target so 2125 2081 we don't lose on default suffix rules or makefiles. */ … … 2128 2084 _("target file `%s' has both : and :: entries"), f->name); 2129 2085 f = enter_file (name); 2130 /* If there was an existing entry and it was a double-colon 2131 ent ry, enter_file will have returned a new one, making it the2132 p rev pointer of the old one, and setting its double_colon2133 pointer tothe first one. */2086 /* If there was an existing entry and it was a double-colon entry, 2087 enter_file will have returned a new one, making it the prev 2088 pointer of the old one, and setting its double_colon pointer to 2089 the first one. */ 2134 2090 if (f->double_colon == 0) 2135 /* This is the first entry for this name, so we must 2136 set itsdouble_colon pointer to itself. */2091 /* This is the first entry for this name, so we must set its 2092 double_colon pointer to itself. */ 2137 2093 f->double_colon = f; 2138 2094 f->is_target = 1; … … 2141 2097 } 2142 2098 2099 /* If this is a static pattern rule, set the stem to the part of its 2100 name that matched the `%' in the pattern, so you can use $* in the 2101 commands. */ 2102 if (pattern) 2103 { 2104 static char *percent = "%"; 2105 char *buffer = variable_expand (""); 2106 char *o = patsubst_expand (buffer, name, pattern, percent, 2107 pattern_percent+1, percent+1); 2108 f->stem = savestring (buffer, o - buffer); 2109 if (this) 2110 { 2111 this->staticpattern = 1; 2112 this->stem = xstrdup (f->stem); 2113 } 2114 } 2115 2143 2116 /* Free name if not needed further. */ 2144 2117 if (f != 0 && name != f->name … … 2150 2123 2151 2124 /* If this target is a default target, update DEFAULT_GOAL_FILE. */ 2152 if (str cmp (*default_goal_name, name) == 02125 if (streq (*default_goal_name, name) 2153 2126 && (default_goal_file == 0 2154 || strcmp (default_goal_file->name, name) != 0))2127 || ! streq (default_goal_file->name, name))) 2155 2128 default_goal_file = f; 2156 2129 } … … 2160 2133 targets[target_idx] = 0; 2161 2134 target_percents[target_idx] = 0; 2135 if (deps) 2136 deps->need_2nd_expansion = second_expansion; 2162 2137 create_pattern_rule (targets, target_percents, two_colon, deps, cmds, 1); 2163 2138 free ((char *) target_percents); … … 2170 2145 Quoting backslashes are removed from STRING by compacting it into 2171 2146 itself. Returns a pointer to the first unquoted STOPCHAR if there is 2172 one, or nil if there are none. */ 2173 2174 char * 2175 find_char_unquote (char *string, int stop1, int stop2, int blank) 2147 one, or nil if there are none. STOPCHARs inside variable references are 2148 ignored if IGNOREVARS is true. 2149 2150 STOPCHAR _cannot_ be '$' if IGNOREVARS is true. */ 2151 2152 static char * 2153 find_char_unquote (char *string, int stop1, int stop2, int blank, 2154 int ignorevars) 2176 2155 { 2177 2156 unsigned int string_len = 0; 2178 2157 register char *p = string; 2179 register int ch; 2158 register int ch; /* bird */ 2159 2160 if (ignorevars) 2161 ignorevars = '$'; 2180 2162 2181 2163 while (1) 2182 2164 { 2183 2165 if (stop2 && blank) 2184 while ((ch = *p) != '\0' && ch != stop1 && ch != stop22166 while ((ch = *p) != '\0' && ch != ignorevars && ch != stop1 && ch != stop2 2185 2167 && ! isblank ((unsigned char) ch)) 2186 2168 ++p; 2187 2169 else if (stop2) 2188 while ((ch = *p) != '\0' && ch != stop1 && ch != stop2)2170 while ((ch = *p) != '\0' && ch != ignorevars && ch != stop1 && ch != stop2) 2189 2171 ++p; 2190 2172 else if (blank) 2191 while ((ch = *p) != '\0' && ch != stop12173 while ((ch = *p) != '\0' && ch != ignorevars && ch != stop1 2192 2174 && ! isblank ((unsigned char) ch)) 2193 2175 ++p; 2194 2176 else 2195 while ((ch = *p) != '\0' && ch != stop1)2177 while ((ch = *p) != '\0' && ch != ignorevars && ch != stop1) 2196 2178 ++p; 2197 2179 2198 2180 if (ch == '\0') 2199 2181 break; 2182 2183 /* If we stopped due to a variable reference, skip over its contents. */ 2184 if (ch == ignorevars) 2185 { 2186 char openparen = p[1]; 2187 2188 p += 2; 2189 2190 /* Skip the contents of a non-quoted, multi-char variable ref. */ 2191 if (openparen == '(' || openparen == '{') 2192 { 2193 unsigned int pcount = 1; 2194 char closeparen = (openparen == '(' ? ')' : '}'); 2195 2196 while ((ch = *p)) 2197 { 2198 if (ch == openparen) 2199 ++pcount; 2200 else if (ch == closeparen) 2201 if (--pcount == 0) 2202 { 2203 ++p; 2204 break; 2205 } 2206 ++p; 2207 } 2208 } 2209 2210 /* Skipped the variable reference: look for STOPCHARS again. */ 2211 continue; 2212 } 2200 2213 2201 2214 if (p > string && p[-1] == '\\') … … 2234 2247 find_percent (char *pattern) 2235 2248 { 2236 return find_char_unquote (pattern, '%', 0, 0 );2249 return find_char_unquote (pattern, '%', 0, 0, 0); 2237 2250 } 2238 2251 … … 2254 2267 parse_file_seq (char **stringp, int stopchar, unsigned int size, int strip) 2255 2268 { 2256 registerstruct nameseq *new = 0;2257 registerstruct nameseq *new1, *lastnew1;2258 registerchar *p = *stringp;2269 struct nameseq *new = 0; 2270 struct nameseq *new1, *lastnew1; 2271 char *p = *stringp; 2259 2272 char *q; 2260 2273 char *name; … … 2277 2290 /* Yes, find end of next name. */ 2278 2291 q = p; 2279 p = find_char_unquote (q, stopchar, VMS_COMMA, 1 );2292 p = find_char_unquote (q, stopchar, VMS_COMMA, 1, 0); 2280 2293 #ifdef VMS 2281 2294 /* convert comma separated list to space separated */ … … 2288 2301 || isspace ((unsigned char)p[-1]))) 2289 2302 { 2290 p = find_char_unquote (p+1, stopchar, VMS_COMMA, 1 );2303 p = find_char_unquote (p+1, stopchar, VMS_COMMA, 1, 0); 2291 2304 } 2292 2305 #endif … … 2299 2312 while (p != 0 && !isspace ((unsigned char)*p) && 2300 2313 (p[1] == '\\' || p[1] == '/') && isalpha ((unsigned char)p[-1])) 2301 p = find_char_unquote (p + 1, stopchar, VMS_COMMA, 1 );2314 p = find_char_unquote (p + 1, stopchar, VMS_COMMA, 1, 0); 2302 2315 #endif 2303 2316 if (p == 0) … … 2909 2922 dirs[idx] = 0; 2910 2923 2911 /* Now compute the maximum length of any name in it. */ 2924 /* Now compute the maximum length of any name in it. Also add each 2925 dir to the .INCLUDE_DIRS variable. */ 2912 2926 2913 2927 max_incl_len = 0; … … 2922 2936 if (len > max_incl_len) 2923 2937 max_incl_len = len; 2938 2939 /* Append to .INCLUDE_DIRS. */ 2940 do_variable_definition (NILF, ".INCLUDE_DIRS", dirs[i], 2941 o_default, f_append, 0); 2924 2942 } 2925 2943
Note:
See TracChangeset
for help on using the changeset viewer.