version 1.101, 2013/07/07 09:41:08 |
version 1.102, 2013/11/24 12:36:13 |
|
|
static char *figure_out_MACHINE_CPU(void); |
static char *figure_out_MACHINE_CPU(void); |
|
|
static char *chdir_verify_path(const char *, struct dirs *); |
static char *chdir_verify_path(const char *, struct dirs *); |
static char *concat_verify(const char *, const char *, char, struct dirs *); |
|
static char *figure_out_CURDIR(void); |
static char *figure_out_CURDIR(void); |
static void setup_CURDIR_OBJDIR(struct dirs *, const char *); |
static void setup_CURDIR_OBJDIR(struct dirs *, const char *); |
|
|
|
|
static char * |
static char * |
chdir_verify_path(const char *path, struct dirs *d) |
chdir_verify_path(const char *path, struct dirs *d) |
{ |
{ |
struct stat sb; |
if (chdir(path) == 0) { |
|
if (path[0] != '/') |
if (stat(path, &sb) == 0 && S_ISDIR(sb.st_mode)) { |
return Str_concat(d->current, path, '/'); |
if (chdir(path)) { |
else |
(void)fprintf(stderr, "make warning: %s: %s.\n", |
return estrdup(path); |
path, strerror(errno)); |
|
return NULL; |
|
} else { |
|
if (path[0] != '/') |
|
return Str_concat(d->current, path, '/'); |
|
else |
|
return estrdup(path); |
|
} |
|
} |
} |
|
|
return NULL; |
return NULL; |
} |
} |
|
|
static char * |
|
concat_verify(const char *p1, const char *p2, char c, struct dirs *d) |
|
{ |
|
char *tmp = Str_concat(p1, p2, c); |
|
char *result = chdir_verify_path(tmp, d); |
|
free(tmp); |
|
return result; |
|
} |
|
|
|
static void |
static void |
setup_CURDIR_OBJDIR(struct dirs *d, const char *machine) |
setup_CURDIR_OBJDIR(struct dirs *d, const char *machine) |
{ |
{ |
char *path, *prefix; |
char *path, *prefix; |
|
|
d->current = figure_out_CURDIR(); |
d->current = figure_out_CURDIR(); |
d->object = NULL; |
|
/* |
/* |
* If the MAKEOBJDIR (or by default, the _PATH_OBJDIR) directory |
* If the MAKEOBJDIR (or by default, the _PATH_OBJDIR) directory |
* exists, change into it and build there. (If a .${MACHINE} suffix |
* exists, change into it and build there. |
* exists, use that directory instead). |
|
* Otherwise check MAKEOBJDIRPREFIX`cwd` (or by default, |
|
* _PATH_OBJDIRPREFIX`cwd`) and build there if it exists. |
|
* If all fails, use the current directory to build. |
|
* |
* |
* Once things are initted, |
* Once things are initted, |
* have to add the original directory to the search path, |
* have to add the original directory to the search path, |
* and modify the paths for the Makefiles appropriately. The |
* and modify the paths for the Makefiles appropriately. The |
* current directory is also placed as a variable for make scripts. |
* current directory is also placed as a variable for make scripts. |
*/ |
*/ |
if ((prefix = getenv("MAKEOBJDIRPREFIX")) != NULL) { |
if ((path = getenv("MAKEOBJDIR")) == NULL) { |
d->object = concat_verify(prefix, d->current, 0, d); |
|
} else if ((path = getenv("MAKEOBJDIR")) != NULL) { |
|
d->object = chdir_verify_path(path, d); |
|
} else { |
|
path = _PATH_OBJDIR; |
path = _PATH_OBJDIR; |
prefix = _PATH_OBJDIRPREFIX; |
} |
d->object = concat_verify(path, machine, '.', d); |
d->object = chdir_verify_path(path, d); |
if (!d->object) |
|
d->object=chdir_verify_path(path, d); |
|
if (!d->object) |
|
d->object = concat_verify(prefix, d->current, 0, d); |
|
} |
|
if (d->object == NULL) |
if (d->object == NULL) |
d->object = d->current; |
d->object = d->current; |
} |
} |