[53] | 1 | /* Reading and parsing of makefiles for GNU Make.
|
---|
[3140] | 2 | Copyright (C) 1988-2016 Free Software Foundation, Inc.
|
---|
[53] | 3 | This file is part of GNU Make.
|
---|
| 4 |
|
---|
[503] | 5 | GNU Make is free software; you can redistribute it and/or modify it under the
|
---|
| 6 | terms of the GNU General Public License as published by the Free Software
|
---|
[1993] | 7 | Foundation; either version 3 of the License, or (at your option) any later
|
---|
| 8 | version.
|
---|
[53] | 9 |
|
---|
[503] | 10 | GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
|
---|
| 11 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
---|
| 12 | A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
---|
[53] | 13 |
|
---|
[503] | 14 | You should have received a copy of the GNU General Public License along with
|
---|
[1993] | 15 | this program. If not, see <http://www.gnu.org/licenses/>. */
|
---|
[53] | 16 |
|
---|
[3140] | 17 | #include "makeint.h"
|
---|
[53] | 18 |
|
---|
| 19 | #include <assert.h>
|
---|
| 20 |
|
---|
[3140] | 21 | #include "filedef.h"
|
---|
[53] | 22 | #include "dep.h"
|
---|
| 23 | #include "job.h"
|
---|
| 24 | #include "commands.h"
|
---|
| 25 | #include "variable.h"
|
---|
| 26 | #include "rule.h"
|
---|
| 27 | #include "debug.h"
|
---|
| 28 | #include "hash.h"
|
---|
[917] | 29 | #ifdef KMK
|
---|
| 30 | # include "kbuild.h"
|
---|
| 31 | #endif
|
---|
[53] | 32 |
|
---|
[3140] | 33 | #ifdef WINDOWS32
|
---|
| 34 | #include <windows.h>
|
---|
[3156] | 35 | # ifndef _MSC_VER
|
---|
| 36 | # ifndef CONFIG_NEW_WIN_CHILDREN
|
---|
| 37 | # include "sub_proc.h"
|
---|
| 38 | # else
|
---|
| 39 | # include "w32/winchildren.h"
|
---|
| 40 | # endif
|
---|
| 41 | # endif
|
---|
[3140] | 42 | #else /* !WINDOWS32 */
|
---|
[53] | 43 | #ifndef _AMIGA
|
---|
| 44 | #ifndef VMS
|
---|
| 45 | #include <pwd.h>
|
---|
| 46 | #else
|
---|
[903] | 47 | struct passwd *getpwnam (char *name);
|
---|
[53] | 48 | #endif
|
---|
| 49 | #endif
|
---|
| 50 | #endif /* !WINDOWS32 */
|
---|
| 51 |
|
---|
| 52 | /* A 'struct ebuffer' controls the origin of the makefile we are currently
|
---|
| 53 | eval'ing.
|
---|
| 54 | */
|
---|
| 55 |
|
---|
| 56 | struct ebuffer
|
---|
| 57 | {
|
---|
| 58 | char *buffer; /* Start of the current line in the buffer. */
|
---|
| 59 | char *bufnext; /* Start of the next line in the buffer. */
|
---|
| 60 | char *bufstart; /* Start of the entire buffer. */
|
---|
[1811] | 61 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
| 62 | char *eol; /* End of the current line in the buffer. */
|
---|
| 63 | #endif
|
---|
[53] | 64 | unsigned int size; /* Malloc'd size of buffer. */
|
---|
| 65 | FILE *fp; /* File, or NULL if this is an internal buffer. */
|
---|
[3140] | 66 | floc floc; /* Info on the file in fp (if any). */
|
---|
[53] | 67 | };
|
---|
| 68 |
|
---|
[2591] | 69 | /* Track the modifiers we can have on variable assignments */
|
---|
| 70 |
|
---|
| 71 | struct vmodifiers
|
---|
| 72 | {
|
---|
| 73 | unsigned int assign_v:1;
|
---|
| 74 | unsigned int define_v:1;
|
---|
| 75 | unsigned int undefine_v:1;
|
---|
| 76 | unsigned int export_v:1;
|
---|
| 77 | unsigned int override_v:1;
|
---|
| 78 | unsigned int private_v:1;
|
---|
| 79 | };
|
---|
| 80 |
|
---|
[53] | 81 | /* Types of "words" that can be read in a makefile. */
|
---|
| 82 | enum make_word_type
|
---|
| 83 | {
|
---|
| 84 | w_bogus, w_eol, w_static, w_variable, w_colon, w_dcolon, w_semicolon,
|
---|
| 85 | w_varassign
|
---|
| 86 | };
|
---|
| 87 |
|
---|
| 88 |
|
---|
[3140] | 89 | /* A 'struct conditionals' contains the information describing
|
---|
[53] | 90 | all the active conditionals in a makefile.
|
---|
| 91 |
|
---|
[3140] | 92 | The global variable 'conditionals' contains the conditionals
|
---|
[53] | 93 | information for the current makefile. It is initialized from
|
---|
[3140] | 94 | the static structure 'toplevel_conditionals' and is later changed
|
---|
[53] | 95 | to new structures for included makefiles. */
|
---|
| 96 |
|
---|
| 97 | struct conditionals
|
---|
| 98 | {
|
---|
[3140] | 99 | unsigned int if_cmds; /* Depth of conditional nesting. */
|
---|
| 100 | unsigned int allocated; /* Elts allocated in following arrays. */
|
---|
| 101 | char *ignoring; /* Are we ignoring or interpreting?
|
---|
[287] | 102 | 0=interpreting, 1=not yet interpreted,
|
---|
| 103 | 2=already interpreted */
|
---|
[3140] | 104 | char *seen_else; /* Have we already seen an 'else'? */
|
---|
[1929] | 105 | #ifdef KMK
|
---|
| 106 | char ignoring_first[8];
|
---|
| 107 | char seen_else_first[8];
|
---|
| 108 | #endif
|
---|
[53] | 109 | };
|
---|
| 110 |
|
---|
[1929] | 111 | #ifdef KMK
|
---|
| 112 | static struct conditionals toplevel_conditionals =
|
---|
| 113 | {
|
---|
| 114 | 0,
|
---|
| 115 | sizeof (toplevel_conditionals.ignoring_first),
|
---|
| 116 | &toplevel_conditionals.ignoring_first[0],
|
---|
| 117 | &toplevel_conditionals.seen_else_first[0],
|
---|
| 118 | "", ""
|
---|
| 119 | };
|
---|
| 120 | #else /* !KMK */
|
---|
[53] | 121 | static struct conditionals toplevel_conditionals;
|
---|
[1929] | 122 | #endif /* !KMK */
|
---|
[53] | 123 | static struct conditionals *conditionals = &toplevel_conditionals;
|
---|
| 124 |
|
---|
| 125 |
|
---|
| 126 | /* Default directories to search for include files in */
|
---|
| 127 |
|
---|
[903] | 128 | static const char *default_include_directories[] =
|
---|
[53] | 129 | {
|
---|
[917] | 130 | #ifndef KMK
|
---|
[53] | 131 | #if defined(WINDOWS32) && !defined(INCLUDEDIR)
|
---|
[903] | 132 | /* This completely up to the user when they install MSVC or other packages.
|
---|
| 133 | This is defined as a placeholder. */
|
---|
| 134 | # define INCLUDEDIR "."
|
---|
[53] | 135 | #endif
|
---|
[919] | 136 | # ifdef INCLUDEDIR /* bird */
|
---|
[53] | 137 | INCLUDEDIR,
|
---|
[919] | 138 | # else /* bird */
|
---|
| 139 | ".", /* bird */
|
---|
| 140 | # endif /* bird */
|
---|
[53] | 141 | #ifndef _AMIGA
|
---|
| 142 | "/usr/gnu/include",
|
---|
| 143 | "/usr/local/include",
|
---|
| 144 | "/usr/include",
|
---|
| 145 | #endif
|
---|
[917] | 146 | #endif /* !KMK */
|
---|
[53] | 147 | 0
|
---|
| 148 | };
|
---|
| 149 |
|
---|
| 150 | /* List of directories to search for include files in */
|
---|
| 151 |
|
---|
[903] | 152 | static const char **include_directories;
|
---|
[53] | 153 |
|
---|
| 154 | /* Maximum length of an element of the above. */
|
---|
| 155 |
|
---|
| 156 | static unsigned int max_incl_len;
|
---|
| 157 |
|
---|
| 158 | /* The filename and pointer to line number of the
|
---|
| 159 | makefile currently being read in. */
|
---|
| 160 |
|
---|
[3140] | 161 | const floc *reading_file = 0;
|
---|
[53] | 162 |
|
---|
[3140] | 163 | /* The chain of files read by read_all_makefiles. */
|
---|
[53] | 164 |
|
---|
[3140] | 165 | static struct goaldep *read_files = 0;
|
---|
[53] | 166 |
|
---|
[3140] | 167 | static struct goaldep *eval_makefile (const char *filename, int flags);
|
---|
[2591] | 168 | static void eval (struct ebuffer *buffer, int flags);
|
---|
[53] | 169 |
|
---|
[903] | 170 | static long readline (struct ebuffer *ebuf);
|
---|
[2591] | 171 | static void do_undefine (char *name, enum variable_origin origin,
|
---|
| 172 | struct ebuffer *ebuf);
|
---|
| 173 | static struct variable *do_define (char *name IF_WITH_VALUE_LENGTH_PARAM(char *eos),
|
---|
| 174 | enum variable_origin origin, struct ebuffer *ebuf);
|
---|
[1817] | 175 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
[3140] | 176 | static int conditional_line (char *line, int len, const floc *flocp);
|
---|
[1817] | 177 | #else
|
---|
[3140] | 178 | static int conditional_line (char *line, char *eol, int len, const floc *flocp);
|
---|
[1817] | 179 | #endif
|
---|
[903] | 180 | static void record_files (struct nameseq *filenames, const char *pattern,
|
---|
[2591] | 181 | const char *pattern_percent, char *depstr,
|
---|
[903] | 182 | unsigned int cmds_started, char *commands,
|
---|
| 183 | unsigned int commands_idx, int two_colon,
|
---|
[3140] | 184 | char prefix, const floc *flocp);
|
---|
[903] | 185 | static void record_target_var (struct nameseq *filenames, char *defn,
|
---|
[2591] | 186 | enum variable_origin origin,
|
---|
| 187 | struct vmodifiers *vmod,
|
---|
[3140] | 188 | const floc *flocp);
|
---|
[903] | 189 | static enum make_word_type get_next_mword (char *buffer, char *delim,
|
---|
| 190 | char **startp, unsigned int *length);
|
---|
[1811] | 191 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
[903] | 192 | static void remove_comments (char *line);
|
---|
[3140] | 193 | static char *find_char_unquote (char *string, int map);
|
---|
| 194 | #else /* CONFIG_WITH_VALUE_LENGTH */
|
---|
| 195 | static char *remove_comments (char *line, char *eos);
|
---|
| 196 | static char *find_char_unquote (char *string, int map, unsigned int string_len);
|
---|
| 197 | K_INLINE char *find_char_unquote_0 (char *string, int stop1, int map, char **eosp);
|
---|
[1980] | 198 | #endif /* CONFIG_WITH_VALUE_LENGTH */
|
---|
[3140] | 199 | static char *unescape_char (char *string, int c);
|
---|
[2591] | 200 |
|
---|
| 201 |
|
---|
| 202 | /* Compare a word, both length and contents.
|
---|
| 203 | P must point to the word to be tested, and WLEN must be the length.
|
---|
| 204 | */
|
---|
[3140] | 205 | #define word1eq(s) (wlen == CSTRLEN (s) && strneq (s, p, CSTRLEN (s)))
|
---|
[2591] | 206 |
|
---|
[53] | 207 | |
---|
[3140] | 208 |
|
---|
[53] | 209 | /* Read in all the makefiles and return a chain of targets to rebuild. */
|
---|
[3140] | 210 |
|
---|
[903] | 211 | struct goaldep *
|
---|
[53] | 212 | read_all_makefiles (const char **makefiles)
|
---|
| 213 | {
|
---|
| 214 | unsigned int num_makefiles = 0;
|
---|
| 215 |
|
---|
| 216 | /* Create *_LIST variables, to hold the makefiles, targets, and variables
|
---|
| 217 | we will be reading. */
|
---|
[2591] | 218 |
|
---|
[53] | 219 | define_variable_cname ("MAKEFILE_LIST", "", o_file, 0);
|
---|
| 220 |
|
---|
| 221 | DB (DB_BASIC, (_("Reading makefiles...\n")));
|
---|
| 222 |
|
---|
| 223 | /* If there's a non-null variable MAKEFILES, its value is a list of
|
---|
| 224 | files to read first thing. But don't let it prevent reading the
|
---|
| 225 | default makefiles and don't let the default goal come from there. */
|
---|
| 226 |
|
---|
| 227 | {
|
---|
| 228 | char *value;
|
---|
| 229 | char *name, *p;
|
---|
| 230 | unsigned int length;
|
---|
| 231 |
|
---|
| 232 | {
|
---|
| 233 | /* Turn off --warn-undefined-variables while we expand MAKEFILES. */
|
---|
| 234 | int save = warn_undefined_variables_flag;
|
---|
| 235 | warn_undefined_variables_flag = 0;
|
---|
[1817] | 236 |
|
---|
[53] | 237 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
[1817] | 238 | value = allocated_variable_expand ("$(MAKEFILES)");
|
---|
| 239 | #else
|
---|
| 240 | value = allocated_variable_expand_2 (STRING_SIZE_TUPLE("$(MAKEFILES)"), NULL);
|
---|
[53] | 241 | #endif
|
---|
| 242 |
|
---|
| 243 | warn_undefined_variables_flag = save;
|
---|
| 244 | }
|
---|
| 245 |
|
---|
| 246 | /* Set NAME to the start of next token and LENGTH to its length.
|
---|
| 247 | MAKEFILES is updated for finding remaining tokens. */
|
---|
| 248 | p = value;
|
---|
[903] | 249 |
|
---|
[53] | 250 | while ((name = find_next_token ((const char **)&p, &length)) != 0)
|
---|
[3140] | 251 | {
|
---|
| 252 | if (*p != '\0')
|
---|
| 253 | *p++ = '\0';
|
---|
[53] | 254 | eval_makefile (name, RM_NO_DEFAULT_GOAL|RM_INCLUDED|RM_DONTCARE);
|
---|
| 255 | }
|
---|
| 256 |
|
---|
| 257 | free (value);
|
---|
| 258 | }
|
---|
| 259 |
|
---|
| 260 | /* Read makefiles specified with -f switches. */
|
---|
| 261 |
|
---|
| 262 | if (makefiles != 0)
|
---|
| 263 | while (*makefiles != 0)
|
---|
[3140] | 264 | {
|
---|
[53] | 265 | struct goaldep *d = eval_makefile (*makefiles, 0);
|
---|
[3140] | 266 |
|
---|
| 267 | if (errno)
|
---|
[53] | 268 | perror_with_name ("", *makefiles);
|
---|
[3140] | 269 |
|
---|
| 270 | /* Reuse the storage allocated for the read_file. */
|
---|
| 271 | *makefiles = dep_name (d);
|
---|
| 272 | ++num_makefiles;
|
---|
[53] | 273 | ++makefiles;
|
---|
| 274 | }
|
---|
| 275 |
|
---|
| 276 | /* If there were no -f switches, try the default names. */
|
---|
| 277 |
|
---|
| 278 | if (num_makefiles == 0)
|
---|
[3140] | 279 | {
|
---|
[53] | 280 | static const char *default_makefiles[] =
|
---|
[3140] | 281 | #ifdef VMS
|
---|
| 282 | /* all lower case since readdir() (the vms version) 'lowercasifies' */
|
---|
[520] | 283 | /* TODO: Above is not always true, this needs more work */
|
---|
[3140] | 284 | # ifdef KMK
|
---|
[520] | 285 | { "makefile.kmk", "makefile.vms", "gnumakefile.", "makefile.", 0 };
|
---|
[3140] | 286 | # else
|
---|
[903] | 287 | { "makefile.vms", "gnumakefile", "makefile", 0 };
|
---|
[53] | 288 | # endif
|
---|
| 289 | #else
|
---|
[520] | 290 | #ifdef _AMIGA
|
---|
[3140] | 291 | # ifdef KMK
|
---|
[520] | 292 | { "Makefile.kmk", "makefile.kmk", "GNUmakefile", "Makefile", "SMakefile", 0 };
|
---|
[3140] | 293 | # else
|
---|
[520] | 294 | { "GNUmakefile", "Makefile", "SMakefile", 0 };
|
---|
[53] | 295 | # endif
|
---|
[3140] | 296 | #else /* !Amiga && !VMS */
|
---|
[520] | 297 | #ifdef WINDOWS32
|
---|
[3140] | 298 | # ifdef KMK
|
---|
[520] | 299 | { "Makefile.kmk", "makefile.kmk", "GNUmakefile", "makefile", "Makefile", "makefile.mak", 0 };
|
---|
[3140] | 300 | # else
|
---|
| 301 | { "GNUmakefile", "makefile", "Makefile", "makefile.mak", 0 };
|
---|
| 302 | # endif
|
---|
| 303 | #else /* !Amiga && !VMS && !WINDOWS32 */
|
---|
| 304 | # ifdef KMK
|
---|
| 305 | { "Makefile.kmk", "makefile.kmk", "GNUmakefile", "makefile", "Makefile", 0 };
|
---|
| 306 | # else
|
---|
[520] | 307 | { "GNUmakefile", "makefile", "Makefile", 0 };
|
---|
[3140] | 308 | # endif
|
---|
[53] | 309 | #endif /* !Amiga && !VMS && !WINDOWS32 */
|
---|
| 310 | #endif /* AMIGA */
|
---|
[3140] | 311 | #endif /* VMS */
|
---|
[53] | 312 | const char **p = default_makefiles;
|
---|
[3140] | 313 | while (*p != 0 && !file_exists_p (*p))
|
---|
[53] | 314 | ++p;
|
---|
| 315 |
|
---|
[3140] | 316 | if (*p != 0)
|
---|
| 317 | {
|
---|
| 318 | eval_makefile (*p, 0);
|
---|
| 319 | if (errno)
|
---|
| 320 | perror_with_name ("", *p);
|
---|
[53] | 321 | }
|
---|
[3140] | 322 | else
|
---|
| 323 | {
|
---|
| 324 | /* No default makefile was found. Add the default makefiles to the
|
---|
| 325 | 'read_files' chain so they will be updated if possible. */
|
---|
| 326 | struct goaldep *tail = read_files;
|
---|
| 327 | /* Add them to the tail, after any MAKEFILES variable makefiles. */
|
---|
| 328 | while (tail != 0 && tail->next != 0)
|
---|
| 329 | tail = tail->next;
|
---|
| 330 | for (p = default_makefiles; *p != 0; ++p)
|
---|
| 331 | {
|
---|
| 332 | struct goaldep *d = alloc_goaldep ();
|
---|
| 333 | d->file = enter_file (strcache_add (*p));
|
---|
| 334 | /* Tell update_goal_chain to bail out as soon as this file is
|
---|
| 335 | made, and main not to die if we can't make this file. */
|
---|
| 336 | d->flags = RM_DONTCARE;
|
---|
| 337 | if (tail == 0)
|
---|
| 338 | read_files = d;
|
---|
| 339 | else
|
---|
| 340 | tail->next = d;
|
---|
| 341 | tail = d;
|
---|
| 342 | }
|
---|
| 343 | if (tail != 0)
|
---|
| 344 | tail->next = 0;
|
---|
[53] | 345 | }
|
---|
| 346 | }
|
---|
[3140] | 347 |
|
---|
[53] | 348 | return read_files;
|
---|
| 349 | }
|
---|
| 350 | |
---|
| 351 |
|
---|
| 352 | /* Install a new conditional and return the previous one. */
|
---|
| 353 |
|
---|
| 354 | static struct conditionals *
|
---|
| 355 | install_conditionals (struct conditionals *new)
|
---|
| 356 | {
|
---|
[1929] | 357 | struct conditionals *save = conditionals;
|
---|
[903] | 358 |
|
---|
[1929] | 359 | #ifndef KMK
|
---|
| 360 | memset (new, '\0', sizeof (*new));
|
---|
| 361 | #else /* KMK */
|
---|
| 362 | new->if_cmds = 0;
|
---|
| 363 | new->allocated = sizeof (new->ignoring_first);
|
---|
| 364 | new->ignoring = new->ignoring_first;
|
---|
[53] | 365 | new->seen_else = new->seen_else_first;
|
---|
| 366 | #endif /* KMK */
|
---|
| 367 | conditionals = new;
|
---|
| 368 |
|
---|
| 369 | return save;
|
---|
| 370 | }
|
---|
| 371 |
|
---|
| 372 | /* Free the current conditionals and reinstate a saved one. */
|
---|
| 373 |
|
---|
| 374 | static void
|
---|
| 375 | restore_conditionals (struct conditionals *saved)
|
---|
[1929] | 376 | {
|
---|
[3140] | 377 | /* Free any space allocated by conditional_line. */
|
---|
| 378 | #ifdef KMK
|
---|
[1929] | 379 | if (conditionals->allocated > sizeof (conditionals->ignoring_first))
|
---|
[3140] | 380 | {
|
---|
| 381 | #endif
|
---|
| 382 | free (conditionals->ignoring);
|
---|
| 383 | free (conditionals->seen_else);
|
---|
| 384 | #ifdef KMK
|
---|
[53] | 385 | }
|
---|
| 386 | #endif
|
---|
| 387 |
|
---|
| 388 | /* Restore state. */
|
---|
| 389 | conditionals = saved;
|
---|
[3140] | 390 | }
|
---|
[903] | 391 | |
---|
[53] | 392 |
|
---|
[3140] | 393 | static struct goaldep *
|
---|
[53] | 394 | eval_makefile (const char *filename, int flags)
|
---|
[3140] | 395 | {
|
---|
[503] | 396 | struct goaldep *deps;
|
---|
[53] | 397 | struct ebuffer ebuf;
|
---|
| 398 | const floc *curfile;
|
---|
[3140] | 399 | char *expanded = 0;
|
---|
[53] | 400 | int makefile_errno;
|
---|
[3140] | 401 |
|
---|
[53] | 402 | ebuf.floc.filenm = filename; /* Use the original file name. */
|
---|
| 403 | ebuf.floc.lineno = 1;
|
---|
| 404 | ebuf.floc.offset = 0;
|
---|
[3140] | 405 |
|
---|
[53] | 406 | if (ISDB (DB_VERBOSE))
|
---|
[3140] | 407 | {
|
---|
[53] | 408 | printf (_("Reading makefile '%s'"), filename);
|
---|
[3140] | 409 | if (flags & RM_NO_DEFAULT_GOAL)
|
---|
[53] | 410 | printf (_(" (no default goal)"));
|
---|
[3140] | 411 | if (flags & RM_INCLUDED)
|
---|
[53] | 412 | printf (_(" (search path)"));
|
---|
[3140] | 413 | if (flags & RM_DONTCARE)
|
---|
[53] | 414 | printf (_(" (don't care)"));
|
---|
| 415 | if (flags & RM_NO_TILDE)
|
---|
| 416 | printf (_(" (no ~ expansion)"));
|
---|
| 417 | puts ("...");
|
---|
| 418 | }
|
---|
[3140] | 419 |
|
---|
[53] | 420 | /* First, get a stream to read. */
|
---|
| 421 |
|
---|
| 422 | /* Expand ~ in FILENAME unless it came from 'include',
|
---|
[503] | 423 | in which case it was already done. */
|
---|
[53] | 424 | if (!(flags & RM_NO_TILDE) && filename[0] == '~')
|
---|
[3140] | 425 | {
|
---|
[53] | 426 | expanded = tilde_expand (filename);
|
---|
| 427 | if (expanded != 0)
|
---|
[3156] | 428 | filename = expanded;
|
---|
| 429 | }
|
---|
| 430 |
|
---|
[3140] | 431 | #ifdef _MSC_VER
|
---|
[3156] | 432 | ENULLLOOP (ebuf.fp, fopen (filename, "rN")); /* N == noinherit */
|
---|
[3140] | 433 | #else
|
---|
[53] | 434 | ENULLLOOP (ebuf.fp, fopen (filename, "r"));
|
---|
| 435 | #endif
|
---|
| 436 |
|
---|
[3140] | 437 | /* Save the error code so we print the right message later. */
|
---|
| 438 | makefile_errno = errno;
|
---|
| 439 |
|
---|
| 440 | /* Check for unrecoverable errors: out of mem or FILE slots. */
|
---|
| 441 | switch (makefile_errno)
|
---|
| 442 | {
|
---|
| 443 | #ifdef EMFILE
|
---|
| 444 | case EMFILE:
|
---|
| 445 | #endif
|
---|
| 446 | #ifdef ENFILE
|
---|
| 447 | case ENFILE:
|
---|
| 448 | #endif
|
---|
| 449 | case ENOMEM:
|
---|
| 450 | {
|
---|
| 451 | const char *err = strerror (makefile_errno);
|
---|
| 452 | OS (fatal, reading_file, "%s", err);
|
---|
[53] | 453 | }
|
---|
[3140] | 454 | }
|
---|
[53] | 455 |
|
---|
| 456 | /* If the makefile wasn't found and it's either a makefile from
|
---|
| 457 | the 'MAKEFILES' variable or an included makefile,
|
---|
[903] | 458 | search the included makefile search path for this makefile. */
|
---|
[53] | 459 | if (ebuf.fp == 0 && (flags & RM_INCLUDED) && *filename != '/')
|
---|
[3140] | 460 | {
|
---|
| 461 | unsigned int i;
|
---|
[2591] | 462 | for (i = 0; include_directories[i] != 0; ++i)
|
---|
[3156] | 463 | {
|
---|
| 464 | const char *included = concat (3, include_directories[i],
|
---|
| 465 | "/", filename);
|
---|
[3140] | 466 | #ifdef _MSC_VER
|
---|
[3156] | 467 | ebuf.fp = fopen (included, "rN"); /* N == noinherit */
|
---|
[3140] | 468 | #else
|
---|
| 469 | ebuf.fp = fopen (included, "r");
|
---|
| 470 | #endif
|
---|
| 471 | if (ebuf.fp)
|
---|
| 472 | {
|
---|
| 473 | filename = included;
|
---|
[53] | 474 | break;
|
---|
| 475 | }
|
---|
[3140] | 476 | }
|
---|
| 477 | }
|
---|
| 478 |
|
---|
| 479 | /* Now we have the final name for this makefile. Enter it into
|
---|
[53] | 480 | the cache. */
|
---|
[3140] | 481 | filename = strcache_add (filename);
|
---|
| 482 |
|
---|
| 483 | /* Add FILENAME to the chain of read makefiles. */
|
---|
[1975] | 484 | deps = alloc_goaldep ();
|
---|
[53] | 485 | deps->next = read_files;
|
---|
[1857] | 486 | read_files = deps;
|
---|
| 487 | #ifndef CONFIG_WITH_STRCACHE2
|
---|
| 488 | deps->file = lookup_file (filename);
|
---|
[53] | 489 | #else
|
---|
[903] | 490 | deps->file = lookup_file_cached (filename);
|
---|
[53] | 491 | #endif
|
---|
[3140] | 492 | if (deps->file == 0)
|
---|
[53] | 493 | deps->file = enter_file (filename);
|
---|
[3140] | 494 | filename = deps->file->name;
|
---|
[503] | 495 | deps->flags = flags;
|
---|
[53] | 496 |
|
---|
| 497 | free (expanded);
|
---|
| 498 |
|
---|
| 499 | /* If the makefile can't be found at all, give up entirely. */
|
---|
| 500 |
|
---|
[3140] | 501 | if (ebuf.fp == 0)
|
---|
| 502 | {
|
---|
[53] | 503 | /* If we did some searching, errno has the error from the last
|
---|
[3140] | 504 | attempt, rather from FILENAME itself. Store it in case the
|
---|
[53] | 505 | caller wants to use it in a message. */
|
---|
| 506 | errno = makefile_errno;
|
---|
[2591] | 507 | return deps;
|
---|
| 508 | }
|
---|
[3156] | 509 |
|
---|
[2591] | 510 | /* Set close-on-exec to avoid leaking the makefile to children, such as
|
---|
| 511 | $(shell ...). */
|
---|
| 512 | #ifndef _MSC_VER /* not necessary, see fopen calls above. */
|
---|
[3156] | 513 | #ifdef HAVE_FILENO
|
---|
[2591] | 514 | CLOSE_ON_EXEC (fileno (ebuf.fp));
|
---|
[53] | 515 | #endif
|
---|
| 516 | #endif
|
---|
| 517 |
|
---|
| 518 | /* Add this makefile to the list. */
|
---|
[2788] | 519 | do_variable_definition (&ebuf.floc, "MAKEFILE_LIST", filename, o_file,
|
---|
| 520 | f_append, 0);
|
---|
| 521 |
|
---|
| 522 | #ifdef CONFIG_WITH_COMPILER
|
---|
| 523 | /* Execute compiled version if repeatedly evaluating this file.
|
---|
[2799] | 524 | ASSUMES file content is unmodified since compilation. */
|
---|
| 525 | deps->file->eval_count++;
|
---|
| 526 | if ( deps->file->evalprog
|
---|
[2788] | 527 | # ifdef CONFIG_WITH_COMPILE_EVERYTHING
|
---|
[2799] | 528 | || ( deps->file->eval_count == 1
|
---|
[2788] | 529 | # else
|
---|
| 530 | || ( deps->file->eval_count == 3
|
---|
| 531 | # endif
|
---|
| 532 | && (deps->file->evalprog = kmk_cc_compile_file_for_eval (ebuf.fp, filename)) != NULL) )
|
---|
| 533 | {
|
---|
| 534 | curfile = reading_file;
|
---|
| 535 | reading_file = &ebuf.floc;
|
---|
| 536 |
|
---|
| 537 | kmk_exec_eval_file (deps->file->evalprog);
|
---|
| 538 |
|
---|
| 539 | reading_file = curfile;
|
---|
| 540 | fclose (ebuf.fp);
|
---|
| 541 | alloca (0);
|
---|
| 542 | return 1;
|
---|
| 543 | }
|
---|
| 544 | #elif defined (CONFIG_WITH_MAKE_STATS)
|
---|
[1499] | 545 | deps->file->eval_count++;
|
---|
| 546 | #endif
|
---|
| 547 |
|
---|
| 548 | #ifdef KMK
|
---|
| 549 | /* Buffer the entire file or at least 256KB (footer.kmk) of it. */
|
---|
[2857] | 550 | {
|
---|
| 551 | void *stream_buf = NULL;
|
---|
| 552 | struct stat st;
|
---|
[1499] | 553 | # ifdef KBUILD_OS_WINDOWS
|
---|
[2857] | 554 | if (!birdStatOnFdJustSize(fileno(ebuf.fp), &st.st_size))
|
---|
[1499] | 555 | # else
|
---|
[1809] | 556 | if (!fstat (fileno (ebuf.fp), &st))
|
---|
[1499] | 557 | # endif
|
---|
[2401] | 558 | {
|
---|
| 559 | int stream_buf_size = 256*1024;
|
---|
| 560 | if (st.st_size < stream_buf_size)
|
---|
| 561 | {
|
---|
| 562 | if (st.st_size)
|
---|
| 563 | stream_buf_size = (st.st_size + 0xfff) & ~0xfff;
|
---|
[1499] | 564 | else
|
---|
| 565 | stream_buf_size = 0x1000;
|
---|
| 566 | }
|
---|
| 567 | stream_buf = xmalloc (stream_buf_size);
|
---|
| 568 | setvbuf (ebuf.fp, stream_buf, _IOFBF, stream_buf_size);
|
---|
[53] | 569 | }
|
---|
| 570 | #endif
|
---|
| 571 |
|
---|
| 572 | /* Evaluate the makefile */
|
---|
[1811] | 573 |
|
---|
| 574 | ebuf.size = 200;
|
---|
| 575 | ebuf.buffer = ebuf.bufnext = ebuf.bufstart = xmalloc (ebuf.size);
|
---|
[53] | 576 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
| 577 | ebuf.eol = NULL;
|
---|
| 578 | #endif
|
---|
| 579 |
|
---|
[2591] | 580 | curfile = reading_file;
|
---|
[53] | 581 | reading_file = &ebuf.floc;
|
---|
| 582 |
|
---|
| 583 | eval (&ebuf, !(flags & RM_NO_DEFAULT_GOAL));
|
---|
| 584 |
|
---|
| 585 | reading_file = curfile;
|
---|
[1499] | 586 |
|
---|
| 587 | fclose (ebuf.fp);
|
---|
| 588 |
|
---|
| 589 | #ifdef KMK
|
---|
[1724] | 590 | if (stream_buf)
|
---|
[53] | 591 | free (stream_buf);
|
---|
[287] | 592 | }
|
---|
[2591] | 593 | #endif
|
---|
[3140] | 594 | free (ebuf.bufstart);
|
---|
| 595 | alloca (0);
|
---|
[53] | 596 |
|
---|
| 597 | errno = 0;
|
---|
[2591] | 598 | return deps;
|
---|
[3140] | 599 | }
|
---|
[53] | 600 |
|
---|
| 601 | void
|
---|
| 602 | eval_buffer (char *buffer, const floc *flocp IF_WITH_VALUE_LENGTH_PARAM(char *eos))
|
---|
| 603 | {
|
---|
[3140] | 604 | struct ebuffer ebuf;
|
---|
[53] | 605 | struct conditionals *saved;
|
---|
| 606 | struct conditionals new;
|
---|
| 607 | const floc *curfile;
|
---|
[1827] | 608 |
|
---|
[53] | 609 | /* Evaluate the buffer */
|
---|
[1827] | 610 |
|
---|
| 611 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
| 612 | ebuf.size = strlen (buffer);
|
---|
| 613 | #else
|
---|
| 614 | ebuf.size = eos - buffer;
|
---|
[53] | 615 | ebuf.eol = eos;
|
---|
| 616 | assert(strchr(buffer, '\0') == eos);
|
---|
| 617 | #endif
|
---|
[3140] | 618 | ebuf.buffer = ebuf.bufnext = ebuf.bufstart = buffer;
|
---|
| 619 | ebuf.fp = NULL;
|
---|
| 620 |
|
---|
[2591] | 621 | if (flocp)
|
---|
| 622 | ebuf.floc = *flocp;
|
---|
[3140] | 623 | else if (reading_file)
|
---|
| 624 | ebuf.floc = *reading_file;
|
---|
| 625 | else
|
---|
| 626 | {
|
---|
| 627 | ebuf.floc.filenm = NULL;
|
---|
[53] | 628 | ebuf.floc.lineno = 1;
|
---|
| 629 | ebuf.floc.offset = 0;
|
---|
| 630 | }
|
---|
| 631 |
|
---|
| 632 | curfile = reading_file;
|
---|
| 633 | reading_file = &ebuf.floc;
|
---|
[2591] | 634 |
|
---|
[53] | 635 | saved = install_conditionals (&new);
|
---|
| 636 |
|
---|
| 637 | eval (&ebuf, 1);
|
---|
| 638 |
|
---|
| 639 | restore_conditionals (saved);
|
---|
[287] | 640 |
|
---|
[53] | 641 | reading_file = curfile;
|
---|
[2591] | 642 |
|
---|
| 643 | alloca (0);
|
---|
[53] | 644 | }
|
---|
[2591] | 645 | |
---|
| 646 |
|
---|
| 647 | /* Check LINE to see if it's a variable assignment or undefine.
|
---|
| 648 |
|
---|
| 649 | It might use one of the modifiers "export", "override", "private", or it
|
---|
| 650 | might be one of the conditional tokens like "ifdef", "include", etc.
|
---|
| 651 |
|
---|
| 652 | If it's not a variable assignment or undefine, VMOD.V_ASSIGN is 0.
|
---|
| 653 | Returns LINE.
|
---|
| 654 |
|
---|
| 655 | Returns a pointer to the first non-modifier character, and sets VMOD
|
---|
| 656 | based on the modifiers found if any, plus V_ASSIGN is 1.
|
---|
| 657 | */
|
---|
| 658 | static char *
|
---|
| 659 | parse_var_assignment (const char *line, struct vmodifiers *vmod)
|
---|
| 660 | {
|
---|
[3140] | 661 | const char *p;
|
---|
[2591] | 662 | memset (vmod, '\0', sizeof (*vmod));
|
---|
| 663 |
|
---|
| 664 | /* Find the start of the next token. If there isn't one we're done. */
|
---|
| 665 | NEXT_TOKEN (line);
|
---|
| 666 | if (*line == '\0')
|
---|
| 667 | return (char *)line;
|
---|
| 668 |
|
---|
| 669 | p = line;
|
---|
[3140] | 670 | while (1)
|
---|
[2591] | 671 | {
|
---|
[3140] | 672 | int wlen;
|
---|
[2591] | 673 | const char *p2;
|
---|
| 674 | struct variable v;
|
---|
| 675 |
|
---|
| 676 | p2 = parse_variable_definition (p, &v);
|
---|
| 677 |
|
---|
| 678 | /* If this is a variable assignment, we're done. */
|
---|
| 679 | if (p2)
|
---|
| 680 | break;
|
---|
| 681 |
|
---|
| 682 | /* It's not a variable; see if it's a modifier. */
|
---|
| 683 | p2 = end_of_token (p);
|
---|
| 684 | wlen = p2 - p;
|
---|
| 685 |
|
---|
| 686 | if (word1eq ("export"))
|
---|
| 687 | vmod->export_v = 1;
|
---|
| 688 | else if (word1eq ("override"))
|
---|
| 689 | vmod->override_v = 1;
|
---|
| 690 | else if (word1eq ("private"))
|
---|
| 691 | vmod->private_v = 1;
|
---|
| 692 | else if (word1eq ("define"))
|
---|
| 693 | {
|
---|
| 694 | /* We can't have modifiers after 'define' */
|
---|
| 695 | vmod->define_v = 1;
|
---|
| 696 | p = next_token (p2);
|
---|
| 697 | break;
|
---|
| 698 | }
|
---|
| 699 | else if (word1eq ("undefine"))
|
---|
| 700 | {
|
---|
| 701 | /* We can't have modifiers after 'undefine' */
|
---|
| 702 | vmod->undefine_v = 1;
|
---|
| 703 | p = next_token (p2);
|
---|
| 704 | break;
|
---|
| 705 | }
|
---|
| 706 | else
|
---|
| 707 | /* Not a variable or modifier: this is not a variable assignment. */
|
---|
| 708 | return (char *)line;
|
---|
| 709 |
|
---|
| 710 | /* It was a modifier. Try the next word. */
|
---|
| 711 | p = next_token (p2);
|
---|
| 712 | if (*p == '\0')
|
---|
| 713 | return (char *)line;
|
---|
| 714 | }
|
---|
| 715 |
|
---|
[53] | 716 | /* Found a variable assignment or undefine. */
|
---|
[2591] | 717 | vmod->assign_v = 1;
|
---|
[53] | 718 | return (char *)p;
|
---|
| 719 | }
|
---|
| 720 | |
---|
| 721 |
|
---|
[2591] | 722 |
|
---|
[53] | 723 | /* Read file FILENAME as a makefile and add its contents to the data base.
|
---|
| 724 |
|
---|
| 725 | SET_DEFAULT is true if we are allowed to set the default goal. */
|
---|
| 726 |
|
---|
| 727 | static void
|
---|
| 728 | eval (struct ebuffer *ebuf, int set_default)
|
---|
| 729 | {
|
---|
| 730 | char *collapsed = 0;
|
---|
| 731 | unsigned int collapsed_length = 0;
|
---|
[3140] | 732 | unsigned int commands_len = 200;
|
---|
[53] | 733 | char *commands;
|
---|
[2591] | 734 | unsigned int commands_idx = 0;
|
---|
[53] | 735 | unsigned int cmds_started, tgts_started;
|
---|
| 736 | int ignoring = 0, in_ignored_define = 0;
|
---|
[3140] | 737 | int no_targets = 0; /* Set when reading a rule without targets. */
|
---|
[903] | 738 | struct nameseq *filenames = 0;
|
---|
| 739 | char *depstr = 0;
|
---|
[3140] | 740 | long nlines = 0;
|
---|
| 741 | int two_colon = 0;
|
---|
[1831] | 742 | char prefix = cmd_prefix;
|
---|
| 743 | const char *pattern = 0;
|
---|
| 744 | const char *pattern_percent;
|
---|
[2548] | 745 | floc *fstart;
|
---|
| 746 | floc fi;
|
---|
| 747 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
| 748 | unsigned int tmp_len;
|
---|
[53] | 749 | #endif
|
---|
[3140] | 750 | #ifdef KMK
|
---|
| 751 | struct kbuild_eval_data *kdata = 0;
|
---|
| 752 | int krc;
|
---|
| 753 | #endif
|
---|
[53] | 754 |
|
---|
[3140] | 755 | #define record_waiting_files() \
|
---|
| 756 | do \
|
---|
| 757 | { \
|
---|
[53] | 758 | if (filenames != 0) \
|
---|
[3140] | 759 | { \
|
---|
| 760 | fi.lineno = tgts_started; \
|
---|
[53] | 761 | fi.offset = 0; \
|
---|
[3140] | 762 | record_files (filenames, pattern, pattern_percent, depstr, \
|
---|
[53] | 763 | cmds_started, commands, commands_idx, two_colon, \
|
---|
[903] | 764 | prefix, &fi); \
|
---|
[53] | 765 | filenames = 0; \
|
---|
| 766 | } \
|
---|
| 767 | commands_idx = 0; \
|
---|
| 768 | no_targets = 0; \
|
---|
| 769 | pattern = 0; \
|
---|
| 770 | } while (0)
|
---|
| 771 |
|
---|
| 772 | pattern_percent = 0;
|
---|
| 773 | cmds_started = tgts_started = 1;
|
---|
| 774 |
|
---|
| 775 | fstart = &ebuf->floc;
|
---|
| 776 | fi.filenm = ebuf->floc.filenm;
|
---|
| 777 |
|
---|
| 778 | /* Loop over lines in the file.
|
---|
[3140] | 779 | The strategy is to accumulate target names in FILENAMES, dependencies
|
---|
| 780 | in DEPS and commands in COMMANDS. These are used to define a rule
|
---|
[53] | 781 | when the start of the next rule (or eof) is encountered.
|
---|
| 782 |
|
---|
| 783 | When you see a "continue" in the loop below, that means we are moving on
|
---|
| 784 | to the next line. If you see record_waiting_files(), then the statement
|
---|
| 785 | we are parsing also finishes the previous rule. */
|
---|
[153] | 786 |
|
---|
[1811] | 787 | commands = xmalloc (200);
|
---|
| 788 |
|
---|
| 789 | while (1)
|
---|
[53] | 790 | {
|
---|
[903] | 791 | unsigned int linelen;
|
---|
[53] | 792 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
| 793 | char *eol;
|
---|
[2591] | 794 | #endif
|
---|
[53] | 795 | char *line;
|
---|
[2591] | 796 | unsigned int wlen;
|
---|
[53] | 797 | char *p;
|
---|
| 798 | char *p2;
|
---|
| 799 | struct vmodifiers vmod;
|
---|
| 800 |
|
---|
| 801 | /* At the top of this loop, we are starting a brand new line. */
|
---|
| 802 | /* Grab the next line to be evaluated */
|
---|
| 803 | ebuf->floc.lineno += nlines;
|
---|
| 804 | nlines = readline (ebuf);
|
---|
[3140] | 805 |
|
---|
| 806 | /* If there is nothing left to eval, we're done. */
|
---|
| 807 | if (nlines < 0)
|
---|
| 808 | break;
|
---|
| 809 |
|
---|
| 810 | line = ebuf->buffer;
|
---|
| 811 |
|
---|
| 812 | /* If this is the first line, check for a UTF-8 BOM and skip it. */
|
---|
| 813 | if (ebuf->floc.lineno == 1 && line[0] == (char)0xEF
|
---|
| 814 | && line[1] == (char)0xBB && line[2] == (char)0xBF)
|
---|
| 815 | {
|
---|
| 816 | line += 3;
|
---|
| 817 | if (ISDB(DB_BASIC))
|
---|
| 818 | {
|
---|
| 819 | if (ebuf->floc.filenm)
|
---|
| 820 | printf (_("Skipping UTF-8 BOM in makefile '%s'\n"),
|
---|
| 821 | ebuf->floc.filenm);
|
---|
[53] | 822 | else
|
---|
| 823 | printf (_("Skipping UTF-8 BOM in makefile buffer\n"));
|
---|
| 824 | }
|
---|
| 825 | }
|
---|
[1811] | 826 |
|
---|
[53] | 827 | /* If this line is empty, skip it. */
|
---|
[1811] | 828 | if (line[0] == '\0')
|
---|
| 829 | continue;
|
---|
| 830 |
|
---|
| 831 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
[53] | 832 | linelen = strlen (line);
|
---|
| 833 | #else
|
---|
[3140] | 834 | linelen = ebuf->eol - line;
|
---|
[903] | 835 | assert (strlen (line) == linelen);
|
---|
[3140] | 836 | #endif
|
---|
| 837 |
|
---|
| 838 | /* Check for a shell command line first.
|
---|
| 839 | If it is not one, we can stop treating cmd_prefix specially. */
|
---|
[53] | 840 | if (line[0] == cmd_prefix)
|
---|
[3140] | 841 | {
|
---|
| 842 | if (no_targets)
|
---|
| 843 | /* Ignore the commands in a rule with no targets. */
|
---|
[53] | 844 | continue;
|
---|
[3140] | 845 |
|
---|
| 846 | /* If there is no preceding rule line, don't treat this line
|
---|
| 847 | as a command, even though it begins with a recipe prefix.
|
---|
| 848 | SunOS 4 make appears to behave this way. */
|
---|
| 849 |
|
---|
[53] | 850 | if (filenames != 0)
|
---|
[3140] | 851 | {
|
---|
| 852 | if (ignoring)
|
---|
[53] | 853 | /* Yep, this is a shell command, and we don't care. */
|
---|
[3140] | 854 | continue;
|
---|
| 855 |
|
---|
| 856 | if (commands_idx == 0)
|
---|
[1993] | 857 | cmds_started = ebuf->floc.lineno;
|
---|
[3140] | 858 |
|
---|
| 859 | /* Append this command line to the line being accumulated.
|
---|
[1993] | 860 | Skip the initial command prefix character. */
|
---|
[3140] | 861 | if (linelen + commands_idx > commands_len)
|
---|
| 862 | {
|
---|
| 863 | commands_len = (linelen + commands_idx) * 2;
|
---|
| 864 | commands = xrealloc (commands, commands_len);
|
---|
| 865 | }
|
---|
| 866 | memcpy (&commands[commands_idx], line + 1, linelen - 1);
|
---|
[53] | 867 | commands_idx += linelen - 1;
|
---|
[2591] | 868 | commands[commands_idx++] = '\n';
|
---|
[53] | 869 | continue;
|
---|
| 870 | }
|
---|
| 871 | }
|
---|
| 872 |
|
---|
[3140] | 873 | /* This line is not a shell command line. Don't worry about whitespace.
|
---|
| 874 | Get more space if we need it; we don't need to preserve the current
|
---|
| 875 | contents of the buffer. */
|
---|
[2591] | 876 |
|
---|
[3140] | 877 | if (collapsed_length < linelen+1)
|
---|
| 878 | {
|
---|
[1811] | 879 | collapsed_length = linelen+1;
|
---|
[53] | 880 | free (collapsed);
|
---|
| 881 | /* Don't need xrealloc: we don't need to preserve the content. */
|
---|
| 882 | collapsed = xmalloc (collapsed_length);
|
---|
| 883 | }
|
---|
[1811] | 884 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
| 885 | strcpy (collapsed, line);
|
---|
| 886 | /* Collapse continuation lines. */
|
---|
| 887 | collapse_continuations (collapsed);
|
---|
| 888 | remove_comments (collapsed);
|
---|
| 889 | #else
|
---|
| 890 | memcpy (collapsed, line, linelen + 1);
|
---|
| 891 | /* Collapse continuation lines. */
|
---|
[53] | 892 | eol = collapse_continuations (collapsed, linelen);
|
---|
[2591] | 893 | assert (strchr (collapsed, '\0') == eol);
|
---|
[53] | 894 | eol = remove_comments (collapsed, eol);
|
---|
[3140] | 895 | assert (strchr (collapsed, '\0') == eol);
|
---|
[53] | 896 | #endif
|
---|
[2591] | 897 |
|
---|
| 898 | /* Get rid if starting space (including formfeed, vtab, etc.) */
|
---|
[3140] | 899 | p = collapsed;
|
---|
[2591] | 900 | NEXT_TOKEN (p);
|
---|
| 901 |
|
---|
| 902 | /* See if this is a variable assignment. We need to do this early, to
|
---|
| 903 | allow variables with names like 'ifdef', 'export', 'private', etc. */
|
---|
[53] | 904 | p = parse_var_assignment (p, &vmod);
|
---|
[2591] | 905 | if (vmod.assign_v)
|
---|
[3140] | 906 | {
|
---|
[2591] | 907 | struct variable *v;
|
---|
| 908 | enum variable_origin origin = vmod.override_v ? o_override : o_file;
|
---|
| 909 |
|
---|
| 910 | /* If we're ignoring then we're done now. */
|
---|
| 911 | if (ignoring)
|
---|
[53] | 912 | {
|
---|
[3140] | 913 | if (vmod.define_v)
|
---|
| 914 | in_ignored_define = 1;
|
---|
| 915 | continue;
|
---|
[2591] | 916 | }
|
---|
| 917 |
|
---|
| 918 | /* Variable assignment ends the previous rule. */
|
---|
[3140] | 919 | record_waiting_files ();
|
---|
[2591] | 920 |
|
---|
| 921 | if (vmod.undefine_v)
|
---|
| 922 | {
|
---|
| 923 | do_undefine (p, origin, ebuf);
|
---|
| 924 | continue;
|
---|
[53] | 925 | }
|
---|
[2591] | 926 | else if (vmod.define_v)
|
---|
[53] | 927 | v = do_define (p IF_WITH_VALUE_LENGTH_PARAM(NULL), origin, ebuf);
|
---|
[2591] | 928 | else
|
---|
| 929 | v = try_variable_definition (fstart, p IF_WITH_VALUE_LENGTH_PARAM(NULL), origin, 0);
|
---|
| 930 |
|
---|
| 931 | assert (v != NULL);
|
---|
[53] | 932 |
|
---|
[2591] | 933 | if (vmod.export_v)
|
---|
[3140] | 934 | v->export = v_export;
|
---|
[2591] | 935 | if (vmod.private_v)
|
---|
[53] | 936 | v->private_var = 1;
|
---|
[2591] | 937 |
|
---|
| 938 | /* This line has been dealt with. */
|
---|
[3140] | 939 | continue;
|
---|
[53] | 940 | }
|
---|
[2591] | 941 |
|
---|
| 942 | /* If this line is completely empty, ignore it. */
|
---|
[3140] | 943 | if (*p == '\0')
|
---|
[53] | 944 | continue;
|
---|
[2591] | 945 |
|
---|
| 946 | p2 = end_of_token (p);
|
---|
[3140] | 947 | wlen = p2 - p;
|
---|
[2591] | 948 | NEXT_TOKEN (p2);
|
---|
[3140] | 949 |
|
---|
[2591] | 950 | /* If we're in an ignored define, skip this line (but maybe get out). */
|
---|
[53] | 951 | if (in_ignored_define)
|
---|
[3140] | 952 | {
|
---|
| 953 | /* See if this is an endef line (plus optional comment). */
|
---|
[53] | 954 | if (word1eq ("endef") && STOP_SET (*p2, MAP_COMMENT|MAP_NUL))
|
---|
[2591] | 955 | in_ignored_define = 0;
|
---|
| 956 |
|
---|
[1811] | 957 | continue;
|
---|
[2591] | 958 | }
|
---|
[1811] | 959 |
|
---|
[2591] | 960 | /* Check for conditional state changes. */
|
---|
[1811] | 961 | {
|
---|
[2591] | 962 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
| 963 | int i = conditional_line (p, wlen, fstart);
|
---|
| 964 | #else
|
---|
[3140] | 965 | int i = conditional_line (p, eol, wlen, fstart);
|
---|
[53] | 966 | #endif
|
---|
[2591] | 967 | if (i != -2)
|
---|
| 968 | {
|
---|
| 969 | if (i == -1)
|
---|
| 970 | O (fatal, fstart, _("invalid syntax in conditional"));
|
---|
| 971 |
|
---|
| 972 | ignoring = i;
|
---|
| 973 | continue;
|
---|
[3140] | 974 | }
|
---|
[2591] | 975 | }
|
---|
[1408] | 976 |
|
---|
| 977 | /* Nothing to see here... move along. */
|
---|
| 978 | if (ignoring)
|
---|
| 979 | continue;
|
---|
[3140] | 980 |
|
---|
[1408] | 981 | #ifdef CONFIG_WITH_LOCAL_VARIABLES
|
---|
| 982 | if (word1eq ("local"))
|
---|
[3140] | 983 | {
|
---|
[1408] | 984 | if (*p2 == '\0')
|
---|
| 985 | O (error, fstart, _("empty `local' directive"));
|
---|
| 986 |
|
---|
| 987 | if (strneq (p2, "define", 6)
|
---|
| 988 | && (ISBLANK (p2[6]) || p2[6] == '\0'))
|
---|
| 989 | {
|
---|
| 990 | if (ignoring)
|
---|
[3140] | 991 | in_ignored_define = 1;
|
---|
[1408] | 992 | else
|
---|
| 993 | {
|
---|
| 994 | p2 = next_token (p2 + 6);
|
---|
| 995 | if (*p2 == '\0')
|
---|
| 996 | O (fatal, fstart, _("empty variable name"));
|
---|
| 997 |
|
---|
[3140] | 998 | /* Let the variable name be the whole rest of the line,
|
---|
[1408] | 999 | with trailing blanks stripped (comments have already been
|
---|
[2591] | 1000 | removed), so it could be a complex variable/function
|
---|
[1408] | 1001 | reference that might contain blanks. */
|
---|
| 1002 | p = strchr (p2, '\0');
|
---|
| 1003 | while (ISBLANK (p[-1]))
|
---|
[2591] | 1004 | --p;
|
---|
[3140] | 1005 | do_define (p2 IF_WITH_VALUE_LENGTH_PARAM(p), o_local, ebuf);
|
---|
[1408] | 1006 | }
|
---|
| 1007 | }
|
---|
| 1008 | else if (!ignoring
|
---|
| 1009 | && !try_variable_definition (fstart, p2 IF_WITH_VALUE_LENGTH_PARAM(eol), o_local, 0))
|
---|
| 1010 | O (error, fstart, _("invalid `local' directive"));
|
---|
[2548] | 1011 |
|
---|
| 1012 | continue;
|
---|
[2717] | 1013 | }
|
---|
| 1014 | #endif /* CONFIG_WITH_LOCAL_VARIABLES */
|
---|
[2548] | 1015 |
|
---|
[2717] | 1016 | #ifdef KMK
|
---|
| 1017 | /* Check for the kBuild language extensions. */
|
---|
| 1018 | if ( wlen > sizeof("kBuild-")
|
---|
| 1019 | && strneq (p, "kBuild-", sizeof("kBuild-") - 1))
|
---|
[3140] | 1020 | {
|
---|
[2717] | 1021 | krc = eval_kbuild_read_hook (&kdata, fstart, p, wlen, p2, eol, ignoring);
|
---|
| 1022 | if (krc != 42)
|
---|
[2548] | 1023 | {
|
---|
| 1024 | if (krc != 0)
|
---|
[2591] | 1025 | ON (error, fstart, _("krc=%d"), krc);
|
---|
| 1026 | continue;
|
---|
| 1027 | }
|
---|
| 1028 | }
|
---|
[3140] | 1029 | #endif /* KMK */
|
---|
[2591] | 1030 |
|
---|
[53] | 1031 | /* Manage the "export" keyword used outside of variable assignment
|
---|
[3140] | 1032 | as well as "unexport". */
|
---|
| 1033 | if (word1eq ("export") || word1eq ("unexport"))
|
---|
| 1034 | {
|
---|
[2591] | 1035 | int exporting = *p == 'u' ? 0 : 1;
|
---|
[3140] | 1036 |
|
---|
[2591] | 1037 | /* Export/unexport ends the previous rule. */
|
---|
[53] | 1038 | record_waiting_files ();
|
---|
| 1039 |
|
---|
[903] | 1040 | /* (un)export by itself causes everything to be (un)exported. */
|
---|
| 1041 | if (*p2 == '\0')
|
---|
[53] | 1042 | export_all_variables = exporting;
|
---|
| 1043 | else
|
---|
| 1044 | {
|
---|
[2591] | 1045 | unsigned int l;
|
---|
[1817] | 1046 | const char *cp;
|
---|
| 1047 | char *ap;
|
---|
| 1048 |
|
---|
[1931] | 1049 | /* Expand the line so we can use indirect and constructed
|
---|
| 1050 | variable names in an (un)export command. */
|
---|
[1817] | 1051 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
[53] | 1052 | cp = ap = allocated_variable_expand (p2);
|
---|
[903] | 1053 | #else
|
---|
| 1054 | unsigned int buf_len;
|
---|
[53] | 1055 | cp = ap = allocated_variable_expand_3 (p2, eol - p2, NULL, &buf_len);
|
---|
[2591] | 1056 | #endif
|
---|
[53] | 1057 |
|
---|
[3140] | 1058 | for (p = find_next_token (&cp, &l); p != 0;
|
---|
[2591] | 1059 | p = find_next_token (&cp, &l))
|
---|
[53] | 1060 | {
|
---|
| 1061 | struct variable *v = lookup_variable (p, l);
|
---|
[1931] | 1062 | if (v == 0)
|
---|
[53] | 1063 | v = define_variable_global (p, l, "", o_file, 0, fstart);
|
---|
[1931] | 1064 | v->export = exporting ? v_export : v_noexport;
|
---|
| 1065 | }
|
---|
| 1066 |
|
---|
[53] | 1067 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
[3140] | 1068 | free (ap);
|
---|
| 1069 | #else
|
---|
[53] | 1070 | recycle_variable_buffer (ap, buf_len);
|
---|
[2591] | 1071 | #endif
|
---|
[53] | 1072 | }
|
---|
[3140] | 1073 | continue;
|
---|
[903] | 1074 | }
|
---|
[3140] | 1075 |
|
---|
| 1076 | /* Handle the special syntax for vpath. */
|
---|
[53] | 1077 | if (word1eq ("vpath"))
|
---|
[3140] | 1078 | {
|
---|
| 1079 | const char *cp;
|
---|
[53] | 1080 | char *vpat;
|
---|
[3140] | 1081 | unsigned int l;
|
---|
| 1082 |
|
---|
| 1083 | /* vpath ends the previous rule. */
|
---|
| 1084 | record_waiting_files ();
|
---|
| 1085 |
|
---|
| 1086 | cp = variable_expand (p2);
|
---|
| 1087 | p = find_next_token (&cp, &l);
|
---|
| 1088 | if (p != 0)
|
---|
| 1089 | {
|
---|
| 1090 | vpat = xstrndup (p, l);
|
---|
| 1091 | p = find_next_token (&cp, &l);
|
---|
| 1092 | /* No searchpath means remove all previous
|
---|
| 1093 | selective VPATH's with the same pattern. */
|
---|
| 1094 | }
|
---|
| 1095 | else
|
---|
| 1096 | /* No pattern means remove all previous selective VPATH's. */
|
---|
| 1097 | vpat = 0;
|
---|
| 1098 | construct_vpath_list (vpat, p);
|
---|
[528] | 1099 | free (vpat);
|
---|
[1811] | 1100 |
|
---|
[1797] | 1101 | continue;
|
---|
[528] | 1102 | }
|
---|
[1797] | 1103 |
|
---|
[1693] | 1104 | #ifdef CONFIG_WITH_INCLUDEDEP
|
---|
| 1105 | assert (strchr (p2, '\0') == eol);
|
---|
| 1106 | if (word1eq ("includedep") || word1eq ("includedep-queue") || word1eq ("includedep-flush"))
|
---|
[1797] | 1107 | {
|
---|
| 1108 | /* We have found an `includedep' line specifying one or more dep files
|
---|
| 1109 | to be read at this point. This include variation does no
|
---|
| 1110 | globbing and do not support multiple names. It's trying to save
|
---|
[1693] | 1111 | time by being dead simple as well as ignoring errors. */
|
---|
[1931] | 1112 | enum incdep_op op = p[wlen - 1] == 'p'
|
---|
[1693] | 1113 | ? incdep_read_it
|
---|
[1811] | 1114 | : p[wlen - 1] == 'e'
|
---|
| 1115 | ? incdep_queue : incdep_flush;
|
---|
[1693] | 1116 | char *free_me = NULL;
|
---|
[1817] | 1117 | unsigned int buf_len;
|
---|
[1931] | 1118 | char *name = p2;
|
---|
[1817] | 1119 |
|
---|
[3140] | 1120 | if (memchr (name, '$', eol - name))
|
---|
[1693] | 1121 | {
|
---|
| 1122 | unsigned int name_len;
|
---|
[528] | 1123 | free_me = name = allocated_variable_expand_3 (name, eol - name, &name_len, &buf_len);
|
---|
[3140] | 1124 | eol = name + name_len;
|
---|
[1811] | 1125 | while (ISSPACE (*name))
|
---|
[530] | 1126 | ++name;
|
---|
[1811] | 1127 | }
|
---|
[1797] | 1128 |
|
---|
[528] | 1129 | while (eol > name && ISSPACE (eol[-1]))
|
---|
[1693] | 1130 | --eol;
|
---|
[1931] | 1131 |
|
---|
[3140] | 1132 | *eol = '\0';
|
---|
[1693] | 1133 | eval_include_dep (name, fstart, op);
|
---|
[528] | 1134 |
|
---|
| 1135 | if (free_me)
|
---|
[2591] | 1136 | recycle_variable_buffer (free_me, buf_len);
|
---|
[53] | 1137 | continue;
|
---|
[3140] | 1138 | }
|
---|
| 1139 | #endif /* CONFIG_WITH_INCLUDEDEP */
|
---|
| 1140 |
|
---|
| 1141 | /* Handle include and variants. */
|
---|
[53] | 1142 | if (word1eq ("include") || word1eq ("-include") || word1eq ("sinclude"))
|
---|
[3140] | 1143 | {
|
---|
| 1144 | /* We have found an 'include' line specifying a nested
|
---|
| 1145 | makefile to be read at this point. */
|
---|
| 1146 | struct conditionals *save;
|
---|
| 1147 | struct conditionals new_conditionals;
|
---|
| 1148 | struct nameseq *files;
|
---|
| 1149 | /* "-include" (vs "include") says no error if the file does not
|
---|
[53] | 1150 | exist. "sinclude" is an alias for this from SGI. */
|
---|
[3140] | 1151 | int noerror = (p[0] != 'i');
|
---|
| 1152 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
| 1153 | unsigned int buf_len;
|
---|
[1817] | 1154 | #endif
|
---|
[3140] | 1155 |
|
---|
[1817] | 1156 | /* Include ends the previous rule. */
|
---|
[1931] | 1157 | record_waiting_files ();
|
---|
[1817] | 1158 |
|
---|
[503] | 1159 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
[3140] | 1160 | p = allocated_variable_expand (p2);
|
---|
[503] | 1161 | #else
|
---|
[3140] | 1162 | p = allocated_variable_expand_3 (p2, eol - p2, NULL, &buf_len);
|
---|
[503] | 1163 | #endif
|
---|
[1931] | 1164 |
|
---|
[503] | 1165 |
|
---|
[1931] | 1166 | /* If no filenames, it's a no-op. */
|
---|
| 1167 | if (*p == '\0')
|
---|
| 1168 | {
|
---|
[503] | 1169 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
| 1170 | free (p);
|
---|
[53] | 1171 | #else
|
---|
[3140] | 1172 | recycle_variable_buffer (p, buf_len);
|
---|
| 1173 | #endif
|
---|
| 1174 | continue;
|
---|
[2591] | 1175 | }
|
---|
[1931] | 1176 |
|
---|
[3140] | 1177 | /* Parse the list of file names. Don't expand archive references! */
|
---|
[1931] | 1178 | p2 = p;
|
---|
| 1179 | files = PARSE_FILE_SEQ (&p2, struct nameseq, MAP_NUL, NULL,
|
---|
| 1180 | PARSEFS_NOAR);
|
---|
[53] | 1181 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
[3140] | 1182 | free (p);
|
---|
| 1183 | #else
|
---|
| 1184 | recycle_variable_buffer (p, buf_len);
|
---|
[53] | 1185 | #endif
|
---|
[3140] | 1186 |
|
---|
| 1187 | /* Save the state of conditionals and start
|
---|
| 1188 | the included makefile with a clean slate. */
|
---|
[53] | 1189 | save = install_conditionals (&new_conditionals);
|
---|
[3140] | 1190 |
|
---|
| 1191 | /* Record the rules that are waiting so they will determine
|
---|
| 1192 | the default goal before those in the included makefile. */
|
---|
| 1193 | record_waiting_files ();
|
---|
| 1194 |
|
---|
| 1195 | /* Read each included makefile. */
|
---|
| 1196 | while (files != 0)
|
---|
| 1197 | {
|
---|
| 1198 | struct nameseq *next = files->next;
|
---|
| 1199 | int flags = (RM_INCLUDED | RM_NO_TILDE
|
---|
| 1200 | | (noerror ? RM_DONTCARE : 0)
|
---|
| 1201 | | (set_default ? 0 : RM_NO_DEFAULT_GOAL));
|
---|
| 1202 |
|
---|
| 1203 | struct goaldep *d = eval_makefile (files->name, flags);
|
---|
| 1204 |
|
---|
| 1205 | if (errno)
|
---|
| 1206 | {
|
---|
| 1207 | d->error = (unsigned short)errno;
|
---|
| 1208 | d->floc = *fstart;
|
---|
| 1209 | }
|
---|
| 1210 |
|
---|
| 1211 | free_ns (files);
|
---|
| 1212 | files = next;
|
---|
| 1213 | }
|
---|
| 1214 |
|
---|
| 1215 | /* Restore conditional state. */
|
---|
| 1216 | restore_conditionals (save);
|
---|
| 1217 |
|
---|
| 1218 | continue;
|
---|
| 1219 | }
|
---|
| 1220 |
|
---|
| 1221 | /* Handle the load operations. */
|
---|
| 1222 | if (word1eq ("load") || word1eq ("-load"))
|
---|
| 1223 | {
|
---|
| 1224 | /* A 'load' line specifies a dynamic object to load. */
|
---|
| 1225 | struct nameseq *files;
|
---|
| 1226 | int noerror = (p[0] == '-');
|
---|
| 1227 |
|
---|
| 1228 | /* Load ends the previous rule. */
|
---|
| 1229 | record_waiting_files ();
|
---|
| 1230 |
|
---|
| 1231 | p = allocated_variable_expand (p2);
|
---|
| 1232 |
|
---|
| 1233 | /* If no filenames, it's a no-op. */
|
---|
| 1234 | if (*p == '\0')
|
---|
| 1235 | {
|
---|
| 1236 | free (p);
|
---|
| 1237 | continue;
|
---|
| 1238 | }
|
---|
| 1239 |
|
---|
| 1240 | /* Parse the list of file names.
|
---|
| 1241 | Don't expand archive references or strip "./" */
|
---|
| 1242 | p2 = p;
|
---|
| 1243 | files = PARSE_FILE_SEQ (&p2, struct nameseq, MAP_NUL, NULL,
|
---|
| 1244 | PARSEFS_NOAR);
|
---|
| 1245 | free (p);
|
---|
| 1246 |
|
---|
| 1247 | /* Load each file. */
|
---|
[53] | 1248 | while (files != 0)
|
---|
| 1249 | {
|
---|
[3140] | 1250 | struct nameseq *next = files->next;
|
---|
| 1251 | const char *name = files->name;
|
---|
| 1252 | struct goaldep *deps;
|
---|
| 1253 | int r;
|
---|
[53] | 1254 |
|
---|
[3140] | 1255 | /* Load the file. 0 means failure. */
|
---|
| 1256 | r = load_file (&ebuf->floc, &name, noerror);
|
---|
[53] | 1257 | if (! r && ! noerror)
|
---|
[3140] | 1258 | OS (fatal, &ebuf->floc, _("%s: failed to load"), name);
|
---|
| 1259 |
|
---|
| 1260 | free_ns (files);
|
---|
[53] | 1261 | files = next;
|
---|
[3140] | 1262 |
|
---|
| 1263 | /* Return of -1 means a special load: don't rebuild it. */
|
---|
| 1264 | if (r == -1)
|
---|
| 1265 | continue;
|
---|
| 1266 |
|
---|
| 1267 | /* It succeeded, so add it to the list "to be rebuilt". */
|
---|
| 1268 | deps = alloc_goaldep ();
|
---|
| 1269 | deps->next = read_files;
|
---|
| 1270 | read_files = deps;
|
---|
[53] | 1271 | deps->file = lookup_file (name);
|
---|
[3140] | 1272 | if (deps->file == 0)
|
---|
| 1273 | deps->file = enter_file (name);
|
---|
| 1274 | deps->file->loaded = 1;
|
---|
[287] | 1275 | }
|
---|
| 1276 |
|
---|
| 1277 | continue;
|
---|
[903] | 1278 | }
|
---|
[3140] | 1279 |
|
---|
[53] | 1280 | /* This line starts with a tab but was not caught above because there
|
---|
| 1281 | was no preceding target, and the line might have been usable as a
|
---|
| 1282 | variable definition. But now we know it is definitely lossage. */
|
---|
| 1283 | if (line[0] == cmd_prefix)
|
---|
[3140] | 1284 | O (fatal, fstart, _("recipe commences before first target"));
|
---|
[53] | 1285 |
|
---|
| 1286 | /* This line describes some target files. This is complicated by
|
---|
[3140] | 1287 | the existence of target-specific variables, because we can't
|
---|
| 1288 | expand the entire line until we know if we have one or not. So
|
---|
[53] | 1289 | we expand the line word by word until we find the first ':',
|
---|
| 1290 | then check to see if it's a target-specific variable.
|
---|
| 1291 |
|
---|
| 1292 | In this algorithm, 'lb_next' will point to the beginning of the
|
---|
| 1293 | unexpanded parts of the input buffer, while 'p2' points to the
|
---|
[903] | 1294 | parts of the expanded buffer we haven't searched yet. */
|
---|
[53] | 1295 |
|
---|
[287] | 1296 | {
|
---|
[53] | 1297 | enum make_word_type wtype;
|
---|
| 1298 | char *cmdleft, *semip, *lb_next;
|
---|
| 1299 | unsigned int plen = 0;
|
---|
| 1300 | char *colonp;
|
---|
| 1301 | const char *end, *beg; /* Helpers for whitespace stripping. */
|
---|
| 1302 |
|
---|
| 1303 | /* Record the previous rule. */
|
---|
| 1304 |
|
---|
[3140] | 1305 | record_waiting_files ();
|
---|
[53] | 1306 | tgts_started = fstart->lineno;
|
---|
| 1307 |
|
---|
| 1308 | /* Search the line for an unquoted ; that is not after an
|
---|
| 1309 | unquoted #. */
|
---|
| 1310 | cmdleft = find_char_unquote (line, MAP_SEMI|MAP_COMMENT|MAP_VARIABLE IF_WITH_VALUE_LENGTH_PARAM(ebuf->eol - line));
|
---|
| 1311 | if (cmdleft != 0 && *cmdleft == '#')
|
---|
| 1312 | {
|
---|
| 1313 | /* We found a comment before a semicolon. */
|
---|
| 1314 | *cmdleft = '\0';
|
---|
| 1315 | cmdleft = 0;
|
---|
| 1316 | }
|
---|
[1811] | 1317 | else if (cmdleft != 0)
|
---|
[53] | 1318 | /* Found one. Cut the line short there before expanding it. */
|
---|
[1811] | 1319 | *(cmdleft++) = '\0';
|
---|
| 1320 | semip = cmdleft;
|
---|
| 1321 |
|
---|
[53] | 1322 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
| 1323 | collapse_continuations (line);
|
---|
| 1324 | #else
|
---|
| 1325 | collapse_continuations (line, strlen (line)); /**@todo fix this */
|
---|
| 1326 | #endif
|
---|
[3140] | 1327 |
|
---|
[53] | 1328 | /* We can't expand the entire line, since if it's a per-target
|
---|
| 1329 | variable we don't want to expand it. So, walk from the
|
---|
| 1330 | beginning, expanding as we go, and looking for "interesting"
|
---|
| 1331 | chars. The first word is always expandable. */
|
---|
[3140] | 1332 | wtype = get_next_mword (line, NULL, &lb_next, &wlen);
|
---|
[53] | 1333 | switch (wtype)
|
---|
| 1334 | {
|
---|
| 1335 | case w_eol:
|
---|
| 1336 | if (cmdleft != 0)
|
---|
| 1337 | O (fatal, fstart, _("missing rule before recipe"));
|
---|
| 1338 | /* This line contained something but turned out to be nothing
|
---|
| 1339 | but whitespace (a comment?). */
|
---|
| 1340 | continue;
|
---|
| 1341 |
|
---|
| 1342 | case w_colon:
|
---|
| 1343 | case w_dcolon:
|
---|
| 1344 | /* We accept and ignore rules without targets for
|
---|
| 1345 | compatibility with SunOS 4 make. */
|
---|
| 1346 | no_targets = 1;
|
---|
| 1347 | continue;
|
---|
[1831] | 1348 |
|
---|
[3140] | 1349 | default:
|
---|
[1831] | 1350 | break;
|
---|
| 1351 | }
|
---|
| 1352 |
|
---|
| 1353 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
[287] | 1354 | p2 = variable_expand_string (NULL, lb_next, wlen);
|
---|
[53] | 1355 | #else
|
---|
| 1356 | p2 = variable_expand_string_2 (NULL, lb_next, wlen, &eol);
|
---|
[903] | 1357 | assert (strchr (p2, '\0') == eol);
|
---|
[53] | 1358 | #endif
|
---|
| 1359 |
|
---|
| 1360 | while (1)
|
---|
[1831] | 1361 | {
|
---|
[3140] | 1362 | lb_next += wlen;
|
---|
[1831] | 1363 | if (cmdleft == 0)
|
---|
[3140] | 1364 | {
|
---|
[1831] | 1365 | /* Look for a semicolon in the expanded line. */
|
---|
[53] | 1366 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
| 1367 | cmdleft = find_char_unquote (p2, MAP_SEMI);
|
---|
| 1368 | #else
|
---|
| 1369 | cmdleft = find_char_unquote_0 (p2, ';', MAP_SEMI, &eol);
|
---|
| 1370 | #endif
|
---|
[1831] | 1371 |
|
---|
[3140] | 1372 | if (cmdleft != 0)
|
---|
[1831] | 1373 | {
|
---|
[53] | 1374 | unsigned long p2_off = p2 - variable_buffer;
|
---|
| 1375 | unsigned long cmd_off = cmdleft - variable_buffer;
|
---|
| 1376 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
| 1377 | char *pend = p2 + strlen (p2);
|
---|
| 1378 | #endif
|
---|
| 1379 |
|
---|
| 1380 | /* Append any remnants of lb, then cut the line short
|
---|
| 1381 | at the semicolon. */
|
---|
| 1382 | *cmdleft = '\0';
|
---|
[3140] | 1383 |
|
---|
[53] | 1384 | /* One school of thought says that you shouldn't expand
|
---|
| 1385 | here, but merely copy, since now you're beyond a ";"
|
---|
| 1386 | and into a command script. However, the old parser
|
---|
[1831] | 1387 | expanded the whole line, so we continue that for
|
---|
[3140] | 1388 | backwards-compatibility. Also, it wouldn't be
|
---|
| 1389 | entirely consistent, since we do an unconditional
|
---|
[1831] | 1390 | expand below once we know we don't have a
|
---|
| 1391 | target-specific variable. */
|
---|
| 1392 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
| 1393 | (void)variable_expand_string (pend, lb_next, (long)-1);
|
---|
| 1394 | lb_next += strlen (lb_next);
|
---|
[53] | 1395 | #else
|
---|
| 1396 | tmp_len = strlen (lb_next);
|
---|
| 1397 | variable_expand_string_2 (eol, lb_next, tmp_len, &eol);
|
---|
| 1398 | lb_next += tmp_len;
|
---|
| 1399 | #endif
|
---|
[1831] | 1400 | p2 = variable_buffer + p2_off;
|
---|
[3140] | 1401 | cmdleft = variable_buffer + cmd_off + 1;
|
---|
[1831] | 1402 | }
|
---|
[3140] | 1403 | }
|
---|
[1831] | 1404 |
|
---|
[53] | 1405 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
| 1406 | colonp = find_char_unquote (p2, MAP_COLON);
|
---|
| 1407 | #else
|
---|
| 1408 | colonp = find_char_unquote_0 (p2, ':', MAP_COLON, &eol);
|
---|
| 1409 | #endif
|
---|
| 1410 | #ifdef HAVE_DOS_PATHS
|
---|
| 1411 | /* The drive spec brain-damage strikes again... */
|
---|
| 1412 | /* Note that the only separators of targets in this context
|
---|
[1831] | 1413 | are whitespace and a left paren. If others are possible,
|
---|
[3140] | 1414 | they should be added to the string in the call to index. */
|
---|
[1831] | 1415 | while (colonp && (colonp[1] == '/' || colonp[1] == '\\') &&
|
---|
[3140] | 1416 | colonp > p2 && isalpha ((unsigned char)colonp[-1]) &&
|
---|
[1831] | 1417 | (colonp == p2 + 1 || strchr (" \t(", colonp[-2]) != 0))
|
---|
[53] | 1418 | # ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
| 1419 | colonp = find_char_unquote (colonp + 1, MAP_COLON);
|
---|
| 1420 | # else
|
---|
| 1421 | colonp = find_char_unquote_0 (colonp + 1, ':', MAP_COLON, &eol);
|
---|
[3140] | 1422 | # endif
|
---|
[53] | 1423 | #endif
|
---|
| 1424 | if (colonp != 0)
|
---|
| 1425 | break;
|
---|
[1831] | 1426 |
|
---|
[3140] | 1427 | wtype = get_next_mword (lb_next, NULL, &lb_next, &wlen);
|
---|
[53] | 1428 | if (wtype == w_eol)
|
---|
[3140] | 1429 | break;
|
---|
[1831] | 1430 |
|
---|
| 1431 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
| 1432 | p2 += strlen (p2);
|
---|
| 1433 | *(p2++) = ' ';
|
---|
[53] | 1434 | p2 = variable_expand_string (p2, lb_next, wlen);
|
---|
| 1435 | #else
|
---|
| 1436 | *(eol++) = ' ';
|
---|
| 1437 | p2 = variable_expand_string_2 (eol, lb_next, wlen, &eol);
|
---|
| 1438 | #endif
|
---|
| 1439 | /* We don't need to worry about cmdleft here, because if it was
|
---|
| 1440 | found in the variable_buffer the entire buffer has already
|
---|
| 1441 | been expanded... we'll never get here. */
|
---|
| 1442 | }
|
---|
| 1443 |
|
---|
| 1444 | p2 = next_token (variable_buffer);
|
---|
| 1445 |
|
---|
[3140] | 1446 | /* If the word we're looking at is EOL, see if there's _anything_
|
---|
| 1447 | on the line. If not, a variable expanded to nothing, so ignore
|
---|
| 1448 | it. If so, we can't parse this line so punt. */
|
---|
| 1449 | if (wtype == w_eol)
|
---|
| 1450 | {
|
---|
| 1451 | if (*p2 == '\0')
|
---|
| 1452 | continue;
|
---|
| 1453 |
|
---|
| 1454 | /* There's no need to be ivory-tower about this: check for
|
---|
[53] | 1455 | one of the most common bugs found in makefiles... */
|
---|
| 1456 | if (cmd_prefix == '\t' && strneq (line, " ", 8))
|
---|
| 1457 | O (fatal, fstart, _("missing separator (did you mean TAB instead of 8 spaces?)"));
|
---|
[3140] | 1458 | else
|
---|
[53] | 1459 | O (fatal, fstart, _("missing separator"));
|
---|
[3140] | 1460 | }
|
---|
| 1461 |
|
---|
| 1462 | /* Make the colon the end-of-string so we know where to stop
|
---|
[53] | 1463 | looking for targets. Start there again once we're done. */
|
---|
| 1464 | *colonp = '\0';
|
---|
| 1465 | filenames = PARSE_SIMPLE_SEQ (&p2, struct nameseq);
|
---|
| 1466 | *colonp = ':';
|
---|
| 1467 | p2 = colonp;
|
---|
| 1468 |
|
---|
| 1469 | if (!filenames)
|
---|
| 1470 | {
|
---|
| 1471 | /* We accept and ignore rules without targets for
|
---|
| 1472 | compatibility with SunOS 4 make. */
|
---|
| 1473 | no_targets = 1;
|
---|
| 1474 | continue;
|
---|
| 1475 | }
|
---|
| 1476 | /* This should never be possible; we handled it above. */
|
---|
| 1477 | assert (*p2 != '\0');
|
---|
| 1478 | ++p2;
|
---|
| 1479 |
|
---|
| 1480 | /* Is this a one-colon or two-colon entry? */
|
---|
| 1481 | two_colon = *p2 == ':';
|
---|
| 1482 | if (two_colon)
|
---|
| 1483 | p2++;
|
---|
| 1484 |
|
---|
| 1485 | /* Test to see if it's a target-specific variable. Copy the rest
|
---|
[287] | 1486 | of the buffer over, possibly temporarily (we'll expand it later
|
---|
[53] | 1487 | if it's not a target-specific variable). PLEN saves the length
|
---|
[903] | 1488 | of the unparsed section of p2, for later. */
|
---|
[287] | 1489 | if (*lb_next != '\0')
|
---|
[53] | 1490 | {
|
---|
| 1491 | unsigned int l = p2 - variable_buffer;
|
---|
[2591] | 1492 | plen = strlen (p2);
|
---|
| 1493 | variable_buffer_output (p2+plen, lb_next, strlen (lb_next)+1);
|
---|
[153] | 1494 | p2 = variable_buffer + l;
|
---|
[53] | 1495 | }
|
---|
| 1496 |
|
---|
| 1497 | p2 = parse_var_assignment (p2, &vmod);
|
---|
| 1498 | if (vmod.assign_v)
|
---|
[3140] | 1499 | {
|
---|
[53] | 1500 | /* If there was a semicolon found, add it back, plus anything
|
---|
[2591] | 1501 | after it. */
|
---|
| 1502 | if (semip)
|
---|
| 1503 | {
|
---|
| 1504 | unsigned int l = p2 - variable_buffer;
|
---|
| 1505 | *(--semip) = ';';
|
---|
[53] | 1506 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
| 1507 | collapse_continuations (semip);
|
---|
[3140] | 1508 | #else
|
---|
[53] | 1509 | collapse_continuations (semip, strlen(semip)); /** @todo fix this */
|
---|
[2591] | 1510 | #endif
|
---|
| 1511 | variable_buffer_output (p2 + strlen (p2),
|
---|
| 1512 | semip, strlen (semip)+1);
|
---|
[53] | 1513 | p2 = variable_buffer + l;
|
---|
| 1514 | }
|
---|
| 1515 | record_target_var (filenames, p2,
|
---|
| 1516 | vmod.override_v ? o_override : o_file,
|
---|
| 1517 | &vmod, fstart);
|
---|
| 1518 | filenames = 0;
|
---|
[3140] | 1519 | continue;
|
---|
| 1520 | }
|
---|
| 1521 |
|
---|
| 1522 | /* This is a normal target, _not_ a target-specific variable.
|
---|
| 1523 | Unquote any = in the dependency list. */
|
---|
| 1524 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
| 1525 | find_char_unquote (lb_next, MAP_EQUALS);
|
---|
| 1526 | #else
|
---|
[53] | 1527 | {
|
---|
[3140] | 1528 | char *tmp_eos = strchr(lb_next, '\0'); /** @todo see if we can optimize this away... */
|
---|
| 1529 | find_char_unquote_0 (lb_next, '=', MAP_EQUALS, &tmp_eos);
|
---|
| 1530 | }
|
---|
[53] | 1531 | #endif
|
---|
| 1532 |
|
---|
| 1533 | /* Remember the command prefix for this target. */
|
---|
| 1534 | prefix = cmd_prefix;
|
---|
| 1535 |
|
---|
| 1536 | /* We have some targets, so don't ignore the following commands. */
|
---|
| 1537 | no_targets = 0;
|
---|
[1831] | 1538 |
|
---|
[53] | 1539 | /* Expand the dependencies, etc. */
|
---|
[1831] | 1540 | if (*lb_next != '\0')
|
---|
| 1541 | {
|
---|
| 1542 | unsigned int l = p2 - variable_buffer;
|
---|
| 1543 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
[53] | 1544 | (void) variable_expand_string (p2 + plen, lb_next, (long)-1);
|
---|
| 1545 | #else
|
---|
| 1546 | char *eos;
|
---|
| 1547 | (void) variable_expand_string_2 (p2 + plen, lb_next, (long)-1, &eos);
|
---|
| 1548 | #endif
|
---|
[1831] | 1549 | p2 = variable_buffer + l;
|
---|
[3140] | 1550 |
|
---|
[1831] | 1551 | /* Look for a semicolon in the expanded line. */
|
---|
[3140] | 1552 | if (cmdleft == 0)
|
---|
[1831] | 1553 | {
|
---|
[53] | 1554 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
| 1555 | cmdleft = find_char_unquote (p2, MAP_SEMI);
|
---|
| 1556 | #else
|
---|
| 1557 | cmdleft = find_char_unquote_0 (p2, ';', MAP_SEMI, &eos);
|
---|
| 1558 | #endif
|
---|
[3140] | 1559 | if (cmdleft != 0)
|
---|
[53] | 1560 | *(cmdleft++) = '\0';
|
---|
| 1561 | }
|
---|
| 1562 | }
|
---|
[2591] | 1563 |
|
---|
| 1564 | /* Is this a static pattern rule: 'target: %targ: %dep; ...'? */
|
---|
[53] | 1565 | p = strchr (p2, ':');
|
---|
| 1566 | while (p != 0 && p[-1] == '\\')
|
---|
| 1567 | {
|
---|
| 1568 | char *q = &p[-1];
|
---|
| 1569 | int backslash = 0;
|
---|
| 1570 | while (*q-- == '\\')
|
---|
| 1571 | backslash = !backslash;
|
---|
| 1572 | if (backslash)
|
---|
| 1573 | p = strchr (p + 1, ':');
|
---|
| 1574 | else
|
---|
| 1575 | break;
|
---|
| 1576 | }
|
---|
| 1577 | #ifdef _AMIGA
|
---|
| 1578 | /* Here, the situation is quite complicated. Let's have a look
|
---|
| 1579 | at a couple of targets:
|
---|
| 1580 |
|
---|
| 1581 | install: dev:make
|
---|
| 1582 |
|
---|
| 1583 | dev:make: make
|
---|
| 1584 |
|
---|
[3140] | 1585 | dev:make:: xyz
|
---|
[53] | 1586 |
|
---|
| 1587 | The rule is that it's only a target, if there are TWO :'s
|
---|
| 1588 | OR a space around the :.
|
---|
| 1589 | */
|
---|
| 1590 | if (p && !(ISSPACE (p[1]) || !p[1] || ISSPACE (p[-1])))
|
---|
| 1591 | p = 0;
|
---|
| 1592 | #endif
|
---|
| 1593 | #ifdef HAVE_DOS_PATHS
|
---|
| 1594 | {
|
---|
| 1595 | int check_again;
|
---|
| 1596 | do {
|
---|
| 1597 | check_again = 0;
|
---|
| 1598 | /* For DOS-style paths, skip a "C:\..." or a "C:/..." */
|
---|
| 1599 | if (p != 0 && (p[1] == '\\' || p[1] == '/') &&
|
---|
| 1600 | isalpha ((unsigned char)p[-1]) &&
|
---|
| 1601 | (p == p2 + 1 || strchr (" \t:(", p[-2]) != 0)) {
|
---|
| 1602 | p = strchr (p + 1, ':');
|
---|
| 1603 | check_again = 1;
|
---|
| 1604 | }
|
---|
| 1605 | } while (check_again);
|
---|
[3140] | 1606 | }
|
---|
[2591] | 1607 | #endif
|
---|
[53] | 1608 | if (p != 0)
|
---|
| 1609 | {
|
---|
[3140] | 1610 | struct nameseq *target;
|
---|
[53] | 1611 | target = PARSE_FILE_SEQ (&p2, struct nameseq, MAP_COLON, NULL,
|
---|
[3140] | 1612 | PARSEFS_NOGLOB);
|
---|
[903] | 1613 | ++p2;
|
---|
[53] | 1614 | if (target == 0)
|
---|
| 1615 | O (fatal, fstart, _("missing target pattern"));
|
---|
[3140] | 1616 | else if (target->next != 0)
|
---|
[2591] | 1617 | OS (fatal, fstart, _("multiple target patterns (target '%s')"), target->name); /* bird added target */
|
---|
[53] | 1618 | pattern_percent = find_percent_cached (&target->name);
|
---|
| 1619 | pattern = target->name;
|
---|
| 1620 | if (pattern_percent == 0)
|
---|
| 1621 | OS (fatal, fstart, _("target pattern contains no '%%' (target '%s')"), target->name); /* bird added target */
|
---|
[287] | 1622 | free_ns (target);
|
---|
| 1623 | }
|
---|
| 1624 | else
|
---|
| 1625 | pattern = 0;
|
---|
| 1626 |
|
---|
[2591] | 1627 | /* Strip leading and trailing whitespaces. */
|
---|
[287] | 1628 | beg = p2;
|
---|
[2591] | 1629 | end = beg + strlen (beg) - 1;
|
---|
[287] | 1630 | strip_whitespace (&beg, &end);
|
---|
[2591] | 1631 |
|
---|
[53] | 1632 | /* Put all the prerequisites here; they'll be parsed later. */
|
---|
| 1633 | if (beg <= end && *beg != '\0')
|
---|
| 1634 | depstr = xstrndup (beg, end - beg + 1);
|
---|
| 1635 | else
|
---|
| 1636 | depstr = 0;
|
---|
[903] | 1637 |
|
---|
[53] | 1638 | commands_idx = 0;
|
---|
| 1639 | if (cmdleft != 0)
|
---|
| 1640 | {
|
---|
| 1641 | /* Semicolon means rest of line is a command. */
|
---|
[903] | 1642 | unsigned int l = strlen (cmdleft);
|
---|
[53] | 1643 |
|
---|
[903] | 1644 | cmds_started = fstart->lineno;
|
---|
| 1645 |
|
---|
[53] | 1646 | /* Add this command line to the buffer. */
|
---|
[903] | 1647 | if (l + 2 > commands_len)
|
---|
| 1648 | {
|
---|
[53] | 1649 | commands_len = (l + 2) * 2;
|
---|
| 1650 | commands = xrealloc (commands, commands_len);
|
---|
| 1651 | }
|
---|
[287] | 1652 | memcpy (commands, cmdleft, l);
|
---|
| 1653 | commands_idx += l;
|
---|
| 1654 | commands[commands_idx++] = '\n';
|
---|
| 1655 | }
|
---|
| 1656 |
|
---|
| 1657 | /* Determine if this target should be made default. We used to do
|
---|
| 1658 | this in record_files() but because of the delayed target recording
|
---|
| 1659 | and because preprocessor directives are legal in target's commands
|
---|
| 1660 | it is too late. Consider this fragment for example:
|
---|
| 1661 |
|
---|
| 1662 | foo:
|
---|
| 1663 |
|
---|
| 1664 | ifeq ($(.DEFAULT_GOAL),foo)
|
---|
[2591] | 1665 | ...
|
---|
[287] | 1666 | endif
|
---|
[2591] | 1667 |
|
---|
[287] | 1668 | Because the target is not recorded until after ifeq directive is
|
---|
| 1669 | evaluated the .DEFAULT_GOAL does not contain foo yet as one
|
---|
| 1670 | would expect. Because of this we have to move the logic here. */
|
---|
| 1671 |
|
---|
| 1672 | if (set_default && default_goal_var->value[0] == '\0')
|
---|
| 1673 | {
|
---|
| 1674 | struct dep *d;
|
---|
[3140] | 1675 | struct nameseq *t = filenames;
|
---|
[287] | 1676 |
|
---|
| 1677 | for (; t != 0; t = t->next)
|
---|
| 1678 | {
|
---|
| 1679 | int reject = 0;
|
---|
| 1680 | const char *name = t->name;
|
---|
[3140] | 1681 |
|
---|
[287] | 1682 | /* We have nothing to do if this is an implicit rule. */
|
---|
| 1683 | if (strchr (name, '%') != 0)
|
---|
| 1684 | break;
|
---|
| 1685 |
|
---|
| 1686 | /* See if this target's name does not start with a '.',
|
---|
| 1687 | unless it contains a slash. */
|
---|
| 1688 | if (*name == '.' && strchr (name, '/') == 0
|
---|
| 1689 | #ifdef HAVE_DOS_PATHS
|
---|
| 1690 | && strchr (name, '\\') == 0
|
---|
| 1691 | #endif
|
---|
| 1692 | )
|
---|
| 1693 | continue;
|
---|
| 1694 |
|
---|
| 1695 |
|
---|
| 1696 | /* If this file is a suffix, don't let it be
|
---|
| 1697 | the default goal file. */
|
---|
| 1698 | for (d = suffix_file->deps; d != 0; d = d->next)
|
---|
| 1699 | {
|
---|
| 1700 | register struct dep *d2;
|
---|
| 1701 | if (*dep_name (d) != '.' && streq (name, dep_name (d)))
|
---|
| 1702 | {
|
---|
[1898] | 1703 | reject = 1;
|
---|
[903] | 1704 | break;
|
---|
[1861] | 1705 | }
|
---|
[1898] | 1706 | for (d2 = suffix_file->deps; d2 != 0; d2 = d2->next)
|
---|
[1861] | 1707 | {
|
---|
[903] | 1708 | #ifndef CONFIG_WITH_STRCACHE2
|
---|
[287] | 1709 | unsigned int l = strlen (dep_name (d2));
|
---|
[903] | 1710 | #else
|
---|
[287] | 1711 | unsigned int l = strcache2_get_len (&file_strcache, dep_name (d2));
|
---|
| 1712 | #endif
|
---|
| 1713 | if (!strneq (name, dep_name (d2), l))
|
---|
| 1714 | continue;
|
---|
| 1715 | if (streq (name + l, dep_name (d)))
|
---|
| 1716 | {
|
---|
| 1717 | reject = 1;
|
---|
| 1718 | break;
|
---|
| 1719 | }
|
---|
| 1720 | }
|
---|
| 1721 |
|
---|
| 1722 | if (reject)
|
---|
| 1723 | break;
|
---|
| 1724 | }
|
---|
| 1725 |
|
---|
| 1726 | if (!reject)
|
---|
| 1727 | {
|
---|
| 1728 | define_variable_global (".DEFAULT_GOAL", 13, t->name,
|
---|
| 1729 | o_file, 0, NILF);
|
---|
[53] | 1730 | break;
|
---|
| 1731 | }
|
---|
| 1732 | }
|
---|
| 1733 | }
|
---|
[3140] | 1734 |
|
---|
| 1735 | continue;
|
---|
[53] | 1736 | }
|
---|
| 1737 |
|
---|
| 1738 | /* We get here except in the case that we just read a rule line.
|
---|
[3140] | 1739 | Record now the last rule we read, so following spurious
|
---|
[53] | 1740 | commands are properly diagnosed. */
|
---|
| 1741 | record_waiting_files ();
|
---|
[3140] | 1742 | }
|
---|
[2548] | 1743 |
|
---|
[53] | 1744 | #undef word1eq
|
---|
[2548] | 1745 |
|
---|
[3140] | 1746 | if (conditionals->if_cmds)
|
---|
[2548] | 1747 | O (fatal, fstart, _("missing 'endif'"));
|
---|
| 1748 | #ifdef KMK
|
---|
[53] | 1749 |
|
---|
| 1750 | if (kdata != NULL)
|
---|
| 1751 | O (fatal, fstart, _("missing `kBuild-endef-*'"));
|
---|
[3140] | 1752 | #endif
|
---|
[903] | 1753 |
|
---|
[53] | 1754 | /* At eof, record the last rule. */
|
---|
[503] | 1755 | record_waiting_files ();
|
---|
[53] | 1756 |
|
---|
[503] | 1757 | free (collapsed);
|
---|
| 1758 | free (commands);
|
---|
| 1759 | }
|
---|
[1811] | 1760 | |
---|
[503] | 1761 |
|
---|
| 1762 |
|
---|
[3140] | 1763 | /* Remove comments from LINE.
|
---|
| 1764 | This is done by copying the text at LINE onto itself. */
|
---|
| 1765 |
|
---|
| 1766 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
[503] | 1767 | static void
|
---|
| 1768 | remove_comments (char *line)
|
---|
| 1769 | #else
|
---|
[3140] | 1770 | static char *
|
---|
| 1771 | remove_comments (char *line, char *eos)
|
---|
[503] | 1772 | #endif
|
---|
| 1773 | {
|
---|
| 1774 | char *comment;
|
---|
| 1775 |
|
---|
[3140] | 1776 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
| 1777 | comment = find_char_unquote (line, MAP_COMMENT);
|
---|
| 1778 |
|
---|
[1831] | 1779 | if (comment != 0)
|
---|
[3140] | 1780 | /* Cut off the line at the #. */
|
---|
| 1781 | *comment = '\0';
|
---|
| 1782 | #else
|
---|
[1831] | 1783 | comment = find_char_unquote_0 (line, '#', MAP_COMMENT, &eos);
|
---|
[3140] | 1784 | if (comment)
|
---|
| 1785 | {
|
---|
[503] | 1786 | /* Cut off the line at the #. */
|
---|
| 1787 | *comment = '\0';
|
---|
[3140] | 1788 | return comment;
|
---|
[2591] | 1789 | }
|
---|
| 1790 | return eos;
|
---|
| 1791 | #endif
|
---|
| 1792 | }
|
---|
| 1793 |
|
---|
| 1794 | /* Execute a 'undefine' directive.
|
---|
| 1795 | The undefine line has already been read, and NAME is the name of
|
---|
| 1796 | the variable to be undefined. */
|
---|
| 1797 |
|
---|
| 1798 | static void
|
---|
| 1799 | do_undefine (char *name, enum variable_origin origin, struct ebuffer *ebuf)
|
---|
| 1800 | {
|
---|
[3140] | 1801 | char *p, *var;
|
---|
[2591] | 1802 |
|
---|
[3140] | 1803 | /* Expand the variable name and find the beginning (NAME) and end. */
|
---|
[2591] | 1804 | var = allocated_variable_expand (name);
|
---|
| 1805 | name = next_token (var);
|
---|
| 1806 | if (*name == '\0')
|
---|
| 1807 | O (fatal, &ebuf->floc, _("empty variable name"));
|
---|
| 1808 | p = name + strlen (name) - 1;
|
---|
| 1809 | while (p > name && ISBLANK (*p))
|
---|
| 1810 | --p;
|
---|
[3140] | 1811 | p[1] = '\0';
|
---|
[53] | 1812 |
|
---|
| 1813 | undefine_variable_global (name, p - name + 1, origin);
|
---|
| 1814 | free (var);
|
---|
[2591] | 1815 | }
|
---|
| 1816 |
|
---|
[53] | 1817 | /* Execute a 'define' directive.
|
---|
| 1818 | The first line has already been read, and NAME is the name of
|
---|
[2591] | 1819 | the variable to be defined. The following lines remain to be read. */
|
---|
[3140] | 1820 |
|
---|
| 1821 | static struct variable *
|
---|
[53] | 1822 | do_define (char *name IF_WITH_VALUE_LENGTH_PARAM(char *eos),
|
---|
| 1823 | enum variable_origin origin, struct ebuffer *ebuf)
|
---|
[903] | 1824 | {
|
---|
[53] | 1825 | struct variable *v;
|
---|
[3140] | 1826 | struct variable var;
|
---|
[53] | 1827 | floc defstart;
|
---|
| 1828 | int nlevels = 1;
|
---|
| 1829 | unsigned int length = 100;
|
---|
[3140] | 1830 | char *definition = xmalloc (length);
|
---|
[2591] | 1831 | unsigned int idx = 0;
|
---|
| 1832 | char *p, *n;
|
---|
[3140] | 1833 |
|
---|
[2591] | 1834 | defstart = ebuf->floc;
|
---|
| 1835 |
|
---|
[3140] | 1836 | p = parse_variable_definition (name, &var);
|
---|
| 1837 | if (p == NULL)
|
---|
[2591] | 1838 | /* No assignment token, so assume recursive. */
|
---|
| 1839 | var.flavor = f_recursive;
|
---|
[3140] | 1840 | else
|
---|
| 1841 | {
|
---|
| 1842 | if (var.value[0] != '\0')
|
---|
| 1843 | O (error, &defstart, _("extraneous text after 'define' directive"));
|
---|
| 1844 |
|
---|
| 1845 | /* Chop the string before the assignment token to get the name. */
|
---|
[2591] | 1846 | #ifndef CONFIG_WITH_STRCACHE2
|
---|
| 1847 | var.name[var.length] = '\0';
|
---|
| 1848 | #else
|
---|
[3140] | 1849 | assert (!strcache2_is_cached (&variable_strcache, var.name));
|
---|
| 1850 | ((char *)var.name)[var.length] = '\0';
|
---|
| 1851 | #endif
|
---|
| 1852 | }
|
---|
[2591] | 1853 |
|
---|
[3140] | 1854 | /* Expand the variable name and find the beginning (NAME) and end. */
|
---|
[2591] | 1855 | n = allocated_variable_expand (name);
|
---|
| 1856 | name = next_token (n);
|
---|
| 1857 | if (name[0] == '\0')
|
---|
| 1858 | O (fatal, &defstart, _("empty variable name"));
|
---|
[53] | 1859 | p = name + strlen (name) - 1;
|
---|
| 1860 | while (p > name && ISBLANK (*p))
|
---|
| 1861 | --p;
|
---|
| 1862 | p[1] = '\0';
|
---|
[2591] | 1863 |
|
---|
[53] | 1864 | /* Now read the value of the variable. */
|
---|
[2591] | 1865 | while (1)
|
---|
[53] | 1866 | {
|
---|
[3140] | 1867 | unsigned int len;
|
---|
[53] | 1868 | char *line;
|
---|
[2591] | 1869 | long nlines = readline (ebuf);
|
---|
[53] | 1870 |
|
---|
| 1871 | /* If there is nothing left to be eval'd, there's no 'endef'!! */
|
---|
[1811] | 1872 | if (nlines < 0)
|
---|
[53] | 1873 | O (fatal, &defstart, _("missing 'endef', unterminated 'define'"));
|
---|
[1811] | 1874 |
|
---|
| 1875 | ebuf->floc.lineno += nlines;
|
---|
| 1876 | line = ebuf->buffer;
|
---|
[53] | 1877 |
|
---|
| 1878 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
[2591] | 1879 | collapse_continuations (line);
|
---|
[903] | 1880 | #else
|
---|
[53] | 1881 | ebuf->eol = collapse_continuations (line, ebuf->eol - line);
|
---|
| 1882 | #endif
|
---|
[1811] | 1883 |
|
---|
[53] | 1884 | /* If the line doesn't begin with a tab, test to see if it introduces
|
---|
[1811] | 1885 | another define, or ends one. Stop if we find an 'endef' */
|
---|
| 1886 | if (line[0] != cmd_prefix)
|
---|
| 1887 | {
|
---|
| 1888 | p = next_token (line);
|
---|
[53] | 1889 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
| 1890 | len = strlen (p);
|
---|
[3140] | 1891 | #else
|
---|
[53] | 1892 | len = ebuf->eol - p;
|
---|
| 1893 | assert (len == strlen (p));
|
---|
| 1894 | #endif
|
---|
| 1895 |
|
---|
| 1896 | /* If this is another 'define', increment the level count. */
|
---|
[3140] | 1897 | if ((len == 6 || (len > 6 && ISBLANK (p[6])))
|
---|
[53] | 1898 | && strneq (p, "define", 6))
|
---|
| 1899 | ++nlevels;
|
---|
| 1900 |
|
---|
[1811] | 1901 | /* If this is an 'endef', decrement the count. If it's now 0,
|
---|
[53] | 1902 | we've found the last one. */
|
---|
[1811] | 1903 | else if ((len == 5 || (len > 5 && ISBLANK (p[5])))
|
---|
| 1904 | && strneq (p, "endef", 5))
|
---|
| 1905 | {
|
---|
[2591] | 1906 | p += 5;
|
---|
[3140] | 1907 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
| 1908 | remove_comments (p);
|
---|
[53] | 1909 | #else
|
---|
| 1910 | ebuf->eol = remove_comments (p, ebuf->eol);
|
---|
[2591] | 1911 | #endif
|
---|
[53] | 1912 | if (*(next_token (p)) != '\0')
|
---|
| 1913 | O (error, &ebuf->floc,
|
---|
| 1914 | _("extraneous text after 'endef' directive"));
|
---|
[2591] | 1915 |
|
---|
[1811] | 1916 | if (--nlevels == 0)
|
---|
[53] | 1917 | break;
|
---|
[1811] | 1918 | }
|
---|
| 1919 | }
|
---|
| 1920 |
|
---|
| 1921 | /* Add this line to the variable definition. */
|
---|
[53] | 1922 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
| 1923 | len = strlen (line);
|
---|
| 1924 | #else
|
---|
[903] | 1925 | len = ebuf->eol - line;
|
---|
[53] | 1926 | assert (len == strlen (line));
|
---|
| 1927 | #endif
|
---|
[903] | 1928 | if (idx + len + 1 > length)
|
---|
[53] | 1929 | {
|
---|
| 1930 | length = (idx + len) * 2;
|
---|
| 1931 | definition = xrealloc (definition, length + 1);
|
---|
| 1932 | }
|
---|
| 1933 |
|
---|
[2591] | 1934 | memcpy (&definition[idx], line, len);
|
---|
| 1935 | idx += len;
|
---|
| 1936 | /* Separate lines with a newline. */
|
---|
| 1937 | definition[idx++] = '\n';
|
---|
| 1938 | }
|
---|
[53] | 1939 |
|
---|
[2717] | 1940 | /* We've got what we need; define the variable. */
|
---|
[3140] | 1941 | if (idx == 0)
|
---|
| 1942 | definition[0] = '\0';
|
---|
[2717] | 1943 | else
|
---|
| 1944 | definition[idx - 1] = '\0';
|
---|
[3140] | 1945 |
|
---|
| 1946 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
[2717] | 1947 | v = do_variable_definition (&defstart, name,
|
---|
| 1948 | definition, origin, var.flavor, 0);
|
---|
[2591] | 1949 | #else
|
---|
[3140] | 1950 | v = do_variable_definition_2 (&defstart, name, definition,
|
---|
[2591] | 1951 | idx ? idx - 1 : idx, var.flavor == f_simple,
|
---|
[53] | 1952 | 0 /* free_value */, origin, var.flavor,
|
---|
| 1953 | 0 /*target_var*/);
|
---|
| 1954 | #endif
|
---|
[1109] | 1955 | free (definition);
|
---|
[53] | 1956 | free (n);
|
---|
| 1957 | return (v);
|
---|
| 1958 | }
|
---|
| 1959 | |
---|
| 1960 |
|
---|
[287] | 1961 | /* Interpret conditional commands "ifdef", "ifndef", "ifeq",
|
---|
| 1962 | "ifneq", "if1of", "ifn1of", "else" and "endif".
|
---|
[53] | 1963 | LINE is the input line, with the command as its first word.
|
---|
| 1964 |
|
---|
| 1965 | FILENAME and LINENO are the filename and line number in the
|
---|
| 1966 | current makefile. They are used for error messages.
|
---|
[3140] | 1967 |
|
---|
[53] | 1968 | Value is -2 if the line is not a conditional at all,
|
---|
[3140] | 1969 | -1 if the line is an invalid conditional,
|
---|
[1724] | 1970 | 0 if following text should be interpreted,
|
---|
[1109] | 1971 | 1 if following text should be ignored. */
|
---|
[1724] | 1972 |
|
---|
[1109] | 1973 | static int
|
---|
[1715] | 1974 | conditional_line (char *line IF_WITH_VALUE_LENGTH_PARAM(char *eol), int len, const floc *flocp)
|
---|
| 1975 | {
|
---|
| 1976 | const char *cmdname;
|
---|
[1724] | 1977 | enum { c_ifdef, c_ifndef, c_ifeq, c_ifneq,
|
---|
[1715] | 1978 | #ifdef CONFIG_WITH_SET_CONDITIONALS
|
---|
[287] | 1979 | c_if1of, c_ifn1of,
|
---|
| 1980 | #endif
|
---|
[1817] | 1981 | #ifdef CONFIG_WITH_IF_CONDITIONALS
|
---|
| 1982 | c_ifcond,
|
---|
| 1983 | #endif
|
---|
[53] | 1984 | c_else, c_endif
|
---|
[287] | 1985 | } cmdtype;
|
---|
[3140] | 1986 | unsigned int i;
|
---|
| 1987 | unsigned int o;
|
---|
[287] | 1988 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
| 1989 | assert (strchr (line, '\0') == eol);
|
---|
| 1990 | #endif
|
---|
| 1991 |
|
---|
| 1992 | /* Compare a word, both length and contents. */
|
---|
| 1993 | #define word1eq(s) (len == CSTRLEN (s) && strneq (s, line, CSTRLEN (s)))
|
---|
[1109] | 1994 | #define chkword(s, t) if (word1eq (s)) { cmdtype = (t); cmdname = (s); }
|
---|
| 1995 |
|
---|
| 1996 | /* Make sure this line is a conditional. */
|
---|
| 1997 | chkword ("ifdef", c_ifdef)
|
---|
[1715] | 1998 | else chkword ("ifndef", c_ifndef)
|
---|
| 1999 | else chkword ("ifeq", c_ifeq)
|
---|
[1724] | 2000 | else chkword ("ifneq", c_ifneq)
|
---|
[287] | 2001 | #ifdef CONFIG_WITH_SET_CONDITIONALS
|
---|
| 2002 | else chkword ("if1of", c_if1of)
|
---|
[53] | 2003 | else chkword ("ifn1of", c_ifn1of)
|
---|
[287] | 2004 | #endif
|
---|
[53] | 2005 | #ifdef CONFIG_WITH_IF_CONDITIONALS
|
---|
[287] | 2006 | else chkword ("if", c_ifcond)
|
---|
[3140] | 2007 | #endif
|
---|
| 2008 | else chkword ("else", c_else)
|
---|
[53] | 2009 | else chkword ("endif", c_endif)
|
---|
[3140] | 2010 | else
|
---|
| 2011 | return -2;
|
---|
[287] | 2012 |
|
---|
| 2013 | /* Found one: skip past it and any whitespace after it. */
|
---|
| 2014 | line += len;
|
---|
[53] | 2015 | NEXT_TOKEN (line);
|
---|
| 2016 |
|
---|
[3140] | 2017 | #define EXTRATEXT() OS (error, flocp, _("extraneous text after '%s' directive"), cmdname)
|
---|
[287] | 2018 | #define EXTRACMD() OS (fatal, flocp, _("extraneous '%s'"), cmdname)
|
---|
| 2019 |
|
---|
[3140] | 2020 | /* An 'endif' cannot contain extra text, and reduces the if-depth by 1 */
|
---|
[287] | 2021 | if (cmdtype == c_endif)
|
---|
| 2022 | {
|
---|
| 2023 | if (*line != '\0')
|
---|
| 2024 | EXTRATEXT ();
|
---|
| 2025 |
|
---|
| 2026 | if (!conditionals->if_cmds)
|
---|
| 2027 | EXTRACMD ();
|
---|
| 2028 |
|
---|
| 2029 | --conditionals->if_cmds;
|
---|
| 2030 |
|
---|
| 2031 | goto DONE;
|
---|
| 2032 | }
|
---|
| 2033 |
|
---|
[3140] | 2034 | /* An 'else' statement can either be simple, or it can have another
|
---|
[287] | 2035 | conditional after it. */
|
---|
| 2036 | if (cmdtype == c_else)
|
---|
| 2037 | {
|
---|
| 2038 | const char *p;
|
---|
[3140] | 2039 |
|
---|
[287] | 2040 | if (!conditionals->if_cmds)
|
---|
| 2041 | EXTRACMD ();
|
---|
| 2042 |
|
---|
| 2043 | o = conditionals->if_cmds - 1;
|
---|
| 2044 |
|
---|
| 2045 | if (conditionals->seen_else[o])
|
---|
| 2046 | O (fatal, flocp, _("only one 'else' per conditional"));
|
---|
| 2047 |
|
---|
| 2048 | /* Change the state of ignorance. */
|
---|
| 2049 | switch (conditionals->ignoring[o])
|
---|
| 2050 | {
|
---|
| 2051 | case 0:
|
---|
| 2052 | /* We've just been interpreting. Never do it again. */
|
---|
| 2053 | conditionals->ignoring[o] = 2;
|
---|
| 2054 | break;
|
---|
| 2055 | case 1:
|
---|
| 2056 | /* We've never interpreted yet. Maybe this time! */
|
---|
| 2057 | conditionals->ignoring[o] = 0;
|
---|
| 2058 | break;
|
---|
| 2059 | }
|
---|
| 2060 |
|
---|
| 2061 | /* It's a simple 'else'. */
|
---|
| 2062 | if (*line == '\0')
|
---|
| 2063 | {
|
---|
| 2064 | conditionals->seen_else[o] = 1;
|
---|
[3140] | 2065 | goto DONE;
|
---|
[287] | 2066 | }
|
---|
| 2067 |
|
---|
| 2068 | /* The 'else' has extra text. That text must be another conditional
|
---|
| 2069 | and cannot be an 'else' or 'endif'. */
|
---|
[3140] | 2070 |
|
---|
| 2071 | /* Find the length of the next word. */
|
---|
| 2072 | for (p = line+1; ! STOP_SET (*p, MAP_SPACE|MAP_NUL); ++p)
|
---|
[53] | 2073 | ;
|
---|
[287] | 2074 | len = p - line;
|
---|
| 2075 |
|
---|
| 2076 | /* If it's 'else' or 'endif' or an illegal conditional, fail. */
|
---|
| 2077 | if (word1eq ("else") || word1eq ("endif")
|
---|
| 2078 | || conditional_line (line IF_WITH_VALUE_LENGTH_PARAM(eol), len, flocp) < 0)
|
---|
| 2079 | EXTRATEXT ();
|
---|
| 2080 | else
|
---|
| 2081 | {
|
---|
| 2082 | /* conditional_line() created a new level of conditional.
|
---|
[53] | 2083 | Raise it back to this level. */
|
---|
| 2084 | if (conditionals->ignoring[o] < 2)
|
---|
[1929] | 2085 | conditionals->ignoring[o] = conditionals->ignoring[o+1];
|
---|
[53] | 2086 | --conditionals->if_cmds;
|
---|
| 2087 | }
|
---|
| 2088 |
|
---|
[903] | 2089 | goto DONE;
|
---|
| 2090 | }
|
---|
[53] | 2091 |
|
---|
[1929] | 2092 | #ifndef KMK
|
---|
[53] | 2093 | if (conditionals->allocated == 0)
|
---|
[287] | 2094 | {
|
---|
[53] | 2095 | conditionals->allocated = 5;
|
---|
| 2096 | conditionals->ignoring = xmalloc (conditionals->allocated);
|
---|
[1929] | 2097 | conditionals->seen_else = xmalloc (conditionals->allocated);
|
---|
| 2098 | }
|
---|
| 2099 | #endif
|
---|
| 2100 |
|
---|
| 2101 | o = conditionals->if_cmds++;
|
---|
| 2102 | if (conditionals->if_cmds > conditionals->allocated)
|
---|
| 2103 | {
|
---|
| 2104 | #ifdef KMK
|
---|
| 2105 | if (conditionals->allocated <= sizeof (conditionals->ignoring_first))
|
---|
| 2106 | {
|
---|
| 2107 | assert (conditionals->allocated == sizeof (conditionals->ignoring_first));
|
---|
| 2108 | conditionals->allocated += 16;
|
---|
| 2109 | conditionals->ignoring = xmalloc (conditionals->allocated);
|
---|
| 2110 | memcpy (conditionals->ignoring, conditionals->ignoring_first,
|
---|
| 2111 | sizeof (conditionals->ignoring_first));
|
---|
| 2112 | conditionals->seen_else = xmalloc (conditionals->allocated);
|
---|
| 2113 | memcpy (conditionals->seen_else, conditionals->seen_else_first,
|
---|
| 2114 | sizeof (conditionals->seen_else_first));
|
---|
| 2115 | }
|
---|
| 2116 | else
|
---|
| 2117 | {
|
---|
| 2118 | conditionals->allocated *= 2;
|
---|
| 2119 | #else /* !KMK */
|
---|
| 2120 | conditionals->allocated += 5;
|
---|
| 2121 | #endif /* !KMK */
|
---|
[53] | 2122 | conditionals->ignoring = xrealloc (conditionals->ignoring,
|
---|
| 2123 | conditionals->allocated);
|
---|
[3140] | 2124 | conditionals->seen_else = xrealloc (conditionals->seen_else,
|
---|
[287] | 2125 | conditionals->allocated);
|
---|
[53] | 2126 | #ifdef KMK
|
---|
| 2127 | }
|
---|
[287] | 2128 | #endif
|
---|
[53] | 2129 | }
|
---|
| 2130 |
|
---|
[3140] | 2131 | /* Record that we have seen an 'if...' but no 'else' so far. */
|
---|
| 2132 | conditionals->seen_else[o] = 0;
|
---|
| 2133 |
|
---|
| 2134 | /* Search through the stack to see if we're already ignoring. */
|
---|
| 2135 | for (i = 0; i < o; ++i)
|
---|
[53] | 2136 | if (conditionals->ignoring[i])
|
---|
| 2137 | {
|
---|
[287] | 2138 | /* We are already ignoring, so just push a level to match the next
|
---|
[53] | 2139 | "else" or "endif", and keep ignoring. We don't want to expand
|
---|
| 2140 | variables in the condition. */
|
---|
| 2141 | conditionals->ignoring[o] = 1;
|
---|
[287] | 2142 | return 1;
|
---|
[53] | 2143 | }
|
---|
| 2144 |
|
---|
| 2145 | if (cmdtype == c_ifdef || cmdtype == c_ifndef)
|
---|
[1817] | 2146 | {
|
---|
[53] | 2147 | char *var;
|
---|
[1817] | 2148 | struct variable *v;
|
---|
[1911] | 2149 | char *p;
|
---|
[1817] | 2150 |
|
---|
[53] | 2151 | /* Expand the thing we're looking up, so we can use indirect and
|
---|
[153] | 2152 | constructed variable names. */
|
---|
| 2153 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
| 2154 | var = allocated_variable_expand (line);
|
---|
[3140] | 2155 | #else
|
---|
[153] | 2156 | var = variable_expand_string_2 (NULL, line, eol - line, &p);
|
---|
[3140] | 2157 | #endif
|
---|
[153] | 2158 |
|
---|
| 2159 | /* Make sure there's only one variable name to test. */
|
---|
[287] | 2160 | p = end_of_token (var);
|
---|
[53] | 2161 | i = p - var;
|
---|
[287] | 2162 | NEXT_TOKEN (p);
|
---|
| 2163 | if (*p != '\0')
|
---|
| 2164 | return -1;
|
---|
[1911] | 2165 |
|
---|
[53] | 2166 | var[i] = '\0';
|
---|
[1911] | 2167 | v = lookup_variable (var, i);
|
---|
[53] | 2168 |
|
---|
[1715] | 2169 | conditionals->ignoring[o] =
|
---|
| 2170 | ((v != 0 && *v->value != '\0') == (cmdtype == c_ifndef));
|
---|
| 2171 |
|
---|
[1724] | 2172 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
[1715] | 2173 | free (var);
|
---|
| 2174 | #endif
|
---|
| 2175 | }
|
---|
| 2176 | #ifdef CONFIG_WITH_IF_CONDITIONALS
|
---|
| 2177 | else if (cmdtype == c_ifcond)
|
---|
[53] | 2178 | {
|
---|
| 2179 | int rval = expr_eval_if_conditionals (line, flocp);
|
---|
[1109] | 2180 | if (rval == -1)
|
---|
| 2181 | return rval;
|
---|
| 2182 | conditionals->ignoring[o] = rval;
|
---|
[903] | 2183 | }
|
---|
[1109] | 2184 | #endif
|
---|
[53] | 2185 | else
|
---|
[903] | 2186 | {
|
---|
[53] | 2187 | #ifdef CONFIG_WITH_SET_CONDITIONALS
|
---|
[1817] | 2188 | /* "ifeq", "ifneq", "if1of" or "ifn1of". */
|
---|
[2426] | 2189 | #else
|
---|
[1817] | 2190 | /* "ifeq" or "ifneq". */
|
---|
[53] | 2191 | #endif
|
---|
| 2192 | char *s1, *s2;
|
---|
[3140] | 2193 | unsigned int l;
|
---|
[53] | 2194 | char termin = *line == '(' ? ',' : *line;
|
---|
| 2195 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
| 2196 | char *s1_end, *s2_end;
|
---|
| 2197 | #endif
|
---|
[3140] | 2198 |
|
---|
| 2199 | if (termin != ',' && termin != '"' && termin != '\'')
|
---|
| 2200 | return -1;
|
---|
| 2201 |
|
---|
| 2202 | s1 = ++line;
|
---|
| 2203 | /* Find the end of the first string. */
|
---|
| 2204 | if (termin == ',')
|
---|
| 2205 | {
|
---|
| 2206 | int count = 0;
|
---|
| 2207 | for (; *line != '\0'; ++line)
|
---|
[53] | 2208 | if (*line == '(')
|
---|
[3140] | 2209 | ++count;
|
---|
| 2210 | else if (*line == ')')
|
---|
[53] | 2211 | --count;
|
---|
| 2212 | else if (*line == ',' && count <= 0)
|
---|
[3140] | 2213 | break;
|
---|
[53] | 2214 | }
|
---|
| 2215 | else
|
---|
[3140] | 2216 | while (*line != '\0' && *line != termin)
|
---|
| 2217 | ++line;
|
---|
| 2218 |
|
---|
| 2219 | if (*line == '\0')
|
---|
| 2220 | return -1;
|
---|
| 2221 |
|
---|
[1817] | 2222 | if (termin == ',')
|
---|
| 2223 | {
|
---|
| 2224 | /* Strip blanks after the first string. */
|
---|
[3140] | 2225 | char *p = line++;
|
---|
[53] | 2226 | while (ISBLANK (p[-1]))
|
---|
[1817] | 2227 | --p;
|
---|
| 2228 | *p = '\0';
|
---|
| 2229 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
| 2230 | l = p - s1;
|
---|
[3140] | 2231 | #endif
|
---|
[1817] | 2232 | }
|
---|
[53] | 2233 | else
|
---|
[1817] | 2234 | {
|
---|
[53] | 2235 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
| 2236 | l = line - s1;
|
---|
[3140] | 2237 | #endif
|
---|
[903] | 2238 | *line++ = '\0';
|
---|
| 2239 | }
|
---|
| 2240 |
|
---|
[1817] | 2241 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
[2426] | 2242 | s2 = variable_expand (s1);
|
---|
[1817] | 2243 | /* We must allocate a new copy of the expanded string because
|
---|
[53] | 2244 | variable_expand re-uses the same buffer. */
|
---|
| 2245 | l = strlen (s2);
|
---|
[3140] | 2246 | s1 = alloca (l + 1);
|
---|
| 2247 | memcpy (s1, s2, l + 1);
|
---|
[53] | 2248 | #else
|
---|
| 2249 | s1 = variable_expand_string_2 (NULL, s1, l, &s1_end);
|
---|
| 2250 | #endif
|
---|
[3140] | 2251 |
|
---|
[53] | 2252 | if (termin != ',')
|
---|
| 2253 | /* Find the start of the second string. */
|
---|
| 2254 | NEXT_TOKEN (line);
|
---|
[3140] | 2255 |
|
---|
| 2256 | termin = termin == ',' ? ')' : *line;
|
---|
| 2257 | if (termin != ')' && termin != '"' && termin != '\'')
|
---|
| 2258 | return -1;
|
---|
| 2259 |
|
---|
| 2260 | /* Find the end of the second string. */
|
---|
| 2261 | if (termin == ')')
|
---|
| 2262 | {
|
---|
| 2263 | int count = 0;
|
---|
| 2264 | s2 = next_token (line);
|
---|
| 2265 | for (line = s2; *line != '\0'; ++line)
|
---|
| 2266 | {
|
---|
| 2267 | if (*line == '(')
|
---|
| 2268 | ++count;
|
---|
| 2269 | else if (*line == ')')
|
---|
| 2270 | {
|
---|
[53] | 2271 | if (count <= 0)
|
---|
[3140] | 2272 | break;
|
---|
| 2273 | else
|
---|
| 2274 | --count;
|
---|
| 2275 | }
|
---|
| 2276 | }
|
---|
| 2277 | }
|
---|
[53] | 2278 | else
|
---|
| 2279 | {
|
---|
[3140] | 2280 | ++line;
|
---|
[53] | 2281 | s2 = line;
|
---|
[1817] | 2282 | while (*line != '\0' && *line != termin)
|
---|
| 2283 | ++line;
|
---|
| 2284 | }
|
---|
[3140] | 2285 |
|
---|
| 2286 | if (*line == '\0')
|
---|
[53] | 2287 | return -1;
|
---|
[3140] | 2288 |
|
---|
[53] | 2289 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
[1817] | 2290 | l = line - s2;
|
---|
[53] | 2291 | #endif
|
---|
[1817] | 2292 | *(line++) = '\0';
|
---|
[2426] | 2293 | NEXT_TOKEN (line);
|
---|
| 2294 | if (*line != '\0')
|
---|
| 2295 | EXTRATEXT ();
|
---|
[1817] | 2296 |
|
---|
[1109] | 2297 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
| 2298 | s2 = variable_expand (s2);
|
---|
| 2299 | #else
|
---|
| 2300 | s2 = variable_expand_string_2 (s1_end + 1, s2, l, &s2_end);
|
---|
| 2301 | if (s2 != s1_end + 1)
|
---|
| 2302 | s1 += s2 - s1_end - 1; /* the variable buffer was reallocated */
|
---|
| 2303 | #endif
|
---|
| 2304 | #ifdef CONFIG_WITH_SET_CONDITIONALS
|
---|
| 2305 | if (cmdtype == c_if1of || cmdtype == c_ifn1of)
|
---|
| 2306 | {
|
---|
| 2307 | const char *s1_cur;
|
---|
| 2308 | unsigned int s1_len;
|
---|
| 2309 | const char *s1_iterator = s1;
|
---|
| 2310 |
|
---|
| 2311 | conditionals->ignoring[o] = (cmdtype == c_if1of); /* if not found */
|
---|
| 2312 | while ((s1_cur = find_next_token (&s1_iterator, &s1_len)) != 0)
|
---|
| 2313 | {
|
---|
| 2314 | const char *s2_cur;
|
---|
| 2315 | unsigned int s2_len;
|
---|
| 2316 | const char *s2_iterator = s2;
|
---|
| 2317 | while ((s2_cur = find_next_token (&s2_iterator, &s2_len)) != 0)
|
---|
| 2318 | if (s2_len == s1_len
|
---|
| 2319 | && strneq (s2_cur, s1_cur, s1_len) )
|
---|
| 2320 | {
|
---|
| 2321 | conditionals->ignoring[o] = (cmdtype != c_if1of); /* found */
|
---|
[287] | 2322 | break;
|
---|
[1109] | 2323 | }
|
---|
[53] | 2324 | }
|
---|
| 2325 | }
|
---|
[287] | 2326 | else
|
---|
[53] | 2327 | conditionals->ignoring[o] = (streq (s1, s2) == (cmdtype == c_ifneq));
|
---|
| 2328 | #else
|
---|
| 2329 | conditionals->ignoring[o] = (streq (s1, s2) == (cmdtype == c_ifneq));
|
---|
| 2330 | #endif
|
---|
| 2331 | }
|
---|
| 2332 |
|
---|
| 2333 | DONE:
|
---|
| 2334 | /* Search through the stack to see if we're ignoring. */
|
---|
| 2335 | for (i = 0; i < conditionals->if_cmds; ++i)
|
---|
| 2336 | if (conditionals->ignoring[i])
|
---|
| 2337 | return 1;
|
---|
| 2338 | return 0;
|
---|
| 2339 | }
|
---|
| 2340 | |
---|
| 2341 |
|
---|
| 2342 | /* Record target-specific variable values for files FILENAMES.
|
---|
| 2343 | TWO_COLON is nonzero if a double colon was used.
|
---|
[153] | 2344 |
|
---|
[2591] | 2345 | The links of FILENAMES are freed, and so are any names in it
|
---|
[3140] | 2346 | that are not incorporated into other data structures.
|
---|
[53] | 2347 |
|
---|
| 2348 | If the target is a pattern, add the variable to the pattern-specific
|
---|
| 2349 | variable value list. */
|
---|
| 2350 |
|
---|
| 2351 | static void
|
---|
| 2352 | record_target_var (struct nameseq *filenames, char *defn,
|
---|
| 2353 | enum variable_origin origin, struct vmodifiers *vmod,
|
---|
| 2354 | const floc *flocp)
|
---|
| 2355 | {
|
---|
| 2356 | struct nameseq *nextf;
|
---|
| 2357 | struct variable_set_list *global;
|
---|
| 2358 |
|
---|
[903] | 2359 | global = current_variable_set_list;
|
---|
| 2360 |
|
---|
[53] | 2361 | /* If the variable is an append version, store that but treat it as a
|
---|
[3140] | 2362 | normal recursive variable. */
|
---|
| 2363 |
|
---|
| 2364 | for (; filenames != 0; filenames = nextf)
|
---|
[53] | 2365 | {
|
---|
| 2366 | struct variable *v;
|
---|
[2591] | 2367 | const char *name = filenames->name;
|
---|
[53] | 2368 | const char *percent;
|
---|
| 2369 | struct pattern_var *p;
|
---|
| 2370 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
[903] | 2371 | const char *fname;
|
---|
[53] | 2372 | #endif
|
---|
| 2373 |
|
---|
| 2374 | nextf = filenames->next;
|
---|
| 2375 | free_ns (filenames);
|
---|
| 2376 |
|
---|
[287] | 2377 | /* If it's a pattern target, then add it to the pattern-specific
|
---|
| 2378 | variable list. */
|
---|
[2591] | 2379 | percent = find_percent_cached (&name);
|
---|
[287] | 2380 | if (percent)
|
---|
| 2381 | {
|
---|
[2591] | 2382 | /* Get a reference for this pattern-specific variable struct. */
|
---|
[2770] | 2383 | p = create_pattern_var (name, percent);
|
---|
[287] | 2384 | p->variable.fileinfo = *flocp;
|
---|
| 2385 | /* I don't think this can fail since we already determined it was a
|
---|
| 2386 | variable definition. */
|
---|
| 2387 | v = assign_variable_definition (&p->variable, defn IF_WITH_VALUE_LENGTH_PARAM(NULL));
|
---|
[2770] | 2388 | assert (v != 0);
|
---|
| 2389 |
|
---|
| 2390 | v->origin = origin;
|
---|
| 2391 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
| 2392 | if (v->flavor == f_simple)
|
---|
| 2393 | v->value = allocated_variable_expand (v->value);
|
---|
| 2394 | else
|
---|
| 2395 | v->value = xstrdup (v->value);
|
---|
[53] | 2396 | #else
|
---|
| 2397 | v->value_length = strlen (v->value);
|
---|
| 2398 | if (v->flavor == f_simple)
|
---|
| 2399 | v->value = allocated_variable_expand_2 (v->value, v->value_length, &v->value_length);
|
---|
| 2400 | else
|
---|
| 2401 | v->value = (char *)memcpy (xmalloc (v->value_length + 1), v->value, v->value_length + 1);
|
---|
| 2402 | v->value_alloc_len = v->value_length + 1;
|
---|
| 2403 | #endif
|
---|
| 2404 | }
|
---|
[1975] | 2405 | else
|
---|
[53] | 2406 | {
|
---|
| 2407 | struct file *f;
|
---|
[903] | 2408 |
|
---|
[1975] | 2409 | /* Get a file reference for this file, and initialize it.
|
---|
[1857] | 2410 | We don't want to just call enter_file() because that allocates a
|
---|
| 2411 | new entry if the file is a double-colon, which we don't want in
|
---|
| 2412 | this situation. */
|
---|
| 2413 | #ifndef CONFIG_WITH_STRCACHE2
|
---|
| 2414 | f = lookup_file (name);
|
---|
[1975] | 2415 | if (!f)
|
---|
[53] | 2416 | f = enter_file (strcache_add (name));
|
---|
| 2417 | #else /* CONFIG_WITH_STRCACHE2 */
|
---|
| 2418 | /* XXX: this is probably already a cached string. */
|
---|
| 2419 | fname = strcache_add (name);
|
---|
| 2420 | f = lookup_file_cached (fname);
|
---|
| 2421 | if (!f)
|
---|
[2591] | 2422 | f = enter_file (fname);
|
---|
[53] | 2423 | #endif /* CONFIG_WITH_STRCACHE2 */
|
---|
[3140] | 2424 | else if (f->double_colon)
|
---|
[53] | 2425 | f = f->double_colon;
|
---|
| 2426 |
|
---|
| 2427 | initialize_file_variables (f, 1);
|
---|
| 2428 |
|
---|
| 2429 | current_variable_set_list = f->variables;
|
---|
[2591] | 2430 | v = try_variable_definition (flocp, defn IF_WITH_VALUE_LENGTH_PARAM(NULL), origin, 1);
|
---|
| 2431 | if (!v)
|
---|
[53] | 2432 | O (fatal, flocp, _("Malformed target-specific variable definition"));
|
---|
| 2433 | current_variable_set_list = global;
|
---|
| 2434 | }
|
---|
[2591] | 2435 |
|
---|
[53] | 2436 | /* Set up the variable to be *-specific. */
|
---|
| 2437 | v->per_target = 1;
|
---|
[1946] | 2438 | v->private_var = vmod->private_v;
|
---|
[3140] | 2439 | v->export = vmod->export_v ? v_export : v_default;
|
---|
[1946] | 2440 |
|
---|
[1947] | 2441 | /* If it's not an override, check to see if there was a command-line
|
---|
| 2442 | setting. If so, reset the value. */
|
---|
| 2443 | if (v->origin != o_override)
|
---|
[1946] | 2444 | {
|
---|
[53] | 2445 | struct variable *gv;
|
---|
| 2446 | #ifndef CONFIG_WITH_STRCACHE2
|
---|
[3140] | 2447 | int len = strlen (v->name);
|
---|
| 2448 | #else
|
---|
[53] | 2449 | int len = !percent
|
---|
[1946] | 2450 | ? strcache2_get_len (&variable_strcache, v->name)
|
---|
| 2451 | : strlen(v->name);
|
---|
| 2452 | #endif
|
---|
[3140] | 2453 |
|
---|
[1946] | 2454 | gv = lookup_variable (v->name, len);
|
---|
[53] | 2455 | if (gv && v != gv
|
---|
[1946] | 2456 | && (gv->origin == o_env_override || gv->origin == o_command))
|
---|
[2591] | 2457 | {
|
---|
[1946] | 2458 | #ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
|
---|
| 2459 | assert (!v->rdonly_val); /* paranoia */
|
---|
[53] | 2460 | #endif
|
---|
| 2461 | free (v->value);
|
---|
| 2462 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
[2770] | 2463 | v->value = xstrdup (gv->value);
|
---|
[53] | 2464 | #else
|
---|
| 2465 | v->value = xstrndup (gv->value, gv->value_length);
|
---|
| 2466 | v->value_length = gv->value_length;
|
---|
| 2467 | #endif
|
---|
| 2468 | v->origin = gv->origin;
|
---|
| 2469 | v->recursive = gv->recursive;
|
---|
| 2470 | v->append = 0;
|
---|
| 2471 | VARIABLE_CHANGED (v);
|
---|
| 2472 | }
|
---|
[3140] | 2473 | }
|
---|
[53] | 2474 | }
|
---|
[3140] | 2475 | }
|
---|
[53] | 2476 | |
---|
| 2477 |
|
---|
| 2478 | /* Record a description line for files FILENAMES,
|
---|
| 2479 | with dependencies DEPS, commands to execute described
|
---|
| 2480 | by COMMANDS and COMMANDS_IDX, coming from FILENAME:COMMANDS_STARTED.
|
---|
[903] | 2481 | TWO_COLON is nonzero if a double colon was used.
|
---|
[2591] | 2482 | If not nil, PATTERN is the '%' pattern to make this
|
---|
[903] | 2483 | a static pattern rule, and PATTERN_PERCENT is a pointer
|
---|
[53] | 2484 | to the '%' within it.
|
---|
[3140] | 2485 |
|
---|
[53] | 2486 | The links of FILENAMES are freed, and so are any names in it
|
---|
[921] | 2487 | that are not incorporated into other data structures. */
|
---|
| 2488 |
|
---|
| 2489 | static void
|
---|
| 2490 | record_files (struct nameseq *filenames, const char *pattern,
|
---|
| 2491 | const char *pattern_percent, char *depstr,
|
---|
[2591] | 2492 | unsigned int cmds_started, char *commands,
|
---|
| 2493 | unsigned int commands_idx, int two_colon,
|
---|
| 2494 | char prefix, const floc *flocp)
|
---|
| 2495 | {
|
---|
[53] | 2496 | #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
|
---|
[287] | 2497 | struct file *prev_file = 0;
|
---|
| 2498 | enum multitarget_mode { m_unsettled, m_no, m_yes, m_yes_maybe }
|
---|
| 2499 | multi_mode = !two_colon && !pattern ? m_unsettled : m_no;
|
---|
| 2500 | #endif
|
---|
| 2501 | struct commands *cmds;
|
---|
[3140] | 2502 | struct dep *deps;
|
---|
[287] | 2503 | const char *implicit_percent;
|
---|
[2591] | 2504 | const char *name;
|
---|
| 2505 |
|
---|
| 2506 | /* If we've already snapped deps, that means we're in an eval being
|
---|
| 2507 | resolved after the makefiles have been read in. We can't add more rules
|
---|
| 2508 | at this time, since they won't get snapped and we'll get core dumps.
|
---|
[53] | 2509 | See Savannah bug # 12124. */
|
---|
| 2510 | if (snapped_deps)
|
---|
[1867] | 2511 | O (fatal, flocp, _("prerequisites cannot be defined in recipes"));
|
---|
[903] | 2512 |
|
---|
[1867] | 2513 | /* Determine if this is a pattern rule or not. */
|
---|
| 2514 | name = filenames->name;
|
---|
| 2515 | implicit_percent = find_percent_cached (&name);
|
---|
[53] | 2516 |
|
---|
| 2517 | /* If there's a recipe, set up a struct for it. */
|
---|
[3140] | 2518 | if (commands_idx > 0)
|
---|
[2591] | 2519 | {
|
---|
[53] | 2520 | #ifndef CONFIG_WITH_ALLOC_CACHES
|
---|
[3140] | 2521 | cmds = xmalloc (sizeof (struct commands));
|
---|
[2056] | 2522 | #else
|
---|
| 2523 | cmds = alloccache_alloc (&commands_cache);
|
---|
| 2524 | #endif
|
---|
[53] | 2525 | cmds->fileinfo.filenm = flocp->filenm;
|
---|
| 2526 | cmds->fileinfo.lineno = cmds_started;
|
---|
[2591] | 2527 | cmds->fileinfo.offset = 0;
|
---|
[53] | 2528 | cmds->commands = xstrndup (commands, commands_idx);
|
---|
[2591] | 2529 | cmds->command_lines = 0;
|
---|
| 2530 | cmds->recipe_prefix = prefix;
|
---|
| 2531 | #ifdef CONFIG_WITH_MEMORY_OPTIMIZATIONS
|
---|
| 2532 | cmds->refs = 0;
|
---|
| 2533 | #endif
|
---|
| 2534 | }
|
---|
[3140] | 2535 | else
|
---|
| 2536 | cmds = 0;
|
---|
| 2537 |
|
---|
| 2538 | /* If there's a prereq string then parse it--unless it's eligible for 2nd
|
---|
| 2539 | expansion: if so, snap_deps() will do it. */
|
---|
| 2540 | if (depstr == 0)
|
---|
| 2541 | deps = 0;
|
---|
| 2542 | else
|
---|
| 2543 | {
|
---|
| 2544 | depstr = unescape_char (depstr, ':');
|
---|
| 2545 | if (second_expansion && strchr (depstr, '$'))
|
---|
| 2546 | {
|
---|
[2591] | 2547 | deps = alloc_dep ();
|
---|
[3140] | 2548 | deps->name = depstr;
|
---|
| 2549 | deps->need_2nd_expansion = 1;
|
---|
| 2550 | deps->staticpattern = pattern != 0;
|
---|
| 2551 | }
|
---|
| 2552 | else
|
---|
| 2553 | {
|
---|
| 2554 | deps = split_prereqs (depstr);
|
---|
[2591] | 2555 | free (depstr);
|
---|
| 2556 |
|
---|
| 2557 | /* We'll enter static pattern prereqs later when we have the stem.
|
---|
| 2558 | We don't want to enter pattern rules at all so that we don't
|
---|
| 2559 | think that they ought to exist (make manual "Implicit Rule Search
|
---|
| 2560 | Algorithm", item 5c). */
|
---|
| 2561 | if (! pattern && ! implicit_percent)
|
---|
| 2562 | deps = enter_prereqs (deps, NULL);
|
---|
| 2563 | }
|
---|
| 2564 | }
|
---|
| 2565 |
|
---|
| 2566 | /* For implicit rules, _all_ the targets must have a pattern. That means we
|
---|
| 2567 | can test the first one to see if we're working with an implicit rule; if
|
---|
[3140] | 2568 | so we handle it specially. */
|
---|
[2591] | 2569 |
|
---|
| 2570 | if (implicit_percent)
|
---|
| 2571 | {
|
---|
| 2572 | struct nameseq *nextf;
|
---|
| 2573 | const char **targets, **target_pats;
|
---|
| 2574 | unsigned int c;
|
---|
| 2575 |
|
---|
| 2576 | if (pattern != 0)
|
---|
| 2577 | O (fatal, flocp, _("mixed implicit and static pattern rules"));
|
---|
| 2578 |
|
---|
| 2579 | /* Count the targets to create an array of target names.
|
---|
| 2580 | We already have the first one. */
|
---|
| 2581 | nextf = filenames->next;
|
---|
| 2582 | free_ns (filenames);
|
---|
| 2583 | filenames = nextf;
|
---|
| 2584 |
|
---|
| 2585 | for (c = 1; nextf; ++c, nextf = nextf->next)
|
---|
| 2586 | ;
|
---|
| 2587 | targets = xmalloc (c * sizeof (const char *));
|
---|
| 2588 | target_pats = xmalloc (c * sizeof (const char *));
|
---|
| 2589 |
|
---|
| 2590 | targets[0] = name;
|
---|
[3140] | 2591 | target_pats[0] = implicit_percent;
|
---|
[2591] | 2592 |
|
---|
[3140] | 2593 | c = 1;
|
---|
| 2594 | while (filenames)
|
---|
[2591] | 2595 | {
|
---|
| 2596 | name = filenames->name;
|
---|
| 2597 | implicit_percent = find_percent_cached (&name);
|
---|
| 2598 |
|
---|
| 2599 | if (implicit_percent == 0)
|
---|
| 2600 | O (fatal, flocp, _("mixed implicit and normal rules"));
|
---|
| 2601 |
|
---|
| 2602 | targets[c] = name;
|
---|
| 2603 | target_pats[c] = implicit_percent;
|
---|
| 2604 | ++c;
|
---|
| 2605 |
|
---|
| 2606 | nextf = filenames->next;
|
---|
| 2607 | free_ns (filenames);
|
---|
| 2608 | filenames = nextf;
|
---|
| 2609 | }
|
---|
| 2610 |
|
---|
| 2611 | create_pattern_rule (targets, target_pats, c, two_colon, deps, cmds, 1);
|
---|
| 2612 |
|
---|
[53] | 2613 | return;
|
---|
[503] | 2614 | }
|
---|
[53] | 2615 |
|
---|
[2591] | 2616 |
|
---|
[53] | 2617 | /* Walk through each target and create it in the database.
|
---|
[503] | 2618 | We already set up the first target, above. */
|
---|
| 2619 | while (1)
|
---|
[53] | 2620 | {
|
---|
[2591] | 2621 | struct nameseq *nextf = filenames->next;
|
---|
| 2622 | struct file *f;
|
---|
| 2623 | struct dep *this = 0;
|
---|
[3140] | 2624 |
|
---|
| 2625 | free_ns (filenames);
|
---|
| 2626 |
|
---|
| 2627 | /* Check for special targets. Do it here instead of, say, snap_deps()
|
---|
| 2628 | so that we can immediately use the value. */
|
---|
| 2629 | if (streq (name, ".POSIX"))
|
---|
| 2630 | {
|
---|
[2591] | 2631 | posix_pedantic = 1;
|
---|
[503] | 2632 | define_variable_cname (".SHELLFLAGS", "-ec", o_default, 0);
|
---|
| 2633 | /* These default values are based on IEEE Std 1003.1-2008. */
|
---|
[1701] | 2634 | define_variable_cname ("ARFLAGS", "-rv", o_default, 0);
|
---|
| 2635 | define_variable_cname ("CC", "c99", o_default, 0);
|
---|
| 2636 | define_variable_cname ("CFLAGS", "-O", o_default, 0);
|
---|
| 2637 | define_variable_cname ("FC", "fort77", o_default, 0);
|
---|
[3140] | 2638 | define_variable_cname ("FFLAGS", "-O 1", o_default, 0);
|
---|
[2591] | 2639 | define_variable_cname ("SCCSGETFLAGS", "-s", o_default, 0);
|
---|
| 2640 | }
|
---|
| 2641 | else if (streq (name, ".SECONDEXPANSION"))
|
---|
[53] | 2642 | second_expansion = 1;
|
---|
[921] | 2643 | #ifdef CONFIG_WITH_2ND_TARGET_EXPANSION
|
---|
| 2644 | else if (streq (name, ".SECONDTARGETEXPANSION"))
|
---|
[1021] | 2645 | second_target_expansion = 1;
|
---|
[921] | 2646 | #endif
|
---|
| 2647 | #if !defined (__MSDOS__) && !defined (__EMX__)
|
---|
| 2648 | else if (streq (name, ".ONESHELL"))
|
---|
| 2649 | one_shell = 1;
|
---|
| 2650 | #endif
|
---|
[922] | 2651 |
|
---|
| 2652 | #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
|
---|
| 2653 | /* Check for the explicit multitarget mode operators. For this to be
|
---|
| 2654 | identified as an explicit multiple target rule, the first + or +|
|
---|
| 2655 | operator *must* appear between the first two files. If not found as
|
---|
| 2656 | the 2nd file or if found as the 1st file, the rule will be rejected
|
---|
| 2657 | as a potential multiple first target rule. For the subsequent files
|
---|
[1109] | 2658 | the operator is only required to switch between maybe and non-maybe
|
---|
[1021] | 2659 | mode:
|
---|
[921] | 2660 | `primary + 2nd 3rd +| 4th-maybe + 5th-for-sure: deps; cmds'
|
---|
| 2661 |
|
---|
| 2662 | The whole idea of the maybe-updated files is this:
|
---|
| 2663 | timestamp +| maybe.h: src1.c src2.c
|
---|
| 2664 | grep goes-into-maybe.h $* > timestamp
|
---|
| 2665 | cmp timestamp maybe.h || cp -f timestamp maybe.h
|
---|
| 2666 |
|
---|
| 2667 | This is implemented in remake.c where we don't consider the mtime of
|
---|
[1021] | 2668 | the maybe-updated targets. */
|
---|
| 2669 | if (multi_mode != m_no && name[0] == '+'
|
---|
| 2670 | && (name[1] == '\0' || (name[1] == '|' && name[2] == '\0')))
|
---|
| 2671 | {
|
---|
| 2672 | if (!prev_file)
|
---|
| 2673 | multi_mode = m_no; /* first */
|
---|
| 2674 | else
|
---|
| 2675 | {
|
---|
| 2676 | if (multi_mode == m_unsettled)
|
---|
| 2677 | {
|
---|
[921] | 2678 | prev_file->multi_head = prev_file;
|
---|
[2591] | 2679 |
|
---|
[921] | 2680 | /* Only the primary file needs the dependencies. */
|
---|
| 2681 | if (deps)
|
---|
| 2682 | {
|
---|
| 2683 | free_dep_chain (deps);
|
---|
| 2684 | deps = NULL;
|
---|
| 2685 | }
|
---|
[503] | 2686 | }
|
---|
[3140] | 2687 | multi_mode = name[1] == '\0' ? m_yes : m_yes_maybe;
|
---|
[503] | 2688 | goto l_next;
|
---|
| 2689 | }
|
---|
[3140] | 2690 | }
|
---|
| 2691 | else if (multi_mode == m_unsettled && prev_file)
|
---|
[503] | 2692 | multi_mode = m_no;
|
---|
[2591] | 2693 | #endif
|
---|
| 2694 |
|
---|
| 2695 | /* If this is a static pattern rule:
|
---|
| 2696 | 'targets: target%pattern: prereq%pattern; recipe',
|
---|
[53] | 2697 | make sure the pattern matches this target name. */
|
---|
[2591] | 2698 | if (pattern && !pattern_matches (pattern, pattern_percent, name))
|
---|
[53] | 2699 | OS (error, flocp,
|
---|
[3140] | 2700 | _("target '%s' doesn't match the target pattern"), name);
|
---|
| 2701 | else if (deps)
|
---|
| 2702 | /* If there are multiple targets, copy the chain DEPS for all but the
|
---|
[1853] | 2703 | last one. It is not safe for the same deps to go in more than one
|
---|
[3140] | 2704 | place in the database. */
|
---|
[1853] | 2705 | this = nextf != 0 ? copy_dep_chain (deps) : deps;
|
---|
| 2706 |
|
---|
| 2707 | /* Find or create an entry in the file database for this target. */
|
---|
[3140] | 2708 | if (!two_colon)
|
---|
| 2709 | {
|
---|
| 2710 | /* Single-colon. Combine this rule with the file's existing record,
|
---|
[53] | 2711 | if any. */
|
---|
[3140] | 2712 | #ifndef KMK
|
---|
| 2713 | f = enter_file (strcache_add (name));
|
---|
| 2714 | #else /* KMK - the name is already in the cache, don't waste time. */
|
---|
| 2715 | f = enter_file (name);
|
---|
| 2716 | #endif
|
---|
| 2717 | if (f->double_colon)
|
---|
[53] | 2718 | OS (fatal, flocp,
|
---|
[3140] | 2719 | _("target file '%s' has both : and :: entries"), f->name);
|
---|
| 2720 |
|
---|
| 2721 | /* If CMDS == F->CMDS, this target was listed in this rule
|
---|
| 2722 | more than once. Just give a warning since this is harmless. */
|
---|
| 2723 | if (cmds != 0 && cmds == f->cmds)
|
---|
| 2724 | OS (error, flocp,
|
---|
| 2725 | _("target '%s' given more than once in the same rule"),
|
---|
| 2726 | f->name);
|
---|
[53] | 2727 |
|
---|
[3140] | 2728 | /* Check for two single-colon entries both with commands.
|
---|
| 2729 | Check is_target so that we don't lose on files such as .c.o
|
---|
[53] | 2730 | whose commands were preinitialized. */
|
---|
[3140] | 2731 | else if (cmds != 0 && f->cmds != 0 && f->is_target)
|
---|
[53] | 2732 | {
|
---|
[3140] | 2733 | size_t l = strlen (f->name);
|
---|
| 2734 | error (&cmds->fileinfo, l,
|
---|
| 2735 | _("warning: overriding recipe for target '%s'"),
|
---|
| 2736 | f->name);
|
---|
| 2737 | error (&f->cmds->fileinfo, l,
|
---|
[287] | 2738 | _("warning: ignoring old recipe for target '%s'"),
|
---|
[1022] | 2739 | f->name);
|
---|
| 2740 | }
|
---|
| 2741 |
|
---|
| 2742 | /* Defining .DEFAULT with no deps or cmds clears it. */
|
---|
| 2743 | if (f == default_file && this == 0 && cmds == 0)
|
---|
| 2744 | f->cmds = 0;
|
---|
| 2745 | if (cmds != 0)
|
---|
| 2746 | f->cmds = cmds;
|
---|
| 2747 |
|
---|
| 2748 | #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
|
---|
| 2749 | /* If this is an explicit multi target rule, add it to the
|
---|
| 2750 | target chain and set the multi_maybe flag according to
|
---|
| 2751 | the current mode. */
|
---|
[3140] | 2752 |
|
---|
| 2753 | if (multi_mode >= m_yes)
|
---|
[1022] | 2754 | {
|
---|
| 2755 | f->multi_maybe = multi_mode == m_yes_maybe;
|
---|
| 2756 | prev_file->multi_next = f;
|
---|
| 2757 | assert (prev_file->multi_head != 0);
|
---|
[3140] | 2758 | f->multi_head = prev_file->multi_head;
|
---|
| 2759 |
|
---|
| 2760 | if (f == suffix_file)
|
---|
| 2761 | O (error, flocp,
|
---|
[503] | 2762 | _(".SUFFIXES encountered in an explicit multi target rule"));
|
---|
[3140] | 2763 | }
|
---|
| 2764 | prev_file = f;
|
---|
| 2765 | #endif
|
---|
[53] | 2766 |
|
---|
[3140] | 2767 | /* Defining .SUFFIXES with no dependencies clears out the list of
|
---|
| 2768 | suffixes. */
|
---|
[1975] | 2769 | if (f == suffix_file && this == 0)
|
---|
[53] | 2770 | {
|
---|
[1975] | 2771 | free_dep_chain (f->deps);
|
---|
[1857] | 2772 | f->deps = 0;
|
---|
[1975] | 2773 | }
|
---|
[503] | 2774 | }
|
---|
[3140] | 2775 | else
|
---|
| 2776 | {
|
---|
| 2777 | /* Double-colon. Make a new record even if there already is one. */
|
---|
| 2778 | #ifndef CONFIG_WITH_STRCACHE2
|
---|
| 2779 | f = lookup_file (name);
|
---|
[2591] | 2780 | #else /* CONFIG_WITH_STRCACHE2 - the name is already in the cache, don't waste time. */
|
---|
[1857] | 2781 | f = lookup_file_cached (name);
|
---|
[3140] | 2782 | #endif /* CONFIG_WITH_STRCACHE2 */
|
---|
[1857] | 2783 |
|
---|
[3140] | 2784 | /* Check for both : and :: rules. Check is_target so we don't lose
|
---|
[1857] | 2785 | on default suffix rules or makefiles. */
|
---|
[3140] | 2786 | if (f != 0 && f->is_target && !f->double_colon)
|
---|
| 2787 | OS (fatal, flocp,
|
---|
| 2788 | _("target file '%s' has both : and :: entries"), f->name);
|
---|
| 2789 |
|
---|
| 2790 | #ifndef KMK
|
---|
| 2791 | f = enter_file (strcache_add (name));
|
---|
| 2792 | #else /* KMK - the name is already in the cache, don't waste time. */
|
---|
| 2793 | f = enter_file (name);
|
---|
[2591] | 2794 | #endif
|
---|
[3140] | 2795 | /* If there was an existing entry and it was a double-colon entry,
|
---|
| 2796 | enter_file will have returned a new one, making it the prev
|
---|
[53] | 2797 | pointer of the old one, and setting its double_colon pointer to
|
---|
[2591] | 2798 | the first one. */
|
---|
| 2799 | if (f->double_colon == 0)
|
---|
[503] | 2800 | /* This is the first entry for this name, so we must set its
|
---|
[3140] | 2801 | double_colon pointer to itself. */
|
---|
[2591] | 2802 | f->double_colon = f;
|
---|
[503] | 2803 |
|
---|
| 2804 | f->cmds = cmds;
|
---|
[903] | 2805 | }
|
---|
[503] | 2806 |
|
---|
[910] | 2807 | f->is_target = 1;
|
---|
[903] | 2808 |
|
---|
| 2809 | /* If this is a static pattern rule, set the stem to the part of its
|
---|
[910] | 2810 | name that matched the '%' in the pattern, so you can use $* in the
|
---|
[903] | 2811 | commands. If we didn't do it before, enter the prereqs now. */
|
---|
[503] | 2812 | if (pattern)
|
---|
| 2813 | {
|
---|
[2591] | 2814 | static const char *percent = "%";
|
---|
| 2815 | char *buffer = variable_expand ("");
|
---|
| 2816 | const size_t buffer_offset = buffer - variable_buffer; /* bird */
|
---|
| 2817 | char *o = patsubst_expand_pat (buffer, name, pattern, percent,
|
---|
[503] | 2818 | pattern_percent+1, percent+1);
|
---|
| 2819 | buffer = variable_buffer + buffer_offset; /* bird - variable_buffer may have been reallocated. */
|
---|
| 2820 | f->stem = strcache_add_len (buffer, o - buffer);
|
---|
[2591] | 2821 | if (this)
|
---|
| 2822 | {
|
---|
| 2823 | if (! this->need_2nd_expansion)
|
---|
| 2824 | this = enter_prereqs (this, f->stem);
|
---|
| 2825 | else
|
---|
| 2826 | this->stem = f->stem;
|
---|
| 2827 | }
|
---|
| 2828 | }
|
---|
| 2829 |
|
---|
| 2830 | /* Add the dependencies to this file entry. */
|
---|
| 2831 | if (this != 0)
|
---|
| 2832 | {
|
---|
| 2833 | /* Add the file's old deps and the new ones in THIS together. */
|
---|
| 2834 | if (f->deps == 0)
|
---|
| 2835 | f->deps = this;
|
---|
| 2836 | else if (cmds != 0)
|
---|
| 2837 | {
|
---|
| 2838 | struct dep *d = this;
|
---|
| 2839 |
|
---|
| 2840 | /* If this rule has commands, put these deps first. */
|
---|
| 2841 | while (d->next != 0)
|
---|
| 2842 | d = d->next;
|
---|
| 2843 |
|
---|
| 2844 | d->next = f->deps;
|
---|
| 2845 | f->deps = this;
|
---|
| 2846 | }
|
---|
| 2847 | else
|
---|
| 2848 | {
|
---|
| 2849 | struct dep *d = f->deps;
|
---|
[903] | 2850 |
|
---|
[53] | 2851 | /* A rule without commands: put its prereqs at the end. */
|
---|
[2591] | 2852 | while (d->next != 0)
|
---|
| 2853 | d = d->next;
|
---|
| 2854 |
|
---|
| 2855 | d->next = this;
|
---|
| 2856 | }
|
---|
| 2857 | }
|
---|
[53] | 2858 |
|
---|
[2591] | 2859 | name = f->name;
|
---|
| 2860 |
|
---|
| 2861 | #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
|
---|
| 2862 | l_next:
|
---|
| 2863 | #endif
|
---|
[3140] | 2864 | /* All done! Set up for the next one. */
|
---|
| 2865 | if (nextf == 0)
|
---|
[53] | 2866 | break;
|
---|
| 2867 |
|
---|
| 2868 | filenames = nextf;
|
---|
| 2869 |
|
---|
| 2870 | /* Reduce escaped percents. If there are any unescaped it's an error */
|
---|
| 2871 | name = filenames->name;
|
---|
| 2872 | if (find_percent_cached (&name))
|
---|
[503] | 2873 | O (error, flocp,
|
---|
| 2874 | _("*** mixed implicit and normal rules: deprecated syntax"));
|
---|
[53] | 2875 | }
|
---|
[503] | 2876 | }
|
---|
| 2877 | |
---|
| 2878 |
|
---|
[3140] | 2879 | /* Search STRING for an unquoted STOPCHAR or blank (if BLANK is nonzero).
|
---|
[53] | 2880 | Backslashes quote STOPCHAR, blanks if BLANK is nonzero, and backslash.
|
---|
[1831] | 2881 | Quoting backslashes are removed from STRING by compacting it into
|
---|
[53] | 2882 | itself. Returns a pointer to the first unquoted STOPCHAR if there is
|
---|
[1831] | 2883 | one, or nil if there are none. STOPCHARs inside variable references are
|
---|
[903] | 2884 | ignored if IGNOREVARS is true.
|
---|
[1831] | 2885 |
|
---|
| 2886 | STOPCHAR _cannot_ be '$' if IGNOREVARS is true. */
|
---|
| 2887 |
|
---|
[53] | 2888 | static char *
|
---|
[3140] | 2889 | find_char_unquote (char *string, int map IF_WITH_VALUE_LENGTH_PARAM(unsigned int string_len))
|
---|
| 2890 | {
|
---|
[503] | 2891 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
[53] | 2892 | unsigned int string_len = 0;
|
---|
| 2893 | #endif
|
---|
[3140] | 2894 | char *p = string;
|
---|
| 2895 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
[53] | 2896 | assert (string_len == 0 || string_len == strlen (string));
|
---|
[3140] | 2897 | #endif
|
---|
| 2898 |
|
---|
[53] | 2899 | /* Always stop on NUL. */
|
---|
[503] | 2900 | map |= MAP_NUL;
|
---|
[3140] | 2901 |
|
---|
[503] | 2902 | while (1)
|
---|
| 2903 | {
|
---|
| 2904 | while (! STOP_SET (*p, map))
|
---|
[3140] | 2905 | ++p;
|
---|
| 2906 |
|
---|
| 2907 | if (*p == '\0')
|
---|
| 2908 | break;
|
---|
[503] | 2909 |
|
---|
| 2910 | /* If we stopped due to a variable reference, skip over its contents. */
|
---|
| 2911 | if (STOP_SET (*p, MAP_VARIABLE))
|
---|
| 2912 | {
|
---|
| 2913 | char openparen = p[1];
|
---|
| 2914 |
|
---|
| 2915 | /* Check if '$' is the last character in the string. */
|
---|
[3140] | 2916 | if (openparen == '\0')
|
---|
[503] | 2917 | break;
|
---|
| 2918 |
|
---|
| 2919 | p += 2;
|
---|
| 2920 |
|
---|
| 2921 | /* Skip the contents of a non-quoted, multi-char variable ref. */
|
---|
| 2922 | if (openparen == '(' || openparen == '{')
|
---|
| 2923 | {
|
---|
| 2924 | unsigned int pcount = 1;
|
---|
| 2925 | char closeparen = (openparen == '(' ? ')' : '}');
|
---|
| 2926 | char ch; /* bird */
|
---|
| 2927 |
|
---|
| 2928 | while ((ch = *p))
|
---|
| 2929 | {
|
---|
| 2930 | if (ch == openparen)
|
---|
| 2931 | ++pcount;
|
---|
| 2932 | else if (ch == closeparen)
|
---|
| 2933 | if (--pcount == 0)
|
---|
| 2934 | {
|
---|
| 2935 | ++p;
|
---|
[53] | 2936 | break;
|
---|
[3140] | 2937 | }
|
---|
| 2938 | ++p;
|
---|
| 2939 | }
|
---|
| 2940 | }
|
---|
| 2941 |
|
---|
| 2942 | /* Skipped the variable reference: look for STOPCHARS again. */
|
---|
| 2943 | continue;
|
---|
| 2944 | }
|
---|
| 2945 |
|
---|
| 2946 | if (p > string && p[-1] == '\\')
|
---|
| 2947 | {
|
---|
| 2948 | /* Search for more backslashes. */
|
---|
| 2949 | int i = -2;
|
---|
| 2950 | while (&p[i] >= string && p[i] == '\\')
|
---|
| 2951 | --i;
|
---|
| 2952 | ++i;
|
---|
| 2953 | /* Only compute the length if really needed. */
|
---|
[53] | 2954 | if (string_len == 0)
|
---|
[3140] | 2955 | string_len = strlen (string);
|
---|
| 2956 | /* The number of backslashes is now -I.
|
---|
[53] | 2957 | Copy P over itself to swallow half of them. */
|
---|
[3140] | 2958 | memmove (&p[i], &p[i/2], (string_len - (p - string)) - (i/2) + 1);
|
---|
| 2959 | p += i/2;
|
---|
[53] | 2960 | if (i % 2 == 0)
|
---|
| 2961 | /* All the backslashes quoted each other; the STOPCHAR was
|
---|
| 2962 | unquoted. */
|
---|
| 2963 | return p;
|
---|
| 2964 |
|
---|
| 2965 | /* The STOPCHAR was quoted by a backslash. Look for another. */
|
---|
[1831] | 2966 | }
|
---|
[3140] | 2967 | else
|
---|
| 2968 | /* No backslash in sight. */
|
---|
| 2969 | return p;
|
---|
| 2970 | }
|
---|
| 2971 |
|
---|
[1831] | 2972 | /* Never hit a STOPCHAR or blank (with BLANK nonzero). */
|
---|
| 2973 | return 0;
|
---|
[3140] | 2974 | }
|
---|
| 2975 |
|
---|
[1831] | 2976 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
[3140] | 2977 | /* Special case version of find_char_unquote that only takes stop character.
|
---|
| 2978 | This is so common that it makes a lot of sense to specialize this. */
|
---|
| 2979 |
|
---|
| 2980 | K_INLINE char *
|
---|
[1831] | 2981 | find_char_unquote_0 (char *string, int stop1, int map, char **eosp)
|
---|
| 2982 | {
|
---|
[3140] | 2983 | unsigned int string_len = *eosp - string;
|
---|
[1831] | 2984 | char *p;
|
---|
| 2985 |
|
---|
[3140] | 2986 | assert (strlen (string) == string_len);
|
---|
[1831] | 2987 | assert (!(map & MAP_VARIABLE) && map != 0);
|
---|
| 2988 | assert ((stopchar_map[(unsigned char)stop1] & map) == map);
|
---|
| 2989 |
|
---|
| 2990 | p = (char *)memchr (string, stop1, string_len);
|
---|
| 2991 | if (!p)
|
---|
[3140] | 2992 | return NULL;
|
---|
| 2993 | if (p <= string || p[-1] != '\\')
|
---|
| 2994 | return p;
|
---|
| 2995 |
|
---|
| 2996 | p = find_char_unquote (string, map, string_len);
|
---|
| 2997 | *eosp = memchr (string, '\0', string_len);
|
---|
| 2998 | return p;
|
---|
| 2999 | }
|
---|
| 3000 | #endif
|
---|
| 3001 |
|
---|
| 3002 | /* Unescape a character in a string. The string is compressed onto itself. */
|
---|
| 3003 |
|
---|
| 3004 | static char *
|
---|
| 3005 | unescape_char (char *string, int c)
|
---|
| 3006 | {
|
---|
| 3007 | char *p = string;
|
---|
| 3008 | char *s = string;
|
---|
| 3009 |
|
---|
| 3010 | while (*s != '\0')
|
---|
| 3011 | {
|
---|
| 3012 | if (*s == '\\')
|
---|
| 3013 | {
|
---|
| 3014 | char *e = s;
|
---|
| 3015 | int l;
|
---|
| 3016 |
|
---|
| 3017 | /* We found a backslash. See if it's escaping our character. */
|
---|
| 3018 | while (*e == '\\')
|
---|
| 3019 | ++e;
|
---|
| 3020 | l = e - s;
|
---|
| 3021 |
|
---|
| 3022 | if (*e != c || l%2 == 0)
|
---|
| 3023 | {
|
---|
| 3024 | /* It's not; just take it all without unescaping. */
|
---|
| 3025 | memmove (p, s, l);
|
---|
| 3026 | p += l;
|
---|
| 3027 |
|
---|
| 3028 | // If we hit the end of the string, we're done
|
---|
| 3029 | if (*e == '\0')
|
---|
| 3030 | break;
|
---|
| 3031 | }
|
---|
| 3032 | else if (l > 1)
|
---|
| 3033 | {
|
---|
| 3034 | /* It is, and there's >1 backslash. Take half of them. */
|
---|
| 3035 | l /= 2;
|
---|
| 3036 | memmove (p, s, l);
|
---|
| 3037 | p += l;
|
---|
| 3038 | }
|
---|
| 3039 |
|
---|
[903] | 3040 | s = e;
|
---|
[53] | 3041 | }
|
---|
| 3042 |
|
---|
| 3043 | *(p++) = *(s++);
|
---|
| 3044 | }
|
---|
[3140] | 3045 |
|
---|
| 3046 | *p = '\0';
|
---|
| 3047 | return string;
|
---|
| 3048 | }
|
---|
| 3049 |
|
---|
| 3050 | /* Search PATTERN for an unquoted % and handle quoting. */
|
---|
[53] | 3051 |
|
---|
[903] | 3052 | char *
|
---|
| 3053 | find_percent (char *pattern)
|
---|
| 3054 | {
|
---|
| 3055 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
| 3056 | return find_char_unquote (pattern, MAP_PERCENT);
|
---|
| 3057 | #else
|
---|
| 3058 | char *eos = strchr(pattern, '\0');
|
---|
| 3059 | return find_char_unquote_0 (pattern, '%', MAP_PERCENT, &eos);
|
---|
| 3060 | #endif
|
---|
| 3061 | }
|
---|
| 3062 |
|
---|
| 3063 | /* Search STRING for an unquoted % and handle quoting. Returns a pointer to
|
---|
[1929] | 3064 | the % or NULL if no % was found.
|
---|
[903] | 3065 | This version is used with strings in the string cache: if there's a need to
|
---|
| 3066 | modify the string a new version will be added to the string cache and
|
---|
| 3067 | *STRING will be set to that. */
|
---|
| 3068 |
|
---|
| 3069 | const char *
|
---|
| 3070 | find_percent_cached (const char **string)
|
---|
| 3071 | {
|
---|
| 3072 | const char *p = *string;
|
---|
[3140] | 3073 | char *new = 0;
|
---|
[903] | 3074 | int slen = 0;
|
---|
| 3075 |
|
---|
| 3076 | /* If the first char is a % return now. This lets us avoid extra tests
|
---|
| 3077 | inside the loop. */
|
---|
| 3078 | if (*p == '%')
|
---|
| 3079 | return p;
|
---|
| 3080 |
|
---|
| 3081 | while (1)
|
---|
| 3082 | {
|
---|
| 3083 | while (! STOP_SET (*p, MAP_PERCENT|MAP_NUL))
|
---|
| 3084 | ++p;
|
---|
| 3085 |
|
---|
| 3086 | if (*p == '\0')
|
---|
| 3087 | break;
|
---|
| 3088 |
|
---|
| 3089 | /* See if this % is escaped with a backslash; if not we're done. */
|
---|
| 3090 | if (p[-1] != '\\')
|
---|
| 3091 | break;
|
---|
| 3092 |
|
---|
| 3093 | {
|
---|
| 3094 | /* Search for more backslashes. */
|
---|
| 3095 | char *pv;
|
---|
| 3096 | int i = -2;
|
---|
| 3097 |
|
---|
| 3098 | while (&p[i] >= *string && p[i] == '\\')
|
---|
| 3099 | --i;
|
---|
| 3100 | ++i;
|
---|
| 3101 |
|
---|
| 3102 | /* At this point we know we'll need to allocate a new string.
|
---|
| 3103 | Make a copy if we haven't yet done so. */
|
---|
| 3104 | if (! new)
|
---|
| 3105 | {
|
---|
| 3106 | slen = strlen (*string);
|
---|
| 3107 | new = alloca (slen + 1);
|
---|
| 3108 | memcpy (new, *string, slen + 1);
|
---|
| 3109 | p = new + (p - *string);
|
---|
| 3110 | *string = new;
|
---|
| 3111 | }
|
---|
| 3112 |
|
---|
| 3113 | /* At this point *string, p, and new all point into the same string.
|
---|
| 3114 | Get a non-const version of p so we can modify new. */
|
---|
| 3115 | pv = new + (p - *string);
|
---|
| 3116 |
|
---|
| 3117 | /* The number of backslashes is now -I.
|
---|
| 3118 | Copy P over itself to swallow half of them. */
|
---|
| 3119 | memmove (&pv[i], &pv[i/2], (slen - (pv - new)) - (i/2) + 1);
|
---|
| 3120 | p += i/2;
|
---|
| 3121 |
|
---|
| 3122 | /* If the backslashes quoted each other; the % was unquoted. */
|
---|
| 3123 | if (i % 2 == 0)
|
---|
| 3124 | break;
|
---|
| 3125 | }
|
---|
| 3126 | }
|
---|
| 3127 |
|
---|
[53] | 3128 | /* If we had to change STRING, add it to the strcache. */
|
---|
| 3129 | if (new)
|
---|
| 3130 | {
|
---|
| 3131 | *string = strcache_add (*string);
|
---|
| 3132 | p = *string + (p - new);
|
---|
| 3133 | }
|
---|
| 3134 |
|
---|
| 3135 | /* If we didn't find a %, return NULL. Otherwise return a ptr to it. */
|
---|
| 3136 | return (*p == '\0') ? NULL : p;
|
---|
| 3137 | }
|
---|
| 3138 | |
---|
| 3139 |
|
---|
| 3140 | /* Find the next line of text in an eval buffer, combining continuation lines
|
---|
| 3141 | into one line.
|
---|
[3140] | 3142 | Return the number of actual lines read (> 1 if continuation lines).
|
---|
[53] | 3143 | Returns -1 if there's nothing left in the buffer.
|
---|
| 3144 |
|
---|
[287] | 3145 | After this function, ebuf->buffer points to the first character of the
|
---|
[1809] | 3146 | line we just found.
|
---|
[1806] | 3147 | */
|
---|
| 3148 |
|
---|
[53] | 3149 | /* Read a line of text from a STRING.
|
---|
| 3150 | Since we aren't really reading from a file, don't bother with linenumbers.
|
---|
[287] | 3151 | */
|
---|
[53] | 3152 |
|
---|
| 3153 | static long
|
---|
| 3154 | readstring (struct ebuffer *ebuf)
|
---|
| 3155 | {
|
---|
| 3156 | char *eol;
|
---|
[287] | 3157 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
[1809] | 3158 | char *end;
|
---|
[1806] | 3159 | #endif
|
---|
| 3160 |
|
---|
[53] | 3161 | /* If there is nothing left in this buffer, return 0. */
|
---|
| 3162 | if (ebuf->bufnext >= ebuf->bufstart + ebuf->size)
|
---|
| 3163 | return -1;
|
---|
| 3164 |
|
---|
[2591] | 3165 | /* Set up a new starting point for the buffer, and find the end of the
|
---|
| 3166 | next logical line (taking into account backslash/newline pairs). */
|
---|
[53] | 3167 |
|
---|
[287] | 3168 | eol = ebuf->buffer = ebuf->bufnext;
|
---|
[1809] | 3169 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
[2591] | 3170 | end = ebuf->bufstart + ebuf->size;
|
---|
[1806] | 3171 | #endif
|
---|
| 3172 |
|
---|
| 3173 | while (1)
|
---|
[2591] | 3174 | {
|
---|
[1806] | 3175 | int backslash = 0;
|
---|
[287] | 3176 | const char *bol = eol;
|
---|
| 3177 | const char *p;
|
---|
| 3178 |
|
---|
[1811] | 3179 | /* Find the next newline. At EOS, stop. */
|
---|
| 3180 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
| 3181 | p = eol = strchr (eol , '\n');
|
---|
[287] | 3182 | #else
|
---|
| 3183 | p = (char *)memchr (eol, '\n', end - eol);
|
---|
[53] | 3184 | assert (!memchr (eol, '\0', p != 0 ? p - eol : end - eol));
|
---|
[287] | 3185 | eol = (char *)p;
|
---|
| 3186 | #endif
|
---|
| 3187 | if (!eol)
|
---|
| 3188 | {
|
---|
[53] | 3189 | ebuf->bufnext = ebuf->bufstart + ebuf->size + 1;
|
---|
[287] | 3190 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
[53] | 3191 | ebuf->eol = end;
|
---|
| 3192 | #endif
|
---|
| 3193 | return 0;
|
---|
[287] | 3194 | }
|
---|
| 3195 |
|
---|
[1811] | 3196 | /* Found a newline; if it's escaped continue; else we're done. */
|
---|
| 3197 | while (p > bol && *(--p) == '\\')
|
---|
| 3198 | backslash = !backslash;
|
---|
[53] | 3199 | if (!backslash)
|
---|
| 3200 | break;
|
---|
| 3201 | ++eol;
|
---|
| 3202 | }
|
---|
| 3203 |
|
---|
| 3204 | /* Overwrite the newline char. */
|
---|
| 3205 | *eol = '\0';
|
---|
| 3206 | ebuf->bufnext = eol+1;
|
---|
| 3207 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
| 3208 | ebuf->eol = eol;
|
---|
| 3209 | #endif
|
---|
| 3210 |
|
---|
| 3211 | return 0;
|
---|
| 3212 | }
|
---|
| 3213 |
|
---|
| 3214 | static long
|
---|
| 3215 | readline (struct ebuffer *ebuf)
|
---|
| 3216 | {
|
---|
| 3217 | char *p;
|
---|
| 3218 | char *end;
|
---|
| 3219 | char *start;
|
---|
| 3220 | long nlines = 0;
|
---|
| 3221 |
|
---|
| 3222 | /* The behaviors between string and stream buffers are different enough to
|
---|
[1811] | 3223 | warrant different functions. Do the Right Thing. */
|
---|
| 3224 |
|
---|
| 3225 | if (!ebuf->fp)
|
---|
[53] | 3226 | return readstring (ebuf);
|
---|
| 3227 |
|
---|
| 3228 | /* When reading from a file, we always start over at the beginning of the
|
---|
| 3229 | buffer for each new line. */
|
---|
| 3230 |
|
---|
| 3231 | p = start = ebuf->bufstart;
|
---|
| 3232 | end = p + ebuf->size;
|
---|
| 3233 | *p = '\0';
|
---|
| 3234 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
[3140] | 3235 | ebuf->eol = p;
|
---|
| 3236 | #endif
|
---|
| 3237 |
|
---|
| 3238 | while (fgets (p, end - p, ebuf->fp) != 0)
|
---|
| 3239 | {
|
---|
| 3240 | char *p2;
|
---|
| 3241 | unsigned long len;
|
---|
| 3242 | int backslash;
|
---|
| 3243 |
|
---|
| 3244 | len = strlen (p);
|
---|
| 3245 | if (len == 0)
|
---|
[53] | 3246 | {
|
---|
| 3247 | /* This only happens when the first thing on the line is a '\0'.
|
---|
| 3248 | It is a pretty hopeless case, but (wonder of wonders) Athena
|
---|
| 3249 | lossage strikes again! (xmkmf puts NULs in its makefiles.)
|
---|
| 3250 | There is nothing really to be done; we synthesize a newline so
|
---|
| 3251 | the following line doesn't appear to be part of this line. */
|
---|
| 3252 | O (error, &ebuf->floc,
|
---|
| 3253 | _("warning: NUL character seen; rest of line ignored"));
|
---|
| 3254 | p[0] = '\n';
|
---|
| 3255 | len = 1;
|
---|
| 3256 | }
|
---|
| 3257 |
|
---|
| 3258 | /* Jump past the text we just read. */
|
---|
| 3259 | p += len;
|
---|
| 3260 |
|
---|
| 3261 | /* If the last char isn't a newline, the whole line didn't fit into the
|
---|
| 3262 | buffer. Get some more buffer and try again. */
|
---|
| 3263 | if (p[-1] != '\n')
|
---|
[3140] | 3264 | goto more_buffer;
|
---|
[53] | 3265 |
|
---|
| 3266 | /* We got a newline, so add one to the count of lines. */
|
---|
| 3267 | ++nlines;
|
---|
| 3268 |
|
---|
| 3269 | #if !defined(WINDOWS32) && !defined(__MSDOS__) && !defined(__EMX__)
|
---|
[3140] | 3270 | /* Check to see if the line was really ended with CRLF; if so ignore
|
---|
| 3271 | the CR. */
|
---|
| 3272 | if ((p - start) > 1 && p[-2] == '\r')
|
---|
[53] | 3273 | {
|
---|
[3140] | 3274 | --p;
|
---|
[53] | 3275 | memmove (p-1, p, strlen (p) + 1);
|
---|
| 3276 | }
|
---|
[3140] | 3277 | #endif
|
---|
| 3278 |
|
---|
[1811] | 3279 | backslash = 0;
|
---|
| 3280 | for (p2 = p - 2; p2 >= start; --p2)
|
---|
| 3281 | {
|
---|
[3140] | 3282 | if (*p2 != '\\')
|
---|
| 3283 | break;
|
---|
[53] | 3284 | backslash = !backslash;
|
---|
| 3285 | }
|
---|
| 3286 |
|
---|
| 3287 | if (!backslash)
|
---|
[1811] | 3288 | {
|
---|
| 3289 | p[-1] = '\0';
|
---|
| 3290 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
| 3291 | ebuf->eol = p - 1;
|
---|
| 3292 | #endif
|
---|
| 3293 | break;
|
---|
[53] | 3294 | }
|
---|
| 3295 |
|
---|
| 3296 | /* It was a backslash/newline combo. If we have more space, read
|
---|
| 3297 | another line. */
|
---|
| 3298 | if (end - p >= 80)
|
---|
| 3299 | {
|
---|
| 3300 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
[903] | 3301 | ebuf->eol = p;
|
---|
[53] | 3302 | #endif
|
---|
| 3303 | continue;
|
---|
| 3304 | }
|
---|
[1811] | 3305 |
|
---|
| 3306 | /* We need more space at the end of our buffer, so realloc it.
|
---|
| 3307 | Make sure to preserve the current offset of p. */
|
---|
[53] | 3308 | more_buffer:
|
---|
| 3309 | {
|
---|
| 3310 | unsigned long off = p - start;
|
---|
| 3311 | ebuf->size *= 2;
|
---|
| 3312 | start = ebuf->buffer = ebuf->bufstart = xrealloc (start, ebuf->size);
|
---|
| 3313 | p = start + off;
|
---|
| 3314 | end = start + ebuf->size;
|
---|
| 3315 | *p = '\0';
|
---|
| 3316 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
| 3317 | ebuf->eol = p;
|
---|
| 3318 | #endif
|
---|
| 3319 | }
|
---|
| 3320 | }
|
---|
| 3321 |
|
---|
| 3322 | if (ferror (ebuf->fp))
|
---|
| 3323 | pfatal_with_name (ebuf->floc.filenm);
|
---|
| 3324 |
|
---|
| 3325 | /* If we found some lines, return how many.
|
---|
| 3326 | If we didn't, but we did find _something_, that indicates we read the last
|
---|
| 3327 | line of a file with no final newline; return 1.
|
---|
| 3328 | If we read nothing, we're at EOF; return -1. */
|
---|
| 3329 |
|
---|
| 3330 | return nlines ? nlines : p == ebuf->bufstart ? -1 : 1;
|
---|
| 3331 | }
|
---|
| 3332 | |
---|
| 3333 |
|
---|
[3140] | 3334 | /* Parse the next "makefile word" from the input buffer, and return info
|
---|
[53] | 3335 | about it.
|
---|
| 3336 |
|
---|
| 3337 | A "makefile word" is one of:
|
---|
| 3338 |
|
---|
| 3339 | w_bogus Should never happen
|
---|
| 3340 | w_eol End of input
|
---|
| 3341 | w_static A static word; cannot be expanded
|
---|
| 3342 | w_variable A word containing one or more variables/functions
|
---|
| 3343 | w_colon A colon
|
---|
| 3344 | w_dcolon A double-colon
|
---|
| 3345 | w_semicolon A semicolon
|
---|
| 3346 | w_varassign A variable assignment operator (=, :=, ::=, +=, >=, ?=, or !=)
|
---|
| 3347 |
|
---|
[3140] | 3348 | Note that this function is only used when reading certain parts of the
|
---|
[53] | 3349 | makefile. Don't use it where special rules hold sway (RHS of a variable,
|
---|
| 3350 | in a command list, etc.) */
|
---|
| 3351 |
|
---|
| 3352 | static enum make_word_type
|
---|
| 3353 | get_next_mword (char *buffer, char *delim, char **startp, unsigned int *length)
|
---|
| 3354 | {
|
---|
| 3355 | enum make_word_type wtype = w_bogus;
|
---|
| 3356 | char *p = buffer, *beg;
|
---|
| 3357 | char c;
|
---|
| 3358 |
|
---|
| 3359 | /* Skip any leading whitespace. */
|
---|
| 3360 | while (ISBLANK (*p))
|
---|
| 3361 | ++p;
|
---|
| 3362 |
|
---|
| 3363 | beg = p;
|
---|
| 3364 | c = *(p++);
|
---|
| 3365 | switch (c)
|
---|
| 3366 | {
|
---|
| 3367 | case '\0':
|
---|
| 3368 | wtype = w_eol;
|
---|
| 3369 | break;
|
---|
| 3370 |
|
---|
| 3371 | case ';':
|
---|
| 3372 | wtype = w_semicolon;
|
---|
[3140] | 3373 | break;
|
---|
| 3374 |
|
---|
| 3375 | case '=':
|
---|
| 3376 | wtype = w_varassign;
|
---|
| 3377 | break;
|
---|
| 3378 |
|
---|
| 3379 | case ':':
|
---|
[53] | 3380 | wtype = w_colon;
|
---|
| 3381 | switch (*p)
|
---|
| 3382 | {
|
---|
| 3383 | case ':':
|
---|
| 3384 | ++p;
|
---|
| 3385 | if (p[1] != '=')
|
---|
| 3386 | wtype = w_dcolon;
|
---|
| 3387 | else
|
---|
| 3388 | {
|
---|
| 3389 | wtype = w_varassign;
|
---|
| 3390 | ++p;
|
---|
[3140] | 3391 | }
|
---|
[937] | 3392 | break;
|
---|
| 3393 |
|
---|
| 3394 | case '=':
|
---|
[53] | 3395 | ++p;
|
---|
| 3396 | wtype = w_varassign;
|
---|
| 3397 | break;
|
---|
| 3398 | }
|
---|
| 3399 | break;
|
---|
| 3400 |
|
---|
[3145] | 3401 | case '+':
|
---|
[53] | 3402 | case '?':
|
---|
| 3403 | case '!':
|
---|
| 3404 | #ifdef CONFIG_WITH_PREPEND_ASSIGNMENT
|
---|
| 3405 | case '>':
|
---|
| 3406 | #endif
|
---|
| 3407 | if (*p == '=')
|
---|
| 3408 | {
|
---|
| 3409 | ++p;
|
---|
| 3410 | wtype = w_varassign;
|
---|
| 3411 | break;
|
---|
| 3412 | }
|
---|
| 3413 | /* fall thru */
|
---|
| 3414 |
|
---|
[3140] | 3415 | default:
|
---|
[53] | 3416 | if (delim && strchr (delim, c))
|
---|
| 3417 | wtype = w_static;
|
---|
| 3418 | break;
|
---|
| 3419 | }
|
---|
| 3420 |
|
---|
| 3421 | /* Did we find something? If so, return now. */
|
---|
| 3422 | if (wtype != w_bogus)
|
---|
| 3423 | goto done;
|
---|
| 3424 |
|
---|
| 3425 | /* This is some non-operator word. A word consists of the longest
|
---|
| 3426 | string of characters that doesn't contain whitespace, one of [:=#],
|
---|
| 3427 | or [?+!]=, or one of the chars in the DELIM string. */
|
---|
| 3428 |
|
---|
| 3429 | /* We start out assuming a static word; if we see a variable we'll
|
---|
| 3430 | adjust our assumptions then. */
|
---|
| 3431 | wtype = w_static;
|
---|
| 3432 |
|
---|
| 3433 | /* We already found the first value of "c", above. */
|
---|
| 3434 | while (1)
|
---|
| 3435 | {
|
---|
| 3436 | char closeparen;
|
---|
[3140] | 3437 | int count;
|
---|
| 3438 |
|
---|
| 3439 | switch (c)
|
---|
| 3440 | {
|
---|
| 3441 | case '\0':
|
---|
| 3442 | case ' ':
|
---|
[53] | 3443 | case '\t':
|
---|
[3140] | 3444 | case '=':
|
---|
[53] | 3445 | goto done_word;
|
---|
| 3446 |
|
---|
| 3447 | case ':':
|
---|
| 3448 | #ifdef HAVE_DOS_PATHS
|
---|
| 3449 | /* A word CAN include a colon in its drive spec. The drive
|
---|
[3140] | 3450 | spec is allowed either at the beginning of a word, or as part
|
---|
| 3451 | of the archive member name, like in "libfoo.a(d:/foo/bar.o)". */
|
---|
[53] | 3452 | if (!(p - beg >= 2
|
---|
| 3453 | && (*p == '/' || *p == '\\') && isalpha ((unsigned char)p[-2])
|
---|
| 3454 | && (p - beg == 2 || p[-3] == '(')))
|
---|
| 3455 | #endif
|
---|
| 3456 | goto done_word;
|
---|
| 3457 |
|
---|
| 3458 | case '$':
|
---|
| 3459 | c = *(p++);
|
---|
| 3460 | if (c == '$')
|
---|
| 3461 | break;
|
---|
| 3462 | if (c == '\0')
|
---|
| 3463 | goto done_word;
|
---|
| 3464 |
|
---|
| 3465 | /* This is a variable reference, so note that it's expandable.
|
---|
| 3466 | Then read it to the matching close paren. */
|
---|
| 3467 | wtype = w_variable;
|
---|
| 3468 |
|
---|
| 3469 | if (c == '(')
|
---|
| 3470 | closeparen = ')';
|
---|
| 3471 | else if (c == '{')
|
---|
| 3472 | closeparen = '}';
|
---|
| 3473 | else
|
---|
| 3474 | /* This is a single-letter variable reference. */
|
---|
| 3475 | break;
|
---|
| 3476 |
|
---|
| 3477 | for (count=0; *p != '\0'; ++p)
|
---|
| 3478 | {
|
---|
[937] | 3479 | if (*p == c)
|
---|
| 3480 | ++count;
|
---|
| 3481 | else if (*p == closeparen && --count < 0)
|
---|
[53] | 3482 | {
|
---|
| 3483 | ++p;
|
---|
| 3484 | break;
|
---|
| 3485 | }
|
---|
| 3486 | }
|
---|
| 3487 | break;
|
---|
| 3488 |
|
---|
| 3489 | case '?':
|
---|
| 3490 | case '+':
|
---|
| 3491 | #ifdef CONFIG_WITH_PREPEND_ASSIGNMENT
|
---|
| 3492 | case '>':
|
---|
| 3493 | #endif
|
---|
| 3494 | if (*p == '=')
|
---|
| 3495 | goto done_word;
|
---|
| 3496 | break;
|
---|
| 3497 |
|
---|
| 3498 | case '\\':
|
---|
| 3499 | switch (*p)
|
---|
| 3500 | {
|
---|
| 3501 | case ':':
|
---|
| 3502 | case ';':
|
---|
| 3503 | case '=':
|
---|
| 3504 | case '\\':
|
---|
| 3505 | ++p;
|
---|
| 3506 | break;
|
---|
| 3507 | }
|
---|
| 3508 | break;
|
---|
| 3509 |
|
---|
| 3510 | default:
|
---|
| 3511 | if (delim && strchr (delim, c))
|
---|
| 3512 | goto done_word;
|
---|
| 3513 | break;
|
---|
| 3514 | }
|
---|
| 3515 |
|
---|
| 3516 | c = *(p++);
|
---|
| 3517 | }
|
---|
| 3518 | done_word:
|
---|
| 3519 | --p;
|
---|
| 3520 |
|
---|
[903] | 3521 | done:
|
---|
[53] | 3522 | if (startp)
|
---|
[3140] | 3523 | *startp = beg;
|
---|
[53] | 3524 | if (length)
|
---|
| 3525 | *length = p - beg;
|
---|
| 3526 | return wtype;
|
---|
| 3527 | }
|
---|
[903] | 3528 | |
---|
| 3529 |
|
---|
| 3530 | /* Construct the list of include directories
|
---|
[53] | 3531 | from the arguments and the default list. */
|
---|
[903] | 3532 |
|
---|
| 3533 | void
|
---|
| 3534 | construct_include_path (const char **arg_dirs)
|
---|
| 3535 | {
|
---|
| 3536 | #ifdef VAXC /* just don't ask ... */
|
---|
[53] | 3537 | stat_t stbuf;
|
---|
| 3538 | #else
|
---|
[903] | 3539 | struct stat stbuf;
|
---|
| 3540 | #endif
|
---|
[53] | 3541 | const char **dirs;
|
---|
[917] | 3542 | const char **cpp;
|
---|
| 3543 | unsigned int idx;
|
---|
| 3544 |
|
---|
| 3545 | /* Compute the number of pointers we need in the table. */
|
---|
[53] | 3546 | idx = sizeof (default_include_directories) / sizeof (const char *);
|
---|
[903] | 3547 | if (arg_dirs)
|
---|
| 3548 | for (cpp = arg_dirs; *cpp != 0; ++cpp)
|
---|
| 3549 | ++idx;
|
---|
| 3550 |
|
---|
| 3551 | #ifdef __MSDOS__
|
---|
[53] | 3552 | /* Add one for $DJDIR. */
|
---|
[903] | 3553 | ++idx;
|
---|
[53] | 3554 | #endif
|
---|
[903] | 3555 | #ifdef KMK
|
---|
[53] | 3556 | /* Add one for the kBuild directory. */
|
---|
| 3557 | ++idx;
|
---|
[3140] | 3558 | #endif
|
---|
[903] | 3559 |
|
---|
[53] | 3560 | dirs = xmalloc (idx * sizeof (const char *));
|
---|
| 3561 |
|
---|
[3140] | 3562 | idx = 0;
|
---|
| 3563 | max_incl_len = 0;
|
---|
| 3564 |
|
---|
| 3565 | /* First consider any dirs specified with -I switches.
|
---|
| 3566 | Ignore any that don't exist. Remember the maximum string length. */
|
---|
| 3567 |
|
---|
[53] | 3568 | if (arg_dirs)
|
---|
| 3569 | while (*arg_dirs != 0)
|
---|
[3140] | 3570 | {
|
---|
[903] | 3571 | const char *dir = *(arg_dirs++);
|
---|
| 3572 | char *expanded = 0;
|
---|
| 3573 | int e;
|
---|
| 3574 |
|
---|
| 3575 | if (dir[0] == '~')
|
---|
| 3576 | {
|
---|
| 3577 | expanded = tilde_expand (dir);
|
---|
| 3578 | if (expanded != 0)
|
---|
| 3579 | dir = expanded;
|
---|
| 3580 | }
|
---|
[3140] | 3581 |
|
---|
[53] | 3582 | EINTRLOOP (e, stat (dir, &stbuf));
|
---|
| 3583 | if (e == 0 && S_ISDIR (stbuf.st_mode))
|
---|
[903] | 3584 | {
|
---|
[53] | 3585 | unsigned int len = strlen (dir);
|
---|
| 3586 | /* If dir name is written with trailing slashes, discard them. */
|
---|
| 3587 | while (len > 1 && dir[len - 1] == '/')
|
---|
[903] | 3588 | --len;
|
---|
| 3589 | if (len > max_incl_len)
|
---|
[53] | 3590 | max_incl_len = len;
|
---|
| 3591 | dirs[idx++] = strcache_add_len (dir, len);
|
---|
| 3592 | }
|
---|
| 3593 |
|
---|
[903] | 3594 | free (expanded);
|
---|
[3140] | 3595 | }
|
---|
[53] | 3596 |
|
---|
[3140] | 3597 | /* Now add the standard default dirs at the end. */
|
---|
| 3598 |
|
---|
[903] | 3599 | #ifdef __MSDOS__
|
---|
| 3600 | {
|
---|
| 3601 | /* The environment variable $DJDIR holds the root of the DJGPP directory
|
---|
[53] | 3602 | tree; add ${DJDIR}/include. */
|
---|
| 3603 | struct variable *djdir = lookup_variable ("DJDIR", 5);
|
---|
| 3604 |
|
---|
[917] | 3605 | if (djdir)
|
---|
[1503] | 3606 | {
|
---|
[917] | 3607 | unsigned int len = strlen (djdir->value) + 8;
|
---|
[1503] | 3608 | char *defdir = alloca (len + 1);
|
---|
| 3609 |
|
---|
[917] | 3610 | strcat (strcpy (defdir, djdir->value), "/include");
|
---|
| 3611 | dirs[idx++] = strcache_add (defdir);
|
---|
| 3612 |
|
---|
| 3613 | if (len > max_incl_len)
|
---|
[53] | 3614 | max_incl_len = len;
|
---|
[903] | 3615 | }
|
---|
[53] | 3616 | }
|
---|
| 3617 | #endif
|
---|
| 3618 | #ifdef KMK
|
---|
[903] | 3619 | /* Add $(KBUILD_PATH). */
|
---|
[53] | 3620 | {
|
---|
[903] | 3621 | size_t len = strlen (get_kbuild_path ());
|
---|
| 3622 | dirs[idx++] = strcache_add_len (get_kbuild_path (), len);
|
---|
| 3623 | if (len > max_incl_len)
|
---|
| 3624 | max_incl_len = len;
|
---|
| 3625 | }
|
---|
| 3626 | #endif
|
---|
| 3627 |
|
---|
[1993] | 3628 | for (cpp = default_include_directories; *cpp != 0; ++cpp)
|
---|
[903] | 3629 | {
|
---|
[53] | 3630 | int e;
|
---|
| 3631 |
|
---|
| 3632 | EINTRLOOP (e, stat (*cpp, &stbuf));
|
---|
| 3633 | if (e == 0 && S_ISDIR (stbuf.st_mode))
|
---|
[903] | 3634 | {
|
---|
[53] | 3635 | unsigned int len = strlen (*cpp);
|
---|
[903] | 3636 | /* If dir name is written with trailing slashes, discard them. */
|
---|
| 3637 | while (len > 1 && (*cpp)[len - 1] == '/')
|
---|
| 3638 | --len;
|
---|
[503] | 3639 | if (len > max_incl_len)
|
---|
[53] | 3640 | max_incl_len = len;
|
---|
| 3641 | dirs[idx++] = strcache_add_len (*cpp, len);
|
---|
| 3642 | }
|
---|
| 3643 | }
|
---|
| 3644 |
|
---|
| 3645 | dirs[idx] = 0;
|
---|
| 3646 |
|
---|
[903] | 3647 | /* Now add each dir to the .INCLUDE_DIRS variable. */
|
---|
[53] | 3648 |
|
---|
| 3649 | for (cpp = dirs; *cpp != 0; ++cpp)
|
---|
| 3650 | do_variable_definition (NILF, ".INCLUDE_DIRS", *cpp,
|
---|
| 3651 | o_default, f_append, 0);
|
---|
| 3652 |
|
---|
| 3653 | include_directories = dirs;
|
---|
| 3654 | }
|
---|
| 3655 | |
---|
[3140] | 3656 |
|
---|
| 3657 | /* Expand ~ or ~USER at the beginning of NAME.
|
---|
| 3658 | Return a newly malloc'd string or 0. */
|
---|
[53] | 3659 |
|
---|
[1817] | 3660 | char *
|
---|
[3140] | 3661 | tilde_expand (const char *name)
|
---|
[1817] | 3662 | {
|
---|
[3140] | 3663 | #ifndef VMS
|
---|
[1817] | 3664 | if (name[1] == '/' || name[1] == '\0')
|
---|
[53] | 3665 | {
|
---|
[3140] | 3666 | char *home_dir;
|
---|
[53] | 3667 | int is_variable;
|
---|
| 3668 |
|
---|
| 3669 | {
|
---|
| 3670 | /* Turn off --warn-undefined-variables while we expand HOME. */
|
---|
[3140] | 3671 | int save = warn_undefined_variables_flag;
|
---|
| 3672 | warn_undefined_variables_flag = 0;
|
---|
| 3673 |
|
---|
| 3674 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
[903] | 3675 | home_dir = allocated_variable_expand ("$(HOME)");
|
---|
[53] | 3676 | #else
|
---|
[3140] | 3677 | home_dir = allocated_variable_expand_2 (STRING_SIZE_TUPLE("$(HOME)"), NULL);
|
---|
| 3678 | #endif
|
---|
| 3679 |
|
---|
| 3680 | warn_undefined_variables_flag = save;
|
---|
| 3681 | }
|
---|
| 3682 |
|
---|
| 3683 | is_variable = home_dir[0] != '\0';
|
---|
| 3684 | if (!is_variable)
|
---|
| 3685 | {
|
---|
| 3686 | free (home_dir);
|
---|
[903] | 3687 | home_dir = getenv ("HOME");
|
---|
[53] | 3688 | }
|
---|
[3140] | 3689 | # if !defined(_AMIGA) && !defined(WINDOWS32)
|
---|
| 3690 | if (home_dir == 0 || home_dir[0] == '\0')
|
---|
| 3691 | {
|
---|
| 3692 | char *logname = getlogin ();
|
---|
| 3693 | home_dir = 0;
|
---|
| 3694 | if (logname != 0)
|
---|
[53] | 3695 | {
|
---|
[903] | 3696 | struct passwd *p = getpwnam (logname);
|
---|
[53] | 3697 | if (p != 0)
|
---|
| 3698 | home_dir = p->pw_dir;
|
---|
| 3699 | }
|
---|
| 3700 | }
|
---|
| 3701 | # endif /* !AMIGA && !WINDOWS32 */
|
---|
[3140] | 3702 | if (home_dir != 0)
|
---|
[53] | 3703 | {
|
---|
| 3704 | char *new = xstrdup (concat (2, home_dir, name + 1));
|
---|
[3140] | 3705 | if (is_variable)
|
---|
| 3706 | free (home_dir);
|
---|
| 3707 | return new;
|
---|
| 3708 | }
|
---|
| 3709 | }
|
---|
| 3710 | # if !defined(_AMIGA) && !defined(WINDOWS32)
|
---|
[53] | 3711 | else
|
---|
[3140] | 3712 | {
|
---|
[53] | 3713 | struct passwd *pwent;
|
---|
[903] | 3714 | char *userend = strchr (name + 1, '/');
|
---|
[53] | 3715 | if (userend != 0)
|
---|
| 3716 | *userend = '\0';
|
---|
| 3717 | pwent = getpwnam (name + 1);
|
---|
[2591] | 3718 | if (pwent != 0)
|
---|
| 3719 | {
|
---|
| 3720 | if (userend == 0)
|
---|
| 3721 | return xstrdup (pwent->pw_dir);
|
---|
[53] | 3722 | else
|
---|
[2591] | 3723 | return xstrdup (concat (3, pwent->pw_dir, "/", userend + 1));
|
---|
| 3724 | }
|
---|
| 3725 | else if (userend != 0)
|
---|
[53] | 3726 | *userend = '/';
|
---|
| 3727 | }
|
---|
| 3728 | # endif /* !AMIGA && !WINDOWS32 */
|
---|
[2591] | 3729 | #endif /* !VMS */
|
---|
[53] | 3730 | return 0;
|
---|
[2591] | 3731 | }
|
---|
| 3732 | |
---|
| 3733 |
|
---|
| 3734 | /* Parse a string into a sequence of filenames represented as a chain of
|
---|
| 3735 | struct nameseq's and return that chain. Optionally expand the strings via
|
---|
| 3736 | glob().
|
---|
| 3737 |
|
---|
| 3738 | The string is passed as STRINGP, the address of a string pointer.
|
---|
| 3739 | The string pointer is updated to point at the first character
|
---|
| 3740 | not parsed, which either is a null char or equals STOPCHAR.
|
---|
| 3741 |
|
---|
| 3742 | SIZE is how big to construct chain elements.
|
---|
[3140] | 3743 | This is useful if we want them actually to be other structures
|
---|
[2591] | 3744 | that have room for additional info.
|
---|
| 3745 |
|
---|
| 3746 | PREFIX, if non-null, is added to the beginning of each filename.
|
---|
| 3747 |
|
---|
| 3748 | FLAGS allows one or more of the following bitflags to be set:
|
---|
| 3749 | PARSEFS_NOSTRIP - Do no strip './'s off the beginning
|
---|
| 3750 | PARSEFS_NOAR - Do not check filenames for archive references
|
---|
[3140] | 3751 | PARSEFS_NOGLOB - Do not expand globbing characters
|
---|
[2591] | 3752 | PARSEFS_EXISTS - Only return globbed files that actually exist
|
---|
| 3753 | (cannot also set NOGLOB)
|
---|
| 3754 | PARSEFS_NOCACHE - Do not add filenames to the strcache (caller frees)
|
---|
[1863] | 3755 | */
|
---|
[2591] | 3756 |
|
---|
| 3757 | void *
|
---|
| 3758 | parse_file_seq (char **stringp, unsigned int size, int stopmap,
|
---|
| 3759 | const char *prefix, int flags
|
---|
| 3760 | IF_WITH_ALLOC_CACHES_PARAM(struct alloccache *alloc_cache) )
|
---|
| 3761 | {
|
---|
[1863] | 3762 | /* tmp points to tmpbuf after the prefix, if any.
|
---|
[2591] | 3763 | tp is the end of the buffer. */
|
---|
| 3764 | static char *tmpbuf = NULL;
|
---|
| 3765 |
|
---|
| 3766 | int cachep = NONE_SET (flags, PARSEFS_NOCACHE);
|
---|
| 3767 |
|
---|
| 3768 | struct nameseq *new = 0;
|
---|
[1863] | 3769 | struct nameseq **newp = &new;
|
---|
[2591] | 3770 | #ifndef CONFIG_WITH_ALLOC_CACHES
|
---|
| 3771 | #define NEWELT(_n) do { \
|
---|
[53] | 3772 | const char *__n = (_n); \
|
---|
[2591] | 3773 | *newp = xcalloc (size); \
|
---|
| 3774 | (*newp)->name = (cachep ? strcache_add (__n) : xstrdup (__n)); \
|
---|
[3140] | 3775 | newp = &(*newp)->next; \
|
---|
| 3776 | } while(0)
|
---|
[53] | 3777 | #else
|
---|
[2591] | 3778 | # define NEWELT(_n) do { \
|
---|
| 3779 | const char *__n = (_n); \
|
---|
[53] | 3780 | *newp = alloccache_calloc (alloc_cache); \
|
---|
[3140] | 3781 | (*newp)->name = (cachep ? strcache_add (__n) : xstrdup (__n)); \
|
---|
[2591] | 3782 | newp = &(*newp)->next; \
|
---|
| 3783 | } while(0)
|
---|
| 3784 | #endif
|
---|
| 3785 |
|
---|
[3140] | 3786 | char *p;
|
---|
[2591] | 3787 | glob_t gl;
|
---|
| 3788 | char *tp;
|
---|
| 3789 |
|
---|
| 3790 | /* Always stop on NUL. */
|
---|
| 3791 | stopmap |= MAP_NUL;
|
---|
| 3792 |
|
---|
| 3793 | if (size < sizeof (struct nameseq))
|
---|
| 3794 | size = sizeof (struct nameseq);
|
---|
| 3795 |
|
---|
| 3796 | if (NONE_SET (flags, PARSEFS_NOGLOB))
|
---|
| 3797 | dir_setup_glob (&gl);
|
---|
| 3798 |
|
---|
[53] | 3799 | /* Get enough temporary space to construct the largest possible target. */
|
---|
[2591] | 3800 | {
|
---|
| 3801 | static int tmpbuf_len = 0;
|
---|
| 3802 | int l = strlen (*stringp) + 1;
|
---|
[3140] | 3803 | if (l > tmpbuf_len)
|
---|
[53] | 3804 | {
|
---|
[903] | 3805 | tmpbuf = xrealloc (tmpbuf, l);
|
---|
| 3806 | tmpbuf_len = l;
|
---|
[53] | 3807 | }
|
---|
[2591] | 3808 | }
|
---|
| 3809 | tp = tmpbuf;
|
---|
| 3810 |
|
---|
[53] | 3811 | /* Parse STRING. P will always point to the end of the parsed content. */
|
---|
[2591] | 3812 | p = *stringp;
|
---|
[3140] | 3813 | while (1)
|
---|
| 3814 | {
|
---|
| 3815 | const char *name;
|
---|
[53] | 3816 | const char **nlist = 0;
|
---|
[2591] | 3817 | char *tildep = 0;
|
---|
| 3818 | int globme = 1;
|
---|
| 3819 | #ifndef NO_ARCHIVES
|
---|
[3140] | 3820 | char *arname = 0;
|
---|
[2591] | 3821 | char *memname = 0;
|
---|
[3140] | 3822 | #endif
|
---|
[2591] | 3823 | char *s;
|
---|
[3140] | 3824 | int nlen;
|
---|
[2591] | 3825 | int i;
|
---|
| 3826 |
|
---|
[3140] | 3827 | /* Skip whitespace; at the end of the string or STOPCHAR we're done. */
|
---|
| 3828 | NEXT_TOKEN (p);
|
---|
| 3829 | if (STOP_SET (*p, stopmap))
|
---|
[2591] | 3830 | break;
|
---|
| 3831 |
|
---|
| 3832 | /* There are names left, so find the end of the next name.
|
---|
| 3833 | Throughout this iteration S points to the start. */
|
---|
| 3834 | s = p;
|
---|
| 3835 | p = find_char_unquote (p, stopmap|MAP_VMSCOMMA|MAP_BLANK IF_WITH_VALUE_LENGTH_PARAM(0));
|
---|
[3140] | 3836 | #ifdef VMS
|
---|
| 3837 | /* convert comma separated list to space separated */
|
---|
[2591] | 3838 | if (p && *p == ',')
|
---|
[3140] | 3839 | *p =' ';
|
---|
[2591] | 3840 | #endif
|
---|
| 3841 | #ifdef _AMIGA
|
---|
[3140] | 3842 | if (p && STOP_SET (*p, stopmap & MAP_COLON)
|
---|
[53] | 3843 | && !(ISSPACE (p[1]) || !p[1] || ISSPACE (p[-1])))
|
---|
[2591] | 3844 | p = find_char_unquote (p+1, stopmap|MAP_VMSCOMMA|MAP_BLANK);
|
---|
[3140] | 3845 | #endif
|
---|
[2591] | 3846 | #ifdef HAVE_DOS_PATHS
|
---|
[3140] | 3847 | /* For DOS paths, skip a "C:\..." or a "C:/..." until we find the
|
---|
| 3848 | first colon which isn't followed by a slash or a backslash.
|
---|
| 3849 | Note that tokens separated by spaces should be treated as separate
|
---|
| 3850 | tokens since make doesn't allow path names with spaces */
|
---|
| 3851 | if (stopmap | MAP_COLON)
|
---|
| 3852 | while (p != 0 && !ISSPACE (*p) &&
|
---|
[425] | 3853 | (p[1] == '\\' || p[1] == '/') && isalpha ((unsigned char)p[-1]))
|
---|
[3140] | 3854 | p = find_char_unquote (p + 1, stopmap|MAP_VMSCOMMA|MAP_BLANK IF_WITH_VALUE_LENGTH_PARAM(0));
|
---|
| 3855 | #endif
|
---|
| 3856 | if (p == 0)
|
---|
[2591] | 3857 | p = s + strlen (s);
|
---|
[3140] | 3858 |
|
---|
| 3859 | /* Strip leading "this directory" references. */
|
---|
| 3860 | if (NONE_SET (flags, PARSEFS_NOSTRIP))
|
---|
| 3861 | #ifdef VMS
|
---|
[903] | 3862 | /* Skip leading '[]'s. should only be one set or bug somwhere else */
|
---|
[2591] | 3863 | if (p - s > 2 && s[0] == '[' && s[1] == ']')
|
---|
| 3864 | s += 2;
|
---|
[53] | 3865 | /* Skip leading '<>'s. should only be one set or bug somwhere else */
|
---|
[2591] | 3866 | if (p - s > 2 && s[0] == '<' && s[1] == '>')
|
---|
| 3867 | s += 2;
|
---|
[3140] | 3868 | #endif
|
---|
| 3869 | /* Skip leading './'s. */
|
---|
[2591] | 3870 | while (p - s > 2 && s[0] == '.' && s[1] == '/')
|
---|
| 3871 | {
|
---|
| 3872 | /* Skip "./" and all following slashes. */
|
---|
[1862] | 3873 | s += 2;
|
---|
[2591] | 3874 | while (*s == '/')
|
---|
| 3875 | ++s;
|
---|
| 3876 | }
|
---|
| 3877 |
|
---|
[1862] | 3878 | /* Extract the filename just found, and skip it.
|
---|
[2591] | 3879 | Set NAME to the string, and NLEN to its length. */
|
---|
| 3880 |
|
---|
[3140] | 3881 | if (s == p)
|
---|
[2591] | 3882 | {
|
---|
| 3883 | /* The name was stripped to empty ("./"). */
|
---|
| 3884 | #if defined(_AMIGA)
|
---|
| 3885 | /* PDS-- This cannot be right!! */
|
---|
| 3886 | tp[0] = '\0';
|
---|
[3140] | 3887 | nlen = 0;
|
---|
| 3888 | #else
|
---|
| 3889 | tp[0] = '.';
|
---|
| 3890 | tp[1] = '/';
|
---|
[2591] | 3891 | tp[2] = '\0';
|
---|
[3140] | 3892 | nlen = 2;
|
---|
| 3893 | #endif
|
---|
[2591] | 3894 | }
|
---|
| 3895 | else
|
---|
[1862] | 3896 | {
|
---|
[2591] | 3897 | #ifdef VMS
|
---|
| 3898 | /* VMS filenames can have a ':' in them but they have to be '\'ed but we need
|
---|
| 3899 | * to remove this '\' before we can use the filename.
|
---|
[1862] | 3900 | * xstrdup called because S may be read-only string constant.
|
---|
[2591] | 3901 | */
|
---|
[53] | 3902 | char *n = tp;
|
---|
[2591] | 3903 | while (s < p)
|
---|
| 3904 | {
|
---|
| 3905 | if (s[0] == '\\' && s[1] == ':')
|
---|
| 3906 | ++s;
|
---|
| 3907 | *(n++) = *(s++);
|
---|
| 3908 | }
|
---|
| 3909 | n[0] = '\0';
|
---|
| 3910 | nlen = strlen (tp);
|
---|
| 3911 | #else
|
---|
[3140] | 3912 | nlen = p - s;
|
---|
[2591] | 3913 | memcpy (tp, s, nlen);
|
---|
| 3914 | tp[nlen] = '\0';
|
---|
| 3915 | #endif
|
---|
| 3916 | }
|
---|
| 3917 |
|
---|
| 3918 | /* At this point, TP points to the element and NLEN is its length. */
|
---|
| 3919 |
|
---|
[3140] | 3920 | #ifndef NO_ARCHIVES
|
---|
[2591] | 3921 | /* If this is the start of an archive group that isn't complete, set up
|
---|
| 3922 | to add the archive prefix for future files. A file list like:
|
---|
| 3923 | "libf.a(x.o y.o z.o)" needs to be expanded as:
|
---|
| 3924 | "libf.a(x.o) libf.a(y.o) libf.a(z.o)"
|
---|
| 3925 |
|
---|
| 3926 | TP == TMP means we're not already in an archive group. Ignore
|
---|
| 3927 | something starting with '(', as that cannot actually be an
|
---|
[3140] | 3928 | archive-member reference (and treating it as such results in an empty
|
---|
[2591] | 3929 | file name, which causes much lossage). Also if it ends in ")" then
|
---|
| 3930 | it's a complete reference so we don't need to treat it specially.
|
---|
[3140] | 3931 |
|
---|
| 3932 | Finally, note that archive groups must end with ')' as the last
|
---|
[2591] | 3933 | character, so ensure there's some word ending like that before
|
---|
| 3934 | considering this an archive group. */
|
---|
| 3935 | if (NONE_SET (flags, PARSEFS_NOAR)
|
---|
[3140] | 3936 | && tp == tmpbuf && tp[0] != '(' && tp[nlen-1] != ')')
|
---|
[2591] | 3937 | {
|
---|
[3140] | 3938 | char *n = strchr (tp, '(');
|
---|
| 3939 | if (n)
|
---|
| 3940 | {
|
---|
[2591] | 3941 | /* This looks like the first element in an open archive group.
|
---|
| 3942 | A valid group MUST have ')' as the last character. */
|
---|
| 3943 | const char *e = p;
|
---|
| 3944 | do
|
---|
| 3945 | {
|
---|
| 3946 | const char *o = e;
|
---|
| 3947 | NEXT_TOKEN (e);
|
---|
| 3948 | /* Find the end of this word. We don't want to unquote and
|
---|
| 3949 | we don't care about quoting since we're looking for the
|
---|
| 3950 | last char in the word. */
|
---|
| 3951 | while (! STOP_SET (*e, stopmap|MAP_BLANK|MAP_VMSCOMMA))
|
---|
| 3952 | ++e;
|
---|
| 3953 | /* If we didn't move, we're done now. */
|
---|
[3140] | 3954 | if (e == o)
|
---|
| 3955 | break;
|
---|
| 3956 | if (e[-1] == ')')
|
---|
| 3957 | {
|
---|
| 3958 | /* Found the end, so this is the first element in an
|
---|
[2591] | 3959 | open archive group. It looks like "lib(mem".
|
---|
| 3960 | Reset TP past the open paren. */
|
---|
| 3961 | nlen -= (n + 1) - tp;
|
---|
| 3962 | tp = n + 1;
|
---|
| 3963 |
|
---|
| 3964 | /* We can stop looking now. */
|
---|
| 3965 | break;
|
---|
| 3966 | }
|
---|
| 3967 | }
|
---|
| 3968 | while (*e != '\0');
|
---|
| 3969 |
|
---|
| 3970 | /* If we have just "lib(", part of something like "lib( a b)",
|
---|
| 3971 | go to the next item. */
|
---|
| 3972 | if (! nlen)
|
---|
| 3973 | continue;
|
---|
| 3974 | }
|
---|
| 3975 | }
|
---|
| 3976 |
|
---|
| 3977 | /* If we are inside an archive group, make sure it has an end. */
|
---|
| 3978 | if (tp > tmpbuf)
|
---|
| 3979 | {
|
---|
| 3980 | if (tp[nlen-1] == ')')
|
---|
| 3981 | {
|
---|
| 3982 | /* This is the natural end; reset TP. */
|
---|
| 3983 | tp = tmpbuf;
|
---|
| 3984 |
|
---|
[3140] | 3985 | /* This is just ")", something like "lib(a b )": skip it. */
|
---|
[2591] | 3986 | if (nlen == 1)
|
---|
[3140] | 3987 | continue;
|
---|
[2591] | 3988 | }
|
---|
| 3989 | else
|
---|
| 3990 | {
|
---|
| 3991 | /* Not the end, so add a "fake" end. */
|
---|
| 3992 | tp[nlen++] = ')';
|
---|
| 3993 | tp[nlen] = '\0';
|
---|
[3140] | 3994 | }
|
---|
[2591] | 3995 | }
|
---|
| 3996 | #endif
|
---|
[3140] | 3997 |
|
---|
| 3998 | /* If we're not globbing we're done: add it to the end of the chain.
|
---|
| 3999 | Go to the next item in the string. */
|
---|
| 4000 | if (ANY_SET (flags, PARSEFS_NOGLOB))
|
---|
[2591] | 4001 | {
|
---|
[3140] | 4002 | NEWELT (concat (2, prefix, tmpbuf));
|
---|
[2591] | 4003 | continue;
|
---|
| 4004 | }
|
---|
| 4005 |
|
---|
| 4006 | /* If we get here we know we're doing glob expansion.
|
---|
| 4007 | TP is a string in tmpbuf. NLEN is no longer used.
|
---|
[3140] | 4008 | We may need to do more work: after this NAME will be set. */
|
---|
| 4009 | name = tmpbuf;
|
---|
| 4010 |
|
---|
| 4011 | /* Expand tilde if applicable. */
|
---|
| 4012 | if (tmpbuf[0] == '~')
|
---|
[2591] | 4013 | {
|
---|
| 4014 | tildep = tilde_expand (tmpbuf);
|
---|
[3140] | 4015 | if (tildep != 0)
|
---|
| 4016 | name = tildep;
|
---|
| 4017 | }
|
---|
| 4018 |
|
---|
| 4019 | #ifndef NO_ARCHIVES
|
---|
| 4020 | /* If NAME is an archive member reference replace it with the archive
|
---|
| 4021 | file name, and save the member name in MEMNAME. We will glob on the
|
---|
| 4022 | archive name and then reattach MEMNAME later. */
|
---|
| 4023 | if (NONE_SET (flags, PARSEFS_NOAR) && ar_name (name))
|
---|
| 4024 | {
|
---|
| 4025 | ar_parse_name (name, &arname, &memname);
|
---|
| 4026 | name = arname;
|
---|
[53] | 4027 | }
|
---|
[3140] | 4028 | #endif /* !NO_ARCHIVES */
|
---|
| 4029 |
|
---|
| 4030 | /* glob() is expensive: don't call it unless we need to. */
|
---|
| 4031 | if (NONE_SET (flags, PARSEFS_EXISTS) && strpbrk (name, "?*[") == NULL)
|
---|
| 4032 | {
|
---|
[2591] | 4033 | globme = 0;
|
---|
[3140] | 4034 | i = 1;
|
---|
| 4035 | nlist = &name;
|
---|
| 4036 | }
|
---|
| 4037 | else
|
---|
| 4038 | switch (glob (name, GLOB_NOSORT|GLOB_ALTDIRFUNC, NULL, &gl))
|
---|
| 4039 | {
|
---|
| 4040 | case GLOB_NOSPACE:
|
---|
| 4041 | OUT_OF_MEM();
|
---|
[2591] | 4042 |
|
---|
[3140] | 4043 | case 0:
|
---|
| 4044 | /* Success. */
|
---|
| 4045 | i = gl.gl_pathc;
|
---|
| 4046 | nlist = (const char **)gl.gl_pathv;
|
---|
| 4047 | break;
|
---|
| 4048 |
|
---|
[903] | 4049 | case GLOB_NOMATCH:
|
---|
[2591] | 4050 | /* If we want only existing items, skip this one. */
|
---|
| 4051 | if (ANY_SET (flags, PARSEFS_EXISTS))
|
---|
[903] | 4052 | {
|
---|
[2591] | 4053 | i = 0;
|
---|
| 4054 | break;
|
---|
| 4055 | }
|
---|
| 4056 | /* FALLTHROUGH */
|
---|
| 4057 |
|
---|
| 4058 | default:
|
---|
| 4059 | /* By default keep this name. */
|
---|
| 4060 | i = 1;
|
---|
| 4061 | nlist = &name;
|
---|
| 4062 | break;
|
---|
[3140] | 4063 | }
|
---|
| 4064 |
|
---|
| 4065 | /* For each matched element, add it to the list. */
|
---|
| 4066 | while (i-- > 0)
|
---|
[2591] | 4067 | #ifndef NO_ARCHIVES
|
---|
| 4068 | if (memname != 0)
|
---|
| 4069 | {
|
---|
| 4070 | /* Try to glob on MEMNAME within the archive. */
|
---|
| 4071 | struct nameseq *found = ar_glob (nlist[i], memname, size);
|
---|
| 4072 | if (! found)
|
---|
| 4073 | /* No matches. Use MEMNAME as-is. */
|
---|
| 4074 | NEWELT (concat (5, prefix, nlist[i], "(", memname, ")"));
|
---|
| 4075 | else
|
---|
| 4076 | {
|
---|
| 4077 | /* We got a chain of items. Attach them. */
|
---|
| 4078 | if (*newp)
|
---|
| 4079 | (*newp)->next = found;
|
---|
| 4080 | else
|
---|
| 4081 | *newp = found;
|
---|
| 4082 |
|
---|
| 4083 | /* Find and set the new end. Massage names if necessary. */
|
---|
| 4084 | while (1)
|
---|
| 4085 | {
|
---|
| 4086 | if (! cachep)
|
---|
| 4087 | found->name = xstrdup (concat (2, prefix, name));
|
---|
[3140] | 4088 | else if (prefix)
|
---|
[2591] | 4089 | found->name = strcache_add (concat (2, prefix, name));
|
---|
| 4090 |
|
---|
| 4091 | if (found->next == 0)
|
---|
[3140] | 4092 | break;
|
---|
[903] | 4093 |
|
---|
[2591] | 4094 | found = found->next;
|
---|
[3140] | 4095 | }
|
---|
[53] | 4096 | newp = &found->next;
|
---|
| 4097 | }
|
---|
[2591] | 4098 | }
|
---|
[53] | 4099 | else
|
---|
| 4100 | #endif /* !NO_ARCHIVES */
|
---|
[1811] | 4101 | NEWELT (concat (2, prefix, nlist[i]));
|
---|
| 4102 |
|
---|
| 4103 | if (globme)
|
---|
| 4104 | globfree (&gl);
|
---|
| 4105 |
|
---|
| 4106 | #ifndef NO_ARCHIVES
|
---|
| 4107 | free (arname);
|
---|
| 4108 | #endif
|
---|
| 4109 |
|
---|
| 4110 | free (tildep);
|
---|
| 4111 | }
|
---|
| 4112 |
|
---|
| 4113 | *stringp = p;
|
---|
| 4114 | return new;
|
---|
| 4115 | }
|
---|
| 4116 |
|
---|