+ struct stat sb;
+ char *path, *getenv();
+
+ /*
+ * if the MAKEOBJDIR (or by default, the _PATH_OBJDIR) directory
+ * exists, change into it and build there. Once things are
+ * initted, have to add the original directory to the search path,
+ * and modify the paths for the Makefiles apropriately. The
+ * current directory is also placed as a variable for make scripts.
+ */
+ if (!(path = getenv("MAKEOBJDIR")))
+ path = _PATH_OBJDIR;
+ if (!lstat(path, &sb)) {
+ if (S_ISDIR(sb.st_mode))
+ curdir = "..";
+ else {
+ curdir = emalloc((u_int)MAXPATHLEN + 1);
+ if (!getwd(curdir)) {
+ (void)fprintf(stderr, "make: %s.\n", curdir);
+ exit(2);
+ }
+ }
+ if (chdir(path)) {
+ extern int errno;
+
+ (void)fprintf(stderr, "make: %s: %s.\n",
+ path, strerror(errno));
+ exit(2);
+ }
+ }