#include "make.h"
#include "dep.h"
#include "filedef.h"
#include "variable.h"
#include "job.h"
#include "commands.h"
#include "rule.h"
#include "debug.h"
#include "getopt.h"
#include <assert.h>
#ifdef _AMIGA
# include <dos/dos.h>
# include <proto/dos.h>
#endif
#ifdef WINDOWS32
#include <windows.h>
#include "pathstuff.h"
#endif
#if defined(MAKE_JOBSERVER) && defined(HAVE_FCNTL_H)
# include <fcntl.h>
#endif
#ifdef _AMIGA
int __stack = 20000;
#endif
extern void init_dir PARAMS ((void));
extern void remote_setup PARAMS ((void));
extern void remote_cleanup PARAMS ((void));
extern RETSIGTYPE fatal_error_signal PARAMS ((int sig));
extern void print_variable_data_base PARAMS ((void));
extern void print_dir_data_base PARAMS ((void));
extern void print_rule_data_base PARAMS ((void));
extern void print_file_data_base PARAMS ((void));
extern void print_vpath_data_base PARAMS ((void));
#if defined HAVE_WAITPID || defined HAVE_WAIT3
# define HAVE_WAIT_NOHANG
#endif
#ifndef HAVE_UNISTD_H
extern int chdir ();
#endif
#ifndef STDC_HEADERS
# ifndef sun
extern void exit PARAMS ((int)) __attribute__ ((noreturn));
# endif
extern double atof ();
#endif
static void print_data_base PARAMS ((void));
static void print_version PARAMS ((void));
static void decode_switches PARAMS ((int argc, char **argv, int env));
static void decode_env_switches PARAMS ((char *envar, unsigned int len));
static void define_makeflags PARAMS ((int all, int makefile));
static char *quote_for_env PARAMS ((char *out, char *in));
#if defined(__APPLE__) || defined(NeXT) || defined(NeXT_PDO)
#endif
struct command_switch
{
int c;
enum
{
flag,
flag_off,
string,
positive_int,
floating,
ignore
} type;
char *value_ptr;
unsigned int env:1;
unsigned int toenv:1;
unsigned int no_makefile:1;
char *noarg_value;
char *default_value;
char *long_name;
char *argdesc;
char *description;
};
#define short_option(c) ((c) <= CHAR_MAX)
struct stringlist
{
char **list;
unsigned int idx;
unsigned int max;
};
int silent_flag;
int touch_flag;
int just_print_flag;
static struct stringlist *db_flags;
static int debug_flag = 0;
int db_level = 0;
#ifdef WINDOWS32
int suspend_flag = 0;
#endif
int env_overrides = 0;
int ignore_errors_flag = 0;
int print_data_base_flag = 0;
int question_flag = 0;
int no_builtin_rules_flag = 0;
int no_builtin_variables_flag = 0;
int keep_going_flag;
int default_keep_going_flag = 0;
int print_directory_flag = 0;
int inhibit_print_directory_flag = 0;
int print_version_flag = 0;
static struct stringlist *makefiles = 0;
#if defined(__APPLE__) || defined(NeXT) || defined(NeXT_PDO)
unsigned int next_flag = 0;
static struct stringlist *next_flag_list = 0;
#endif
unsigned int job_slots = 1;
unsigned int default_job_slots = 1;
static unsigned int inf_jobs = 0;
static struct stringlist *jobserver_fds = 0;
int job_fds[2] = { -1, -1 };
int job_rfd = -1;
#ifndef NO_FLOAT
double max_load_average = -1.0;
double default_load_average = -1.0;
#else
int max_load_average = -1;
int default_load_average = -1;
#endif
static struct stringlist *directories = 0;
static struct stringlist *include_directories = 0;
static struct stringlist *old_files = 0;
static struct stringlist *new_files = 0;
static int print_usage_flag = 0;
int warn_undefined_variables_flag;
static const struct command_switch switches[] =
{
{ 'b', ignore, 0, 0, 0, 0, 0, 0,
0, 0,
N_("Ignored for compatibility") },
{ 'C', string, (char *) &directories, 0, 0, 0, 0, 0,
"directory", N_("DIRECTORY"),
N_("Change to DIRECTORY before doing anything") },
{ 'd', flag, (char *) &debug_flag, 1, 1, 0, 0, 0,
0, 0,
N_("Print lots of debugging information") },
{ CHAR_MAX+1, string, (char *) &db_flags, 1, 1, 0,
"basic", 0,
"debug", N_("FLAGS"),
N_("Print various types of debugging information") },
#ifdef WINDOWS32
{ 'D', flag, (char *) &suspend_flag, 1, 1, 0, 0, 0,
"suspend-for-debug", 0,
N_("Suspend process to allow a debugger to attach") },
#endif
{ 'e', flag, (char *) &env_overrides, 1, 1, 0, 0, 0,
"environment-overrides", 0,
N_("Environment variables override makefiles") },
{ 'f', string, (char *) &makefiles, 0, 0, 0, 0, 0,
"file", N_("FILE"),
N_("Read FILE as a makefile") },
{ 'h', flag, (char *) &print_usage_flag, 0, 0, 0, 0, 0,
"help", 0,
N_("Print this message and exit") },
{ 'i', flag, (char *) &ignore_errors_flag, 1, 1, 0, 0, 0,
"ignore-errors", 0,
N_("Ignore errors from commands") },
{ 'I', string, (char *) &include_directories, 1, 1, 0, 0, 0,
"include-dir", N_("DIRECTORY"),
N_("Search DIRECTORY for included makefiles") },
{ 'j',
positive_int, (char *) &job_slots, 1, 1, 0,
(char *) &inf_jobs, (char *) &default_job_slots,
"jobs", "N",
N_("Allow N jobs at once; infinite jobs with no arg") },
{ CHAR_MAX+2, string, (char *) &jobserver_fds, 1, 1, 0, 0, 0,
"jobserver-fds", 0,
0 },
{ 'k', flag, (char *) &keep_going_flag, 1, 1, 0,
0, (char *) &default_keep_going_flag,
"keep-going", 0,
N_("Keep going when some targets can't be made") },
#ifndef NO_FLOAT
{ 'l', floating, (char *) &max_load_average, 1, 1, 0,
(char *) &default_load_average, (char *) &default_load_average,
"load-average", "N",
N_("Don't start multiple jobs unless load is below N") },
#else
{ 'l', positive_int, (char *) &max_load_average, 1, 1, 0,
(char *) &default_load_average, (char *) &default_load_average,
"load-average", "N",
N_("Don't start multiple jobs unless load is below N") },
#endif
{ 'm', ignore, 0, 0, 0, 0, 0, 0,
0, 0,
"-b" },
{ 'n', flag, (char *) &just_print_flag, 1, 1, 1, 0, 0,
"just-print", 0,
N_("Don't actually run any commands; just print them") },
{ 'o', string, (char *) &old_files, 0, 0, 0, 0, 0,
"old-file", N_("FILE"),
N_("Consider FILE to be very old and don't remake it") },
{ 'p', flag, (char *) &print_data_base_flag, 1, 1, 0, 0, 0,
"print-data-base", 0,
N_("Print make's internal database") },
{ 'q', flag, (char *) &question_flag, 1, 1, 1, 0, 0,
"question", 0,
N_("Run no commands; exit status says if up to date") },
{ 'r', flag, (char *) &no_builtin_rules_flag, 1, 1, 0, 0, 0,
"no-builtin-rules", 0,
N_("Disable the built-in implicit rules") },
{ 'R', flag, (char *) &no_builtin_variables_flag, 1, 1, 0, 0, 0,
"no-builtin-variables", 0,
N_("Disable the built-in variable settings") },
{ 's', flag, (char *) &silent_flag, 1, 1, 0, 0, 0,
"silent", 0,
N_("Don't echo commands") },
{ 'S', flag_off, (char *) &keep_going_flag, 1, 1, 0,
0, (char *) &default_keep_going_flag,
"no-keep-going", 0,
N_("Turns off -k") },
{ 't', flag, (char *) &touch_flag, 1, 1, 1, 0, 0,
"touch", 0,
N_("Touch targets instead of remaking them") },
{ 'v', flag, (char *) &print_version_flag, 1, 1, 0, 0, 0,
"version", 0,
N_("Print the version number of make and exit") },
{ 'w', flag, (char *) &print_directory_flag, 1, 1, 0, 0, 0,
"print-directory", 0,
N_("Print the current directory") },
{ CHAR_MAX+3, flag, (char *) &inhibit_print_directory_flag, 1, 1, 0, 0, 0,
"no-print-directory", 0,
N_("Turn off -w, even if it was turned on implicitly") },
{ 'W', string, (char *) &new_files, 0, 0, 0, 0, 0,
"what-if", N_("FILE"),
N_("Consider FILE to be infinitely new") },
{ CHAR_MAX+4, flag, (char *) &warn_undefined_variables_flag, 1, 1, 0, 0, 0,
"warn-undefined-variables", 0,
N_("Warn when an undefined variable is referenced") },
#if defined(__APPLE__) || defined(NeXT) || defined(NeXT_PDO)
{ 'N', string, (char *) &next_flag_list, 0, 0, 0, 0, 0,
"NeXT-option", N_("OPTION"),
N_("Turn on value of NeXT OPTION") },
#endif
{ '\0', }
};
static struct option long_option_aliases[] =
{
{ "quiet", no_argument, 0, 's' },
{ "stop", no_argument, 0, 'S' },
{ "new-file", required_argument, 0, 'W' },
{ "assume-new", required_argument, 0, 'W' },
{ "assume-old", required_argument, 0, 'o' },
{ "max-load", optional_argument, 0, 'l' },
{ "dry-run", no_argument, 0, 'n' },
{ "recon", no_argument, 0, 'n' },
{ "makefile", required_argument, 0, 'f' },
};
#define DESCRIPTION_COLUMN 30
static struct dep *goals, *lastgoal;
struct command_variable
{
struct command_variable *next;
struct variable *variable;
};
static struct command_variable *command_variables;
char *program;
char *directory_before_chdir;
char *starting_directory;
unsigned int makelevel;
struct file *default_goal_file;
struct file *default_file;
int posix_pedantic;
int not_parallel;
int clock_skew_detected;
#ifdef POSIX
sigset_t fatal_signal_set;
#else
#ifdef HAVE_SIGSETMASK
int fatal_signal_mask;
#endif
#endif
static struct file *
enter_command_line_file (name)
char *name;
{
if (name[0] == '\0')
fatal (NILF, _("empty string invalid as file name"));
if (name[0] == '~')
{
char *expanded = tilde_expand (name);
if (expanded != 0)
name = expanded;
}
while (name[0] == '.' && name[1] == '/' && name[2] != '\0')
{
name += 2;
while (*name == '/')
++name;
}
if (*name == '\0')
{
do
--name;
while (name[0] != '.');
name[2] = '\0';
}
return enter_file (xstrdup (name));
}
static RETSIGTYPE
debug_signal_handler (sig)
int sig;
{
db_level = db_level ? DB_NONE : DB_BASIC;
}
static void
decode_debug_flags ()
{
char **pp;
if (debug_flag)
db_level = DB_ALL;
if (!db_flags)
return;
for (pp=db_flags->list; *pp; ++pp)
{
const char *p = *pp;
while (1)
{
switch (tolower (p[0]))
{
case 'a':
db_level |= DB_ALL;
break;
case 'b':
db_level |= DB_BASIC;
break;
case 'i':
db_level |= DB_BASIC | DB_IMPLICIT;
break;
case 'j':
db_level |= DB_JOBS;
break;
case 'm':
db_level |= DB_BASIC | DB_MAKEFILES;
break;
case 'v':
db_level |= DB_BASIC | DB_VERBOSE;
break;
default:
fatal (NILF, _("unknown debug level specification `%s'"), p);
}
while (*(++p) != '\0')
if (*p == ',' || *p == ' ')
break;
if (*p == '\0')
break;
++p;
}
}
}
#ifdef WINDOWS32
LONG WINAPI
handle_runtime_exceptions( struct _EXCEPTION_POINTERS *exinfo )
{
PEXCEPTION_RECORD exrec = exinfo->ExceptionRecord;
LPSTR cmdline = GetCommandLine();
LPSTR prg = strtok(cmdline, " ");
CHAR errmsg[1024];
#ifdef USE_EVENT_LOG
HANDLE hEventSource;
LPTSTR lpszStrings[1];
#endif
if (! ISDB (DB_VERBOSE))
{
sprintf(errmsg,
_("%s: Interrupt/Exception caught (code = 0x%x, addr = 0x%x)\n"),
prg, exrec->ExceptionCode, exrec->ExceptionAddress);
fprintf(stderr, errmsg);
exit(255);
}
sprintf(errmsg,
_("\nUnhandled exception filter called from program %s\nExceptionCode = %x\nExceptionFlags = %x\nExceptionAddress = %x\n"),
prg, exrec->ExceptionCode, exrec->ExceptionFlags,
exrec->ExceptionAddress);
if (exrec->ExceptionCode == EXCEPTION_ACCESS_VIOLATION
&& exrec->NumberParameters >= 2)
sprintf(&errmsg[strlen(errmsg)],
(exrec->ExceptionInformation[0]
? _("Access violation: write operation at address %x\n")
: _("Access violation: read operation at address %x\n")),
exrec->ExceptionInformation[1]);
#ifdef USE_EVENT_LOG
hEventSource = RegisterEventSource(NULL, "GNU Make");
lpszStrings[0] = errmsg;
if (hEventSource != NULL)
{
ReportEvent(hEventSource,
EVENTLOG_ERROR_TYPE,
0,
0,
NULL,
1,
0,
lpszStrings,
NULL);
(VOID) DeregisterEventSource(hEventSource);
}
#endif
fprintf(stderr, errmsg);
#ifdef DEBUG
return EXCEPTION_CONTINUE_SEARCH;
#else
exit(255);
return (255);
#endif
}
int
find_and_set_default_shell(char *token)
{
int sh_found = 0;
char* search_token;
PATH_VAR(sh_path);
extern char *default_shell;
if (!token)
search_token = default_shell;
else
search_token = token;
if (!no_default_sh_exe &&
(token == NULL || !strcmp(search_token, default_shell))) {
sh_found = 1;
} else if (file_exists_p(search_token)) {
sprintf(sh_path, "%s", search_token);
default_shell = xstrdup(w32ify(sh_path,0));
DB (DB_VERBOSE,
(_("find_and_set_shell setting default_shell = %s\n"), default_shell));
sh_found = 1;
} else {
char *p;
struct variable *v = lookup_variable ("Path", 4);
if (v && v->value) {
char *ep;
p = v->value;
ep = strchr(p, PATH_SEPARATOR_CHAR);
while (ep && *ep) {
*ep = '\0';
if (dir_file_exists_p(p, search_token)) {
sprintf(sh_path, "%s/%s", p, search_token);
default_shell = xstrdup(w32ify(sh_path,0));
sh_found = 1;
*ep = PATH_SEPARATOR_CHAR;
p += strlen(p);
} else {
*ep = PATH_SEPARATOR_CHAR;
p = ++ep;
}
ep = strchr(p, PATH_SEPARATOR_CHAR);
}
if (p && *p && dir_file_exists_p(p, search_token)) {
sprintf(sh_path, "%s/%s", p, search_token);
default_shell = xstrdup(w32ify(sh_path,0));
sh_found = 1;
}
if (sh_found)
DB (DB_VERBOSE,
(_("find_and_set_shell path search set default_shell = %s\n"),
default_shell));
}
}
if (!unixy_shell && sh_found &&
(strstr(default_shell, "sh") || strstr(default_shell, "SH"))) {
unixy_shell = 1;
batch_mode_shell = 0;
}
#ifdef BATCH_MODE_ONLY_SHELL
batch_mode_shell = 1;
#endif
return (sh_found);
}
#endif
#ifdef __MSDOS__
static void
msdos_return_to_initial_directory ()
{
if (directory_before_chdir)
chdir (directory_before_chdir);
}
#endif
extern char *mktemp ();
extern int mkstemp ();
FILE *
open_tmpfile(name, template)
char **name;
const char *template;
{
int fd;
#if defined HAVE_MKSTEMP || defined HAVE_MKTEMP
# define TEMPLATE_LEN strlen (template)
#else
# define TEMPLATE_LEN L_tmpnam
#endif
*name = xmalloc (TEMPLATE_LEN + 1);
strcpy (*name, template);
#if defined HAVE_MKSTEMP && defined HAVE_FDOPEN
fd = mkstemp (*name);
if (fd == -1)
return 0;
return fdopen (fd, "w");
#else
# ifdef HAVE_MKTEMP
(void) mktemp (*name);
# else
(void) tmpnam (*name);
# endif
# ifdef HAVE_FDOPEN
fd = open (*name, O_CREAT|O_EXCL|O_WRONLY, 0600);
if (fd == -1)
return 0;
return fdopen (fd, "w");
# else
return fopen (*name, "w");
# endif
#endif
}
#ifndef _AMIGA
int
main (argc, argv, envp)
int argc;
char **argv;
char **envp;
#else
int main (int argc, char ** argv)
#endif
{
static char *stdin_nm = 0;
register struct file *f;
register unsigned int i;
char **p;
struct dep *read_makefiles;
PATH_VAR (current_directory);
#ifdef WINDOWS32
char *unix_path = NULL;
char *windows32_path = NULL;
SetUnhandledExceptionFilter(handle_runtime_exceptions);
unixy_shell = 0;
no_default_sh_exe = 1;
#endif
default_goal_file = 0;
reading_file = 0;
#if defined (__MSDOS__) && !defined (_POSIX_SOURCE)
__system_flags = (__system_redirect
| __system_use_shell
| __system_allow_multiple_cmds
| __system_allow_long_cmds
| __system_handle_null_commands
| __system_emulate_chdir);
#endif
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
#if !defined (HAVE_STRSIGNAL) && !defined (HAVE_SYS_SIGLIST)
{
extern void signame_init ();
signame_init ();
}
#endif
#ifdef POSIX
sigemptyset (&fatal_signal_set);
#define ADD_SIG(sig) sigaddset (&fatal_signal_set, sig)
#else
#ifdef HAVE_SIGSETMASK
fatal_signal_mask = 0;
#define ADD_SIG(sig) fatal_signal_mask |= sigmask (sig)
#else
#define ADD_SIG(sig)
#endif
#endif
#define FATAL_SIG(sig) \
if (signal ((sig), fatal_error_signal) == SIG_IGN) \
(void) signal ((sig), SIG_IGN); \
else \
ADD_SIG (sig);
#ifdef SIGHUP
FATAL_SIG (SIGHUP);
#endif
#ifdef SIGQUIT
FATAL_SIG (SIGQUIT);
#endif
FATAL_SIG (SIGINT);
FATAL_SIG (SIGTERM);
#ifdef SIGDANGER
FATAL_SIG (SIGDANGER);
#endif
#ifdef SIGXCPU
FATAL_SIG (SIGXCPU);
#endif
#ifdef SIGXFSZ
FATAL_SIG (SIGXFSZ);
#endif
#undef FATAL_SIG
#ifdef HAVE_WAIT_NOHANG
# if defined SIGCHLD
(void) signal (SIGCHLD, SIG_DFL);
# endif
# if defined SIGCLD && SIGCLD != SIGCHLD
(void) signal (SIGCLD, SIG_DFL);
# endif
#endif
#ifdef HAVE_SETLINEBUF
setlinebuf (stdout);
#else
#ifndef SETVBUF_REVERSED
setvbuf (stdout, (char *) 0, _IOLBF, BUFSIZ);
#else
setvbuf (stdout, _IOLBF, xmalloc (BUFSIZ), BUFSIZ);
#endif
#endif
if (argv[0] == 0)
argv[0] = "";
if (argv[0][0] == '\0')
program = "make";
else
{
#ifdef VMS
program = strrchr (argv[0], ']');
#else
program = strrchr (argv[0], '/');
#endif
#ifdef __MSDOS__
if (program == 0)
program = strrchr (argv[0], '\\');
else
{
char *p = strrchr (argv[0], '\\');
if (p && p > program)
program = p;
}
if (program == 0 && argv[0][1] == ':')
program = argv[0] + 1;
#endif
if (program == 0)
program = argv[0];
else
++program;
}
user_access ();
#ifdef WINDOWS32
if (getcwd_fs (current_directory, GET_PATH_MAX) == 0)
#else
if (getcwd (current_directory, GET_PATH_MAX) == 0)
#endif
{
#ifdef HAVE_GETCWD
perror_with_name ("getcwd: ", "");
#else
error (NILF, "getwd: %s", current_directory);
#endif
current_directory[0] = '\0';
directory_before_chdir = 0;
}
else
directory_before_chdir = xstrdup (current_directory);
#ifdef __MSDOS__
atexit (msdos_return_to_initial_directory);
#endif
#ifndef _AMIGA
for (i = 0; envp[i] != 0; ++i)
{
int do_not_define;
register char *ep = envp[i];
do_not_define = 0;
while (*ep != '=')
++ep;
#ifdef WINDOWS32
if (!unix_path && strneq(envp[i], "PATH=", 5))
unix_path = ep+1;
else if (!windows32_path && !strnicmp(envp[i], "Path=", 5)) {
do_not_define = 1;
windows32_path = ep+1;
}
#endif
if (!do_not_define)
define_variable (envp[i], (unsigned int) (ep - envp[i]),
ep + 1, o_env, 1)
->export = v_export;
}
#ifdef WINDOWS32
if (windows32_path)
define_variable("Path", 4, windows32_path, o_env, 1)->export = v_export;
else if (unix_path)
define_variable("Path", 4, unix_path, o_env, 1)->export = v_export;
else
define_variable("Path", 4, "", o_env, 1)->export = v_export;
if (!unix_path && windows32_path)
define_variable("PATH", 4, windows32_path, o_env, 1)->export = v_export;
#endif
#else
{
BPTR env, file, old;
char buffer[1024];
int len;
__aligned struct FileInfoBlock fib;
env = Lock ("ENV:", ACCESS_READ);
if (env)
{
old = CurrentDir (DupLock(env));
Examine (env, &fib);
while (ExNext (env, &fib))
{
if (fib.fib_DirEntryType < 0)
{
define_variable (fib.fib_FileName,
strlen (fib.fib_FileName),
"", o_env, 1)->export = v_export;
}
}
UnLock (env);
UnLock(CurrentDir(old));
}
}
#endif
decode_env_switches ("MAKEFLAGS", 9);
#if 0
decode_env_switches ("MFLAGS", 6);
#endif
decode_switches (argc, argv, 0);
#if defined(__APPLE__) || defined(NeXT) || defined(NeXT_PDO)
if (next_flag_list != 0) {
char **p;
next_flag = 0;
for (p = next_flag_list->list; *p != 0; p++) {
if (strcmp(*p, "vpath") == 0) {
next_flag |= NEXT_VPATH_FLAG;
} else if (strcmp(*p, "quiet") == 0) {
next_flag |= NEXT_QUIET_FLAG;
} else if (strcmp(*p, "makefiles") == 0) {
next_flag |= NEXT_MAKEFILES_FLAG;
} else if (strcmp(*p, "errexit") == 0) {
next_flag |= NEXT_ERREXIT_FLAG;
} else if (strcmp(*p, "all") == 0) {
next_flag = NEXT_ALL_FLAGS;
} else {
error ("Unrecognized flag `%s'.", *p);
}
}
}
#endif
#ifdef WINDOWS32
if (suspend_flag) {
fprintf(stderr, "%s (pid = %d)\n", argv[0], GetCurrentProcessId());
fprintf(stderr, _("%s is suspending for 30 seconds..."), argv[0]);
Sleep(30 * 1000);
fprintf(stderr, _("done sleep(30). Continuing.\n"));
}
#endif
decode_debug_flags ();
if (print_version_flag || print_data_base_flag || db_level)
print_version ();
if (print_version_flag)
die (0);
#ifndef VMS
#ifdef WINDOWS32
if (strpbrk(argv[0], "/:\\") ||
strstr(argv[0], "..") ||
strneq(argv[0], "//", 2))
argv[0] = xstrdup(w32ify(argv[0],1));
#else
#ifdef __MSDOS__
if (strchr (argv[0], '\\'))
{
char *p;
argv[0] = xstrdup (argv[0]);
for (p = argv[0]; *p; p++)
if (*p == '\\')
*p = '/';
}
if (current_directory[0] != '\0'
&& argv[0] != 0
&& (argv[0][0] != '/' && (argv[0][0] == '\0' || argv[0][1] != ':')))
argv[0] = concat (current_directory, "/", argv[0]);
#else
if (current_directory[0] != '\0'
&& argv[0] != 0 && argv[0][0] != '/' && strchr (argv[0], '/') != 0)
argv[0] = concat (current_directory, "/", argv[0]);
#endif
#endif
#endif
(void) define_variable ("MAKE_COMMAND", 12, argv[0], o_default, 0);
(void) define_variable ("MAKE", 4, "$(MAKE_COMMAND)", o_default, 1);
if (command_variables != 0)
{
struct command_variable *cv;
struct variable *v;
unsigned int len = 0;
char *value, *p;
for (cv = command_variables; cv != 0; cv = cv->next)
{
v = cv->variable;
len += 2 * strlen (v->name);
if (! v->recursive)
++len;
++len;
len += 2 * strlen (v->value);
++len;
}
p = value = (char *) alloca (len);
for (cv = command_variables; cv != 0; cv = cv->next)
{
v = cv->variable;
p = quote_for_env (p, v->name);
if (! v->recursive)
*p++ = ':';
*p++ = '=';
p = quote_for_env (p, v->value);
*p++ = ' ';
}
p[-1] = '\0';
(void) define_variable ("-*-command-variables-*-", 23,
value, o_automatic, 0);
(void) define_variable ("MAKEOVERRIDES", 13,
"${-*-command-variables-*-}", o_env, 1);
}
if (directories != 0)
for (i = 0; directories->list[i] != 0; ++i)
{
char *dir = directories->list[i];
if (dir[0] == '~')
{
char *expanded = tilde_expand (dir);
if (expanded != 0)
dir = expanded;
}
if (chdir (dir) < 0)
pfatal_with_name (dir);
if (dir != directories->list[i])
free (dir);
}
#ifdef WINDOWS32
no_default_sh_exe = !find_and_set_default_shell(NULL);
#endif
{
struct variable *v = lookup_variable ("MAKELEVEL", 9);
if (v != 0 && *v->value != '\0' && *v->value != '-')
makelevel = (unsigned int) atoi (v->value);
else
makelevel = 0;
}
#if ! (defined(__APPLE__) || defined(NeXT) || defined(NeXT_PDO))
if (!silent_flag && (directories != 0 || makelevel > 0))
print_directory_flag = 1;
#endif
if (inhibit_print_directory_flag)
print_directory_flag = 0;
if (no_builtin_variables_flag)
no_builtin_rules_flag = 1;
construct_include_path (include_directories == 0 ? (char **) 0
: include_directories->list);
if (directories == 0)
starting_directory = current_directory;
else
{
#ifdef WINDOWS32
if (getcwd_fs (current_directory, GET_PATH_MAX) == 0)
#else
if (getcwd (current_directory, GET_PATH_MAX) == 0)
#endif
{
#ifdef HAVE_GETCWD
perror_with_name ("getcwd: ", "");
#else
error (NILF, "getwd: %s", current_directory);
#endif
starting_directory = 0;
}
else
starting_directory = current_directory;
}
(void) define_variable ("CURDIR", 6, current_directory, o_default, 0);
if (makefiles != 0)
{
register unsigned int i;
for (i = 0; i < makefiles->idx; ++i)
if (makefiles->list[i][0] == '-' && makefiles->list[i][1] == '\0')
{
FILE *outfile;
if (stdin_nm)
fatal (NILF, _("Makefile from standard input specified twice."));
#ifdef VMS
# define TMP_TEMPLATE "sys$scratch:GmXXXXXX"
#else
# define TMP_TEMPLATE "/tmp/GmXXXXXX"
#endif
outfile = open_tmpfile (&stdin_nm, TMP_TEMPLATE);
if (outfile == 0)
pfatal_with_name (_("fopen (temporary file)"));
while (!feof (stdin))
{
char buf[2048];
unsigned int n = fread (buf, 1, sizeof (buf), stdin);
if (n > 0 && fwrite (buf, 1, n, outfile) != n)
pfatal_with_name (_("fwrite (temporary file)"));
}
(void) fclose (outfile);
makefiles->list[i] = xstrdup (stdin_nm);
f = enter_file (stdin_nm);
f->updated = 1;
f->update_status = 0;
f->command_state = cs_finished;
f->intermediate = 0;
f->dontcare = 0;
}
}
#if defined(MAKE_JOBSERVER) || !defined(HAVE_WAIT_NOHANG)
{
extern RETSIGTYPE child_handler PARAMS ((int sig));
# if defined HAVE_SIGACTION
struct sigaction sa;
bzero ((char *)&sa, sizeof (struct sigaction));
sa.sa_handler = child_handler;
# if defined SA_INTERRUPT
sa.sa_flags = SA_INTERRUPT;
# endif
# define HANDLESIG(s) sigaction (s, &sa, NULL)
# else
# define HANDLESIG(s) signal (s, child_handler)
# endif
# if defined SIGCHLD
(void) HANDLESIG (SIGCHLD);
# endif
# if defined SIGCLD && SIGCLD != SIGCHLD
(void) HANDLESIG (SIGCLD);
# endif
}
#endif
#ifdef SIGUSR1
(void) signal (SIGUSR1, debug_signal_handler);
#endif
set_default_suffixes ();
install_default_suffix_rules ();
define_automatic_variables ();
define_makeflags (0, 0);
define_default_variables ();
default_file = enter_file (".DEFAULT");
read_makefiles
= read_all_makefiles (makefiles == 0 ? (char **) 0 : makefiles->list);
#ifdef WINDOWS32
if (no_default_sh_exe)
no_default_sh_exe = !find_and_set_default_shell(NULL);
if (no_default_sh_exe && job_slots != 1) {
error (NILF, _("Do not specify -j or --jobs if sh.exe is not available."));
error (NILF, _("Resetting make for single job mode."));
job_slots = 1;
}
#endif
#ifdef __MSDOS__
{
extern int _is_unixy_shell (const char *_path);
struct variable *shv = lookup_variable ("SHELL", 5);
extern int unixy_shell;
extern char *default_shell;
if (shv && *shv->value)
{
char *shell_path = recursively_expand(shv);
if (shell_path && _is_unixy_shell (shell_path))
unixy_shell = 1;
else
unixy_shell = 0;
if (shell_path)
default_shell = shell_path;
}
}
#endif
decode_env_switches ("MAKEFLAGS", 9);
#if 0
decode_env_switches ("MFLAGS", 6);
#endif
#ifdef __MSDOS__
if (job_slots != 1)
{
error (NILF,
_("Parallel jobs (-j) are not supported on this platform."));
error (NILF, _("Resetting to single job (-j1) mode."));
job_slots = 1;
}
#endif
#ifdef MAKE_JOBSERVER
if (jobserver_fds)
{
char *cp;
for (i=1; i < jobserver_fds->idx; ++i)
if (!streq (jobserver_fds->list[0], jobserver_fds->list[i]))
fatal (NILF, _("internal error: multiple --jobserver-fds options"));
cp = jobserver_fds->list[0];
if (sscanf (cp, "%d,%d", &job_fds[0], &job_fds[1]) != 2)
fatal (NILF,
_("internal error: invalid --jobserver-fds string `%s'"), cp);
if (job_slots > 0)
error (NILF,
_("warning: -jN forced in submake: disabling jobserver mode."));
else if ((job_rfd = dup (job_fds[0])) < 0)
{
if (errno != EBADF)
pfatal_with_name (_("dup jobserver"));
error (NILF,
_("warning: jobserver unavailable: using -j1. Add `+' to parent make rule."));
job_slots = 1;
}
if (job_slots > 0)
{
close (job_fds[0]);
close (job_fds[1]);
job_fds[0] = job_fds[1] = -1;
free (jobserver_fds->list);
free (jobserver_fds);
jobserver_fds = 0;
}
}
if (job_slots > 1)
{
char c = '+';
if (pipe (job_fds) < 0 || (job_rfd = dup (job_fds[0])) < 0)
pfatal_with_name (_("creating jobs pipe"));
while (--job_slots)
while (write (job_fds[1], &c, 1) != 1)
if (!EINTR_SET)
pfatal_with_name (_("init jobserver pipe"));
jobserver_fds = (struct stringlist *)
xmalloc (sizeof (struct stringlist));
jobserver_fds->list = (char **) xmalloc (sizeof (char *));
jobserver_fds->list[0] = xmalloc ((sizeof ("1024")*2)+1);
sprintf (jobserver_fds->list[0], "%d,%d", job_fds[0], job_fds[1]);
jobserver_fds->idx = 1;
jobserver_fds->max = 1;
}
#endif
define_makeflags (1, 0);
snap_deps ();
convert_to_pattern ();
install_default_implicit_rules ();
count_implicit_rule_limits ();
build_vpath_lists ();
if (old_files != 0)
for (p = old_files->list; *p != 0; ++p)
{
f = enter_command_line_file (*p);
f->last_mtime = f->mtime_before_update = (FILE_TIMESTAMP) 1;
f->updated = 1;
f->update_status = 0;
f->command_state = cs_finished;
}
if (new_files != 0)
{
for (p = new_files->list; *p != 0; ++p)
{
f = enter_command_line_file (*p);
f->last_mtime = f->mtime_before_update = NEW_MTIME;
}
}
remote_setup ();
if (read_makefiles != 0)
#if defined(__APPLE__) || defined(NeXT) || defined(NeXT_PDO)
if (!(next_flag & NEXT_MAKEFILES_FLAG))
#endif
{
FILE_TIMESTAMP *makefile_mtimes = 0;
unsigned int mm_idx = 0;
char **nargv = argv;
int nargc = argc;
int orig_db_level = db_level;
if (! ISDB (DB_MAKEFILES))
db_level = DB_NONE;
DB (DB_BASIC, (_("Updating makefiles....\n")));
{
register struct dep *d, *last;
last = 0;
d = read_makefiles;
while (d != 0)
{
register struct file *f = d->file;
if (f->double_colon)
for (f = f->double_colon; f != NULL; f = f->prev)
{
if (f->deps == 0 && f->cmds != 0)
{
DB (DB_VERBOSE,
(_("Makefile `%s' might loop; not remaking it.\n"),
f->name));
if (last == 0)
read_makefiles = d->next;
else
last->next = d->next;
free ((char *) d);
d = last == 0 ? read_makefiles : last->next;
break;
}
}
if (f == NULL || !f->double_colon)
{
makefile_mtimes = (FILE_TIMESTAMP *)
xrealloc ((char *) makefile_mtimes,
(mm_idx + 1) * sizeof (FILE_TIMESTAMP));
makefile_mtimes[mm_idx++] = file_mtime_no_search (d->file);
last = d;
d = d->next;
}
}
}
define_makeflags (1, 1);
switch (update_goal_chain (read_makefiles, 1))
{
case 1:
default:
#define BOGUS_UPDATE_STATUS 0
assert (BOGUS_UPDATE_STATUS);
break;
case -1:
break;
case 2:
{
int any_remade = 0;
int any_failed = 0;
register unsigned int i;
struct dep *d;
for (i = 0, d = read_makefiles; d != 0; ++i, d = d->next)
{
d->file->considered = 0;
if (d->file->updated)
{
if (d->file->update_status == 0)
{
any_remade |= (file_mtime_no_search (d->file)
!= makefile_mtimes[i]);
}
else if (! (d->changed & RM_DONTCARE))
{
FILE_TIMESTAMP mtime;
error (NILF, _("Failed to remake makefile `%s'."),
d->file->name);
mtime = file_mtime_no_search (d->file);
any_remade |= (mtime != (FILE_TIMESTAMP) -1
&& mtime != makefile_mtimes[i]);
}
}
else
if (! (d->changed & RM_DONTCARE))
{
if (d->changed & RM_INCLUDED)
error (NILF,
_("Included makefile `%s' was not found."),
dep_name (d));
else
{
error (NILF, _("Makefile `%s' was not found"),
dep_name (d));
any_failed = 1;
}
}
}
read_makefiles = 0;
if (any_remade)
goto re_exec;
if (any_failed)
die (2);
break;
}
case 0:
re_exec:
remove_intermediates (0);
if (print_data_base_flag)
print_data_base ();
log_working_directory (0);
if (makefiles != 0)
{
register unsigned int i, j = 0;
for (i = 1; i < argc; ++i)
if (strneq (argv[i], "-f", 2))
{
char *p = &argv[i][2];
if (*p == '\0')
argv[++i] = makefiles->list[j];
else
argv[i] = concat ("-f", makefiles->list[j], "");
++j;
}
}
if (stdin_nm)
{
nargv = (char **) xmalloc ((nargc + 2) * sizeof (char *));
bcopy ((char *) argv, (char *) nargv, argc * sizeof (char *));
nargv[nargc++] = concat ("-o", stdin_nm, "");
nargv[nargc] = 0;
}
if (directories != 0 && directories->idx > 0)
{
char bad;
if (directory_before_chdir != 0)
{
if (chdir (directory_before_chdir) < 0)
{
perror_with_name ("chdir", "");
bad = 1;
}
else
bad = 0;
}
else
bad = 1;
if (bad)
fatal (NILF, _("Couldn't change back to original directory."));
}
#ifndef _AMIGA
for (p = environ; *p != 0; ++p)
if (strneq (*p, "MAKELEVEL=", 10))
{
char *sgi_loses;
sgi_loses = (char *) alloca (40);
*p = sgi_loses;
sprintf (*p, "MAKELEVEL=%u", makelevel);
break;
}
#else
{
char buffer[256];
int len;
len = GetVar ("MAKELEVEL", buffer, sizeof (buffer), GVF_GLOBAL_ONLY);
if (len != -1)
{
sprintf (buffer, "%u", makelevel);
SetVar ("MAKELEVEL", buffer, -1, GVF_GLOBAL_ONLY);
}
}
#endif
if (ISDB (DB_BASIC))
{
char **p;
fputs (_("Re-executing:"), stdout);
for (p = nargv; *p != 0; ++p)
printf (" %s", *p);
putchar ('\n');
}
fflush (stdout);
fflush (stderr);
if (job_rfd >= 0)
close (job_rfd);
#ifndef _AMIGA
exec_command (nargv, environ);
#else
exec_command (nargv);
exit (0);
#endif
}
db_level = orig_db_level;
}
define_makeflags (1, 0);
if (stdin_nm && unlink (stdin_nm) < 0 && errno != ENOENT)
perror_with_name (_("unlink (temporary file): "), stdin_nm);
{
int status;
if (goals == 0)
{
if (default_goal_file != 0)
{
goals = (struct dep *) xmalloc (sizeof (struct dep));
goals->next = 0;
goals->name = 0;
goals->file = default_goal_file;
}
}
else
lastgoal->next = 0;
if (!goals)
{
if (read_makefiles == 0)
fatal (NILF, _("No targets specified and no makefile found"));
fatal (NILF, _("No targets"));
}
DB (DB_BASIC, (_("Updating goal targets....\n")));
switch (update_goal_chain (goals, 0))
{
case -1:
case 0:
status = EXIT_SUCCESS;
break;
case 2:
status = EXIT_FAILURE ? 2 : EXIT_FAILURE;
break;
case 1:
status = EXIT_FAILURE;
break;
default:
abort ();
}
if (clock_skew_detected)
error (NILF,
_("warning: Clock skew detected. Your build may be incomplete."));
die (status);
}
return 0;
}
static char options[1 + sizeof (switches) / sizeof (switches[0]) * 3];
static struct option long_options[(sizeof (switches) / sizeof (switches[0])) +
(sizeof (long_option_aliases) /
sizeof (long_option_aliases[0]))];
static void
init_switches ()
{
register char *p;
register int c;
register unsigned int i;
if (options[0] != '\0')
return;
p = options;
*p++ = '-';
for (i = 0; switches[i].c != '\0'; ++i)
{
long_options[i].name = (switches[i].long_name == 0 ? "" :
switches[i].long_name);
long_options[i].flag = 0;
long_options[i].val = switches[i].c;
if (short_option (switches[i].c))
*p++ = switches[i].c;
switch (switches[i].type)
{
case flag:
case flag_off:
case ignore:
long_options[i].has_arg = no_argument;
break;
case string:
case positive_int:
case floating:
if (short_option (switches[i].c))
*p++ = ':';
if (switches[i].noarg_value != 0)
{
if (short_option (switches[i].c))
*p++ = ':';
long_options[i].has_arg = optional_argument;
}
else
long_options[i].has_arg = required_argument;
break;
}
}
*p = '\0';
for (c = 0; c < (sizeof (long_option_aliases) /
sizeof (long_option_aliases[0]));
++c)
long_options[i++] = long_option_aliases[c];
long_options[i].name = 0;
}
static void
handle_non_switch_argument (arg, env)
char *arg;
int env;
{
struct variable *v;
if (arg[0] == '-' && arg[1] == '\0')
return;
v = try_variable_definition (0, arg, o_command, 0);
if (v != 0)
{
struct command_variable *cv
= (struct command_variable *) xmalloc (sizeof (*cv));
cv->variable = v;
cv->next = command_variables;
command_variables = cv;
}
else if (! env)
{
struct file *f = enter_command_line_file (arg);
f->cmd_target = 1;
if (goals == 0)
{
goals = (struct dep *) xmalloc (sizeof (struct dep));
lastgoal = goals;
}
else
{
lastgoal->next = (struct dep *) xmalloc (sizeof (struct dep));
lastgoal = lastgoal->next;
}
lastgoal->name = 0;
lastgoal->file = f;
{
struct variable *v;
char *value;
v = lookup_variable ("MAKECMDGOALS", 12);
if (v == 0)
value = f->name;
else
{
unsigned int oldlen, newlen;
oldlen = strlen (v->value);
newlen = strlen (f->name);
value = (char *) alloca (oldlen + 1 + newlen + 1);
bcopy (v->value, value, oldlen);
value[oldlen] = ' ';
bcopy (f->name, &value[oldlen + 1], newlen + 1);
}
define_variable ("MAKECMDGOALS", 12, value, o_default, 0);
}
}
}
static void
print_usage (bad)
int bad;
{
register const struct command_switch *cs;
FILE *usageto;
if (print_version_flag)
print_version ();
usageto = bad ? stderr : stdout;
fprintf (usageto, _("Usage: %s [options] [target] ...\n"), program);
fputs (_("Options:\n"), usageto);
for (cs = switches; cs->c != '\0'; ++cs)
{
char buf[1024], shortarg[50], longarg[50], *p;
if (!cs->description || cs->description[0] == '-')
continue;
switch (long_options[cs - switches].has_arg)
{
case no_argument:
shortarg[0] = longarg[0] = '\0';
break;
case required_argument:
sprintf (longarg, "=%s", gettext (cs->argdesc));
sprintf (shortarg, " %s", gettext (cs->argdesc));
break;
case optional_argument:
sprintf (longarg, "[=%s]", gettext (cs->argdesc));
sprintf (shortarg, " [%s]", gettext (cs->argdesc));
break;
}
p = buf;
if (short_option (cs->c))
{
sprintf (buf, " -%c%s", cs->c, shortarg);
p += strlen (p);
}
if (cs->long_name != 0)
{
unsigned int i;
sprintf (p, "%s--%s%s",
!short_option (cs->c) ? " " : ", ",
cs->long_name, longarg);
p += strlen (p);
for (i = 0; i < (sizeof (long_option_aliases) /
sizeof (long_option_aliases[0]));
++i)
if (long_option_aliases[i].val == cs->c)
{
sprintf (p, ", --%s%s",
long_option_aliases[i].name, longarg);
p += strlen (p);
}
}
{
const struct command_switch *ncs = cs;
while ((++ncs)->c != '\0')
if (ncs->description
&& ncs->description[0] == '-'
&& ncs->description[1] == cs->c)
{
sprintf (p, ", -%c%s", ncs->c, shortarg);
p += strlen (p);
if (ncs->long_name != 0)
{
sprintf (p, ", --%s%s", ncs->long_name, longarg);
p += strlen (p);
}
}
}
if (p - buf > DESCRIPTION_COLUMN - 2)
{
fprintf (usageto, "%s\n", buf);
buf[0] = '\0';
}
fprintf (usageto, "%*s%s.\n",
- DESCRIPTION_COLUMN,
buf, gettext (cs->description));
}
fprintf (usageto, _("\nReport bugs to <bug-make@gnu.org>.\n"));
}
static void
decode_switches (argc, argv, env)
int argc;
char **argv;
int env;
{
int bad = 0;
register const struct command_switch *cs;
register struct stringlist *sl;
register int c;
init_switches ();
opterr = !env;
optind = 0;
while (optind < argc)
{
c = getopt_long (argc, argv, options, long_options, (int *) 0);
if (c == EOF)
break;
else if (c == 1)
handle_non_switch_argument (optarg, env);
else if (c == '?')
bad = 1;
else
for (cs = switches; cs->c != '\0'; ++cs)
if (cs->c == c)
{
int doit = !env || cs->env;
switch (cs->type)
{
default:
abort ();
case ignore:
break;
case flag:
case flag_off:
if (doit)
*(int *) cs->value_ptr = cs->type == flag;
break;
case string:
if (!doit)
break;
if (optarg == 0)
optarg = cs->noarg_value;
sl = *(struct stringlist **) cs->value_ptr;
if (sl == 0)
{
sl = (struct stringlist *)
xmalloc (sizeof (struct stringlist));
sl->max = 5;
sl->idx = 0;
sl->list = (char **) xmalloc (5 * sizeof (char *));
*(struct stringlist **) cs->value_ptr = sl;
}
else if (sl->idx == sl->max - 1)
{
sl->max += 5;
sl->list = (char **)
xrealloc ((char *) sl->list,
sl->max * sizeof (char *));
}
sl->list[sl->idx++] = optarg;
sl->list[sl->idx] = 0;
break;
case positive_int:
if (optarg == 0 && argc > optind
&& ISDIGIT (argv[optind][0]))
optarg = argv[optind++];
if (!doit)
break;
if (optarg != 0)
{
int i = atoi (optarg);
if (i < 1)
{
if (doit)
error (NILF, _("the `-%c' option requires a positive integral argument"),
cs->c);
bad = 1;
}
else
*(unsigned int *) cs->value_ptr = i;
}
else
*(unsigned int *) cs->value_ptr
= *(unsigned int *) cs->noarg_value;
break;
#ifndef NO_FLOAT
case floating:
if (optarg == 0 && optind < argc
&& (ISDIGIT (argv[optind][0]) || argv[optind][0] == '.'))
optarg = argv[optind++];
if (doit)
*(double *) cs->value_ptr
= (optarg != 0 ? atof (optarg)
: *(double *) cs->noarg_value);
break;
#endif
}
break;
}
}
while (optind < argc)
handle_non_switch_argument (argv[optind++], env);
if (!env && (bad || print_usage_flag))
{
print_usage (bad);
die (bad ? 2 : 0);
}
}
static void
decode_env_switches (envar, len)
char *envar;
unsigned int len;
{
char *varref = (char *) alloca (2 + len + 2);
char *value, *p;
int argc;
char **argv;
varref[0] = '$';
varref[1] = '(';
bcopy (envar, &varref[2], len);
varref[2 + len] = ')';
varref[2 + len + 1] = '\0';
value = variable_expand (varref);
value = next_token (value);
len = strlen (value);
if (len == 0)
return;
argv = (char **) alloca ((1 + len + 1) * sizeof (char *));
p = (char *) xmalloc (2 * len);
argv[0] = 0;
argc = 1;
argv[argc] = p;
while (*value != '\0')
{
if (*value == '\\' && value[1] != '\0')
++value;
else if (isblank (*value))
{
*p++ = '\0';
argv[++argc] = p;
do
++value;
while (isblank (*value));
continue;
}
*p++ = *value++;
}
*p = '\0';
argv[++argc] = 0;
if (argv[1][0] != '-' && strchr (argv[1], '=') == 0)
argv[1] = concat ("-", argv[1], "");
decode_switches (argc, argv, 1);
}
static char *
quote_for_env (out, in)
char *out, *in;
{
while (*in != '\0')
{
if (*in == '$')
*out++ = '$';
else if (isblank (*in) || *in == '\\')
*out++ = '\\';
*out++ = *in++;
}
return out;
}
static void
define_makeflags (all, makefile)
int all, makefile;
{
static const char ref[] = "$(MAKEOVERRIDES)";
static const char posixref[] = "$(-*-command-variables-*-)";
register const struct command_switch *cs;
char *flagstring;
register char *p;
unsigned int words;
struct variable *v;
struct flag
{
struct flag *next;
const struct command_switch *cs;
char *arg;
};
struct flag *flags = 0;
unsigned int flagslen = 0;
#define ADD_FLAG(ARG, LEN) \
do { \
struct flag *new = (struct flag *) alloca (sizeof (struct flag)); \
new->cs = cs; \
new->arg = (ARG); \
new->next = flags; \
flags = new; \
if (new->arg == 0) \
++flagslen; \
else \
flagslen += 1 + 1 + 1 + 1 + 3 * (LEN); \
if (!short_option (cs->c)) \
\
flagslen += 2 + strlen (cs->long_name); \
} while (0)
for (cs = switches; cs->c != '\0'; ++cs)
if (cs->toenv && (!makefile || !cs->no_makefile))
switch (cs->type)
{
default:
abort ();
case ignore:
break;
case flag:
case flag_off:
if (!*(int *) cs->value_ptr == (cs->type == flag_off)
&& (cs->default_value == 0
|| *(int *) cs->value_ptr != *(int *) cs->default_value))
ADD_FLAG (0, 0);
break;
case positive_int:
if (all)
{
if ((cs->default_value != 0
&& (*(unsigned int *) cs->value_ptr
== *(unsigned int *) cs->default_value)))
break;
else if (cs->noarg_value != 0
&& (*(unsigned int *) cs->value_ptr ==
*(unsigned int *) cs->noarg_value))
ADD_FLAG ("", 0);
else if (cs->c == 'j')
ADD_FLAG ("1", 1);
else
{
char *buf = (char *) alloca (30);
sprintf (buf, "%u", *(unsigned int *) cs->value_ptr);
ADD_FLAG (buf, strlen (buf));
}
}
break;
#ifndef NO_FLOAT
case floating:
if (all)
{
if (cs->default_value != 0
&& (*(double *) cs->value_ptr
== *(double *) cs->default_value))
break;
else if (cs->noarg_value != 0
&& (*(double *) cs->value_ptr
== *(double *) cs->noarg_value))
ADD_FLAG ("", 0);
else
{
char *buf = (char *) alloca (100);
sprintf (buf, "%g", *(double *) cs->value_ptr);
ADD_FLAG (buf, strlen (buf));
}
}
break;
#endif
case string:
if (all)
{
struct stringlist *sl = *(struct stringlist **) cs->value_ptr;
if (sl != 0)
{
register unsigned int i = sl->idx;
while (i-- > 0)
ADD_FLAG (sl->list[i], strlen (sl->list[i]));
}
}
break;
}
flagslen += 4 + sizeof posixref;
#undef ADD_FLAG
flagstring = (char *) alloca (1 + flagslen + 1);
bzero (flagstring, 1 + flagslen + 1);
p = flagstring;
words = 1;
*p++ = '-';
while (flags != 0)
{
if (short_option (flags->cs->c))
*p++ = flags->cs->c;
else
{
if (*p != '-')
{
*p++ = ' ';
*p++ = '-';
}
*p++ = '-';
strcpy (p, flags->cs->long_name);
p += strlen (p);
}
if (flags->arg != 0)
{
if (flags->arg[0] != '\0')
{
*p++ = !short_option (flags->cs->c) ? '=' : ' ';
p = quote_for_env (p, flags->arg);
}
++words;
*p++ = ' ';
*p++ = '-';
}
else if (!short_option (flags->cs->c))
{
++words;
*p++ = ' ';
*p++ = '-';
}
flags = flags->next;
}
if (p == &flagstring[1])
flagstring[0] = '\0';
else if (p[-1] == '-')
{
p -= 2;
*p = '\0';
}
else
*p = '\0';
(void) define_variable ("MFLAGS", 6, flagstring, o_env, 1);
if (all && command_variables != 0)
{
if (p == &flagstring[1])
p = flagstring;
else
{
if (p[-1] != '-')
{
*p++ = ' ';
*p++ = '-';
}
*p++ = '-';
*p++ = ' ';
}
if (posix_pedantic)
{
bcopy (posixref, p, sizeof posixref - 1);
p += sizeof posixref - 1;
}
else
{
bcopy (ref, p, sizeof ref - 1);
p += sizeof ref - 1;
}
}
else if (p == &flagstring[1])
{
words = 0;
--p;
}
else if (p[-1] == '-')
p -= 2;
*p = '\0';
v = define_variable ("MAKEFLAGS", 9,
&flagstring[(flagstring[0] == '-'
&& flagstring[1] != '-')
? 1 : 0],
o_file, 1);
if (! all)
v->export = v_export;
}
static void
print_version ()
{
extern char *make_host;
static int printed_version = 0;
char *precede = print_data_base_flag ? "# " : "";
if (printed_version)
return;
printf ("%sGNU Make version %s", precede, version_string);
if (remote_description != 0 && *remote_description != '\0')
printf ("-%s", remote_description);
printf (_(", by Richard Stallman and Roland McGrath.\n\
%sBuilt for %s\n\
%sCopyright (C) 1988, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99\n\
%s\tFree Software Foundation, Inc.\n\
%sThis is free software; see the source for copying conditions.\n\
%sThere is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A\n\
%sPARTICULAR PURPOSE.\n\n\
%sReport bugs to <bug-make@gnu.org>.\n\n"),
precede, make_host,
precede, precede, precede, precede, precede, precede);
printed_version = 1;
fflush (stdout);
}
static void
print_data_base ()
{
time_t when;
when = time ((time_t *) 0);
printf (_("\n# Make data base, printed on %s"), ctime (&when));
print_variable_data_base ();
print_dir_data_base ();
print_rule_data_base ();
print_file_data_base ();
print_vpath_data_base ();
when = time ((time_t *) 0);
printf (_("\n# Finished Make data base on %s\n"), ctime (&when));
}
void
die (status)
int status;
{
static char dying = 0;
if (!dying)
{
int err;
dying = 1;
if (print_version_flag)
print_version ();
for (err = (status != 0); job_slots_used > 0; err = 0)
reap_children (1, err);
remote_cleanup ();
remove_intermediates (0);
if (print_data_base_flag)
print_data_base ();
if (directory_before_chdir != 0)
chdir (directory_before_chdir);
log_working_directory (0);
}
exit (status);
}
void
log_working_directory (entering)
int entering;
{
static int entered = 0;
char *msg = entering ? _("Entering") : _("Leaving");
if (! print_directory_flag || entering == entered)
return;
entered = entering;
if (print_data_base_flag)
fputs ("# ", stdout);
if (makelevel == 0)
printf ("%s: %s ", program, msg);
else
printf ("%s[%u]: %s ", program, makelevel, msg);
if (starting_directory == 0)
puts (_("an unknown directory"));
else
printf (_("directory `%s'\n"), starting_directory);
}