1994-03-23 14:12:55 +00:00
|
|
|
|
/* Argument parsing and main program of GNU Make.
|
|
|
|
|
Copyright (C) 1988, 89, 90, 91, 94 Free Software Foundation, Inc.
|
1992-01-29 23:54:36 +00:00
|
|
|
|
This file is part of GNU Make.
|
|
|
|
|
|
|
|
|
|
GNU Make is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
|
|
GNU Make is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with GNU Make; see the file COPYING. If not, write to
|
|
|
|
|
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
|
|
|
|
|
|
|
|
|
|
#include "make.h"
|
|
|
|
|
#include "commands.h"
|
|
|
|
|
#include "dep.h"
|
|
|
|
|
#include "file.h"
|
|
|
|
|
#include "variable.h"
|
|
|
|
|
#include "job.h"
|
1992-05-09 04:28:28 +00:00
|
|
|
|
#include "getopt.h"
|
1992-01-29 23:54:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extern void print_variable_data_base ();
|
|
|
|
|
extern void print_dir_data_base ();
|
|
|
|
|
extern void print_rule_data_base ();
|
|
|
|
|
extern void print_file_data_base ();
|
|
|
|
|
extern void print_vpath_data_base ();
|
|
|
|
|
|
1992-06-11 04:58:20 +00:00
|
|
|
|
#ifndef HAVE_UNISTD_H
|
1992-01-29 23:54:36 +00:00
|
|
|
|
extern int chdir ();
|
1992-06-11 04:58:20 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifndef STDC_HEADERS
|
1992-07-16 18:31:50 +00:00
|
|
|
|
#ifndef sun /* Sun has an incorrect decl in a header. */
|
1992-01-29 23:54:36 +00:00
|
|
|
|
extern void exit ();
|
1992-07-16 18:31:50 +00:00
|
|
|
|
#endif
|
1992-01-29 23:54:36 +00:00
|
|
|
|
extern double atof ();
|
|
|
|
|
#endif
|
|
|
|
|
extern char *mktemp ();
|
|
|
|
|
|
|
|
|
|
static void log_working_directory ();
|
|
|
|
|
static void print_data_base (), print_version ();
|
|
|
|
|
static void decode_switches (), decode_env_switches ();
|
|
|
|
|
static void define_makeflags ();
|
1994-09-26 22:37:10 +00:00
|
|
|
|
static char *quote_as_word ();
|
1993-06-25 19:47:20 +00:00
|
|
|
|
|
1992-01-29 23:54:36 +00:00
|
|
|
|
/* The structure that describes an accepted command switch. */
|
|
|
|
|
|
|
|
|
|
struct command_switch
|
|
|
|
|
{
|
1992-05-09 04:28:28 +00:00
|
|
|
|
char c; /* The switch character. */
|
1993-04-14 18:20:33 +00:00
|
|
|
|
|
1992-05-09 04:28:28 +00:00
|
|
|
|
enum /* Type of the value. */
|
1992-01-29 23:54:36 +00:00
|
|
|
|
{
|
1992-05-09 04:28:28 +00:00
|
|
|
|
flag, /* Turn int flag on. */
|
|
|
|
|
flag_off, /* Turn int flag off. */
|
|
|
|
|
string, /* One string per switch. */
|
|
|
|
|
positive_int, /* A positive integer. */
|
|
|
|
|
floating, /* A floating-point number (double). */
|
1993-05-22 20:20:16 +00:00
|
|
|
|
ignore /* Ignored. */
|
1992-01-29 23:54:36 +00:00
|
|
|
|
} type;
|
|
|
|
|
|
|
|
|
|
char *value_ptr; /* Pointer to the value-holding variable. */
|
|
|
|
|
|
|
|
|
|
unsigned int env:1; /* Can come from MAKEFLAGS. */
|
|
|
|
|
unsigned int toenv:1; /* Should be put in MAKEFLAGS. */
|
|
|
|
|
unsigned int no_makefile:1; /* Don't propagate when remaking makefiles. */
|
|
|
|
|
|
|
|
|
|
char *noarg_value; /* Pointer to value used if no argument is given. */
|
|
|
|
|
char *default_value;/* Pointer to default value. */
|
1992-05-09 04:28:28 +00:00
|
|
|
|
|
|
|
|
|
char *long_name; /* Long option name. */
|
|
|
|
|
char *argdesc; /* Descriptive word for argument. */
|
|
|
|
|
char *description; /* Description for usage message. */
|
1992-01-29 23:54:36 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* The structure used to hold the list of strings given
|
|
|
|
|
in command switches of a type that takes string arguments. */
|
|
|
|
|
|
|
|
|
|
struct stringlist
|
|
|
|
|
{
|
|
|
|
|
char **list; /* Nil-terminated list of strings. */
|
|
|
|
|
unsigned int idx; /* Index into above. */
|
|
|
|
|
unsigned int max; /* Number of pointers allocated. */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* The recognized command switches. */
|
|
|
|
|
|
|
|
|
|
/* Nonzero means do not print commands to be executed (-s). */
|
|
|
|
|
|
|
|
|
|
int silent_flag;
|
|
|
|
|
|
|
|
|
|
/* Nonzero means just touch the files
|
|
|
|
|
that would appear to need remaking (-t) */
|
|
|
|
|
|
|
|
|
|
int touch_flag;
|
|
|
|
|
|
|
|
|
|
/* Nonzero means just print what commands would need to be executed,
|
|
|
|
|
don't actually execute them (-n). */
|
|
|
|
|
|
|
|
|
|
int just_print_flag;
|
|
|
|
|
|
|
|
|
|
/* Print debugging trace info (-d). */
|
|
|
|
|
|
|
|
|
|
int debug_flag = 0;
|
|
|
|
|
|
|
|
|
|
/* Environment variables override makefile definitions. */
|
|
|
|
|
|
|
|
|
|
int env_overrides = 0;
|
|
|
|
|
|
|
|
|
|
/* Nonzero means ignore status codes returned by commands
|
|
|
|
|
executed to remake files. Just treat them all as successful (-i). */
|
|
|
|
|
|
|
|
|
|
int ignore_errors_flag = 0;
|
|
|
|
|
|
|
|
|
|
/* Nonzero means don't remake anything, just print the data base
|
|
|
|
|
that results from reading the makefile (-p). */
|
|
|
|
|
|
|
|
|
|
int print_data_base_flag = 0;
|
|
|
|
|
|
|
|
|
|
/* Nonzero means don't remake anything; just return a nonzero status
|
|
|
|
|
if the specified targets are not up to date (-q). */
|
|
|
|
|
|
|
|
|
|
int question_flag = 0;
|
|
|
|
|
|
|
|
|
|
/* Nonzero means do not use any of the builtin rules (-r). */
|
|
|
|
|
|
|
|
|
|
int no_builtin_rules_flag = 0;
|
|
|
|
|
|
|
|
|
|
/* Nonzero means keep going even if remaking some file fails (-k). */
|
|
|
|
|
|
|
|
|
|
int keep_going_flag;
|
|
|
|
|
int default_keep_going_flag = 0;
|
|
|
|
|
|
1993-04-07 20:40:35 +00:00
|
|
|
|
/* Nonzero means print directory before starting and when done (-w). */
|
1992-01-29 23:54:36 +00:00
|
|
|
|
|
|
|
|
|
int print_directory_flag = 0;
|
|
|
|
|
|
1993-04-07 20:40:35 +00:00
|
|
|
|
/* Nonzero means ignore print_directory_flag and never print the directory.
|
|
|
|
|
This is necessary because print_directory_flag is set implicitly. */
|
|
|
|
|
|
|
|
|
|
int inhibit_print_directory_flag = 0;
|
|
|
|
|
|
1992-01-29 23:54:36 +00:00
|
|
|
|
/* Nonzero means print version information. */
|
|
|
|
|
|
|
|
|
|
int print_version_flag = 0;
|
|
|
|
|
|
|
|
|
|
/* List of makefiles given with -f switches. */
|
|
|
|
|
|
|
|
|
|
static struct stringlist *makefiles = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Number of job slots (commands that can be run at once). */
|
|
|
|
|
|
|
|
|
|
unsigned int job_slots = 1;
|
|
|
|
|
unsigned int default_job_slots = 1;
|
|
|
|
|
|
|
|
|
|
/* Value of job_slots that means no limit. */
|
|
|
|
|
|
|
|
|
|
static unsigned int inf_jobs = 0;
|
|
|
|
|
|
|
|
|
|
/* Maximum load average at which multiple jobs will be run.
|
|
|
|
|
Negative values mean unlimited, while zero means limit to
|
|
|
|
|
zero load (which could be useful to start infinite jobs remotely
|
|
|
|
|
but one at a time locally). */
|
|
|
|
|
|
|
|
|
|
double max_load_average = -1.0;
|
|
|
|
|
double default_load_average = -1.0;
|
|
|
|
|
|
1993-06-08 00:08:45 +00:00
|
|
|
|
/* List of directories given with -C switches. */
|
1992-01-29 23:54:36 +00:00
|
|
|
|
|
|
|
|
|
static struct stringlist *directories = 0;
|
|
|
|
|
|
|
|
|
|
/* List of include directories given with -I switches. */
|
|
|
|
|
|
|
|
|
|
static struct stringlist *include_directories = 0;
|
|
|
|
|
|
|
|
|
|
/* List of files given with -o switches. */
|
|
|
|
|
|
|
|
|
|
static struct stringlist *old_files = 0;
|
|
|
|
|
|
|
|
|
|
/* List of files given with -W switches. */
|
|
|
|
|
|
|
|
|
|
static struct stringlist *new_files = 0;
|
1993-05-22 20:20:16 +00:00
|
|
|
|
|
|
|
|
|
/* If nonzero, we should just print usage and exit. */
|
|
|
|
|
|
|
|
|
|
static int print_usage_flag = 0;
|
1993-06-25 19:47:20 +00:00
|
|
|
|
|
|
|
|
|
/* If nonzero, we should print a warning message
|
|
|
|
|
for each reference to an undefined variable. */
|
|
|
|
|
|
|
|
|
|
int warn_undefined_variables_flag;
|
1992-05-11 05:28:52 +00:00
|
|
|
|
|
1992-01-29 23:54:36 +00:00
|
|
|
|
/* The table of command switches. */
|
|
|
|
|
|
1993-04-14 18:20:33 +00:00
|
|
|
|
static const struct command_switch switches[] =
|
1992-01-29 23:54:36 +00:00
|
|
|
|
{
|
1992-05-09 04:28:28 +00:00
|
|
|
|
{ 'b', ignore, 0, 0, 0, 0, 0, 0,
|
|
|
|
|
0, 0,
|
|
|
|
|
"Ignored for compatibility" },
|
|
|
|
|
{ 'C', string, (char *) &directories, 0, 0, 0, 0, 0,
|
|
|
|
|
"directory", "DIRECTORY",
|
|
|
|
|
"Change to DIRECTORY before doing anything" },
|
|
|
|
|
{ 'd', flag, (char *) &debug_flag, 1, 1, 0, 0, 0,
|
|
|
|
|
"debug", 0,
|
|
|
|
|
"Print lots of debugging information" },
|
|
|
|
|
{ 'e', flag, (char *) &env_overrides, 1, 1, 0, 0, 0,
|
|
|
|
|
"environment-overrides", 0,
|
|
|
|
|
"Environment variables override makefiles" },
|
|
|
|
|
{ 'f', string, (char *) &makefiles, 0, 0, 0, 0, 0,
|
|
|
|
|
"file", "FILE",
|
|
|
|
|
"Read FILE as a makefile" },
|
1993-05-22 20:20:16 +00:00
|
|
|
|
{ 'h', flag, (char *) &print_usage_flag, 0, 0, 0, 0, 0,
|
1992-07-24 06:02:26 +00:00
|
|
|
|
"help", 0,
|
1992-09-30 01:26:59 +00:00
|
|
|
|
"Print this message and exit" },
|
1992-05-09 04:28:28 +00:00
|
|
|
|
{ 'i', flag, (char *) &ignore_errors_flag, 1, 1, 0, 0, 0,
|
|
|
|
|
"ignore-errors", 0,
|
|
|
|
|
"Ignore errors from commands" },
|
1993-01-08 21:48:11 +00:00
|
|
|
|
{ 'I', string, (char *) &include_directories, 1, 1, 0, 0, 0,
|
1992-05-11 05:28:52 +00:00
|
|
|
|
"include-dir", "DIRECTORY",
|
1992-05-09 04:28:28 +00:00
|
|
|
|
"Search DIRECTORY for included makefiles" },
|
1992-01-29 23:54:36 +00:00
|
|
|
|
{ 'j', positive_int, (char *) &job_slots, 1, 1, 0,
|
1992-05-09 04:28:28 +00:00
|
|
|
|
(char *) &inf_jobs, (char *) &default_job_slots,
|
|
|
|
|
"jobs", "N",
|
|
|
|
|
"Allow N jobs at once; infinite jobs with no arg" },
|
1992-01-29 23:54:36 +00:00
|
|
|
|
{ 'k', flag, (char *) &keep_going_flag, 1, 1, 0,
|
1992-05-09 04:28:28 +00:00
|
|
|
|
0, (char *) &default_keep_going_flag,
|
|
|
|
|
"keep-going", 0,
|
|
|
|
|
"Keep going when some targets can't be made" },
|
1992-01-29 23:54:36 +00:00
|
|
|
|
{ 'l', floating, (char *) &max_load_average, 1, 1, 0,
|
1992-05-09 04:28:28 +00:00
|
|
|
|
(char *) &default_load_average, (char *) &default_load_average,
|
|
|
|
|
"load-average", "N",
|
|
|
|
|
"Don't start multiple jobs unless load is below N" },
|
|
|
|
|
{ 'm', ignore, 0, 0, 0, 0, 0, 0,
|
|
|
|
|
0, 0,
|
1992-05-11 05:28:52 +00:00
|
|
|
|
"-b" },
|
1992-05-09 04:28:28 +00:00
|
|
|
|
{ 'n', flag, (char *) &just_print_flag, 1, 1, 1, 0, 0,
|
|
|
|
|
"just-print", 0,
|
|
|
|
|
"Don't actually run any commands; just print them" },
|
|
|
|
|
{ 'o', string, (char *) &old_files, 0, 0, 0, 0, 0,
|
|
|
|
|
"old-file", "FILE",
|
|
|
|
|
"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,
|
|
|
|
|
"Print make's internal database" },
|
|
|
|
|
{ 'q', flag, (char *) &question_flag, 1, 1, 1, 0, 0,
|
|
|
|
|
"question", 0,
|
|
|
|
|
"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,
|
|
|
|
|
"Disable the built-in implicit rules" },
|
|
|
|
|
{ 's', flag, (char *) &silent_flag, 1, 1, 0, 0, 0,
|
|
|
|
|
"silent", 0,
|
|
|
|
|
"Don't echo commands" },
|
1992-01-29 23:54:36 +00:00
|
|
|
|
{ 'S', flag_off, (char *) &keep_going_flag, 1, 1, 0,
|
1992-05-09 04:28:28 +00:00
|
|
|
|
0, (char *) &default_keep_going_flag,
|
1992-05-11 05:28:52 +00:00
|
|
|
|
"no-keep-going", 0,
|
1992-05-09 04:28:28 +00:00
|
|
|
|
"Turns off -k" },
|
|
|
|
|
{ 't', flag, (char *) &touch_flag, 1, 1, 1, 0, 0,
|
|
|
|
|
"touch", 0,
|
|
|
|
|
"Touch targets instead of remaking them" },
|
1993-01-08 21:48:11 +00:00
|
|
|
|
{ 'v', flag, (char *) &print_version_flag, 1, 1, 0, 0, 0,
|
1992-05-09 04:28:28 +00:00
|
|
|
|
"version", 0,
|
1993-05-14 21:50:11 +00:00
|
|
|
|
"Print the version number of make and exit" },
|
1992-05-09 04:28:28 +00:00
|
|
|
|
{ 'w', flag, (char *) &print_directory_flag, 1, 1, 0, 0, 0,
|
|
|
|
|
"print-directory", 0,
|
|
|
|
|
"Print the current directory" },
|
1994-10-16 05:01:46 +00:00
|
|
|
|
{ 2, flag, (char *) &inhibit_print_directory_flag, 1, 1, 0, 0, 0,
|
1993-04-07 20:40:35 +00:00
|
|
|
|
"no-print-directory", 0,
|
|
|
|
|
"Turn off -w, even if it was turned on implicitly" },
|
1992-05-09 04:28:28 +00:00
|
|
|
|
{ 'W', string, (char *) &new_files, 0, 0, 0, 0, 0,
|
|
|
|
|
"what-if", "FILE",
|
|
|
|
|
"Consider FILE to be infinitely new" },
|
1994-10-16 05:01:46 +00:00
|
|
|
|
{ 3, flag, (char *) &warn_undefined_variables_flag, 1, 1, 0, 0, 0,
|
1993-06-25 19:47:20 +00:00
|
|
|
|
"warn-undefined-variables", 0,
|
|
|
|
|
"Warn when an undefined variable is referenced" },
|
1992-05-09 04:28:28 +00:00
|
|
|
|
{ '\0', }
|
1992-01-29 23:54:36 +00:00
|
|
|
|
};
|
|
|
|
|
|
1992-05-11 05:28:52 +00:00
|
|
|
|
/* Secondary long names for options. */
|
1992-01-29 23:54:36 +00:00
|
|
|
|
|
1992-05-11 05:28:52 +00:00
|
|
|
|
static struct option long_option_aliases[] =
|
|
|
|
|
{
|
|
|
|
|
{ "quiet", no_argument, 0, 's' },
|
1992-09-15 20:10:46 +00:00
|
|
|
|
{ "stop", no_argument, 0, 'S' },
|
1992-12-09 22:10:14 +00:00
|
|
|
|
{ "new-file", required_argument, 0, 'W' },
|
1992-05-11 05:28:52 +00:00
|
|
|
|
{ "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' },
|
|
|
|
|
};
|
1992-01-29 23:54:36 +00:00
|
|
|
|
|
1992-09-30 01:26:59 +00:00
|
|
|
|
/* The usage message prints the descriptions of options starting in
|
|
|
|
|
this column. Make sure it leaves enough room for the longest
|
|
|
|
|
description to fit in less than 80 characters. */
|
|
|
|
|
|
|
|
|
|
#define DESCRIPTION_COLUMN 30
|
|
|
|
|
|
1994-09-09 05:37:40 +00:00
|
|
|
|
/* List of goal targets. */
|
1992-01-29 23:54:36 +00:00
|
|
|
|
|
1994-09-09 05:37:40 +00:00
|
|
|
|
static struct dep *goals, *lastgoal;
|
1994-09-09 06:45:51 +00:00
|
|
|
|
|
|
|
|
|
/* List of variables which were defined on the command line
|
|
|
|
|
(or, equivalently, in MAKEFLAGS). */
|
|
|
|
|
|
|
|
|
|
struct command_variable
|
|
|
|
|
{
|
|
|
|
|
struct command_variable *next;
|
|
|
|
|
struct variable *variable;
|
|
|
|
|
};
|
|
|
|
|
static struct command_variable *command_variables;
|
1992-05-11 05:28:52 +00:00
|
|
|
|
|
1992-01-29 23:54:36 +00:00
|
|
|
|
/* The name we were invoked with. */
|
|
|
|
|
|
|
|
|
|
char *program;
|
|
|
|
|
|
1994-07-25 23:33:26 +00:00
|
|
|
|
/* Our current directory before processing any -C options. */
|
|
|
|
|
|
|
|
|
|
char *directory_before_chdir;
|
|
|
|
|
|
1993-02-04 18:23:19 +00:00
|
|
|
|
/* Our current directory after processing all -C options. */
|
|
|
|
|
|
|
|
|
|
char *starting_directory;
|
|
|
|
|
|
1992-01-29 23:54:36 +00:00
|
|
|
|
/* Value of the MAKELEVEL variable at startup (or 0). */
|
|
|
|
|
|
|
|
|
|
unsigned int makelevel;
|
|
|
|
|
|
|
|
|
|
/* First file defined in the makefile whose name does not
|
|
|
|
|
start with `.'. This is the default to remake if the
|
|
|
|
|
command line does not specify. */
|
|
|
|
|
|
|
|
|
|
struct file *default_goal_file;
|
|
|
|
|
|
|
|
|
|
/* Pointer to structure for the file .DEFAULT
|
|
|
|
|
whose commands are used for any file that has none of its own.
|
|
|
|
|
This is zero if the makefiles do not define .DEFAULT. */
|
|
|
|
|
|
|
|
|
|
struct file *default_file;
|
1994-09-30 01:04:54 +00:00
|
|
|
|
|
|
|
|
|
/* Nonzero if we have seen the magic `.POSIX' target.
|
|
|
|
|
This turns on pedantic compliance with POSIX.2. */
|
|
|
|
|
|
|
|
|
|
int posix_pedantic;
|
1992-01-29 23:54:36 +00:00
|
|
|
|
|
|
|
|
|
/* Mask of signals that are being caught with fatal_error_signal. */
|
1992-04-30 22:17:12 +00:00
|
|
|
|
|
|
|
|
|
#ifdef POSIX
|
|
|
|
|
sigset_t fatal_signal_set;
|
|
|
|
|
#else
|
1992-07-05 00:52:48 +00:00
|
|
|
|
#ifdef HAVE_SIGSETMASK
|
1992-01-29 23:54:36 +00:00
|
|
|
|
int fatal_signal_mask;
|
1992-04-30 22:17:12 +00:00
|
|
|
|
#endif
|
|
|
|
|
#endif
|
1992-01-29 23:54:36 +00:00
|
|
|
|
|
1993-06-02 20:51:28 +00:00
|
|
|
|
static struct file *
|
|
|
|
|
enter_command_line_file (name)
|
|
|
|
|
char *name;
|
|
|
|
|
{
|
1993-06-08 00:08:45 +00:00
|
|
|
|
if (name[0] == '~')
|
|
|
|
|
{
|
|
|
|
|
char *expanded = tilde_expand (name);
|
|
|
|
|
if (expanded != 0)
|
|
|
|
|
name = expanded; /* Memory leak; I don't care. */
|
|
|
|
|
}
|
|
|
|
|
|
1993-06-02 20:51:28 +00:00
|
|
|
|
/* This is also done in parse_file_seq, so this is redundant
|
|
|
|
|
for names read from makefiles. It is here for names passed
|
|
|
|
|
on the command line. */
|
|
|
|
|
while (name[0] == '.' && name[1] == '/' && name[2] != '\0')
|
|
|
|
|
{
|
|
|
|
|
name += 2;
|
|
|
|
|
while (*name == '/')
|
|
|
|
|
/* Skip following slashes: ".//foo" is "foo", not "/foo". */
|
|
|
|
|
++name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (*name == '\0')
|
|
|
|
|
{
|
|
|
|
|
/* It was all slashes! Move back to the dot and truncate
|
|
|
|
|
it after the first slash, so it becomes just "./". */
|
|
|
|
|
do
|
|
|
|
|
--name;
|
|
|
|
|
while (name[0] != '.');
|
|
|
|
|
name[2] = '\0';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return enter_file (savestring (name, strlen (name)));
|
|
|
|
|
}
|
|
|
|
|
|
1992-01-29 23:54:36 +00:00
|
|
|
|
int
|
|
|
|
|
main (argc, argv, envp)
|
|
|
|
|
int argc;
|
|
|
|
|
char **argv;
|
|
|
|
|
char **envp;
|
|
|
|
|
{
|
1993-01-07 00:34:28 +00:00
|
|
|
|
extern void init_dir ();
|
1992-06-11 04:58:20 +00:00
|
|
|
|
extern RETSIGTYPE fatal_error_signal (), child_handler ();
|
1992-01-29 23:54:36 +00:00
|
|
|
|
register struct file *f;
|
|
|
|
|
register unsigned int i;
|
|
|
|
|
char **p;
|
|
|
|
|
struct dep *read_makefiles;
|
|
|
|
|
PATH_VAR (current_directory);
|
|
|
|
|
|
|
|
|
|
default_goal_file = 0;
|
|
|
|
|
reading_filename = 0;
|
|
|
|
|
reading_lineno_ptr = 0;
|
|
|
|
|
|
1992-07-05 00:52:48 +00:00
|
|
|
|
#ifndef HAVE_SYS_SIGLIST
|
1992-11-23 20:04:19 +00:00
|
|
|
|
signame_init ();
|
1992-01-29 23:54:36 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
1992-04-30 22:17:12 +00:00
|
|
|
|
#ifdef POSIX
|
|
|
|
|
sigemptyset (&fatal_signal_set);
|
1992-05-01 15:39:36 +00:00
|
|
|
|
#define ADD_SIG(sig) sigaddset (&fatal_signal_set, sig)
|
1992-04-30 22:17:12 +00:00
|
|
|
|
#else
|
1992-07-05 00:52:48 +00:00
|
|
|
|
#ifdef HAVE_SIGSETMASK
|
1992-01-29 23:54:36 +00:00
|
|
|
|
fatal_signal_mask = 0;
|
1992-04-30 22:17:12 +00:00
|
|
|
|
#define ADD_SIG(sig) fatal_signal_mask |= sigmask (sig)
|
|
|
|
|
#else
|
|
|
|
|
#define ADD_SIG(sig)
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
1992-01-29 23:54:36 +00:00
|
|
|
|
|
|
|
|
|
#define FATAL_SIG(sig) \
|
1992-06-11 04:58:20 +00:00
|
|
|
|
if (signal ((sig), fatal_error_signal) == SIG_IGN) \
|
|
|
|
|
(void) signal ((sig), SIG_IGN); \
|
1992-01-29 23:54:36 +00:00
|
|
|
|
else \
|
1992-04-30 22:17:12 +00:00
|
|
|
|
ADD_SIG (sig);
|
1992-01-29 23:54:36 +00:00
|
|
|
|
|
|
|
|
|
FATAL_SIG (SIGHUP);
|
|
|
|
|
FATAL_SIG (SIGQUIT);
|
|
|
|
|
FATAL_SIG (SIGINT);
|
1992-06-05 01:04:07 +00:00
|
|
|
|
FATAL_SIG (SIGTERM);
|
|
|
|
|
|
1992-01-29 23:54:36 +00:00
|
|
|
|
#ifdef SIGDANGER
|
|
|
|
|
FATAL_SIG (SIGDANGER);
|
1992-06-05 01:04:07 +00:00
|
|
|
|
#endif
|
1992-01-29 23:54:36 +00:00
|
|
|
|
#ifdef SIGXCPU
|
|
|
|
|
FATAL_SIG (SIGXCPU);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef SIGXFSZ
|
|
|
|
|
FATAL_SIG (SIGXFSZ);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#undef FATAL_SIG
|
|
|
|
|
|
|
|
|
|
/* Make sure stdout is line-buffered. */
|
|
|
|
|
|
1992-07-05 00:52:48 +00:00
|
|
|
|
#ifdef HAVE_SETLINEBUF
|
1992-06-11 04:58:20 +00:00
|
|
|
|
setlinebuf (stdout);
|
|
|
|
|
#else
|
1992-06-11 20:05:40 +00:00
|
|
|
|
#ifndef SETVBUF_REVERSED
|
1992-01-29 23:54:36 +00:00
|
|
|
|
setvbuf (stdout, (char *) 0, _IOLBF, BUFSIZ);
|
1992-06-11 20:05:40 +00:00
|
|
|
|
#else /* setvbuf not reversed. */
|
|
|
|
|
/* Some buggy systems lose if we pass 0 instead of allocating ourselves. */
|
1992-01-29 23:54:36 +00:00
|
|
|
|
setvbuf (stdout, _IOLBF, xmalloc (BUFSIZ), BUFSIZ);
|
1992-06-11 20:05:40 +00:00
|
|
|
|
#endif /* setvbuf reversed. */
|
1992-06-11 04:58:20 +00:00
|
|
|
|
#endif /* setlinebuf missing. */
|
|
|
|
|
|
1992-10-11 21:26:57 +00:00
|
|
|
|
/* Initialize the directory hashing code. */
|
|
|
|
|
init_dir ();
|
|
|
|
|
|
1992-01-29 23:54:36 +00:00
|
|
|
|
/* Figure out where this program lives. */
|
|
|
|
|
|
|
|
|
|
if (argv[0] == 0)
|
|
|
|
|
argv[0] = "";
|
|
|
|
|
if (argv[0][0] == '\0')
|
|
|
|
|
program = "make";
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
program = rindex (argv[0], '/');
|
1994-07-25 23:33:26 +00:00
|
|
|
|
#ifdef __MSDOS__
|
|
|
|
|
if (program == 0)
|
|
|
|
|
program = rindex (argv[0], '\\');
|
|
|
|
|
if (program == 0)
|
|
|
|
|
program = rindex (argv[0], ':');
|
|
|
|
|
#endif
|
1992-01-29 23:54:36 +00:00
|
|
|
|
if (program == 0)
|
|
|
|
|
program = argv[0];
|
|
|
|
|
else
|
|
|
|
|
++program;
|
|
|
|
|
}
|
|
|
|
|
|
1994-02-16 21:13:16 +00:00
|
|
|
|
/* Set up to access user data (files). */
|
|
|
|
|
user_access ();
|
|
|
|
|
|
1992-01-29 23:54:36 +00:00
|
|
|
|
/* Figure out where we are. */
|
|
|
|
|
|
1992-06-11 04:58:20 +00:00
|
|
|
|
if (getcwd (current_directory, GET_PATH_MAX) == 0)
|
1992-01-29 23:54:36 +00:00
|
|
|
|
{
|
1992-07-05 00:52:48 +00:00
|
|
|
|
#ifdef HAVE_GETCWD
|
1992-01-29 23:54:36 +00:00
|
|
|
|
perror_with_name ("getcwd: ", "");
|
|
|
|
|
#else
|
|
|
|
|
error ("getwd: %s", current_directory);
|
|
|
|
|
#endif
|
|
|
|
|
current_directory[0] = '\0';
|
1993-03-08 18:49:51 +00:00
|
|
|
|
directory_before_chdir = 0;
|
1992-01-29 23:54:36 +00:00
|
|
|
|
}
|
1993-03-08 18:49:51 +00:00
|
|
|
|
else
|
|
|
|
|
directory_before_chdir = savestring (current_directory,
|
|
|
|
|
strlen (current_directory));
|
1992-01-29 23:54:36 +00:00
|
|
|
|
|
|
|
|
|
/* Read in variables from the environment. It is important that this be
|
1994-09-09 05:37:40 +00:00
|
|
|
|
done before $(MAKE) is are figured out so its definitions will not be
|
|
|
|
|
one from the environment. */
|
1992-01-29 23:54:36 +00:00
|
|
|
|
|
|
|
|
|
for (i = 0; envp[i] != 0; ++i)
|
|
|
|
|
{
|
|
|
|
|
register char *ep = envp[i];
|
1993-08-11 20:04:39 +00:00
|
|
|
|
while (*ep != '=')
|
|
|
|
|
++ep;
|
1993-12-15 22:49:45 +00:00
|
|
|
|
/* The result of pointer arithmetic is cast to unsigned int for
|
|
|
|
|
machines where ptrdiff_t is a different size that doesn't widen
|
|
|
|
|
the same. */
|
|
|
|
|
define_variable (envp[i], (unsigned int) (ep - envp[i]),
|
|
|
|
|
ep + 1, o_env, 1)
|
1993-08-11 20:04:39 +00:00
|
|
|
|
/* Force exportation of every variable culled from the environment.
|
|
|
|
|
We used to rely on target_environment's v_default code to do this.
|
|
|
|
|
But that does not work for the case where an environment variable
|
|
|
|
|
is redefined in a makefile with `override'; it should then still
|
|
|
|
|
be exported, because it was originally in the environment. */
|
|
|
|
|
->export = v_export;
|
1992-01-29 23:54:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Decode the switches. */
|
|
|
|
|
|
1993-01-07 00:34:28 +00:00
|
|
|
|
decode_env_switches ("MAKEFLAGS", 9);
|
1993-08-11 06:54:23 +00:00
|
|
|
|
#if 0
|
|
|
|
|
/* People write things like:
|
|
|
|
|
MFLAGS="CC=gcc -pipe" "CFLAGS=-g"
|
|
|
|
|
and we set the -p, -i and -e switches. Doesn't seem quite right. */
|
1993-01-07 00:34:28 +00:00
|
|
|
|
decode_env_switches ("MFLAGS", 6);
|
1993-08-11 06:54:23 +00:00
|
|
|
|
#endif
|
1993-01-07 00:34:28 +00:00
|
|
|
|
decode_switches (argc, argv, 0);
|
1992-01-29 23:54:36 +00:00
|
|
|
|
|
|
|
|
|
/* Print version information. */
|
|
|
|
|
|
|
|
|
|
if (print_version_flag || print_data_base_flag || debug_flag)
|
|
|
|
|
print_version ();
|
|
|
|
|
|
1993-05-14 21:50:11 +00:00
|
|
|
|
/* `make --version' is supposed to just print the version and exit. */
|
|
|
|
|
if (print_version_flag)
|
1993-05-22 20:20:16 +00:00
|
|
|
|
die (0);
|
1993-05-14 21:50:11 +00:00
|
|
|
|
|
1994-07-25 23:33:26 +00:00
|
|
|
|
#ifndef __MSDOS__
|
1992-12-09 22:10:14 +00:00
|
|
|
|
/* Set the "MAKE_COMMAND" variable to the name we were invoked with.
|
1992-01-29 23:54:36 +00:00
|
|
|
|
(If it is a relative pathname with a slash, prepend our directory name
|
|
|
|
|
so the result will run the same program regardless of the current dir.
|
|
|
|
|
If it is a name with no slash, we can only hope that PATH did not
|
1992-12-09 22:10:14 +00:00
|
|
|
|
find it in the current directory.) */
|
1992-01-29 23:54:36 +00:00
|
|
|
|
|
|
|
|
|
if (current_directory[0] != '\0'
|
|
|
|
|
&& argv[0] != 0 && argv[0][0] != '/' && index (argv[0], '/') != 0)
|
|
|
|
|
argv[0] = concat (current_directory, "/", argv[0]);
|
1994-07-25 23:33:26 +00:00
|
|
|
|
#endif
|
1992-01-29 23:54:36 +00:00
|
|
|
|
|
1994-09-09 05:37:40 +00:00
|
|
|
|
/* The extra indirection through $(MAKE_COMMAND) is done
|
|
|
|
|
for hysterical raisins. */
|
1993-01-07 00:34:28 +00:00
|
|
|
|
(void) define_variable ("MAKE_COMMAND", 12, argv[0], o_default, 0);
|
1994-09-09 05:37:40 +00:00
|
|
|
|
(void) define_variable ("MAKE", 4, "$(MAKE_COMMAND)", o_default, 1);
|
1992-01-29 23:54:36 +00:00
|
|
|
|
|
1994-09-26 22:37:10 +00:00
|
|
|
|
if (command_variables != 0)
|
|
|
|
|
{
|
|
|
|
|
struct command_variable *cv;
|
|
|
|
|
struct variable *v;
|
|
|
|
|
unsigned int len = 0;
|
|
|
|
|
char *value, *p;
|
|
|
|
|
|
|
|
|
|
/* Figure out how much space will be taken up by the command-line
|
|
|
|
|
variable definitions. */
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Now allocate a buffer big enough and fill it. */
|
|
|
|
|
p = value = alloca (len);
|
|
|
|
|
for (cv = command_variables; cv != 0; cv = cv->next)
|
|
|
|
|
{
|
|
|
|
|
v = cv->variable;
|
|
|
|
|
p = quote_as_word (p, v->name, 0);
|
|
|
|
|
if (! v->recursive)
|
|
|
|
|
*p++ = ':';
|
|
|
|
|
*p++ = '=';
|
|
|
|
|
p = quote_as_word (p, v->value, 0);
|
|
|
|
|
*p++ = ' ';
|
|
|
|
|
}
|
|
|
|
|
p[-1] = '\0'; /* Kill the final space and terminate. */
|
|
|
|
|
|
1994-10-01 08:07:35 +00:00
|
|
|
|
/* Define an unchangeable variable with a name that no POSIX.2
|
|
|
|
|
makefile could validly use for its own variable. */
|
|
|
|
|
(void) define_variable ("-*-command-variables-*-", 23,
|
|
|
|
|
value, o_automatic, 0);
|
|
|
|
|
|
|
|
|
|
/* Define the variable; this will not override any user definition.
|
|
|
|
|
Normally a reference to this variable is written into the value of
|
|
|
|
|
MAKEFLAGS, allowing the user to override this value to affect the
|
|
|
|
|
exported value of MAKEFLAGS. In POSIX-pedantic mode, we cannot
|
|
|
|
|
allow the user's setting of MAKEOVERRIDES to affect MAKEFLAGS, so
|
|
|
|
|
a reference to this hidden variable is written instead. */
|
|
|
|
|
(void) define_variable ("MAKEOVERRIDES", 13,
|
|
|
|
|
"${-*-command-variables-*-}", o_env, 1);
|
1994-09-26 22:37:10 +00:00
|
|
|
|
}
|
1992-01-29 23:54:36 +00:00
|
|
|
|
|
1993-01-07 00:34:28 +00:00
|
|
|
|
/* If there were -C flags, move ourselves about. */
|
1992-01-29 23:54:36 +00:00
|
|
|
|
if (directories != 0)
|
|
|
|
|
for (i = 0; directories->list[i] != 0; ++i)
|
|
|
|
|
{
|
|
|
|
|
char *dir = directories->list[i];
|
1993-06-08 00:08:45 +00:00
|
|
|
|
if (dir[0] == '~')
|
|
|
|
|
{
|
|
|
|
|
char *expanded = tilde_expand (dir);
|
|
|
|
|
if (expanded != 0)
|
|
|
|
|
dir = expanded;
|
|
|
|
|
}
|
1992-01-29 23:54:36 +00:00
|
|
|
|
if (chdir (dir) < 0)
|
|
|
|
|
pfatal_with_name (dir);
|
1993-06-08 00:08:45 +00:00
|
|
|
|
if (dir != directories->list[i])
|
|
|
|
|
free (dir);
|
1992-01-29 23:54:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Figure out the level of recursion. */
|
|
|
|
|
{
|
|
|
|
|
struct variable *v = lookup_variable ("MAKELEVEL", 9);
|
|
|
|
|
if (v != 0 && *v->value != '\0' && *v->value != '-')
|
|
|
|
|
makelevel = (unsigned int) atoi (v->value);
|
|
|
|
|
else
|
|
|
|
|
makelevel = 0;
|
|
|
|
|
}
|
|
|
|
|
|
1992-09-30 23:21:22 +00:00
|
|
|
|
/* Except under -s, always do -w in sub-makes and under -C. */
|
|
|
|
|
if (!silent_flag && (directories != 0 || makelevel > 0))
|
|
|
|
|
print_directory_flag = 1;
|
1992-07-02 22:48:17 +00:00
|
|
|
|
|
1993-04-07 20:40:35 +00:00
|
|
|
|
/* Let the user disable that with --no-print-directory. */
|
|
|
|
|
if (inhibit_print_directory_flag)
|
|
|
|
|
print_directory_flag = 0;
|
|
|
|
|
|
1992-01-29 23:54:36 +00:00
|
|
|
|
/* Construct the list of include directories to search. */
|
|
|
|
|
|
|
|
|
|
construct_include_path (include_directories == 0 ? (char **) 0
|
|
|
|
|
: include_directories->list);
|
|
|
|
|
|
1993-02-04 18:23:19 +00:00
|
|
|
|
/* Figure out where we are now, after chdir'ing. */
|
|
|
|
|
if (directories == 0)
|
|
|
|
|
/* We didn't move, so we're still in the same place. */
|
|
|
|
|
starting_directory = current_directory;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (getcwd (current_directory, GET_PATH_MAX) == 0)
|
|
|
|
|
{
|
|
|
|
|
#ifdef HAVE_GETCWD
|
|
|
|
|
perror_with_name ("getcwd: ", "");
|
|
|
|
|
#else
|
|
|
|
|
error ("getwd: %s", current_directory);
|
|
|
|
|
#endif
|
|
|
|
|
starting_directory = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
starting_directory = current_directory;
|
|
|
|
|
}
|
|
|
|
|
|
1992-01-29 23:54:36 +00:00
|
|
|
|
/* Tell the user where he is. */
|
|
|
|
|
|
|
|
|
|
if (print_directory_flag)
|
|
|
|
|
log_working_directory (1);
|
|
|
|
|
|
|
|
|
|
/* Read any stdin makefiles into temporary files. */
|
|
|
|
|
|
|
|
|
|
if (makefiles != 0)
|
|
|
|
|
{
|
|
|
|
|
register unsigned int i;
|
|
|
|
|
for (i = 0; i < makefiles->idx; ++i)
|
|
|
|
|
if (makefiles->list[i][0] == '-' && makefiles->list[i][1] == '\0')
|
|
|
|
|
{
|
|
|
|
|
/* This makefile is standard input. Since we may re-exec
|
|
|
|
|
and thus re-read the makefiles, we read standard input
|
|
|
|
|
into a temporary file and read from that. */
|
|
|
|
|
static char name[] = "/tmp/GmXXXXXX";
|
|
|
|
|
FILE *outfile;
|
|
|
|
|
|
|
|
|
|
/* Make a unique filename. */
|
|
|
|
|
(void) mktemp (name);
|
|
|
|
|
|
|
|
|
|
outfile = fopen (name, "w");
|
|
|
|
|
if (outfile == 0)
|
|
|
|
|
pfatal_with_name ("fopen (temporary file)");
|
|
|
|
|
while (!feof (stdin))
|
|
|
|
|
{
|
|
|
|
|
char buf[2048];
|
|
|
|
|
int n = fread (buf, 1, sizeof(buf), stdin);
|
|
|
|
|
if (n > 0 && fwrite (buf, 1, n, outfile) != n)
|
|
|
|
|
pfatal_with_name ("fwrite (temporary file)");
|
|
|
|
|
}
|
|
|
|
|
/* Try to make sure we won't remake the temporary
|
|
|
|
|
file when we are re-exec'd. Kludge-o-matic! */
|
|
|
|
|
fprintf (outfile, "%s:;\n", name);
|
|
|
|
|
(void) fclose (outfile);
|
|
|
|
|
|
|
|
|
|
/* Replace the name that read_all_makefiles will
|
|
|
|
|
see with the name of the temporary file. */
|
1993-06-02 20:51:28 +00:00
|
|
|
|
{
|
1993-06-04 19:53:32 +00:00
|
|
|
|
char *temp;
|
|
|
|
|
/* SGI compiler requires alloca's result be assigned simply. */
|
|
|
|
|
temp = (char *) alloca (sizeof (name));
|
|
|
|
|
bcopy (name, temp, sizeof (name));
|
|
|
|
|
makefiles->list[i] = temp;
|
1993-06-02 20:51:28 +00:00
|
|
|
|
}
|
1992-01-29 23:54:36 +00:00
|
|
|
|
|
|
|
|
|
/* Make sure the temporary file will not be remade. */
|
|
|
|
|
f = enter_file (savestring (name, sizeof name - 1));
|
|
|
|
|
f->updated = 1;
|
|
|
|
|
f->update_status = 0;
|
1992-08-26 21:47:38 +00:00
|
|
|
|
f->command_state = cs_finished;
|
1992-01-29 23:54:36 +00:00
|
|
|
|
/* Let it be removed when we're done. */
|
|
|
|
|
f->intermediate = 1;
|
|
|
|
|
/* But don't mention it. */
|
|
|
|
|
f->dontcare = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Set up to handle children dying. This must be done before
|
|
|
|
|
reading in the makefiles so that `shell' function calls will work. */
|
|
|
|
|
|
1993-04-12 20:51:42 +00:00
|
|
|
|
#ifdef SIGCHLD
|
1992-06-11 04:58:20 +00:00
|
|
|
|
(void) signal (SIGCHLD, child_handler);
|
1993-04-12 20:51:42 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef SIGCLD
|
1992-06-11 04:58:20 +00:00
|
|
|
|
(void) signal (SIGCLD, child_handler);
|
1992-01-29 23:54:36 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Define the initial list of suffixes for old-style rules. */
|
|
|
|
|
|
|
|
|
|
set_default_suffixes ();
|
|
|
|
|
|
1993-10-14 22:23:39 +00:00
|
|
|
|
/* Define the file rules for the built-in suffix rules. These will later
|
|
|
|
|
be converted into pattern rules. We used to do this in
|
|
|
|
|
install_default_implicit_rules, but since that happens after reading
|
|
|
|
|
makefiles, it results in the built-in pattern rules taking precedence
|
|
|
|
|
over makefile-specified suffix rules, which is wrong. */
|
|
|
|
|
|
|
|
|
|
install_default_suffix_rules ();
|
|
|
|
|
|
1992-01-29 23:54:36 +00:00
|
|
|
|
/* Define some internal and special variables. */
|
|
|
|
|
|
|
|
|
|
define_automatic_variables ();
|
|
|
|
|
|
|
|
|
|
/* Set up the MAKEFLAGS and MFLAGS variables
|
|
|
|
|
so makefiles can look at them. */
|
|
|
|
|
|
|
|
|
|
define_makeflags (0, 0);
|
|
|
|
|
|
|
|
|
|
/* Define the default variables. */
|
|
|
|
|
define_default_variables ();
|
|
|
|
|
|
|
|
|
|
/* Read all the makefiles. */
|
|
|
|
|
|
|
|
|
|
default_file = enter_file (".DEFAULT");
|
|
|
|
|
|
|
|
|
|
read_makefiles
|
|
|
|
|
= read_all_makefiles (makefiles == 0 ? (char **) 0 : makefiles->list);
|
|
|
|
|
|
1993-01-07 00:34:28 +00:00
|
|
|
|
/* Decode switches again, in case the variables were set by the makefile. */
|
1992-01-29 23:54:36 +00:00
|
|
|
|
decode_env_switches ("MAKEFLAGS", 9);
|
1993-08-11 06:59:04 +00:00
|
|
|
|
#if 0
|
1992-01-29 23:54:36 +00:00
|
|
|
|
decode_env_switches ("MFLAGS", 6);
|
1993-08-11 06:59:04 +00:00
|
|
|
|
#endif
|
1992-01-29 23:54:36 +00:00
|
|
|
|
|
|
|
|
|
/* Set up MAKEFLAGS and MFLAGS again, so they will be right. */
|
|
|
|
|
|
|
|
|
|
define_makeflags (1, 0);
|
|
|
|
|
|
1994-10-24 22:57:07 +00:00
|
|
|
|
/* Make each `struct dep' point at the `struct file' for the file
|
|
|
|
|
depended on. Also do magic for special targets. */
|
1992-01-29 23:54:36 +00:00
|
|
|
|
|
|
|
|
|
snap_deps ();
|
|
|
|
|
|
1993-10-14 22:23:39 +00:00
|
|
|
|
/* Convert old-style suffix rules to pattern rules. It is important to
|
|
|
|
|
do this before installing the built-in pattern rules below, so that
|
|
|
|
|
makefile-specified suffix rules take precedence over built-in pattern
|
|
|
|
|
rules. */
|
|
|
|
|
|
|
|
|
|
convert_to_pattern ();
|
|
|
|
|
|
|
|
|
|
/* Install the default implicit pattern rules.
|
1992-01-29 23:54:36 +00:00
|
|
|
|
This used to be done before reading the makefiles.
|
|
|
|
|
But in that case, built-in pattern rules were in the chain
|
|
|
|
|
before user-defined ones, so they matched first. */
|
|
|
|
|
|
|
|
|
|
install_default_implicit_rules ();
|
|
|
|
|
|
|
|
|
|
/* Compute implicit rule limits. */
|
|
|
|
|
|
|
|
|
|
count_implicit_rule_limits ();
|
|
|
|
|
|
|
|
|
|
/* Construct the listings of directories in VPATH lists. */
|
|
|
|
|
|
|
|
|
|
build_vpath_lists ();
|
|
|
|
|
|
|
|
|
|
/* Mark files given with -o flags as very old (00:00:01.00 Jan 1, 1970)
|
1993-10-27 22:14:41 +00:00
|
|
|
|
and as having been updated already, and files given with -W flags as
|
|
|
|
|
brand new (time-stamp as far as possible into the future). */
|
1992-01-29 23:54:36 +00:00
|
|
|
|
|
|
|
|
|
if (old_files != 0)
|
|
|
|
|
for (p = old_files->list; *p != 0; ++p)
|
|
|
|
|
{
|
1993-06-02 20:51:28 +00:00
|
|
|
|
f = enter_command_line_file (*p);
|
1992-01-29 23:54:36 +00:00
|
|
|
|
f->last_mtime = (time_t) 1;
|
|
|
|
|
f->updated = 1;
|
|
|
|
|
f->update_status = 0;
|
1992-07-15 02:15:53 +00:00
|
|
|
|
f->command_state = cs_finished;
|
1992-01-29 23:54:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (new_files != 0)
|
|
|
|
|
{
|
|
|
|
|
for (p = new_files->list; *p != 0; ++p)
|
|
|
|
|
{
|
1993-06-02 20:51:28 +00:00
|
|
|
|
f = enter_command_line_file (*p);
|
1993-10-27 22:14:41 +00:00
|
|
|
|
f->last_mtime = NEW_MTIME;
|
1992-01-29 23:54:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (read_makefiles != 0)
|
|
|
|
|
{
|
|
|
|
|
/* Update any makefiles if necessary. */
|
|
|
|
|
|
|
|
|
|
time_t *makefile_mtimes = 0;
|
|
|
|
|
unsigned int mm_idx = 0;
|
|
|
|
|
|
|
|
|
|
if (debug_flag)
|
|
|
|
|
puts ("Updating makefiles....");
|
|
|
|
|
|
|
|
|
|
/* Remove any makefiles we don't want to try to update.
|
|
|
|
|
Also record the current modtimes so we can compare them later. */
|
|
|
|
|
{
|
|
|
|
|
register struct dep *d, *last;
|
|
|
|
|
last = 0;
|
|
|
|
|
d = read_makefiles;
|
|
|
|
|
while (d != 0)
|
|
|
|
|
{
|
|
|
|
|
register struct file *f = d->file;
|
|
|
|
|
if (f->double_colon)
|
1994-04-05 10:20:03 +00:00
|
|
|
|
for (f = f->double_colon; f != NULL; f = f->prev)
|
1992-11-16 23:59:17 +00:00
|
|
|
|
{
|
|
|
|
|
if (f->deps == 0 && f->cmds != 0)
|
|
|
|
|
{
|
|
|
|
|
/* This makefile is a :: target with commands, but
|
|
|
|
|
no dependencies. So, it will always be remade.
|
|
|
|
|
This might well cause an infinite loop, so don't
|
|
|
|
|
try to remake it. (This will only happen if
|
|
|
|
|
your makefiles are written exceptionally
|
|
|
|
|
stupidly; but if you work for Athena, that's how
|
|
|
|
|
you write your makefiles.) */
|
|
|
|
|
|
|
|
|
|
if (debug_flag)
|
|
|
|
|
printf ("Makefile `%s' might loop; not remaking it.\n",
|
|
|
|
|
f->name);
|
|
|
|
|
|
|
|
|
|
if (last == 0)
|
|
|
|
|
read_makefiles = d->next;
|
|
|
|
|
else
|
|
|
|
|
last->next = d->next;
|
|
|
|
|
|
|
|
|
|
/* Free the storage. */
|
|
|
|
|
free ((char *) d);
|
|
|
|
|
|
|
|
|
|
d = last == 0 ? 0 : last->next;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
1992-01-29 23:54:36 +00:00
|
|
|
|
if (f == NULL || !f->double_colon)
|
|
|
|
|
{
|
|
|
|
|
if (makefile_mtimes == 0)
|
|
|
|
|
makefile_mtimes = (time_t *) xmalloc (sizeof (time_t));
|
|
|
|
|
else
|
|
|
|
|
makefile_mtimes = (time_t *)
|
|
|
|
|
xrealloc ((char *) makefile_mtimes,
|
|
|
|
|
(mm_idx + 1) * sizeof (time_t));
|
|
|
|
|
makefile_mtimes[mm_idx++] = file_mtime_no_search (d->file);
|
|
|
|
|
last = d;
|
|
|
|
|
d = d->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Set up `MAKEFLAGS' specially while remaking makefiles. */
|
|
|
|
|
define_makeflags (1, 1);
|
|
|
|
|
|
|
|
|
|
switch (update_goal_chain (read_makefiles, 1))
|
|
|
|
|
{
|
|
|
|
|
default:
|
|
|
|
|
abort ();
|
|
|
|
|
|
|
|
|
|
case -1:
|
|
|
|
|
/* Did nothing. */
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
/* Failed to update. Figure out if we care. */
|
|
|
|
|
{
|
|
|
|
|
/* Nonzero if any makefile was successfully remade. */
|
|
|
|
|
int any_remade = 0;
|
|
|
|
|
/* Nonzero if any makefile we care about failed
|
|
|
|
|
in updating or could not be found at all. */
|
|
|
|
|
int any_failed = 0;
|
|
|
|
|
register unsigned int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; read_makefiles != 0; ++i)
|
|
|
|
|
{
|
|
|
|
|
struct dep *d = read_makefiles;
|
|
|
|
|
read_makefiles = d->next;
|
|
|
|
|
if (d->file->updated)
|
|
|
|
|
{
|
|
|
|
|
/* This makefile was updated. */
|
|
|
|
|
if (d->file->update_status == 0)
|
|
|
|
|
{
|
|
|
|
|
/* It was successfully updated. */
|
|
|
|
|
any_remade |= (file_mtime_no_search (d->file)
|
|
|
|
|
!= makefile_mtimes[i]);
|
|
|
|
|
}
|
1993-07-14 22:56:38 +00:00
|
|
|
|
else if (! (d->changed & RM_DONTCARE))
|
1992-01-29 23:54:36 +00:00
|
|
|
|
{
|
|
|
|
|
time_t mtime;
|
|
|
|
|
/* The update failed and this makefile was not
|
|
|
|
|
from the MAKEFILES variable, so we care. */
|
|
|
|
|
error ("Failed to remake makefile `%s'.",
|
|
|
|
|
d->file->name);
|
|
|
|
|
mtime = file_mtime_no_search (d->file);
|
|
|
|
|
any_remade |= (mtime != (time_t) -1
|
|
|
|
|
&& mtime != makefile_mtimes[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
/* This makefile was not found at all. */
|
1993-07-14 22:56:38 +00:00
|
|
|
|
if (! (d->changed & RM_DONTCARE))
|
1992-01-29 23:54:36 +00:00
|
|
|
|
{
|
1993-07-14 22:56:38 +00:00
|
|
|
|
/* This is a makefile we care about. See how much. */
|
|
|
|
|
if (d->changed & RM_INCLUDED)
|
|
|
|
|
/* An included makefile. We don't need
|
|
|
|
|
to die, but we do want to complain. */
|
|
|
|
|
error ("Included makefile `%s' was not found.",
|
|
|
|
|
dep_name (d));
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* A normal makefile. We must die later. */
|
|
|
|
|
error ("Makefile `%s' was not found", dep_name (d));
|
|
|
|
|
any_failed = 1;
|
|
|
|
|
}
|
1992-01-29 23:54:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
free ((char *) d);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (any_remade)
|
|
|
|
|
goto re_exec;
|
|
|
|
|
else if (any_failed)
|
1994-04-21 02:08:28 +00:00
|
|
|
|
die (2);
|
1992-01-29 23:54:36 +00:00
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case 0:
|
1993-06-04 00:27:28 +00:00
|
|
|
|
re_exec:
|
1992-01-29 23:54:36 +00:00
|
|
|
|
/* Updated successfully. Re-exec ourselves. */
|
1993-06-04 00:27:28 +00:00
|
|
|
|
|
|
|
|
|
remove_intermediates (0);
|
|
|
|
|
|
|
|
|
|
if (print_data_base_flag)
|
|
|
|
|
print_data_base ();
|
|
|
|
|
|
1992-01-29 23:54:36 +00:00
|
|
|
|
if (print_directory_flag)
|
|
|
|
|
log_working_directory (0);
|
1993-06-04 00:27:28 +00:00
|
|
|
|
|
1992-01-29 23:54:36 +00:00
|
|
|
|
if (makefiles != 0)
|
|
|
|
|
{
|
|
|
|
|
/* These names might have changed. */
|
|
|
|
|
register unsigned int i, j = 0;
|
|
|
|
|
for (i = 1; i < argc; ++i)
|
1993-06-08 00:08:45 +00:00
|
|
|
|
if (!strcmp (argv[i], "-f")) /* XXX */
|
1993-01-25 22:16:33 +00:00
|
|
|
|
{
|
|
|
|
|
char *p = &argv[i][2];
|
|
|
|
|
if (*p == '\0')
|
|
|
|
|
argv[++i] = makefiles->list[j];
|
|
|
|
|
else
|
|
|
|
|
argv[i] = concat ("-f", makefiles->list[j], "");
|
|
|
|
|
++j;
|
|
|
|
|
}
|
1992-01-29 23:54:36 +00:00
|
|
|
|
}
|
1993-06-04 00:27:28 +00:00
|
|
|
|
|
1992-01-29 23:54:36 +00:00
|
|
|
|
if (directories != 0 && directories->idx > 0)
|
|
|
|
|
{
|
|
|
|
|
char bad;
|
1993-03-08 18:49:51 +00:00
|
|
|
|
if (directory_before_chdir != 0)
|
1992-01-29 23:54:36 +00:00
|
|
|
|
{
|
1993-03-08 18:49:51 +00:00
|
|
|
|
if (chdir (directory_before_chdir) < 0)
|
1992-01-29 23:54:36 +00:00
|
|
|
|
{
|
|
|
|
|
perror_with_name ("chdir", "");
|
|
|
|
|
bad = 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
bad = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
bad = 1;
|
|
|
|
|
if (bad)
|
|
|
|
|
fatal ("Couldn't change back to original directory.");
|
|
|
|
|
}
|
1993-06-04 00:27:28 +00:00
|
|
|
|
|
1992-01-29 23:54:36 +00:00
|
|
|
|
for (p = environ; *p != 0; ++p)
|
|
|
|
|
if (!strncmp (*p, "MAKELEVEL=", 10))
|
|
|
|
|
{
|
1992-07-15 02:15:53 +00:00
|
|
|
|
/* The SGI compiler apparently can't understand
|
|
|
|
|
the concept of storing the result of a function
|
|
|
|
|
in something other than a local variable. */
|
|
|
|
|
char *sgi_loses;
|
|
|
|
|
sgi_loses = (char *) alloca (40);
|
|
|
|
|
*p = sgi_loses;
|
1992-01-29 23:54:36 +00:00
|
|
|
|
sprintf (*p, "MAKELEVEL=%u", makelevel);
|
|
|
|
|
break;
|
|
|
|
|
}
|
1993-06-04 00:27:28 +00:00
|
|
|
|
|
|
|
|
|
if (debug_flag)
|
|
|
|
|
{
|
|
|
|
|
char **p;
|
|
|
|
|
fputs ("Re-executing:", stdout);
|
|
|
|
|
for (p = argv; *p != 0; ++p)
|
|
|
|
|
printf (" %s", *p);
|
|
|
|
|
puts ("");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fflush (stdout);
|
|
|
|
|
fflush (stderr);
|
|
|
|
|
|
1992-01-29 23:54:36 +00:00
|
|
|
|
exec_command (argv, environ);
|
|
|
|
|
/* NOTREACHED */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Set up `MAKEFLAGS' again for the normal targets. */
|
|
|
|
|
define_makeflags (1, 0);
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
int status;
|
|
|
|
|
|
|
|
|
|
/* If there were no command-line goals, use the default. */
|
|
|
|
|
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 != 0)
|
|
|
|
|
{
|
|
|
|
|
/* Update the goals. */
|
|
|
|
|
|
|
|
|
|
if (debug_flag)
|
|
|
|
|
puts ("Updating goal targets....");
|
|
|
|
|
|
|
|
|
|
switch (update_goal_chain (goals, 0))
|
|
|
|
|
{
|
|
|
|
|
case -1:
|
|
|
|
|
/* Nothing happened. */
|
|
|
|
|
case 0:
|
|
|
|
|
/* Updated successfully. */
|
|
|
|
|
status = 0;
|
|
|
|
|
break;
|
1994-04-21 02:08:28 +00:00
|
|
|
|
case 2:
|
1992-01-29 23:54:36 +00:00
|
|
|
|
/* Updating failed. */
|
1994-04-21 02:08:28 +00:00
|
|
|
|
status = 2;
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
/* We are under -q and would run some commands. */
|
1992-01-29 23:54:36 +00:00
|
|
|
|
status = 1;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
abort ();
|
|
|
|
|
}
|
|
|
|
|
}
|
1993-01-25 22:16:33 +00:00
|
|
|
|
else
|
1992-01-29 23:54:36 +00:00
|
|
|
|
{
|
|
|
|
|
if (read_makefiles == 0)
|
|
|
|
|
fatal ("No targets specified and no makefile found");
|
|
|
|
|
else
|
|
|
|
|
fatal ("No targets");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Exit. */
|
|
|
|
|
die (status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
1993-01-07 00:34:28 +00:00
|
|
|
|
/* Parsing of arguments, decoding of switches. */
|
|
|
|
|
|
1994-09-06 23:13:43 +00:00
|
|
|
|
static char options[1 + sizeof (switches) / sizeof (switches[0]) * 3];
|
1993-01-07 00:34:28 +00:00
|
|
|
|
static struct option long_options[(sizeof (switches) / sizeof (switches[0])) +
|
|
|
|
|
(sizeof (long_option_aliases) /
|
|
|
|
|
sizeof (long_option_aliases[0]))];
|
|
|
|
|
|
|
|
|
|
/* Fill in the string and vector for getopt. */
|
1992-01-29 23:54:36 +00:00
|
|
|
|
static void
|
1993-01-07 00:34:28 +00:00
|
|
|
|
init_switches ()
|
1992-01-29 23:54:36 +00:00
|
|
|
|
{
|
1993-01-07 00:34:28 +00:00
|
|
|
|
register char *p;
|
1992-05-09 04:28:28 +00:00
|
|
|
|
register int c;
|
1993-01-07 00:34:28 +00:00
|
|
|
|
register unsigned int i;
|
1992-01-29 23:54:36 +00:00
|
|
|
|
|
1993-01-07 00:34:28 +00:00
|
|
|
|
if (options[0] != '\0')
|
|
|
|
|
/* Already done. */
|
|
|
|
|
return;
|
1992-01-29 23:54:36 +00:00
|
|
|
|
|
1992-05-09 04:28:28 +00:00
|
|
|
|
p = options;
|
1994-09-09 05:37:40 +00:00
|
|
|
|
|
|
|
|
|
/* Return switch and non-switch args in order, regardless of
|
1994-09-09 06:45:51 +00:00
|
|
|
|
POSIXLY_CORRECT. Non-switch args are returned as option 1. */
|
1994-09-09 05:37:40 +00:00
|
|
|
|
*p++ = '-';
|
|
|
|
|
|
1992-05-09 04:28:28 +00:00
|
|
|
|
for (i = 0; switches[i].c != '\0'; ++i)
|
|
|
|
|
{
|
1992-05-11 18:11:40 +00:00
|
|
|
|
long_options[i].name = (switches[i].long_name == 0 ? "" :
|
|
|
|
|
switches[i].long_name);
|
1992-05-25 23:02:13 +00:00
|
|
|
|
long_options[i].flag = 0;
|
1993-04-14 18:20:33 +00:00
|
|
|
|
long_options[i].val = switches[i].c;
|
|
|
|
|
if (isalnum (switches[i].c))
|
|
|
|
|
*p++ = switches[i].c;
|
1992-05-09 04:28:28 +00:00
|
|
|
|
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:
|
1993-04-14 18:20:33 +00:00
|
|
|
|
if (isalnum (switches[i].c))
|
|
|
|
|
*p++ = ':';
|
1992-05-09 04:28:28 +00:00
|
|
|
|
if (switches[i].noarg_value != 0)
|
|
|
|
|
{
|
1993-04-14 18:20:33 +00:00
|
|
|
|
if (isalnum (switches[i].c))
|
|
|
|
|
*p++ = ':';
|
1992-05-09 04:28:28 +00:00
|
|
|
|
long_options[i].has_arg = optional_argument;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
long_options[i].has_arg = required_argument;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*p = '\0';
|
1992-05-11 05:28:52 +00:00
|
|
|
|
for (c = 0; c < (sizeof (long_option_aliases) /
|
|
|
|
|
sizeof (long_option_aliases[0]));
|
|
|
|
|
++c)
|
|
|
|
|
long_options[i++] = long_option_aliases[c];
|
1992-05-09 04:28:28 +00:00
|
|
|
|
long_options[i].name = 0;
|
1993-01-07 00:34:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Decode switches from ARGC and ARGV.
|
|
|
|
|
They came from the environment if ENV is nonzero. */
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
decode_switches (argc, argv, env)
|
|
|
|
|
int argc;
|
|
|
|
|
char **argv;
|
|
|
|
|
int env;
|
|
|
|
|
{
|
|
|
|
|
int bad = 0;
|
1993-04-14 18:20:33 +00:00
|
|
|
|
register const struct command_switch *cs;
|
1993-01-07 00:34:28 +00:00
|
|
|
|
register struct stringlist *sl;
|
|
|
|
|
register int c;
|
|
|
|
|
|
|
|
|
|
/* getopt does most of the parsing for us.
|
|
|
|
|
First, get its vectors set up. */
|
|
|
|
|
|
|
|
|
|
init_switches ();
|
|
|
|
|
|
|
|
|
|
/* Let getopt produce error messages for the command line,
|
|
|
|
|
but not for options from the environment. */
|
|
|
|
|
opterr = !env;
|
|
|
|
|
/* Reset getopt's state. */
|
|
|
|
|
optind = 0;
|
1992-05-09 04:28:28 +00:00
|
|
|
|
|
1994-09-10 07:01:10 +00:00
|
|
|
|
c = 0;
|
|
|
|
|
while (optind < argc)
|
1992-01-29 23:54:36 +00:00
|
|
|
|
{
|
1994-09-10 07:01:10 +00:00
|
|
|
|
if (c == EOF)
|
|
|
|
|
{
|
|
|
|
|
/* There are no more options according to getting getopt, but
|
|
|
|
|
there are some arguments left. Since we have asked for
|
|
|
|
|
non-option arguments to be returned in order, I think this
|
|
|
|
|
only happens when there is a "--" argument to prevent later
|
|
|
|
|
argument from being options. Since getopt has finished its
|
|
|
|
|
job, just update its state variables for the next argument and
|
|
|
|
|
set C as if it had returned 1, indicating a non-option
|
|
|
|
|
argument. */
|
|
|
|
|
optarg = argv[optind++];
|
|
|
|
|
c = 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
/* Parse the next argument. */
|
|
|
|
|
c = getopt_long (argc, argv, options, long_options, (int *) 0);
|
|
|
|
|
|
1994-09-09 06:45:51 +00:00
|
|
|
|
if (c == 1)
|
1994-09-09 05:37:40 +00:00
|
|
|
|
{
|
|
|
|
|
/* Non-option argument. It might be a variable definition. */
|
1994-09-09 06:45:51 +00:00
|
|
|
|
struct variable *v;
|
|
|
|
|
v = try_variable_definition ((char *) 0, 0, optarg, o_command);
|
|
|
|
|
if (v != 0)
|
|
|
|
|
{
|
|
|
|
|
/* It is indeed a variable definition. Record a pointer to
|
|
|
|
|
the variable for later use in define_makeflags. */
|
|
|
|
|
struct command_variable *cv
|
|
|
|
|
= (struct command_variable *) xmalloc (sizeof (*cv));
|
|
|
|
|
cv->variable = v;
|
|
|
|
|
cv->next = command_variables;
|
|
|
|
|
command_variables = cv;
|
|
|
|
|
}
|
|
|
|
|
else if (! env)
|
1994-09-09 05:37:40 +00:00
|
|
|
|
{
|
|
|
|
|
/* Not an option or variable definition; it must be a goal
|
|
|
|
|
target! Enter it as a file and add it to the dep chain of
|
|
|
|
|
goals. */
|
|
|
|
|
struct file *f = enter_command_line_file (optarg);
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (c == '?')
|
1992-05-09 04:28:28 +00:00
|
|
|
|
/* Bad option. We will print a usage message and die later.
|
|
|
|
|
But continue to parse the other options so the user can
|
|
|
|
|
see all he did wrong. */
|
|
|
|
|
bad = 1;
|
|
|
|
|
else
|
|
|
|
|
for (cs = switches; cs->c != '\0'; ++cs)
|
1992-05-11 18:11:40 +00:00
|
|
|
|
if (cs->c == c)
|
|
|
|
|
{
|
1993-01-07 00:34:28 +00:00
|
|
|
|
/* Whether or not we will actually do anything with
|
|
|
|
|
this switch. We test this individually inside the
|
|
|
|
|
switch below rather than just once outside it, so that
|
|
|
|
|
options which are to be ignored still consume args. */
|
|
|
|
|
int doit = !env || cs->env;
|
|
|
|
|
|
1992-05-09 04:28:28 +00:00
|
|
|
|
switch (cs->type)
|
1992-01-29 23:54:36 +00:00
|
|
|
|
{
|
1992-05-09 04:28:28 +00:00
|
|
|
|
default:
|
|
|
|
|
abort ();
|
1992-01-29 23:54:36 +00:00
|
|
|
|
|
1992-05-09 04:28:28 +00:00
|
|
|
|
case ignore:
|
|
|
|
|
break;
|
1992-01-29 23:54:36 +00:00
|
|
|
|
|
1992-05-09 04:28:28 +00:00
|
|
|
|
case flag:
|
|
|
|
|
case flag_off:
|
1993-01-07 00:34:28 +00:00
|
|
|
|
if (doit)
|
|
|
|
|
*(int *) cs->value_ptr = cs->type == flag;
|
1992-05-09 04:28:28 +00:00
|
|
|
|
break;
|
1992-01-29 23:54:36 +00:00
|
|
|
|
|
1992-05-09 04:28:28 +00:00
|
|
|
|
case string:
|
1993-01-07 00:34:28 +00:00
|
|
|
|
if (!doit)
|
|
|
|
|
break;
|
|
|
|
|
|
1992-05-09 04:28:28 +00:00
|
|
|
|
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 *));
|
|
|
|
|
}
|
1993-06-02 20:51:28 +00:00
|
|
|
|
sl->list[sl->idx++] = optarg;
|
1992-05-09 04:28:28 +00:00
|
|
|
|
sl->list[sl->idx] = 0;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case positive_int:
|
1992-05-12 17:29:57 +00:00
|
|
|
|
if (optarg == 0 && argc > optind
|
|
|
|
|
&& isdigit (argv[optind][0]))
|
|
|
|
|
optarg = argv[optind++];
|
1993-01-07 00:34:28 +00:00
|
|
|
|
|
|
|
|
|
if (!doit)
|
|
|
|
|
break;
|
|
|
|
|
|
1992-05-09 04:28:28 +00:00
|
|
|
|
if (optarg != 0)
|
|
|
|
|
{
|
|
|
|
|
int i = atoi (optarg);
|
|
|
|
|
if (i < 1)
|
1992-01-29 23:54:36 +00:00
|
|
|
|
{
|
1993-01-07 00:34:28 +00:00
|
|
|
|
if (doit)
|
|
|
|
|
error ("the `-%c' option requires a \
|
1992-05-09 04:28:28 +00:00
|
|
|
|
positive integral argument",
|
1993-01-07 00:34:28 +00:00
|
|
|
|
cs->c);
|
1992-05-09 04:28:28 +00:00
|
|
|
|
bad = 1;
|
1992-01-29 23:54:36 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
1992-05-09 04:28:28 +00:00
|
|
|
|
*(unsigned int *) cs->value_ptr = i;
|
1992-01-29 23:54:36 +00:00
|
|
|
|
}
|
1992-05-09 04:28:28 +00:00
|
|
|
|
else
|
|
|
|
|
*(unsigned int *) cs->value_ptr
|
|
|
|
|
= *(unsigned int *) cs->noarg_value;
|
|
|
|
|
break;
|
1992-01-29 23:54:36 +00:00
|
|
|
|
|
1992-05-09 04:28:28 +00:00
|
|
|
|
case floating:
|
1993-01-07 00:34:28 +00:00
|
|
|
|
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);
|
|
|
|
|
|
1992-01-29 23:54:36 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
1992-05-09 04:28:28 +00:00
|
|
|
|
|
1992-05-11 18:11:40 +00:00
|
|
|
|
/* We've found the switch. Stop looking. */
|
|
|
|
|
break;
|
|
|
|
|
}
|
1992-01-29 23:54:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
1993-05-22 20:20:16 +00:00
|
|
|
|
if (!env && (bad || print_usage_flag))
|
1992-05-09 04:28:28 +00:00
|
|
|
|
{
|
|
|
|
|
/* Print a nice usage message. */
|
1992-09-30 01:26:59 +00:00
|
|
|
|
|
|
|
|
|
if (print_version_flag)
|
|
|
|
|
print_version ();
|
|
|
|
|
|
1992-05-09 04:28:28 +00:00
|
|
|
|
fprintf (stderr, "Usage: %s [options] [target] ...\n", program);
|
1992-09-30 01:26:59 +00:00
|
|
|
|
|
1992-05-09 04:28:28 +00:00
|
|
|
|
fputs ("Options:\n", stderr);
|
|
|
|
|
for (cs = switches; cs->c != '\0'; ++cs)
|
|
|
|
|
{
|
1993-05-26 18:33:12 +00:00
|
|
|
|
char buf[1024], shortarg[50], longarg[50], *p;
|
1992-05-11 05:28:52 +00:00
|
|
|
|
|
|
|
|
|
if (cs->description[0] == '-')
|
|
|
|
|
continue;
|
1992-05-09 04:28:28 +00:00
|
|
|
|
|
|
|
|
|
switch (long_options[cs - switches].has_arg)
|
|
|
|
|
{
|
|
|
|
|
case no_argument:
|
1993-05-26 18:33:12 +00:00
|
|
|
|
shortarg[0] = longarg[0] = '\0';
|
1992-05-09 04:28:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case required_argument:
|
1993-05-26 18:33:12 +00:00
|
|
|
|
sprintf (longarg, "=%s", cs->argdesc);
|
|
|
|
|
sprintf (shortarg, " %s", cs->argdesc);
|
1992-05-09 04:28:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case optional_argument:
|
1993-05-26 18:33:12 +00:00
|
|
|
|
sprintf (longarg, "[=%s]", cs->argdesc);
|
|
|
|
|
sprintf (shortarg, " [%s]", cs->argdesc);
|
1992-05-09 04:28:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
1992-05-11 05:28:52 +00:00
|
|
|
|
p = buf;
|
1993-04-07 20:40:35 +00:00
|
|
|
|
|
1993-04-14 18:20:33 +00:00
|
|
|
|
if (isalnum (cs->c))
|
1993-04-07 20:40:35 +00:00
|
|
|
|
{
|
1993-05-26 18:33:12 +00:00
|
|
|
|
sprintf (buf, " -%c%s", cs->c, shortarg);
|
1993-04-07 20:40:35 +00:00
|
|
|
|
p += strlen (p);
|
|
|
|
|
}
|
1992-05-11 05:28:52 +00:00
|
|
|
|
if (cs->long_name != 0)
|
|
|
|
|
{
|
1993-01-07 00:34:28 +00:00
|
|
|
|
unsigned int i;
|
1993-04-07 20:40:35 +00:00
|
|
|
|
sprintf (p, "%s--%s%s",
|
1993-04-14 18:20:33 +00:00
|
|
|
|
!isalnum (cs->c) ? " " : ", ",
|
1993-05-26 18:33:12 +00:00
|
|
|
|
cs->long_name, longarg);
|
1992-05-11 05:28:52 +00:00
|
|
|
|
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)
|
|
|
|
|
{
|
1993-05-26 18:33:12 +00:00
|
|
|
|
sprintf (p, ", --%s%s",
|
|
|
|
|
long_option_aliases[i].name, longarg);
|
1992-05-11 05:28:52 +00:00
|
|
|
|
p += strlen (p);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
{
|
1993-04-14 18:20:33 +00:00
|
|
|
|
const struct command_switch *ncs = cs;
|
1992-05-11 05:28:52 +00:00
|
|
|
|
while ((++ncs)->c != '\0')
|
|
|
|
|
if (ncs->description[0] == '-' &&
|
|
|
|
|
ncs->description[1] == cs->c)
|
|
|
|
|
{
|
|
|
|
|
/* This is another switch that does the same
|
|
|
|
|
one as the one we are processing. We want
|
|
|
|
|
to list them all together on one line. */
|
1993-05-26 18:33:12 +00:00
|
|
|
|
sprintf (p, ", -%c%s", ncs->c, shortarg);
|
1992-05-11 05:28:52 +00:00
|
|
|
|
p += strlen (p);
|
|
|
|
|
if (ncs->long_name != 0)
|
|
|
|
|
{
|
1993-05-26 18:33:12 +00:00
|
|
|
|
sprintf (p, ", --%s%s", ncs->long_name, longarg);
|
1992-05-11 05:28:52 +00:00
|
|
|
|
p += strlen (p);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
1992-05-09 04:28:28 +00:00
|
|
|
|
|
1992-09-30 01:26:59 +00:00
|
|
|
|
if (p - buf > DESCRIPTION_COLUMN - 2)
|
|
|
|
|
/* The list of option names is too long to fit on the same
|
|
|
|
|
line with the description, leaving at least two spaces.
|
|
|
|
|
Print it on its own line instead. */
|
1992-05-09 04:28:28 +00:00
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "%s\n", buf);
|
|
|
|
|
buf[0] = '\0';
|
|
|
|
|
}
|
|
|
|
|
|
1992-09-30 01:26:59 +00:00
|
|
|
|
fprintf (stderr, "%*s%s.\n",
|
|
|
|
|
- DESCRIPTION_COLUMN,
|
|
|
|
|
buf, cs->description);
|
1992-05-09 04:28:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
1994-04-21 02:08:28 +00:00
|
|
|
|
die (bad ? 2 : 0);
|
1992-05-09 04:28:28 +00:00
|
|
|
|
}
|
1992-01-29 23:54:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
1993-01-07 00:34:28 +00:00
|
|
|
|
/* Decode switches from environment variable ENVAR (which is LEN chars long).
|
|
|
|
|
We do this by chopping the value into a vector of words, prepending a
|
|
|
|
|
dash to the first word if it lacks one, and passing the vector to
|
|
|
|
|
decode_switches. */
|
|
|
|
|
|
1992-01-29 23:54:36 +00:00
|
|
|
|
static void
|
|
|
|
|
decode_env_switches (envar, len)
|
|
|
|
|
char *envar;
|
|
|
|
|
unsigned int len;
|
|
|
|
|
{
|
1993-01-08 21:48:11 +00:00
|
|
|
|
char *varref = (char *) alloca (2 + len + 2);
|
1994-09-10 07:01:10 +00:00
|
|
|
|
char *value, *p;
|
1993-01-07 00:34:28 +00:00
|
|
|
|
int argc;
|
|
|
|
|
char **argv;
|
|
|
|
|
|
|
|
|
|
/* Get the variable's value. */
|
|
|
|
|
varref[0] = '$';
|
|
|
|
|
varref[1] = '(';
|
|
|
|
|
bcopy (envar, &varref[2], len);
|
|
|
|
|
varref[2 + len] = ')';
|
|
|
|
|
varref[2 + len + 1] = '\0';
|
1994-09-10 07:01:10 +00:00
|
|
|
|
value = variable_expand (varref);
|
1993-01-07 00:34:28 +00:00
|
|
|
|
|
|
|
|
|
/* Skip whitespace, and check for an empty value. */
|
|
|
|
|
value = next_token (value);
|
|
|
|
|
len = strlen (value);
|
|
|
|
|
if (len == 0)
|
1992-01-29 23:54:36 +00:00
|
|
|
|
return;
|
|
|
|
|
|
1993-01-07 00:34:28 +00:00
|
|
|
|
/* Allocate a vector that is definitely big enough. */
|
1993-02-04 18:23:19 +00:00
|
|
|
|
argv = (char **) alloca ((1 + len + 1) * sizeof (char *));
|
1993-01-12 19:42:13 +00:00
|
|
|
|
|
1994-09-10 07:01:10 +00:00
|
|
|
|
/* Allocate a buffer to copy the value into while we split it into words
|
|
|
|
|
and unquote it. We must use permanent storage for this because
|
|
|
|
|
decode_switches may store pointers into the passed argument words. */
|
|
|
|
|
p = (char *) xmalloc (2 * len);
|
|
|
|
|
|
1993-01-12 19:42:13 +00:00
|
|
|
|
/* getopt will look at the arguments starting at ARGV[1].
|
|
|
|
|
Prepend a spacer word. */
|
|
|
|
|
argv[0] = 0;
|
|
|
|
|
argc = 1;
|
1994-09-10 07:01:10 +00:00
|
|
|
|
argv[argc] = p;
|
|
|
|
|
while (*value != '\0')
|
|
|
|
|
{
|
|
|
|
|
if (*value == '\\')
|
|
|
|
|
++value; /* Skip the backslash. */
|
|
|
|
|
else if (isblank (*value))
|
|
|
|
|
{
|
|
|
|
|
/* End of the word. */
|
|
|
|
|
*p++ = '\0';
|
|
|
|
|
argv[++argc] = p;
|
|
|
|
|
do
|
|
|
|
|
++value;
|
|
|
|
|
while (isblank (*value));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
*p++ = *value++;
|
|
|
|
|
}
|
|
|
|
|
*p = '\0';
|
|
|
|
|
argv[++argc] = 0;
|
1994-09-09 05:37:40 +00:00
|
|
|
|
|
|
|
|
|
if (argc == 2 && argv[1][0] != '-')
|
1993-01-07 00:34:28 +00:00
|
|
|
|
{
|
1994-09-09 05:37:40 +00:00
|
|
|
|
/* There is just one word in the value, and it is not a switch.
|
|
|
|
|
Either this is the single-word form and we should prepend a dash
|
|
|
|
|
before calling decode_switches, or this is the multi-word form and
|
|
|
|
|
there is no dash because it is a variable definition. */
|
1994-09-09 06:45:51 +00:00
|
|
|
|
struct variable *v;
|
|
|
|
|
v = try_variable_definition ((char *) 0, 0, argv[1], o_command);
|
|
|
|
|
if (v != 0)
|
|
|
|
|
{
|
|
|
|
|
/* It was indeed a variable definition, and now it has been
|
|
|
|
|
processed. There is nothing for decode_switches to do.
|
|
|
|
|
Record a pointer to the variable for later use in
|
|
|
|
|
define_makeflags. */
|
|
|
|
|
struct command_variable *cv
|
|
|
|
|
= (struct command_variable *) xmalloc (sizeof (*cv));
|
|
|
|
|
cv->variable = v;
|
|
|
|
|
cv->next = command_variables;
|
|
|
|
|
command_variables = cv;
|
|
|
|
|
return;
|
|
|
|
|
}
|
1994-09-09 05:37:40 +00:00
|
|
|
|
|
|
|
|
|
/* It wasn't a variable definition, so it's some switches without a
|
|
|
|
|
leading dash. Add one and pass it along to decode_switches. We
|
|
|
|
|
need permanent storage for this in case decode_switches saves
|
|
|
|
|
pointers into the value. */
|
|
|
|
|
argv[1] = concat ("-", argv[1], "");
|
|
|
|
|
}
|
1993-01-07 00:34:28 +00:00
|
|
|
|
|
|
|
|
|
/* Parse those words. */
|
|
|
|
|
decode_switches (argc, argv, 1);
|
1992-01-29 23:54:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
1994-09-10 07:01:10 +00:00
|
|
|
|
/* Quote the string IN so that it will be interpreted as a single word with
|
1994-09-26 22:37:10 +00:00
|
|
|
|
no magic by the shell; if DOUBLE_DOLLARS is nonzero, also double dollar
|
|
|
|
|
signs to avoid variable expansion in make itself. Write the result into
|
|
|
|
|
OUT, returning the address of the next character to be written.
|
|
|
|
|
Allocating space for OUT twice the length of IN (thrice if
|
|
|
|
|
DOUBLE_DOLLARS is nonzero) is always sufficient. */
|
|
|
|
|
|
|
|
|
|
static char *
|
|
|
|
|
quote_as_word (out, in, double_dollars)
|
1994-09-10 07:01:10 +00:00
|
|
|
|
char *out, *in;
|
1994-09-26 22:37:10 +00:00
|
|
|
|
int double_dollars;
|
1994-09-10 07:01:10 +00:00
|
|
|
|
{
|
|
|
|
|
while (*in != '\0')
|
|
|
|
|
{
|
|
|
|
|
if (index ("^;'\"*?[]$<>(){}|&~`\\ \t\r\n\f\v", *in) != 0)
|
|
|
|
|
*out++ = '\\';
|
1994-09-26 22:45:08 +00:00
|
|
|
|
if (double_dollars && *in == '$')
|
1994-09-26 22:37:10 +00:00
|
|
|
|
*out++ = '$';
|
1994-09-10 07:01:10 +00:00
|
|
|
|
*out++ = *in++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
1992-01-29 23:54:36 +00:00
|
|
|
|
/* Define the MAKEFLAGS and MFLAGS variables to reflect the settings of the
|
1993-01-08 21:48:11 +00:00
|
|
|
|
command switches. Include options with args if ALL is nonzero.
|
1993-01-07 00:34:28 +00:00
|
|
|
|
Don't include options with the `no_makefile' flag set if MAKEFILE. */
|
1992-01-29 23:54:36 +00:00
|
|
|
|
|
|
|
|
|
static void
|
1993-01-08 21:48:11 +00:00
|
|
|
|
define_makeflags (all, makefile)
|
|
|
|
|
int all, makefile;
|
1992-01-29 23:54:36 +00:00
|
|
|
|
{
|
1994-09-26 22:37:10 +00:00
|
|
|
|
static const char ref[] = "$(MAKEOVERRIDES)";
|
1994-10-01 08:07:35 +00:00
|
|
|
|
static const char posixref[] = "$(-*-command-variables-*-)";
|
1993-04-14 18:20:33 +00:00
|
|
|
|
register const struct command_switch *cs;
|
1993-01-08 21:48:11 +00:00
|
|
|
|
char *flagstring;
|
1994-09-09 06:45:51 +00:00
|
|
|
|
register char *p;
|
|
|
|
|
unsigned int words;
|
1993-12-16 20:10:36 +00:00
|
|
|
|
struct variable *v;
|
1993-01-08 21:48:11 +00:00
|
|
|
|
|
|
|
|
|
/* We will construct a linked list of `struct flag's describing
|
|
|
|
|
all the flags which need to go in MAKEFLAGS. Then, once we
|
|
|
|
|
know how many there are and their lengths, we can put them all
|
|
|
|
|
together in a string. */
|
|
|
|
|
|
|
|
|
|
struct flag
|
|
|
|
|
{
|
|
|
|
|
struct flag *next;
|
1993-04-14 18:20:33 +00:00
|
|
|
|
const struct command_switch *cs;
|
1993-01-08 21:48:11 +00:00
|
|
|
|
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)); \
|
1993-04-08 22:14:23 +00:00
|
|
|
|
new->cs = cs; \
|
1993-01-08 21:48:11 +00:00
|
|
|
|
new->arg = (ARG); \
|
|
|
|
|
new->next = flags; \
|
|
|
|
|
flags = new; \
|
|
|
|
|
if (new->arg == 0) \
|
|
|
|
|
++flagslen; /* Just a single flag letter. */ \
|
|
|
|
|
else \
|
1994-09-26 22:37:10 +00:00
|
|
|
|
flagslen += 1 + 1 + 1 + 1 + 3 * (LEN); /* " -x foo" */ \
|
1993-04-14 18:20:33 +00:00
|
|
|
|
if (!isalnum (cs->c)) \
|
1993-04-07 20:40:35 +00:00
|
|
|
|
/* This switch has no single-letter version, so we use the long. */ \
|
|
|
|
|
flagslen += 2 + strlen (cs->long_name); \
|
1993-01-08 21:48:11 +00:00
|
|
|
|
} while (0)
|
1992-01-29 23:54:36 +00:00
|
|
|
|
|
|
|
|
|
for (cs = switches; cs->c != '\0'; ++cs)
|
|
|
|
|
if (cs->toenv && (!makefile || !cs->no_makefile))
|
1993-01-08 21:48:11 +00:00
|
|
|
|
switch (cs->type)
|
|
|
|
|
{
|
|
|
|
|
default:
|
|
|
|
|
abort ();
|
1992-01-29 23:54:36 +00:00
|
|
|
|
|
1993-01-08 21:48:11 +00:00
|
|
|
|
case ignore:
|
|
|
|
|
break;
|
1992-01-29 23:54:36 +00:00
|
|
|
|
|
1993-01-08 21:48:11 +00:00
|
|
|
|
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;
|
1992-01-29 23:54:36 +00:00
|
|
|
|
|
1993-01-08 21:48:11 +00:00
|
|
|
|
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))
|
1993-01-25 22:16:33 +00:00
|
|
|
|
ADD_FLAG ("", 0); /* Optional value omitted; see below. */
|
1993-01-08 21:48:11 +00:00
|
|
|
|
else if (cs->c == 'j')
|
|
|
|
|
/* Special case for `-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;
|
1992-01-29 23:54:36 +00:00
|
|
|
|
|
1993-01-08 21:48:11 +00:00
|
|
|
|
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))
|
1993-01-25 22:16:33 +00:00
|
|
|
|
ADD_FLAG ("", 0); /* Optional value omitted; see below. */
|
1993-01-08 21:48:11 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
char *buf = (char *) alloca (100);
|
1993-04-26 20:05:02 +00:00
|
|
|
|
sprintf (buf, "%g", *(double *) cs->value_ptr);
|
1993-01-08 21:48:11 +00:00
|
|
|
|
ADD_FLAG (buf, strlen (buf));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case string:
|
|
|
|
|
if (all)
|
|
|
|
|
{
|
|
|
|
|
struct stringlist *sl = *(struct stringlist **) cs->value_ptr;
|
|
|
|
|
if (sl != 0)
|
1993-03-18 01:02:20 +00:00
|
|
|
|
{
|
|
|
|
|
/* Add the elements in reverse order, because
|
|
|
|
|
all the flags get reversed below; and the order
|
|
|
|
|
matters for some switches (like -I). */
|
|
|
|
|
register unsigned int i = sl->idx;
|
|
|
|
|
while (i-- > 0)
|
|
|
|
|
ADD_FLAG (sl->list[i], strlen (sl->list[i]));
|
|
|
|
|
}
|
1993-01-08 21:48:11 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
1992-01-29 23:54:36 +00:00
|
|
|
|
|
1994-10-01 08:07:35 +00:00
|
|
|
|
flagslen += 4 + sizeof posixref; /* Four more for the possible " -- ". */
|
1993-01-08 21:48:11 +00:00
|
|
|
|
|
1994-09-26 22:37:10 +00:00
|
|
|
|
#undef ADD_FLAG
|
1994-09-09 06:45:51 +00:00
|
|
|
|
|
|
|
|
|
/* Construct the value in FLAGSTRING.
|
|
|
|
|
We allocate enough space for a preceding dash and trailing null. */
|
|
|
|
|
flagstring = (char *) alloca (1 + flagslen + 1);
|
|
|
|
|
p = flagstring;
|
|
|
|
|
words = 1;
|
|
|
|
|
*p++ = '-';
|
|
|
|
|
while (flags != 0)
|
|
|
|
|
{
|
|
|
|
|
/* Add the flag letter or name to the string. */
|
|
|
|
|
if (!isalnum (flags->cs->c))
|
|
|
|
|
{
|
|
|
|
|
*p++ = '-';
|
|
|
|
|
strcpy (p, flags->cs->long_name);
|
|
|
|
|
p += strlen (p);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
*p++ = flags->cs->c;
|
|
|
|
|
if (flags->arg != 0)
|
|
|
|
|
{
|
1994-09-26 22:37:10 +00:00
|
|
|
|
/* A flag that takes an optional argument which in this case is
|
|
|
|
|
omitted is specified by ARG being "". We must distinguish
|
|
|
|
|
because a following flag appended without an intervening " -"
|
|
|
|
|
is considered the arg for the first. */
|
|
|
|
|
if (flags->arg[0] != '\0')
|
1993-01-08 21:48:11 +00:00
|
|
|
|
{
|
1994-09-09 06:45:51 +00:00
|
|
|
|
/* Add its argument too. */
|
|
|
|
|
*p++ = !isalnum (flags->cs->c) ? '=' : ' ';
|
1994-09-26 22:37:10 +00:00
|
|
|
|
p = quote_as_word (p, flags->arg, 1);
|
1993-01-08 21:48:11 +00:00
|
|
|
|
}
|
1994-09-09 06:45:51 +00:00
|
|
|
|
++words;
|
|
|
|
|
/* Write a following space and dash, for the next flag. */
|
|
|
|
|
*p++ = ' ';
|
|
|
|
|
*p++ = '-';
|
|
|
|
|
}
|
|
|
|
|
else if (!isalnum (flags->cs->c))
|
|
|
|
|
{
|
|
|
|
|
++words;
|
|
|
|
|
/* Long options must each go in their own word,
|
|
|
|
|
so we write the following space and dash. */
|
|
|
|
|
*p++ = ' ';
|
|
|
|
|
*p++ = '-';
|
|
|
|
|
}
|
|
|
|
|
flags = flags->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (all && command_variables != 0)
|
|
|
|
|
{
|
1994-09-26 22:37:10 +00:00
|
|
|
|
/* Now write a reference to $(MAKEOVERRIDES), which contains all the
|
|
|
|
|
command-line variable definitions. */
|
|
|
|
|
|
1994-09-09 06:45:51 +00:00
|
|
|
|
if (p == &flagstring[1])
|
|
|
|
|
/* No flags written, so elide the leading dash already written. */
|
|
|
|
|
p = flagstring;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Separate the variables from the switches with a "--" arg. */
|
|
|
|
|
if (p[-1] != '-')
|
1993-04-07 20:40:35 +00:00
|
|
|
|
{
|
1994-09-09 06:45:51 +00:00
|
|
|
|
/* We did not already write a trailing " -". */
|
1993-04-07 20:40:35 +00:00
|
|
|
|
*p++ = ' ';
|
|
|
|
|
*p++ = '-';
|
|
|
|
|
}
|
1994-09-09 06:45:51 +00:00
|
|
|
|
/* There is a trailing " -"; fill it out to " -- ". */
|
|
|
|
|
*p++ = '-';
|
|
|
|
|
*p++ = ' ';
|
|
|
|
|
}
|
1994-09-26 22:37:10 +00:00
|
|
|
|
|
|
|
|
|
/* Copy in the string. */
|
1994-10-01 08:07:35 +00:00
|
|
|
|
if (posix_pedantic)
|
|
|
|
|
{
|
|
|
|
|
bcopy (posixref, p, sizeof posixref - 1);
|
|
|
|
|
p += sizeof posixref - 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
bcopy (ref, p, sizeof ref - 1);
|
|
|
|
|
p += sizeof ref - 1;
|
|
|
|
|
}
|
1993-01-08 21:48:11 +00:00
|
|
|
|
}
|
1994-11-06 23:33:55 +00:00
|
|
|
|
else if (p == &flagstring[1])
|
1994-11-07 18:57:56 +00:00
|
|
|
|
{
|
|
|
|
|
words = 0;
|
|
|
|
|
--p;
|
|
|
|
|
}
|
1994-09-09 06:45:51 +00:00
|
|
|
|
else if (p[-1] == '-')
|
|
|
|
|
/* Kill the final space and dash. */
|
|
|
|
|
p -= 2;
|
|
|
|
|
/* Terminate the string. */
|
|
|
|
|
*p = '\0';
|
1992-01-29 23:54:36 +00:00
|
|
|
|
|
1993-12-16 20:10:36 +00:00
|
|
|
|
v = define_variable ("MAKEFLAGS", 9,
|
1994-09-09 06:45:51 +00:00
|
|
|
|
/* If there is just a single word of switches,
|
|
|
|
|
omit the leading dash unless it is a single
|
|
|
|
|
long option with two leading dashes. */
|
|
|
|
|
&flagstring[(words == 1 && command_variables == 0
|
|
|
|
|
&& flagstring[1] != '-')
|
|
|
|
|
? 1 : 0],
|
1993-12-16 20:10:36 +00:00
|
|
|
|
/* This used to use o_env, but that lost when a
|
|
|
|
|
makefile defined MAKEFLAGS. Makefiles set
|
|
|
|
|
MAKEFLAGS to add switches, but we still want
|
|
|
|
|
to redefine its value with the full set of
|
|
|
|
|
switches. Of course, an override or command
|
|
|
|
|
definition will still take precedence. */
|
1994-09-26 22:37:10 +00:00
|
|
|
|
o_file, 1);
|
1993-12-16 20:10:36 +00:00
|
|
|
|
if (! all)
|
|
|
|
|
/* The first time we are called, set MAKEFLAGS to always be exported.
|
|
|
|
|
We should not do this again on the second call, because that is
|
|
|
|
|
after reading makefiles which might have done `unexport MAKEFLAGS'. */
|
|
|
|
|
v->export = v_export;
|
1993-09-09 00:14:18 +00:00
|
|
|
|
/* Since MFLAGS is not parsed for flags, there is no reason to
|
|
|
|
|
override any makefile redefinition. */
|
1994-09-26 22:37:10 +00:00
|
|
|
|
(void) define_variable ("MFLAGS", 6, flagstring, o_env, 1);
|
1992-01-29 23:54:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Print version information. */
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
print_version ()
|
|
|
|
|
{
|
1992-09-30 01:26:59 +00:00
|
|
|
|
static int printed_version = 0;
|
|
|
|
|
|
1992-01-29 23:54:36 +00:00
|
|
|
|
char *precede = print_data_base_flag ? "# " : "";
|
|
|
|
|
|
1992-09-30 01:26:59 +00:00
|
|
|
|
if (printed_version)
|
|
|
|
|
/* Do it only once. */
|
|
|
|
|
return;
|
|
|
|
|
|
1992-01-29 23:54:36 +00:00
|
|
|
|
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\
|
1994-01-06 23:12:09 +00:00
|
|
|
|
%sCopyright (C) 1988, 89, 90, 91, 92, 93, 94 Free Software Foundation, Inc.\n\
|
1992-01-29 23:54:36 +00:00
|
|
|
|
%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", precede, precede, precede, precede);
|
|
|
|
|
|
|
|
|
|
printed_version = 1;
|
|
|
|
|
|
|
|
|
|
/* Flush stdout so the user doesn't have to wait to see the
|
|
|
|
|
version information while things are thought about. */
|
|
|
|
|
fflush (stdout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Print a bunch of information about this and that. */
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
print_data_base ()
|
|
|
|
|
{
|
|
|
|
|
extern char *ctime ();
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Exit with STATUS, cleaning up as necessary. */
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
die (status)
|
|
|
|
|
int status;
|
|
|
|
|
{
|
|
|
|
|
static char dying = 0;
|
|
|
|
|
|
|
|
|
|
if (!dying)
|
|
|
|
|
{
|
1992-04-21 07:56:07 +00:00
|
|
|
|
int err;
|
|
|
|
|
|
1992-01-29 23:54:36 +00:00
|
|
|
|
dying = 1;
|
|
|
|
|
|
1994-07-25 23:33:26 +00:00
|
|
|
|
/* Try to move back to the original directory. This is essential on
|
|
|
|
|
MS-DOS (where there is really only one process), and on Unix it
|
|
|
|
|
puts core files in the original directory instead of the -C
|
|
|
|
|
directory. */
|
|
|
|
|
if (directory_before_chdir != 0)
|
|
|
|
|
chdir (directory_before_chdir);
|
|
|
|
|
|
1992-09-30 01:26:59 +00:00
|
|
|
|
if (print_version_flag)
|
1992-01-29 23:54:36 +00:00
|
|
|
|
print_version ();
|
|
|
|
|
|
|
|
|
|
/* Wait for children to die. */
|
1992-04-21 07:56:07 +00:00
|
|
|
|
for (err = status != 0; job_slots_used > 0; err = 0)
|
1992-04-29 21:15:52 +00:00
|
|
|
|
reap_children (1, err);
|
1992-01-29 23:54:36 +00:00
|
|
|
|
|
|
|
|
|
/* Remove the intermediate files. */
|
|
|
|
|
remove_intermediates (0);
|
|
|
|
|
|
1993-01-12 19:42:13 +00:00
|
|
|
|
if (print_data_base_flag)
|
|
|
|
|
print_data_base ();
|
|
|
|
|
|
1992-01-29 23:54:36 +00:00
|
|
|
|
if (print_directory_flag)
|
|
|
|
|
log_working_directory (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
exit (status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Write a message indicating that we've just entered or
|
|
|
|
|
left (according to ENTERING) the current directory. */
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
log_working_directory (entering)
|
|
|
|
|
int entering;
|
|
|
|
|
{
|
|
|
|
|
static int entered = 0;
|
|
|
|
|
char *message = entering ? "Entering" : "Leaving";
|
|
|
|
|
|
1992-05-09 04:28:28 +00:00
|
|
|
|
if (entering)
|
|
|
|
|
entered = 1;
|
|
|
|
|
else if (!entered)
|
1992-01-29 23:54:36 +00:00
|
|
|
|
/* Don't print the leaving message if we
|
|
|
|
|
haven't printed the entering message. */
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (print_data_base_flag)
|
|
|
|
|
fputs ("# ", stdout);
|
|
|
|
|
|
|
|
|
|
if (makelevel == 0)
|
|
|
|
|
printf ("%s: %s ", program, message);
|
|
|
|
|
else
|
|
|
|
|
printf ("%s[%u]: %s ", program, makelevel, message);
|
|
|
|
|
|
1993-02-04 18:23:19 +00:00
|
|
|
|
if (starting_directory == 0)
|
|
|
|
|
puts ("an unknown directory");
|
1992-01-29 23:54:36 +00:00
|
|
|
|
else
|
1993-02-04 18:23:19 +00:00
|
|
|
|
printf ("directory `%s'\n", starting_directory);
|
1992-01-29 23:54:36 +00:00
|
|
|
|
}
|