fprintf (stderr, " -I DIRECTORY Search DIRECTORY for included makefiles.\n");
fprintf (stderr, "\n");
+ fprintf (stderr, " -e Environment variables override makefiles.\n");
fprintf (stderr, " -f FILE Read FILE as a makefile.\n");
fprintf (stderr, " -s Don't echo recipes.\n");
fprintf (stderr, "\n");
}
+static int set_env_override (const char *arg) {
+
+ (void) arg;
+
+ state->env_override = 1;
+ return 0;
+
+}
+
static int add_include_path (const char *path) {
const char *in = path;
static struct option opts[] = {
- { "--help", &print_help },
- { "-h", &print_help },
-
- { "--version", &print_version },
+ { "--help", &print_help },
+ { "-h", &print_help },
- { "--silent", &set_quiet },
- { "--quiet", &set_quiet },
- { "-s", &set_quiet },
+ { "--version", &print_version },
- { "--no-print-directory", &set_no_print },
+ { "--silent", &set_quiet },
+ { "--quiet", &set_quiet },
+ { "-s", &set_quiet },
- { "--no-builtin-rules", &ignored },
- { "-r", &ignored },
+ { "--no-print-directory", &set_no_print },
- { "--include_dir=", &add_include_path },
- { "-I:", &add_include_path },
+ { "--no-builtin-rules", &ignored },
+ { "-r", &ignored },
- { "--always-make", &ignored },
- { "-B", &ignored },
+ { "--include_dir=", &add_include_path },
+ { "-I:", &add_include_path },
- { "--directory=", &add_directory },
- { "-C:", &add_directory },
+ { "--always-make", &ignored },
+ { "-B", &ignored },
- { "--makefile=", &add_makefile },
- { "--file=", &add_makefile },
- { "-f:", &add_makefile },
+ { "--directory=", &add_directory },
+ { "-C:", &add_directory },
- { "--ignore-errors", &set_ignore_errors },
- { "-i", &set_ignore_errors },
+ { "--makefile=", &add_makefile },
+ { "--file=", &add_makefile },
+ { "-f:", &add_makefile },
- { "--dry_run", &set_dry_run },
- { "-n", &set_dry_run },
+ { "--ignore-errors", &set_ignore_errors },
+ { "-i", &set_ignore_errors },
+ { "--dry_run", &set_dry_run },
+ { "-n", &set_dry_run },
+ { "--environment-overrides", &set_env_override },
+ { "-e", &set_env_override },
- { 0, &non_option }
+ { 0, &non_option }
};
lpCommandLine = xstrdup (skip_whitespace (p));
} else {
- lpCommandLine = xstrdup (input);
+ lpApplicationName = xstrdup (skip_whitespace (input));
}
if (!(p = strchr (lpApplicationName, '\\'))) {
while (ReadFile (hStdOutPipeRead, p, end - p, &dwRead, 0)) {
size_t offset;
- p += strlen (p);
+ p += dwRead;
offset = p - lbuf.start;
}
+ if (isspace ((int) *(p - 1))) {
+ *(p - 1) = '\0';
+ }
+
return lbuf.start;
}
p = lbuf.start;
- while ((ch = *p++)) {
+ while ((ch = *p)) {
if (ch == '\n' || ch == '\r') {
- p[-1] = ' ';
+ *p = ' ';
}
+
+ p++;
}
+ if (isspace ((int) *(p - 1))) {
+ *(p - 1) = '\0';
+ }
+
return lbuf.start;
}
q++;
}
- if ((alloc_replacement = func->func (filename, line_no, q))) {
+ /*if ((alloc_replacement = func->func (filename, line_no, q))) {
new = xmalloc (pos + strlen (alloc_replacement) + 1);
free (alloc_replacement);
return new;
- }
+ }*/
+
+ alloc_replacement = func->func (filename, line_no, q);
} else if ((q = strchr (content, '='))) {
}
} else {
+
+ if (state->env_override) {
+
+ if ((alloc_replacement = getenv (content))) {
+
+ alloc_replacement = xstrdup (alloc_replacement);
+ goto got_value;
+
+ }
+
+ }
+
var = variable_find (content);
+
}
+ got_value:
+
free (content);
} else if (line[pos + 1]) {
pos += strlen (replacement);
}
- free (alloc_replacement);
+ if (alloc_replacement) {
+ free (alloc_replacement);
+ }
+
continue;
void parse_var_line (const char *filename, unsigned long line_no, char *line, enum variable_origin origin) {
enum {
+
VAR_ASSIGN,
VAR_CONDITIONAL_ASSIGN,
VAR_APPEND,
VAR_SHELL
+
} opt = VAR_ASSIGN;
enum variable_flavor flavor = VAR_FLAVOR_RECURSIVELY_EXPANDED;
HANDLE hStdInPipeRead, hStdInPipeWrite;
HANDLE hStdOutPipeRead, hStdOutPipeWrite;
- char *lpApplicationName = getenv ("COMSPEC"), *lpCommandLine = 0, *p;
+ char *lpApplicationName = getenv ("COMSPEC"), *lpCommandLine = 0;
struct linebuf lbuf;
input = skip_whitespace (input);
- for (p = input; !isspace ((int) *p); p++) {
+ /*for (p = input; !isspace ((int) *p); p++) {
if (*p == '/') {
*p = '\\';
}
- }
+ }*/
lpCommandLine = xmalloc (4 + strlen (input) + 1);
sprintf (lpCommandLine, "/C %s", input);
while (ReadFile (hStdOutPipeRead, p, end - p, &dwRead, 0)) {
size_t offset;
- p += strlen (p);
+ p += dwRead;
offset = p - lbuf.start;
}
+ } else {
+ printf ("%s", lbuf.start);
}
}
}
+ } else {
+
+ char *p = lbuf.start, ch;
+
+ while ((ch = *p)) {
+
+ if (ch == '"') {
+
+ memmove (p, p + 1, strlen (p + 1));
+ *(p + strlen (p) - 1) = '\0';
+
+ continue;
+
+ }
+
+ if (ch == '\n' || ch == '\r') {
+ *p = ' ';
+ }
+
+ p++;
+
+ }
+
+ if (isspace ((int) *(p - 1))) {
+ *(p - 1) = '\0';
+ }
+
+ printf ("%s\n", lbuf.start);
+
}
}