1991-10-08 20:20:29 +00:00
|
|
|
|
/* Command processing for GNU Make.
|
2013-05-17 05:46:11 +00:00
|
|
|
|
Copyright (C) 1988-2013 Free Software Foundation, Inc.
|
1991-10-08 20:20:29 +00:00
|
|
|
|
This file is part of GNU Make.
|
|
|
|
|
|
2006-02-11 19:02:21 +00:00
|
|
|
|
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
|
2007-07-04 19:35:15 +00:00
|
|
|
|
Foundation; either version 3 of the License, or (at your option) any later
|
|
|
|
|
version.
|
1991-10-08 20:20:29 +00:00
|
|
|
|
|
2006-02-11 19:02:21 +00:00
|
|
|
|
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.
|
1991-10-08 20:20:29 +00:00
|
|
|
|
|
2006-02-11 19:02:21 +00:00
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
2007-07-04 19:35:15 +00:00
|
|
|
|
this program. If not, see <http://www.gnu.org/licenses/>. */
|
1991-10-08 20:20:29 +00:00
|
|
|
|
|
2013-05-03 13:09:12 +00:00
|
|
|
|
#include <dlfcn.h>
|
|
|
|
|
|
2013-01-20 16:01:01 +00:00
|
|
|
|
#include "makeint.h"
|
1996-03-20 14:57:41 +00:00
|
|
|
|
#include "filedef.h"
|
2013-09-22 04:48:05 +00:00
|
|
|
|
#include "dep.h"
|
1991-10-08 20:20:29 +00:00
|
|
|
|
#include "variable.h"
|
|
|
|
|
#include "job.h"
|
1996-03-20 14:57:41 +00:00
|
|
|
|
#include "commands.h"
|
2005-08-08 05:08:00 +00:00
|
|
|
|
#ifdef WINDOWS32
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
#include "w32err.h"
|
|
|
|
|
#endif
|
1991-10-08 20:20:29 +00:00
|
|
|
|
|
2002-07-08 13:05:02 +00:00
|
|
|
|
#if VMS
|
|
|
|
|
# define FILE_LIST_SEPARATOR ','
|
|
|
|
|
#else
|
|
|
|
|
# define FILE_LIST_SEPARATOR ' '
|
|
|
|
|
#endif
|
|
|
|
|
|
2006-04-07 01:43:44 +00:00
|
|
|
|
int remote_kill (int id, int sig);
|
1991-10-08 20:20:29 +00:00
|
|
|
|
|
2013-05-17 06:29:46 +00:00
|
|
|
|
#ifndef HAVE_UNISTD_H
|
2006-04-07 01:43:44 +00:00
|
|
|
|
int getpid ();
|
1991-10-08 20:20:29 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2009-10-06 12:36:29 +00:00
|
|
|
|
|
|
|
|
|
static unsigned long
|
|
|
|
|
dep_hash_1 (const void *key)
|
|
|
|
|
{
|
2009-10-25 00:26:34 +00:00
|
|
|
|
const struct dep *d = key;
|
|
|
|
|
return_STRING_HASH_1 (dep_name (d));
|
2009-10-06 12:36:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static unsigned long
|
|
|
|
|
dep_hash_2 (const void *key)
|
|
|
|
|
{
|
2009-10-25 00:26:34 +00:00
|
|
|
|
const struct dep *d = key;
|
|
|
|
|
return_STRING_HASH_2 (dep_name (d));
|
2009-10-06 12:36:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
dep_hash_cmp (const void *x, const void *y)
|
|
|
|
|
{
|
2009-10-25 00:26:34 +00:00
|
|
|
|
const struct dep *dx = x;
|
|
|
|
|
const struct dep *dy = y;
|
2009-10-07 09:34:42 +00:00
|
|
|
|
return strcmp (dep_name (dx), dep_name (dy));
|
2009-10-06 12:36:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
1991-10-08 20:20:29 +00:00
|
|
|
|
/* Set FILE's automatic variables up. */
|
|
|
|
|
|
2005-02-27 21:40:23 +00:00
|
|
|
|
void
|
2002-10-14 21:54:04 +00:00
|
|
|
|
set_file_variables (struct file *file)
|
1991-10-08 20:20:29 +00:00
|
|
|
|
{
|
2009-10-07 09:34:42 +00:00
|
|
|
|
struct dep *d;
|
2006-11-18 20:53:44 +00:00
|
|
|
|
const char *at, *percent, *star, *less;
|
1991-10-08 20:20:29 +00:00
|
|
|
|
|
2013-05-17 06:29:46 +00:00
|
|
|
|
#ifndef NO_ARCHIVES
|
2012-03-04 00:24:20 +00:00
|
|
|
|
/* If the target is an archive member 'lib(member)',
|
|
|
|
|
then $@ is 'lib' and $% is 'member'. */
|
1991-10-08 20:20:29 +00:00
|
|
|
|
|
|
|
|
|
if (ar_name (file->name))
|
|
|
|
|
{
|
1993-02-21 20:05:54 +00:00
|
|
|
|
unsigned int len;
|
2006-11-18 20:53:44 +00:00
|
|
|
|
const char *cp;
|
2002-07-08 13:05:02 +00:00
|
|
|
|
char *p;
|
|
|
|
|
|
2006-11-18 20:53:44 +00:00
|
|
|
|
cp = strchr (file->name, '(');
|
|
|
|
|
p = alloca (cp - file->name + 1);
|
|
|
|
|
memcpy (p, file->name, cp - file->name);
|
|
|
|
|
p[cp - file->name] = '\0';
|
|
|
|
|
at = p;
|
|
|
|
|
len = strlen (cp + 1);
|
|
|
|
|
p = alloca (len);
|
|
|
|
|
memcpy (p, cp + 1, len - 1);
|
|
|
|
|
p[len - 1] = '\0';
|
|
|
|
|
percent = p;
|
1991-10-08 20:20:29 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2013-05-17 06:29:46 +00:00
|
|
|
|
#endif /* NO_ARCHIVES. */
|
1991-10-08 20:20:29 +00:00
|
|
|
|
{
|
1993-01-28 23:01:09 +00:00
|
|
|
|
at = file->name;
|
1991-10-08 20:20:29 +00:00
|
|
|
|
percent = "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* $* is the stem from an implicit or static pattern rule. */
|
|
|
|
|
if (file->stem == 0)
|
|
|
|
|
{
|
|
|
|
|
/* In Unix make, $* is set to the target name with
|
2013-05-17 06:29:46 +00:00
|
|
|
|
any suffix in the .SUFFIXES list stripped off for
|
|
|
|
|
explicit rules. We store this in the 'stem' member. */
|
2006-11-18 20:53:44 +00:00
|
|
|
|
const char *name;
|
1992-03-31 00:24:58 +00:00
|
|
|
|
unsigned int len;
|
|
|
|
|
|
2013-05-17 06:29:46 +00:00
|
|
|
|
#ifndef NO_ARCHIVES
|
1992-03-31 00:24:58 +00:00
|
|
|
|
if (ar_name (file->name))
|
2013-05-17 06:29:46 +00:00
|
|
|
|
{
|
|
|
|
|
name = strchr (file->name, '(') + 1;
|
|
|
|
|
len = strlen (name) - 1;
|
|
|
|
|
}
|
1992-03-31 00:24:58 +00:00
|
|
|
|
else
|
|
|
|
|
#endif
|
2013-05-17 06:29:46 +00:00
|
|
|
|
{
|
|
|
|
|
name = file->name;
|
|
|
|
|
len = strlen (name);
|
|
|
|
|
}
|
1992-03-31 00:24:58 +00:00
|
|
|
|
|
2007-03-20 03:02:26 +00:00
|
|
|
|
for (d = enter_file (strcache_add (".SUFFIXES"))->deps; d ; d = d->next)
|
2013-05-17 06:29:46 +00:00
|
|
|
|
{
|
|
|
|
|
unsigned int slen = strlen (dep_name (d));
|
|
|
|
|
if (len > slen && strneq (dep_name (d), name + (len - slen), slen))
|
|
|
|
|
{
|
|
|
|
|
file->stem = strcache_add_len (name, len - slen);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
1991-10-08 20:20:29 +00:00
|
|
|
|
if (d == 0)
|
2013-05-17 06:29:46 +00:00
|
|
|
|
file->stem = "";
|
1991-10-08 20:20:29 +00:00
|
|
|
|
}
|
|
|
|
|
star = file->stem;
|
|
|
|
|
|
2004-05-16 19:16:52 +00:00
|
|
|
|
/* $< is the first not order-only dependency. */
|
|
|
|
|
less = "";
|
|
|
|
|
for (d = file->deps; d != 0; d = d->next)
|
|
|
|
|
if (!d->ignore_mtime)
|
|
|
|
|
{
|
2009-09-24 02:41:44 +00:00
|
|
|
|
if (!d->need_2nd_expansion)
|
|
|
|
|
less = dep_name (d);
|
2004-05-16 19:16:52 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
1991-10-08 20:20:29 +00:00
|
|
|
|
|
|
|
|
|
if (file->cmds == default_file->cmds)
|
|
|
|
|
/* This file got its commands from .DEFAULT.
|
|
|
|
|
In this case $< is the same as $@. */
|
|
|
|
|
less = at;
|
|
|
|
|
|
2013-05-17 06:29:46 +00:00
|
|
|
|
#define DEFINE_VARIABLE(name, len, value) \
|
2000-02-05 07:37:40 +00:00
|
|
|
|
(void) define_variable_for_file (name,len,value,o_automatic,0,file)
|
1991-10-08 20:20:29 +00:00
|
|
|
|
|
1993-01-28 23:01:09 +00:00
|
|
|
|
/* Define the variables. */
|
|
|
|
|
|
|
|
|
|
DEFINE_VARIABLE ("<", 1, less);
|
|
|
|
|
DEFINE_VARIABLE ("*", 1, star);
|
|
|
|
|
DEFINE_VARIABLE ("@", 1, at);
|
|
|
|
|
DEFINE_VARIABLE ("%", 1, percent);
|
1991-10-08 20:20:29 +00:00
|
|
|
|
|
2002-07-09 06:35:56 +00:00
|
|
|
|
/* Compute the values for $^, $+, $?, and $|. */
|
1991-10-08 20:20:29 +00:00
|
|
|
|
|
|
|
|
|
{
|
2002-10-13 18:50:10 +00:00
|
|
|
|
static char *plus_value=0, *bar_value=0, *qmark_value=0;
|
2006-11-18 20:53:44 +00:00
|
|
|
|
static unsigned int plus_max=0, bar_max=0, qmark_max=0;
|
2002-10-13 18:50:10 +00:00
|
|
|
|
|
2002-07-08 13:05:02 +00:00
|
|
|
|
unsigned int qmark_len, plus_len, bar_len;
|
|
|
|
|
char *cp;
|
2002-10-13 18:50:10 +00:00
|
|
|
|
char *caret_value;
|
2002-07-08 13:05:02 +00:00
|
|
|
|
char *qp;
|
|
|
|
|
char *bp;
|
1991-10-08 20:20:29 +00:00
|
|
|
|
unsigned int len;
|
|
|
|
|
|
2009-10-06 12:36:29 +00:00
|
|
|
|
struct hash_table dep_hash;
|
|
|
|
|
void **slot;
|
|
|
|
|
|
1994-09-29 08:23:25 +00:00
|
|
|
|
/* Compute first the value for $+, which is supposed to contain
|
|
|
|
|
duplicate dependencies as they were listed in the makefile. */
|
|
|
|
|
|
|
|
|
|
plus_len = 0;
|
2009-10-06 12:36:29 +00:00
|
|
|
|
bar_len = 0;
|
1994-09-29 08:23:25 +00:00
|
|
|
|
for (d = file->deps; d != 0; d = d->next)
|
2009-10-06 12:36:29 +00:00
|
|
|
|
{
|
|
|
|
|
if (!d->need_2nd_expansion)
|
|
|
|
|
{
|
|
|
|
|
if (d->ignore_mtime)
|
|
|
|
|
bar_len += strlen (dep_name (d)) + 1;
|
|
|
|
|
else
|
|
|
|
|
plus_len += strlen (dep_name (d)) + 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bar_len == 0)
|
|
|
|
|
bar_len++;
|
|
|
|
|
|
2002-07-08 13:05:02 +00:00
|
|
|
|
if (plus_len == 0)
|
|
|
|
|
plus_len++;
|
1994-09-29 08:23:25 +00:00
|
|
|
|
|
2002-10-13 18:50:10 +00:00
|
|
|
|
if (plus_len > plus_max)
|
2006-02-20 02:14:00 +00:00
|
|
|
|
plus_value = xrealloc (plus_value, plus_max = plus_len);
|
2009-10-06 12:36:29 +00:00
|
|
|
|
|
2002-10-13 18:50:10 +00:00
|
|
|
|
cp = plus_value;
|
1994-09-29 08:23:25 +00:00
|
|
|
|
|
2013-05-17 06:29:46 +00:00
|
|
|
|
qmark_len = plus_len + 1; /* Will be this or less. */
|
1991-10-08 20:20:29 +00:00
|
|
|
|
for (d = file->deps; d != 0; d = d->next)
|
2009-09-24 02:41:44 +00:00
|
|
|
|
if (! d->ignore_mtime && ! d->need_2nd_expansion)
|
2002-07-08 13:05:02 +00:00
|
|
|
|
{
|
2006-11-18 20:53:44 +00:00
|
|
|
|
const char *c = dep_name (d);
|
1994-09-29 08:23:25 +00:00
|
|
|
|
|
2013-05-17 06:29:46 +00:00
|
|
|
|
#ifndef NO_ARCHIVES
|
2002-07-08 13:05:02 +00:00
|
|
|
|
if (ar_name (c))
|
|
|
|
|
{
|
|
|
|
|
c = strchr (c, '(') + 1;
|
|
|
|
|
len = strlen (c) - 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
1994-09-29 08:23:25 +00:00
|
|
|
|
#endif
|
2002-07-08 13:05:02 +00:00
|
|
|
|
len = strlen (c);
|
1994-09-29 08:23:25 +00:00
|
|
|
|
|
2006-04-09 22:09:24 +00:00
|
|
|
|
memcpy (cp, c, len);
|
2002-07-08 13:05:02 +00:00
|
|
|
|
cp += len;
|
|
|
|
|
*cp++ = FILE_LIST_SEPARATOR;
|
2009-09-16 17:07:01 +00:00
|
|
|
|
if (! (d->changed || always_make_flag))
|
2013-05-17 06:29:46 +00:00
|
|
|
|
qmark_len -= len + 1; /* Don't space in $? for this one. */
|
2002-07-08 13:05:02 +00:00
|
|
|
|
}
|
1991-10-08 20:20:29 +00:00
|
|
|
|
|
1994-09-29 08:23:25 +00:00
|
|
|
|
/* Kill the last space and define the variable. */
|
|
|
|
|
|
|
|
|
|
cp[cp > plus_value ? -1 : 0] = '\0';
|
|
|
|
|
DEFINE_VARIABLE ("+", 1, plus_value);
|
|
|
|
|
|
2002-07-08 13:05:02 +00:00
|
|
|
|
/* Compute the values for $^, $?, and $|. */
|
1994-09-29 08:23:25 +00:00
|
|
|
|
|
|
|
|
|
cp = caret_value = plus_value; /* Reuse the buffer; it's big enough. */
|
2002-10-13 18:50:10 +00:00
|
|
|
|
|
|
|
|
|
if (qmark_len > qmark_max)
|
2006-02-20 02:14:00 +00:00
|
|
|
|
qmark_value = xrealloc (qmark_value, qmark_max = qmark_len);
|
2002-10-13 18:50:10 +00:00
|
|
|
|
qp = qmark_value;
|
|
|
|
|
|
|
|
|
|
if (bar_len > bar_max)
|
2006-02-20 02:14:00 +00:00
|
|
|
|
bar_value = xrealloc (bar_value, bar_max = bar_len);
|
2002-10-13 18:50:10 +00:00
|
|
|
|
bp = bar_value;
|
1991-10-08 20:20:29 +00:00
|
|
|
|
|
2009-10-06 12:36:29 +00:00
|
|
|
|
/* Make sure that no dependencies are repeated in $^, $?, and $|. It
|
|
|
|
|
would be natural to combine the next two loops but we can't do it
|
|
|
|
|
because of a situation where we have two dep entries, the first
|
2009-10-07 09:34:42 +00:00
|
|
|
|
is order-only and the second is normal (see below). */
|
2009-10-06 12:36:29 +00:00
|
|
|
|
|
|
|
|
|
hash_init (&dep_hash, 500, dep_hash_1, dep_hash_2, dep_hash_cmp);
|
|
|
|
|
|
1991-10-08 20:20:29 +00:00
|
|
|
|
for (d = file->deps; d != 0; d = d->next)
|
|
|
|
|
{
|
2009-09-24 02:41:44 +00:00
|
|
|
|
if (d->need_2nd_expansion)
|
|
|
|
|
continue;
|
|
|
|
|
|
2009-10-06 12:36:29 +00:00
|
|
|
|
slot = hash_find_slot (&dep_hash, d);
|
|
|
|
|
if (HASH_VACANT (*slot))
|
|
|
|
|
hash_insert_at (&dep_hash, d, slot);
|
2009-10-07 09:34:42 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Check if the two prerequisites have different ignore_mtime.
|
|
|
|
|
If so then we need to "upgrade" one that is order-only. */
|
|
|
|
|
|
|
|
|
|
struct dep* hd = (struct dep*) *slot;
|
|
|
|
|
|
|
|
|
|
if (d->ignore_mtime != hd->ignore_mtime)
|
|
|
|
|
d->ignore_mtime = hd->ignore_mtime = 0;
|
|
|
|
|
}
|
2009-10-06 12:36:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (d = file->deps; d != 0; d = d->next)
|
|
|
|
|
{
|
|
|
|
|
const char *c;
|
|
|
|
|
|
|
|
|
|
if (d->need_2nd_expansion || hash_find_item (&dep_hash, d) != d)
|
|
|
|
|
continue;
|
|
|
|
|
|
2009-09-24 02:41:44 +00:00
|
|
|
|
c = dep_name (d);
|
2013-05-17 06:29:46 +00:00
|
|
|
|
#ifndef NO_ARCHIVES
|
2009-10-06 12:36:29 +00:00
|
|
|
|
if (ar_name (c))
|
2013-05-17 06:29:46 +00:00
|
|
|
|
{
|
|
|
|
|
c = strchr (c, '(') + 1;
|
|
|
|
|
len = strlen (c) - 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
1992-07-13 21:51:47 +00:00
|
|
|
|
#endif
|
2013-05-17 06:29:46 +00:00
|
|
|
|
len = strlen (c);
|
1992-07-13 21:51:47 +00:00
|
|
|
|
|
2002-07-08 13:05:02 +00:00
|
|
|
|
if (d->ignore_mtime)
|
|
|
|
|
{
|
2009-10-06 12:36:29 +00:00
|
|
|
|
memcpy (bp, c, len);
|
2013-05-17 06:29:46 +00:00
|
|
|
|
bp += len;
|
|
|
|
|
*bp++ = FILE_LIST_SEPARATOR;
|
|
|
|
|
}
|
|
|
|
|
else
|
2009-10-06 12:36:29 +00:00
|
|
|
|
{
|
2006-04-09 22:09:24 +00:00
|
|
|
|
memcpy (cp, c, len);
|
2002-07-08 13:05:02 +00:00
|
|
|
|
cp += len;
|
|
|
|
|
*cp++ = FILE_LIST_SEPARATOR;
|
2009-06-13 21:21:48 +00:00
|
|
|
|
if (d->changed || always_make_flag)
|
2002-07-08 13:05:02 +00:00
|
|
|
|
{
|
2006-04-09 22:09:24 +00:00
|
|
|
|
memcpy (qp, c, len);
|
2002-07-08 13:05:02 +00:00
|
|
|
|
qp += len;
|
|
|
|
|
*qp++ = FILE_LIST_SEPARATOR;
|
|
|
|
|
}
|
|
|
|
|
}
|
1991-10-08 20:20:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-10-06 12:36:29 +00:00
|
|
|
|
hash_free (&dep_hash, 0);
|
|
|
|
|
|
1991-10-08 20:20:29 +00:00
|
|
|
|
/* Kill the last spaces and define the variables. */
|
|
|
|
|
|
|
|
|
|
cp[cp > caret_value ? -1 : 0] = '\0';
|
|
|
|
|
DEFINE_VARIABLE ("^", 1, caret_value);
|
|
|
|
|
|
|
|
|
|
qp[qp > qmark_value ? -1 : 0] = '\0';
|
|
|
|
|
DEFINE_VARIABLE ("?", 1, qmark_value);
|
2002-07-08 13:05:02 +00:00
|
|
|
|
|
|
|
|
|
bp[bp > bar_value ? -1 : 0] = '\0';
|
|
|
|
|
DEFINE_VARIABLE ("|", 1, bar_value);
|
1991-10-08 20:20:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-17 06:29:46 +00:00
|
|
|
|
#undef DEFINE_VARIABLE
|
1991-10-08 20:20:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
1993-02-05 22:34:51 +00:00
|
|
|
|
/* Chop CMDS up into individual command lines if necessary.
|
2012-03-04 00:24:20 +00:00
|
|
|
|
Also set the 'lines_flags' and 'any_recurse' members. */
|
1991-10-08 20:20:29 +00:00
|
|
|
|
|
|
|
|
|
void
|
2002-10-14 21:54:04 +00:00
|
|
|
|
chop_commands (struct commands *cmds)
|
1991-10-08 20:20:29 +00:00
|
|
|
|
{
|
1999-10-13 07:00:23 +00:00
|
|
|
|
unsigned int nlines, idx;
|
|
|
|
|
char **lines;
|
|
|
|
|
|
|
|
|
|
/* If we don't have any commands,
|
|
|
|
|
or we already parsed them, never mind. */
|
|
|
|
|
|
|
|
|
|
if (!cmds || cmds->command_lines != 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2010-07-12 05:23:19 +00:00
|
|
|
|
/* Chop CMDS->commands up into lines in CMDS->command_lines. */
|
1991-10-08 20:20:29 +00:00
|
|
|
|
|
2010-07-12 05:23:19 +00:00
|
|
|
|
if (one_shell)
|
1999-10-13 07:00:23 +00:00
|
|
|
|
{
|
2010-07-12 05:23:19 +00:00
|
|
|
|
int l = strlen (cmds->commands);
|
|
|
|
|
|
|
|
|
|
nlines = 1;
|
|
|
|
|
lines = xmalloc (nlines * sizeof (char *));
|
|
|
|
|
lines[0] = xstrdup (cmds->commands);
|
|
|
|
|
|
|
|
|
|
/* Strip the trailing newline. */
|
|
|
|
|
if (l > 0 && lines[0][l-1] == '\n')
|
|
|
|
|
lines[0][l-1] = '\0';
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const char *p;
|
|
|
|
|
|
|
|
|
|
nlines = 5;
|
|
|
|
|
lines = xmalloc (nlines * sizeof (char *));
|
|
|
|
|
idx = 0;
|
|
|
|
|
p = cmds->commands;
|
|
|
|
|
while (*p != '\0')
|
1999-10-13 07:00:23 +00:00
|
|
|
|
{
|
2010-07-12 05:23:19 +00:00
|
|
|
|
const char *end = p;
|
|
|
|
|
find_end:;
|
|
|
|
|
end = strchr (end, '\n');
|
|
|
|
|
if (end == 0)
|
|
|
|
|
end = p + strlen (p);
|
|
|
|
|
else if (end > p && end[-1] == '\\')
|
1999-10-13 07:00:23 +00:00
|
|
|
|
{
|
2010-07-12 05:23:19 +00:00
|
|
|
|
int backslash = 1;
|
|
|
|
|
const char *b;
|
|
|
|
|
for (b = end - 2; b >= p && *b == '\\'; --b)
|
|
|
|
|
backslash = !backslash;
|
|
|
|
|
if (backslash)
|
|
|
|
|
{
|
|
|
|
|
++end;
|
|
|
|
|
goto find_end;
|
|
|
|
|
}
|
1999-10-13 07:00:23 +00:00
|
|
|
|
}
|
2010-07-12 05:23:19 +00:00
|
|
|
|
|
|
|
|
|
if (idx == nlines)
|
|
|
|
|
{
|
|
|
|
|
nlines += 2;
|
|
|
|
|
lines = xrealloc (lines, nlines * sizeof (char *));
|
|
|
|
|
}
|
|
|
|
|
lines[idx++] = xstrndup (p, end - p);
|
|
|
|
|
p = end;
|
|
|
|
|
if (*p != '\0')
|
|
|
|
|
++p;
|
1999-10-13 07:00:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-07-12 05:23:19 +00:00
|
|
|
|
if (idx != nlines)
|
1999-10-13 07:00:23 +00:00
|
|
|
|
{
|
2010-07-12 05:23:19 +00:00
|
|
|
|
nlines = idx;
|
2006-04-09 22:09:24 +00:00
|
|
|
|
lines = xrealloc (lines, nlines * sizeof (char *));
|
1999-10-13 07:00:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1991-10-08 20:20:29 +00:00
|
|
|
|
|
2010-07-12 05:23:19 +00:00
|
|
|
|
/* Finally, set the corresponding CMDS->lines_flags elements and the
|
|
|
|
|
CMDS->any_recurse flag. */
|
1991-10-08 20:20:29 +00:00
|
|
|
|
|
2010-11-06 21:56:23 +00:00
|
|
|
|
if (nlines > USHRT_MAX)
|
|
|
|
|
fatal (&cmds->fileinfo, _("Recipe has too many lines (%ud)"), nlines);
|
|
|
|
|
|
1999-10-13 07:00:23 +00:00
|
|
|
|
cmds->ncommand_lines = nlines;
|
|
|
|
|
cmds->command_lines = lines;
|
1993-02-05 22:34:51 +00:00
|
|
|
|
|
1999-10-13 07:00:23 +00:00
|
|
|
|
cmds->any_recurse = 0;
|
2006-04-09 22:09:24 +00:00
|
|
|
|
cmds->lines_flags = xmalloc (nlines);
|
2010-07-12 05:23:19 +00:00
|
|
|
|
|
1999-10-13 07:00:23 +00:00
|
|
|
|
for (idx = 0; idx < nlines; ++idx)
|
|
|
|
|
{
|
|
|
|
|
int flags = 0;
|
2010-07-12 05:23:19 +00:00
|
|
|
|
const char *p = lines[idx];
|
1999-10-13 07:00:23 +00:00
|
|
|
|
|
2010-07-12 05:23:19 +00:00
|
|
|
|
while (isblank (*p) || *p == '-' || *p == '@' || *p == '+')
|
|
|
|
|
switch (*(p++))
|
1999-10-13 07:00:23 +00:00
|
|
|
|
{
|
|
|
|
|
case '+':
|
|
|
|
|
flags |= COMMANDS_RECURSE;
|
|
|
|
|
break;
|
|
|
|
|
case '@':
|
|
|
|
|
flags |= COMMANDS_SILENT;
|
|
|
|
|
break;
|
|
|
|
|
case '-':
|
|
|
|
|
flags |= COMMANDS_NOERROR;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2004-09-21 12:07:12 +00:00
|
|
|
|
|
|
|
|
|
/* If no explicit '+' was given, look for MAKE variable references. */
|
|
|
|
|
if (!(flags & COMMANDS_RECURSE)
|
|
|
|
|
&& (strstr (p, "$(MAKE)") != 0 || strstr (p, "${MAKE}") != 0))
|
|
|
|
|
flags |= COMMANDS_RECURSE;
|
1999-10-13 07:00:23 +00:00
|
|
|
|
|
|
|
|
|
cmds->lines_flags[idx] = flags;
|
2010-11-06 21:56:23 +00:00
|
|
|
|
cmds->any_recurse |= flags & COMMANDS_RECURSE ? 1 : 0;
|
1991-10-08 20:20:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Execute the commands to remake FILE. If they are currently executing,
|
|
|
|
|
return or have already finished executing, just return. Otherwise,
|
|
|
|
|
fork off a child process to run the first command line in the sequence. */
|
|
|
|
|
|
|
|
|
|
void
|
2002-10-14 21:54:04 +00:00
|
|
|
|
execute_file_commands (struct file *file)
|
1991-10-08 20:20:29 +00:00
|
|
|
|
{
|
2006-11-18 20:53:44 +00:00
|
|
|
|
const char *p;
|
1991-10-08 20:20:29 +00:00
|
|
|
|
|
|
|
|
|
/* Don't go through all the preparations if
|
|
|
|
|
the commands are nothing but whitespace. */
|
|
|
|
|
|
|
|
|
|
for (p = file->cmds->commands; *p != '\0'; ++p)
|
1999-10-15 07:00:58 +00:00
|
|
|
|
if (!isspace ((unsigned char)*p) && *p != '-' && *p != '@')
|
1991-10-08 20:20:29 +00:00
|
|
|
|
break;
|
|
|
|
|
if (*p == '\0')
|
|
|
|
|
{
|
1999-10-13 07:00:23 +00:00
|
|
|
|
/* If there are no commands, assume everything worked. */
|
1999-07-20 22:34:41 +00:00
|
|
|
|
set_command_state (file, cs_running);
|
2013-07-14 23:18:21 +00:00
|
|
|
|
file->update_status = us_success;
|
1991-10-08 20:20:29 +00:00
|
|
|
|
notice_finished_file (file);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* First set the automatic variables according to this file. */
|
|
|
|
|
|
2000-02-05 07:37:40 +00:00
|
|
|
|
initialize_file_variables (file, 0);
|
1991-10-08 20:20:29 +00:00
|
|
|
|
|
|
|
|
|
set_file_variables (file);
|
|
|
|
|
|
2013-05-03 13:09:12 +00:00
|
|
|
|
/* If this is a loaded dynamic object, unload it before remaking.
|
2013-05-17 05:20:39 +00:00
|
|
|
|
Some systems don't support overwriting a loaded object. */
|
|
|
|
|
if (file->loaded)
|
|
|
|
|
unload_file (file->name);
|
2013-05-03 13:09:12 +00:00
|
|
|
|
|
1991-10-08 20:20:29 +00:00
|
|
|
|
/* Start the commands running. */
|
|
|
|
|
new_job (file);
|
|
|
|
|
}
|
|
|
|
|
|
1993-05-06 21:30:42 +00:00
|
|
|
|
/* This is set while we are inside fatal_error_signal,
|
|
|
|
|
so things can avoid nonreentrant operations. */
|
|
|
|
|
|
|
|
|
|
int handling_fatal_signal = 0;
|
|
|
|
|
|
1991-10-08 20:20:29 +00:00
|
|
|
|
/* Handle fatal signals. */
|
|
|
|
|
|
1992-06-11 05:12:44 +00:00
|
|
|
|
RETSIGTYPE
|
2002-10-14 21:54:04 +00:00
|
|
|
|
fatal_error_signal (int sig)
|
1991-10-08 20:20:29 +00:00
|
|
|
|
{
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#ifdef __MSDOS__
|
|
|
|
|
extern int dos_status, dos_command_running;
|
|
|
|
|
|
|
|
|
|
if (dos_command_running)
|
|
|
|
|
{
|
|
|
|
|
/* That was the child who got the signal, not us. */
|
|
|
|
|
dos_status |= (sig << 8);
|
|
|
|
|
return;
|
|
|
|
|
}
|
1994-07-25 22:47:14 +00:00
|
|
|
|
remove_intermediates (1);
|
1999-06-14 05:26:28 +00:00
|
|
|
|
exit (EXIT_FAILURE);
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#else /* not __MSDOS__ */
|
Thu May 9 13:54:49 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
* GNUmakefile (globfiles): Add AmigaDOS support files.
(distfiles): Add $(amigafiles).
(amigafiles): New variable.
Thu Nov 7 10:18:16 1995 Aaron Digulla <digulla@fh-konstanz.de>
* Added Amiga support in commands.c, dir.c, function.c,
job.c, main.c, make.h, read.c, remake.c
* commands.c: Amiga has neither SIGHUP nor SIGQUIT
* dir.c: Amiga has filenames with Upper- and Lowercase,
but "FileName" is the same as "filename". Added strieq()
which is use to compare filenames. This is like streq()
on all other systems. Also there is no such thing as
"." under AmigaDOS.
* function.c: On Amiga, the environment is not passed as envp,
there are no pipes and Amiga can't fork. Use my own function
to create a new child.
* job.c: default_shell is "" (The system automatically chooses
a shell for me). Have to use the same workaround as MSDOS for
running batch commands. Added HAVE_SYS_PARAM_H. NOFILE isn't
known on Amiga. Cloned code to run children from MSDOS. Own
version of sh_chars[] and sh_cmds[]. No dup2() or dup() on Amiga.
* main.c: Force stack to 20000 bytes. Read environment from ENV:
device. On Amiga, exec_command() does return, so I exit()
afterwards.
* make.h: Added strieq() to compare filenames.
* read.c: Amiga needs special extension to have passwd. Only
one include-dir. "Makefile" and "makefile" are the same.
Added "SMakefile". Added special code to handle device names (xxx:)
and "./" in rules.
* remake.c: Only one lib-dir. Amiga link-libs are named "%s.lib"
instead of "lib%s.a".
* main.c, rule.c, variable.c: Avoid floats at all costs.
* vpath.c: Get rid of as many alloca()s as possible.
1996-05-09 18:02:06 +00:00
|
|
|
|
#ifdef _AMIGA
|
1997-04-07 07:21:16 +00:00
|
|
|
|
remove_intermediates (1);
|
Thu May 9 13:54:49 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
* GNUmakefile (globfiles): Add AmigaDOS support files.
(distfiles): Add $(amigafiles).
(amigafiles): New variable.
Thu Nov 7 10:18:16 1995 Aaron Digulla <digulla@fh-konstanz.de>
* Added Amiga support in commands.c, dir.c, function.c,
job.c, main.c, make.h, read.c, remake.c
* commands.c: Amiga has neither SIGHUP nor SIGQUIT
* dir.c: Amiga has filenames with Upper- and Lowercase,
but "FileName" is the same as "filename". Added strieq()
which is use to compare filenames. This is like streq()
on all other systems. Also there is no such thing as
"." under AmigaDOS.
* function.c: On Amiga, the environment is not passed as envp,
there are no pipes and Amiga can't fork. Use my own function
to create a new child.
* job.c: default_shell is "" (The system automatically chooses
a shell for me). Have to use the same workaround as MSDOS for
running batch commands. Added HAVE_SYS_PARAM_H. NOFILE isn't
known on Amiga. Cloned code to run children from MSDOS. Own
version of sh_chars[] and sh_cmds[]. No dup2() or dup() on Amiga.
* main.c: Force stack to 20000 bytes. Read environment from ENV:
device. On Amiga, exec_command() does return, so I exit()
afterwards.
* make.h: Added strieq() to compare filenames.
* read.c: Amiga needs special extension to have passwd. Only
one include-dir. "Makefile" and "makefile" are the same.
Added "SMakefile". Added special code to handle device names (xxx:)
and "./" in rules.
* remake.c: Only one lib-dir. Amiga link-libs are named "%s.lib"
instead of "lib%s.a".
* main.c, rule.c, variable.c: Avoid floats at all costs.
* vpath.c: Get rid of as many alloca()s as possible.
1996-05-09 18:02:06 +00:00
|
|
|
|
if (sig == SIGINT)
|
1999-07-28 06:23:37 +00:00
|
|
|
|
fputs (_("*** Break.\n"), stderr);
|
Thu May 9 13:54:49 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
* GNUmakefile (globfiles): Add AmigaDOS support files.
(distfiles): Add $(amigafiles).
(amigafiles): New variable.
Thu Nov 7 10:18:16 1995 Aaron Digulla <digulla@fh-konstanz.de>
* Added Amiga support in commands.c, dir.c, function.c,
job.c, main.c, make.h, read.c, remake.c
* commands.c: Amiga has neither SIGHUP nor SIGQUIT
* dir.c: Amiga has filenames with Upper- and Lowercase,
but "FileName" is the same as "filename". Added strieq()
which is use to compare filenames. This is like streq()
on all other systems. Also there is no such thing as
"." under AmigaDOS.
* function.c: On Amiga, the environment is not passed as envp,
there are no pipes and Amiga can't fork. Use my own function
to create a new child.
* job.c: default_shell is "" (The system automatically chooses
a shell for me). Have to use the same workaround as MSDOS for
running batch commands. Added HAVE_SYS_PARAM_H. NOFILE isn't
known on Amiga. Cloned code to run children from MSDOS. Own
version of sh_chars[] and sh_cmds[]. No dup2() or dup() on Amiga.
* main.c: Force stack to 20000 bytes. Read environment from ENV:
device. On Amiga, exec_command() does return, so I exit()
afterwards.
* make.h: Added strieq() to compare filenames.
* read.c: Amiga needs special extension to have passwd. Only
one include-dir. "Makefile" and "makefile" are the same.
Added "SMakefile". Added special code to handle device names (xxx:)
and "./" in rules.
* remake.c: Only one lib-dir. Amiga link-libs are named "%s.lib"
instead of "lib%s.a".
* main.c, rule.c, variable.c: Avoid floats at all costs.
* vpath.c: Get rid of as many alloca()s as possible.
1996-05-09 18:02:06 +00:00
|
|
|
|
|
|
|
|
|
exit (10);
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#else /* not Amiga */
|
2005-08-08 05:08:00 +00:00
|
|
|
|
#ifdef WINDOWS32
|
|
|
|
|
extern HANDLE main_thread;
|
|
|
|
|
|
|
|
|
|
/* Windows creates a sperate thread for handling Ctrl+C, so we need
|
|
|
|
|
to suspend the main thread, or else we will have race conditions
|
|
|
|
|
when both threads call reap_children. */
|
|
|
|
|
if (main_thread)
|
|
|
|
|
{
|
|
|
|
|
DWORD susp_count = SuspendThread (main_thread);
|
|
|
|
|
|
|
|
|
|
if (susp_count != 0)
|
2013-05-17 06:29:46 +00:00
|
|
|
|
fprintf (stderr, "SuspendThread: suspend count = %ld\n", susp_count);
|
2005-08-08 05:08:00 +00:00
|
|
|
|
else if (susp_count == (DWORD)-1)
|
2013-05-17 06:29:46 +00:00
|
|
|
|
{
|
|
|
|
|
DWORD ierr = GetLastError ();
|
2005-08-08 05:08:00 +00:00
|
|
|
|
|
2013-05-17 06:29:46 +00:00
|
|
|
|
fprintf (stderr, "SuspendThread: error %ld: %s\n",
|
|
|
|
|
ierr, map_windows32_error_to_string (ierr));
|
|
|
|
|
}
|
2005-08-08 05:08:00 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
1993-05-06 21:30:42 +00:00
|
|
|
|
handling_fatal_signal = 1;
|
|
|
|
|
|
1994-04-06 01:17:43 +00:00
|
|
|
|
/* Set the handling for this signal to the default.
|
|
|
|
|
It is blocked now while we run this handler. */
|
1991-10-08 20:20:29 +00:00
|
|
|
|
signal (sig, SIG_DFL);
|
|
|
|
|
|
|
|
|
|
/* A termination signal won't be sent to the entire
|
|
|
|
|
process group, but it means we want to kill the children. */
|
|
|
|
|
|
|
|
|
|
if (sig == SIGTERM)
|
|
|
|
|
{
|
2006-11-18 20:53:44 +00:00
|
|
|
|
struct child *c;
|
1991-10-08 20:20:29 +00:00
|
|
|
|
for (c = children; c != 0; c = c->next)
|
2013-05-17 06:29:46 +00:00
|
|
|
|
if (!c->remote)
|
|
|
|
|
(void) kill (c->pid, SIGTERM);
|
1991-10-08 20:20:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If we got a signal that means the user
|
|
|
|
|
wanted to kill make, remove pending targets. */
|
|
|
|
|
|
Thu May 9 13:54:49 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
* GNUmakefile (globfiles): Add AmigaDOS support files.
(distfiles): Add $(amigafiles).
(amigafiles): New variable.
Thu Nov 7 10:18:16 1995 Aaron Digulla <digulla@fh-konstanz.de>
* Added Amiga support in commands.c, dir.c, function.c,
job.c, main.c, make.h, read.c, remake.c
* commands.c: Amiga has neither SIGHUP nor SIGQUIT
* dir.c: Amiga has filenames with Upper- and Lowercase,
but "FileName" is the same as "filename". Added strieq()
which is use to compare filenames. This is like streq()
on all other systems. Also there is no such thing as
"." under AmigaDOS.
* function.c: On Amiga, the environment is not passed as envp,
there are no pipes and Amiga can't fork. Use my own function
to create a new child.
* job.c: default_shell is "" (The system automatically chooses
a shell for me). Have to use the same workaround as MSDOS for
running batch commands. Added HAVE_SYS_PARAM_H. NOFILE isn't
known on Amiga. Cloned code to run children from MSDOS. Own
version of sh_chars[] and sh_cmds[]. No dup2() or dup() on Amiga.
* main.c: Force stack to 20000 bytes. Read environment from ENV:
device. On Amiga, exec_command() does return, so I exit()
afterwards.
* make.h: Added strieq() to compare filenames.
* read.c: Amiga needs special extension to have passwd. Only
one include-dir. "Makefile" and "makefile" are the same.
Added "SMakefile". Added special code to handle device names (xxx:)
and "./" in rules.
* remake.c: Only one lib-dir. Amiga link-libs are named "%s.lib"
instead of "lib%s.a".
* main.c, rule.c, variable.c: Avoid floats at all costs.
* vpath.c: Get rid of as many alloca()s as possible.
1996-05-09 18:02:06 +00:00
|
|
|
|
if (sig == SIGTERM || sig == SIGINT
|
|
|
|
|
#ifdef SIGHUP
|
|
|
|
|
|| sig == SIGHUP
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef SIGQUIT
|
|
|
|
|
|| sig == SIGQUIT
|
|
|
|
|
#endif
|
|
|
|
|
)
|
1991-10-08 20:20:29 +00:00
|
|
|
|
{
|
2006-11-18 20:53:44 +00:00
|
|
|
|
struct child *c;
|
1991-10-08 20:20:29 +00:00
|
|
|
|
|
|
|
|
|
/* Remote children won't automatically get signals sent
|
2013-05-17 06:29:46 +00:00
|
|
|
|
to the process group, so we must send them. */
|
1991-10-08 20:20:29 +00:00
|
|
|
|
for (c = children; c != 0; c = c->next)
|
2013-05-17 06:29:46 +00:00
|
|
|
|
if (c->remote)
|
|
|
|
|
(void) remote_kill (c->pid, sig);
|
1991-10-08 20:20:29 +00:00
|
|
|
|
|
|
|
|
|
for (c = children; c != 0; c = c->next)
|
2013-05-17 06:29:46 +00:00
|
|
|
|
delete_child_targets (c);
|
1991-10-08 20:20:29 +00:00
|
|
|
|
|
|
|
|
|
/* Clean up the children. We don't just use the call below because
|
2013-05-17 06:29:46 +00:00
|
|
|
|
we don't want to print the "Waiting for children" message. */
|
1992-04-21 07:50:13 +00:00
|
|
|
|
while (job_slots_used > 0)
|
2013-05-17 06:29:46 +00:00
|
|
|
|
reap_children (1, 0);
|
1991-10-08 20:20:29 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
/* Wait for our children to die. */
|
1992-04-21 07:50:13 +00:00
|
|
|
|
while (job_slots_used > 0)
|
|
|
|
|
reap_children (1, 1);
|
1991-10-08 20:20:29 +00:00
|
|
|
|
|
|
|
|
|
/* Delete any non-precious intermediate files that were made. */
|
|
|
|
|
|
|
|
|
|
remove_intermediates (1);
|
|
|
|
|
|
1996-05-09 20:07:14 +00:00
|
|
|
|
#ifdef SIGQUIT
|
1991-10-08 20:20:29 +00:00
|
|
|
|
if (sig == SIGQUIT)
|
|
|
|
|
/* We don't want to send ourselves SIGQUIT, because it will
|
|
|
|
|
cause a core dump. Just exit instead. */
|
1996-03-20 14:57:41 +00:00
|
|
|
|
exit (EXIT_FAILURE);
|
1996-05-09 20:07:14 +00:00
|
|
|
|
#endif
|
1991-10-08 20:20:29 +00:00
|
|
|
|
|
2005-03-04 12:52:32 +00:00
|
|
|
|
#ifdef WINDOWS32
|
2005-08-08 05:08:00 +00:00
|
|
|
|
if (main_thread)
|
|
|
|
|
CloseHandle (main_thread);
|
|
|
|
|
/* Cannot call W32_kill with a pid (it needs a handle). The exit
|
|
|
|
|
status of 130 emulates what happens in Bash. */
|
|
|
|
|
exit (130);
|
2005-03-04 12:52:32 +00:00
|
|
|
|
#else
|
1994-04-06 01:17:43 +00:00
|
|
|
|
/* Signal the same code; this time it will really be fatal. The signal
|
|
|
|
|
will be unblocked when we return and arrive then to kill us. */
|
1991-10-08 20:20:29 +00:00
|
|
|
|
if (kill (getpid (), sig) < 0)
|
|
|
|
|
pfatal_with_name ("kill");
|
2005-03-04 12:52:32 +00:00
|
|
|
|
#endif /* not WINDOWS32 */
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#endif /* not Amiga */
|
|
|
|
|
#endif /* not __MSDOS__ */
|
1991-10-08 20:20:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
1994-01-25 21:51:25 +00:00
|
|
|
|
/* Delete FILE unless it's precious or not actually a file (phony),
|
|
|
|
|
and it has changed on disk since we last stat'd it. */
|
|
|
|
|
|
|
|
|
|
static void
|
2006-11-18 20:53:44 +00:00
|
|
|
|
delete_target (struct file *file, const char *on_behalf_of)
|
1994-01-25 21:51:25 +00:00
|
|
|
|
{
|
1994-02-16 21:09:47 +00:00
|
|
|
|
struct stat st;
|
2003-01-30 05:22:52 +00:00
|
|
|
|
int e;
|
1994-02-16 21:09:47 +00:00
|
|
|
|
|
|
|
|
|
if (file->precious || file->phony)
|
1994-01-25 21:51:25 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
#ifndef NO_ARCHIVES
|
|
|
|
|
if (ar_name (file->name))
|
|
|
|
|
{
|
2000-06-13 05:22:52 +00:00
|
|
|
|
time_t file_date = (file->last_mtime == NONEXISTENT_MTIME
|
2013-05-17 06:29:46 +00:00
|
|
|
|
? (time_t) -1
|
|
|
|
|
: (time_t) FILE_TIMESTAMP_S (file->last_mtime));
|
2000-06-13 05:22:52 +00:00
|
|
|
|
if (ar_member_date (file->name) != file_date)
|
2013-05-17 06:29:46 +00:00
|
|
|
|
{
|
|
|
|
|
if (on_behalf_of)
|
|
|
|
|
error (NILF, _("*** [%s] Archive member '%s' may be bogus; not deleted"),
|
|
|
|
|
on_behalf_of, file->name);
|
|
|
|
|
else
|
|
|
|
|
error (NILF, _("*** Archive member '%s' may be bogus; not deleted"),
|
|
|
|
|
file->name);
|
|
|
|
|
}
|
1994-01-25 21:51:25 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-01-30 05:22:52 +00:00
|
|
|
|
EINTRLOOP (e, stat (file->name, &st));
|
|
|
|
|
if (e == 0
|
1994-01-25 21:51:25 +00:00
|
|
|
|
&& S_ISREG (st.st_mode)
|
2000-06-13 05:22:52 +00:00
|
|
|
|
&& FILE_TIMESTAMP_STAT_MODTIME (file->name, st) != file->last_mtime)
|
1994-01-25 21:51:25 +00:00
|
|
|
|
{
|
|
|
|
|
if (on_behalf_of)
|
2013-05-17 06:29:46 +00:00
|
|
|
|
error (NILF, _("*** [%s] Deleting file '%s'"), on_behalf_of, file->name);
|
1994-01-25 21:51:25 +00:00
|
|
|
|
else
|
2013-05-17 06:29:46 +00:00
|
|
|
|
error (NILF, _("*** Deleting file '%s'"), file->name);
|
1995-09-09 10:32:56 +00:00
|
|
|
|
if (unlink (file->name) < 0
|
2013-05-17 06:29:46 +00:00
|
|
|
|
&& errno != ENOENT) /* It disappeared; so what. */
|
|
|
|
|
perror_with_name ("unlink: ", file->name);
|
1994-01-25 21:51:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1995-12-12 03:26:08 +00:00
|
|
|
|
|
1994-01-25 21:51:25 +00:00
|
|
|
|
|
1991-10-08 20:20:29 +00:00
|
|
|
|
/* Delete all non-precious targets of CHILD unless they were already deleted.
|
|
|
|
|
Set the flag in CHILD to say they've been deleted. */
|
|
|
|
|
|
|
|
|
|
void
|
2002-10-14 21:54:04 +00:00
|
|
|
|
delete_child_targets (struct child *child)
|
1991-10-08 20:20:29 +00:00
|
|
|
|
{
|
|
|
|
|
struct dep *d;
|
|
|
|
|
|
|
|
|
|
if (child->deleted)
|
|
|
|
|
return;
|
|
|
|
|
|
1994-01-25 21:51:25 +00:00
|
|
|
|
/* Delete the target file if it changed. */
|
2006-11-18 20:53:44 +00:00
|
|
|
|
delete_target (child->file, NULL);
|
1991-10-08 20:20:29 +00:00
|
|
|
|
|
2012-03-04 00:24:20 +00:00
|
|
|
|
/* Also remove any non-precious targets listed in the 'also_make' member. */
|
1991-10-08 20:20:29 +00:00
|
|
|
|
for (d = child->file->also_make; d != 0; d = d->next)
|
1994-01-25 21:51:25 +00:00
|
|
|
|
delete_target (d->file, child->file->name);
|
1991-10-08 20:20:29 +00:00
|
|
|
|
|
|
|
|
|
child->deleted = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Print out the commands in CMDS. */
|
|
|
|
|
|
|
|
|
|
void
|
2006-11-18 20:53:44 +00:00
|
|
|
|
print_commands (const struct commands *cmds)
|
1991-10-08 20:20:29 +00:00
|
|
|
|
{
|
2006-11-18 20:53:44 +00:00
|
|
|
|
const char *s;
|
1991-10-08 20:20:29 +00:00
|
|
|
|
|
2007-11-04 21:54:00 +00:00
|
|
|
|
fputs (_("# recipe to execute"), stdout);
|
1991-10-08 20:20:29 +00:00
|
|
|
|
|
1998-10-03 05:39:55 +00:00
|
|
|
|
if (cmds->fileinfo.filenm == 0)
|
1999-07-28 06:23:37 +00:00
|
|
|
|
puts (_(" (built-in):"));
|
1991-10-08 20:20:29 +00:00
|
|
|
|
else
|
2012-03-04 00:24:20 +00:00
|
|
|
|
printf (_(" (from '%s', line %lu):\n"),
|
1998-10-03 05:39:55 +00:00
|
|
|
|
cmds->fileinfo.filenm, cmds->fileinfo.lineno);
|
1991-10-08 20:20:29 +00:00
|
|
|
|
|
|
|
|
|
s = cmds->commands;
|
|
|
|
|
while (*s != '\0')
|
|
|
|
|
{
|
2006-11-18 20:53:44 +00:00
|
|
|
|
const char *end;
|
2010-11-06 21:56:23 +00:00
|
|
|
|
int bs;
|
1991-10-08 20:20:29 +00:00
|
|
|
|
|
2010-11-06 21:56:23 +00:00
|
|
|
|
/* Print one full logical recipe line: find a non-escaped newline. */
|
|
|
|
|
for (end = s, bs = 0; *end != '\0'; ++end)
|
|
|
|
|
{
|
|
|
|
|
if (*end == '\n' && !bs)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
bs = *end == '\\' ? !bs : 0;
|
|
|
|
|
}
|
1991-10-08 20:20:29 +00:00
|
|
|
|
|
2007-11-04 21:54:00 +00:00
|
|
|
|
printf ("%c%.*s\n", cmd_prefix, (int) (end - s), s);
|
1991-10-08 20:20:29 +00:00
|
|
|
|
|
2007-11-04 21:54:00 +00:00
|
|
|
|
s = end + (end[0] == '\n');
|
1991-10-08 20:20:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|