version 1.1, 1995/10/18 08:45:42 |
version 1.2, 1995/12/14 03:23:33 |
|
|
/* $NetBSD: main.c,v 1.20 1995/09/27 18:42:21 jtc Exp $ */ |
/* $NetBSD: main.c,v 1.23 1995/11/22 17:40:14 christos Exp $ */ |
|
|
/* |
/* |
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California. |
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California. |
|
|
#if 0 |
#if 0 |
static char sccsid[] = "@(#)main.c 5.25 (Berkeley) 4/1/91"; |
static char sccsid[] = "@(#)main.c 5.25 (Berkeley) 4/1/91"; |
#else |
#else |
static char rcsid[] = "$NetBSD: main.c,v 1.20 1995/09/27 18:42:21 jtc Exp $"; |
static char rcsid[] = "$NetBSD: main.c,v 1.23 1995/11/22 17:40:14 christos Exp $"; |
#endif |
#endif |
#endif /* not lint */ |
#endif /* not lint */ |
|
|
|
|
#include <sys/time.h> |
#include <sys/time.h> |
#include <sys/param.h> |
#include <sys/param.h> |
#include <sys/resource.h> |
#include <sys/resource.h> |
|
#include <sys/signal.h> |
#include <sys/stat.h> |
#include <sys/stat.h> |
#include <sys/utsname.h> |
#include <sys/utsname.h> |
|
#include <sys/resource.h> |
#include <errno.h> |
#include <errno.h> |
#include <fcntl.h> |
#include <fcntl.h> |
#include <signal.h> |
|
#include <stdio.h> |
#include <stdio.h> |
#if __STDC__ |
#if __STDC__ |
#include <stdarg.h> |
#include <stdarg.h> |
|
|
|
|
static Boolean noBuiltins; /* -r flag */ |
static Boolean noBuiltins; /* -r flag */ |
static Lst makefiles; /* ordered list of makefiles to read */ |
static Lst makefiles; /* ordered list of makefiles to read */ |
int maxJobs; /* -J argument */ |
int maxJobs; /* -j argument */ |
static int maxLocal; /* -L argument */ |
static int maxLocal; /* -L argument */ |
Boolean compatMake; /* -B argument */ |
Boolean compatMake; /* -B argument */ |
Boolean debug; /* -d flag */ |
Boolean debug; /* -d flag */ |
|
|
extern int optind; |
extern int optind; |
extern char *optarg; |
extern char *optarg; |
int c; |
int c; |
|
int forceJobs = 0; |
|
|
optind = 1; /* since we're called more than once */ |
optind = 1; /* since we're called more than once */ |
#ifdef notyet |
#ifdef REMOTE |
# define OPTFLAGS "BD:I:L:PSd:ef:ij:knqrst" |
# define OPTFLAGS "BD:I:L:PSd:ef:ij:knqrst" |
#else |
#else |
# define OPTFLAGS "D:I:d:ef:ij:knqrst" |
# define OPTFLAGS "BD:I:PSd:ef:ij:knqrst" |
#endif |
#endif |
rearg: while((c = getopt(argc, argv, OPTFLAGS)) != EOF) { |
rearg: while((c = getopt(argc, argv, OPTFLAGS)) != EOF) { |
switch(c) { |
switch(c) { |
|
|
Var_Append(MAKEFLAGS, "-I", VAR_GLOBAL); |
Var_Append(MAKEFLAGS, "-I", VAR_GLOBAL); |
Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL); |
Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL); |
break; |
break; |
#ifdef notyet |
|
case 'B': |
case 'B': |
compatMake = TRUE; |
compatMake = TRUE; |
break; |
break; |
|
#ifdef REMOTE |
case 'L': |
case 'L': |
maxLocal = atoi(optarg); |
maxLocal = atoi(optarg); |
Var_Append(MAKEFLAGS, "-L", VAR_GLOBAL); |
Var_Append(MAKEFLAGS, "-L", VAR_GLOBAL); |
Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL); |
Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL); |
break; |
break; |
|
#endif |
case 'P': |
case 'P': |
usePipes = FALSE; |
usePipes = FALSE; |
Var_Append(MAKEFLAGS, "-P", VAR_GLOBAL); |
Var_Append(MAKEFLAGS, "-P", VAR_GLOBAL); |
|
|
keepgoing = FALSE; |
keepgoing = FALSE; |
Var_Append(MAKEFLAGS, "-S", VAR_GLOBAL); |
Var_Append(MAKEFLAGS, "-S", VAR_GLOBAL); |
break; |
break; |
#endif |
|
case 'd': { |
case 'd': { |
char *modules = optarg; |
char *modules = optarg; |
|
|
|
|
Var_Append(MAKEFLAGS, "-i", VAR_GLOBAL); |
Var_Append(MAKEFLAGS, "-i", VAR_GLOBAL); |
break; |
break; |
case 'j': |
case 'j': |
|
forceJobs = TRUE; |
maxJobs = atoi(optarg); |
maxJobs = atoi(optarg); |
|
#ifndef REMOTE |
|
maxLocal = maxJobs; |
|
#endif |
Var_Append(MAKEFLAGS, "-j", VAR_GLOBAL); |
Var_Append(MAKEFLAGS, "-j", VAR_GLOBAL); |
Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL); |
Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL); |
break; |
break; |
|
|
} |
} |
} |
} |
|
|
|
/* |
|
* Be compatible if user did not specify -j and did not explicitly |
|
* turned compatibility on |
|
*/ |
|
if (!compatMake && !forceJobs) |
|
compatMake = TRUE; |
|
|
oldVars = TRUE; |
oldVars = TRUE; |
|
|
/* |
/* |
|
|
struct utsname utsname; |
struct utsname utsname; |
char *machine = getenv("MACHINE"); |
char *machine = getenv("MACHINE"); |
|
|
|
#ifdef RLIMIT_NOFILE |
/* |
/* |
|
* get rid of resource limit on file descriptors |
|
*/ |
|
{ |
|
struct rlimit rl; |
|
if (getrlimit(RLIMIT_NOFILE, &rl) != -1 && |
|
rl.rlim_cur != rl.rlim_max) { |
|
rl.rlim_cur = rl.rlim_max; |
|
(void) setrlimit(RLIMIT_NOFILE, &rl); |
|
} |
|
} |
|
#endif |
|
/* |
* Find where we are and take care of PWD for the automounter... |
* Find where we are and take care of PWD for the automounter... |
* All this code is so that we know where we are when we start up |
* All this code is so that we know where we are when we start up |
* on a different machine with pmake. |
* on a different machine with pmake. |
|
|
* MACHINE_ARCH is always known at compile time. |
* MACHINE_ARCH is always known at compile time. |
*/ |
*/ |
if (!machine) { |
if (!machine) { |
if (uname(&utsname)) { |
if (uname(&utsname) == -1) { |
perror("make: uname"); |
perror("make: uname"); |
exit(2); |
exit(2); |
} |
} |
|
|
debug = 0; /* No debug verbosity, please. */ |
debug = 0; /* No debug verbosity, please. */ |
jobsRunning = FALSE; |
jobsRunning = FALSE; |
|
|
maxJobs = DEFMAXJOBS; /* Set default max concurrency */ |
|
maxLocal = DEFMAXLOCAL; /* Set default local max concurrency */ |
maxLocal = DEFMAXLOCAL; /* Set default local max concurrency */ |
#ifdef notyet |
#ifdef REMOTE |
compatMake = FALSE; /* No compat mode */ |
maxJobs = DEFMAXJOBS; /* Set default max concurrency */ |
#else |
#else |
compatMake = TRUE; /* No compat mode */ |
maxJobs = maxLocal; |
#endif |
#endif |
|
compatMake = FALSE; /* No compat mode */ |
|
|
|
|
/* |
/* |
|
|
else |
else |
targs = Targ_FindList(create, TARG_CREATE); |
targs = Targ_FindList(create, TARG_CREATE); |
|
|
/* |
|
* this was original amMake -- want to allow parallelism, so put this |
|
* back in, eventually. |
|
*/ |
|
if (!compatMake) { |
if (!compatMake) { |
/* |
/* |
* Initialize job module before traversing the graph, now that |
* Initialize job module before traversing the graph, now that |
|
|
{ |
{ |
(void)fprintf(stderr, "make: %s.\n", strerror(errno)); |
(void)fprintf(stderr, "make: %s.\n", strerror(errno)); |
exit(2); |
exit(2); |
|
} |
|
|
|
/* |
|
* enunlink -- |
|
* Remove a file carefully, avoiding directories. |
|
*/ |
|
int |
|
eunlink(file) |
|
const char *file; |
|
{ |
|
struct stat st; |
|
|
|
if (lstat(file, &st) == -1) |
|
return -1; |
|
|
|
if (S_ISDIR(st.st_mode)) { |
|
errno = EISDIR; |
|
return -1; |
|
} |
|
return unlink(file); |
} |
} |
|
|
/* |
/* |