static struct variable *do_define (char *name, enum variable_origin origin,
struct ebuffer *ebuf);
static int conditional_line (char *line, size_t len, const floc *flocp);
+static void check_specials (const struct nameseq *file, int set_default);
static void record_files (struct nameseq *filenames, int are_also_makes,
const char *pattern,
const char *pattern_percent, char *depstr,
commands[commands_idx++] = '\n';
}
- /* Determine if this target should be made default. We used to do
- this in record_files() but because of the delayed target recording
- and because preprocessor directives are legal in target's commands
- it is too late. Consider this fragment for example:
-
- foo:
-
- ifeq ($(.DEFAULT_GOAL),foo)
- ...
- endif
-
- Because the target is not recorded until after ifeq directive is
- evaluated the .DEFAULT_GOAL does not contain foo yet as one
- would expect. Because of this we have to move the logic here. */
-
- if (set_default && default_goal_var->value[0] == '\0')
- {
- struct dep *d;
- struct nameseq *t = filenames;
-
- for (; t != 0; t = t->next)
- {
- int reject = 0;
- const char *name = t->name;
-
- /* We have nothing to do if this is an implicit rule. */
- if (strchr (name, '%') != 0)
- break;
-
- /* See if this target's name does not start with a '.',
- unless it contains a slash. */
- if (*name == '.' && strchr (name, '/') == 0
-#ifdef HAVE_DOS_PATHS
- && strchr (name, '\\') == 0
-#endif
- )
- continue;
-
-
- /* If this file is a suffix, don't let it be
- the default goal file. */
- for (d = suffix_file->deps; d != 0; d = d->next)
- {
- struct dep *d2;
- if (*dep_name (d) != '.' && streq (name, dep_name (d)))
- {
- reject = 1;
- break;
- }
- for (d2 = suffix_file->deps; d2 != 0; d2 = d2->next)
- {
- size_t l = strlen (dep_name (d2));
- if (!strneq (name, dep_name (d2), l))
- continue;
- if (streq (name + l, dep_name (d)))
- {
- reject = 1;
- break;
- }
- }
-
- if (reject)
- break;
- }
-
- if (!reject)
- {
- define_variable_global (".DEFAULT_GOAL", 13, t->name,
- o_file, 0, NILF);
- break;
- }
- }
- }
+ check_specials (filenames, set_default);
}
}
}
}
\f
+
+/* Check for special targets. We used to do this in record_files() but that's
+ too late: by the time we get there we'll have already parsed the next line
+ and it have been mis-parsed because these special targets haven't been
+ considered yet. */
+
+static void check_specials (const struct nameseq* files, int set_default)
+{
+ const struct nameseq *t = files;
+
+ /* Unlikely but ... */
+ if (posix_pedantic && second_expansion && one_shell
+ && (!set_default || default_goal_var->value[0] == '\0'))
+ return;
+
+ for (; t != 0; t = t->next)
+ {
+ const char* nm = t->name;
+
+ if (!posix_pedantic && streq (nm, ".POSIX"))
+ {
+ posix_pedantic = 1;
+ define_variable_cname (".SHELLFLAGS", "-ec", o_default, 0);
+ /* These default values are based on IEEE Std 1003.1-2008.
+ It requires '-O 1' for [CF]FLAGS, but GCC doesn't allow
+ space between -O and the number so omit it here. */
+ define_variable_cname ("ARFLAGS", "-rv", o_default, 0);
+ define_variable_cname ("CC", "c99", o_default, 0);
+ define_variable_cname ("CFLAGS", "-O1", o_default, 0);
+ define_variable_cname ("FC", "fort77", o_default, 0);
+ define_variable_cname ("FFLAGS", "-O1", o_default, 0);
+ define_variable_cname ("SCCSGETFLAGS", "-s", o_default, 0);
+ continue;
+ }
+
+ if (!second_expansion && streq (nm, ".SECONDEXPANSION"))
+ {
+ second_expansion = 1;
+ continue;
+ }
+
+#if !defined (__MSDOS__) && !defined (__EMX__)
+ if (!one_shell && streq (nm, ".ONESHELL"))
+ {
+ one_shell = 1;
+ continue;
+ }
+#endif
+
+ /* Determine if this target should be made default. */
+
+ if (set_default && default_goal_var->value[0] == '\0')
+ {
+ struct dep *d;
+ int reject = 0;
+
+ /* We have nothing to do if this is an implicit rule. */
+ if (strchr (nm, '%') != 0)
+ break;
+
+ /* See if this target's name does not start with a '.',
+ unless it contains a slash. */
+ if (*nm == '.' && strchr (nm, '/') == 0
+#ifdef HAVE_DOS_PATHS
+ && strchr (nm, '\\') == 0
+#endif
+ )
+ continue;
+
+ /* If this file is a suffix, it can't be the default goal file. */
+ for (d = suffix_file->deps; d != 0; d = d->next)
+ {
+ struct dep *d2;
+ if (*dep_name (d) != '.' && streq (nm, dep_name (d)))
+ {
+ reject = 1;
+ break;
+ }
+ for (d2 = suffix_file->deps; d2 != 0; d2 = d2->next)
+ {
+ size_t l = strlen (dep_name (d2));
+ if (!strneq (nm, dep_name (d2), l))
+ continue;
+ if (streq (nm + l, dep_name (d)))
+ {
+ reject = 1;
+ break;
+ }
+ }
+
+ if (reject)
+ break;
+ }
+
+ if (!reject)
+ define_variable_global (".DEFAULT_GOAL", 13, t->name,
+ o_file, 0, NILF);
+ }
+ }
+}
+\f
/* Record a description line for files FILENAMES,
with dependencies DEPS, commands to execute described
by COMMANDS and COMMANDS_IDX, coming from FILENAME:COMMANDS_STARTED.
free_ns (filenames);
- /* Check for special targets. Do it here instead of, say, snap_deps()
- so that we can immediately use the value. */
- if (!posix_pedantic && streq (name, ".POSIX"))
- {
- posix_pedantic = 1;
- define_variable_cname (".SHELLFLAGS", "-ec", o_default, 0);
- /* These default values are based on IEEE Std 1003.1-2008.
- It requires '-O 1' for [CF]FLAGS, but GCC doesn't allow space
- between -O and the number so omit it here. */
- define_variable_cname ("ARFLAGS", "-rv", o_default, 0);
- define_variable_cname ("CC", "c99", o_default, 0);
- define_variable_cname ("CFLAGS", "-O1", o_default, 0);
- define_variable_cname ("FC", "fort77", o_default, 0);
- define_variable_cname ("FFLAGS", "-O1", o_default, 0);
- define_variable_cname ("SCCSGETFLAGS", "-s", o_default, 0);
- }
- else if (!second_expansion && streq (name, ".SECONDEXPANSION"))
- second_expansion = 1;
-#if !defined (__MSDOS__) && !defined (__EMX__)
- else if (!one_shell && streq (name, ".ONESHELL"))
- one_shell = 1;
-#endif
-
/* If this is a static pattern rule:
'targets: target%pattern: prereq%pattern; recipe',
make sure the pattern matches this target name. */