Print this page
make: be serial if 'make', parallel if 'dmake', and parallel if '-j' is specified either way

*** 38,47 **** --- 38,48 ---- #include <bsd/bsd.h> /* bsd_signal() */ #include <locale.h> /* setlocale() */ + #include <libgen.h> #include <mk/defs.h> #include <mksdmsi18n/mksdmsi18n.h> /* libmksdmsi18n_init() */ #include <mksh/macro.h> /* getvar() */ #include <mksh/misc.h> /* getmem(), setup_char_semantics() */
*** 80,91 **** #define MAKE_PREFIX NOCATGETS("/usr") #define LD_SUPPORT_ENV_VAR NOCATGETS("SGS_SUPPORT_32") #define LD_SUPPORT_ENV_VAR_32 NOCATGETS("SGS_SUPPORT_32") #define LD_SUPPORT_ENV_VAR_64 NOCATGETS("SGS_SUPPORT_64") #define LD_SUPPORT_MAKE_LIB NOCATGETS("libmakestate.so.1") ! #define LD_SUPPORT_MAKE_LIB_DIR NOCATGETS("/lib") ! #define LD_SUPPORT_MAKE_LIB_DIR_64 NOCATGETS("/64") /* * typedefs & structs */ --- 81,97 ---- #define MAKE_PREFIX NOCATGETS("/usr") #define LD_SUPPORT_ENV_VAR NOCATGETS("SGS_SUPPORT_32") #define LD_SUPPORT_ENV_VAR_32 NOCATGETS("SGS_SUPPORT_32") #define LD_SUPPORT_ENV_VAR_64 NOCATGETS("SGS_SUPPORT_64") #define LD_SUPPORT_MAKE_LIB NOCATGETS("libmakestate.so.1") ! #ifdef __i386 ! #define LD_SUPPORT_MAKE_ARCH NOCATGETS("i386") ! #elif __sparc ! #define LD_SUPPORT_MAKE_ARCH NOCATGETS("sparc") ! #else ! #error "Unsupported architecture" ! #endif /* * typedefs & structs */
*** 411,427 **** /* * Find the dmake_mode: parallel, or serial. */ if ((!pmake_cap_r_specified) && (!pmake_machinesfile_specified)) { MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_MODE")); dmake_name2 = GETNAME(wcs_buffer, FIND_LENGTH); prop2 = get_prop(dmake_name2->prop, macro_prop); ! if (prop2 == NULL) { ! /* DMAKE_MODE not defined, default to parallel mode */ dmake_mode_type = parallel_mode; no_parallel = false; } else { dmake_value2 = prop2->body.macro.value; if (IS_EQUAL(dmake_value2->string_mb, NOCATGETS("parallel"))) { dmake_mode_type = parallel_mode; no_parallel = false; --- 417,447 ---- /* * Find the dmake_mode: parallel, or serial. */ if ((!pmake_cap_r_specified) && (!pmake_machinesfile_specified)) { + char *s = strdup(argv[0]); + MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_MODE")); dmake_name2 = GETNAME(wcs_buffer, FIND_LENGTH); prop2 = get_prop(dmake_name2->prop, macro_prop); ! // If we're invoked as 'make' run serially, regardless of DMAKE_MODE ! // If we're invoked as 'make' but passed -j, run parallel ! // If we're invoked as 'dmake', without DMAKE_MODE, default parallel ! // If we're invoked as 'dmake' and DMAKE_MODE is set, honour it. ! if ((strcmp(basename(s), NOCATGETS("make")) == 0) && ! !dmake_max_jobs_specified) { ! dmake_mode_type = serial_mode; ! no_parallel = true; ! } else if (prop2 == NULL) { ! /* DMAKE_MODE not defined, default based on our name */ ! char *s = strdup(argv[0]); ! ! if (strcmp(basename(s), NOCATGETS("dmake")) == 0) { dmake_mode_type = parallel_mode; no_parallel = false; + } } else { dmake_value2 = prop2->body.macro.value; if (IS_EQUAL(dmake_value2->string_mb, NOCATGETS("parallel"))) { dmake_mode_type = parallel_mode; no_parallel = false;
*** 430,440 **** no_parallel = true; } else { fatal(catgets(catd, 1, 307, "Unknown dmake mode argument `%s' after -m flag"), dmake_value2->string_mb); } } ! } parallel_flag = true; putenv(strdup(NOCATGETS("DMAKE_CHILD=TRUE"))); --- 450,460 ---- no_parallel = true; } else { fatal(catgets(catd, 1, 307, "Unknown dmake mode argument `%s' after -m flag"), dmake_value2->string_mb); } } ! free(s); } parallel_flag = true; putenv(strdup(NOCATGETS("DMAKE_CHILD=TRUE")));
*** 1361,1370 **** --- 1381,1392 ---- return 0; case 'j': /* Use alternative DMake max jobs */ if (invert_this) { dmake_max_jobs_specified = false; } else { + dmake_mode_type = parallel_mode; + no_parallel = false; dmake_max_jobs_specified = true; } return 8; case 'K': /* Read alternative .make.state */ return 256;
*** 1597,1606 **** --- 1619,1672 ---- } } } } + char * + make_install_prefix(void) + { + int ret; + char origin[PATH_MAX]; + char *dir; + + if ((ret = readlink("/proc/self/path/a.out", origin, + PATH_MAX - 1)) < 0) + fatal("failed to read origin from /proc\n"); + + + origin[ret] = '\0'; + return strdup(dirname(origin)); + } + + static char * + add_to_env(const char *var, const char *value, const char *fallback) + { + const char *oldpath; + char *newpath; + + oldpath = getenv(var); + if (oldpath == NULL) { + if (value != NULL) { + asprintf(&newpath, "%s=%s", + var, value); + } else { + asprintf(&newpath, "%s=%s", + var, fallback); + } + } else { + if (value != NULL) { + asprintf(&newpath, "%s=%s:%s", + var, oldpath, value); + } else { + asprintf(&newpath, "%s=%s:%s", + var, oldpath, fallback); + } + } + + return (newpath); + } + /* * set_sgs_support() * * Add the libmakestate.so.1 lib to the env var SGS_SUPPORT * if it's not already in there.
*** 1616,1675 **** static void set_sgs_support() { int len; char *newpath, *newpath64; ! char *oldpath, *oldpath64; static char *prev_path, *prev_path64; ! oldpath = getenv(LD_SUPPORT_ENV_VAR_32); ! if (oldpath == NULL) { ! len = snprintf(NULL, 0, "%s=%s/%s/%s:%s", ! LD_SUPPORT_ENV_VAR_32, ! MAKE_PREFIX, ! LD_SUPPORT_MAKE_LIB_DIR, ! LD_SUPPORT_MAKE_LIB, LD_SUPPORT_MAKE_LIB) + 1; ! newpath = (char *) malloc(len); ! sprintf(newpath, "%s=%s/%s/%s:%s", ! LD_SUPPORT_ENV_VAR_32, ! MAKE_PREFIX, ! LD_SUPPORT_MAKE_LIB_DIR, ! LD_SUPPORT_MAKE_LIB, LD_SUPPORT_MAKE_LIB); ! } else { ! len = snprintf(NULL, 0, "%s=%s:%s/%s/%s:%s", ! LD_SUPPORT_ENV_VAR_32, oldpath, MAKE_PREFIX, ! LD_SUPPORT_MAKE_LIB_DIR, LD_SUPPORT_MAKE_LIB, ! LD_SUPPORT_MAKE_LIB) + 1; ! newpath = (char *) malloc(len); ! sprintf(newpath, "%s=%s:%s/%s/%s:%s", ! LD_SUPPORT_ENV_VAR_32, oldpath, MAKE_PREFIX, ! LD_SUPPORT_MAKE_LIB_DIR, LD_SUPPORT_MAKE_LIB, LD_SUPPORT_MAKE_LIB); } ! oldpath64 = getenv(LD_SUPPORT_ENV_VAR_64); ! if (oldpath64 == NULL) { ! len = snprintf(NULL, 0, "%s=%s/%s/%s/%s:%s", ! LD_SUPPORT_ENV_VAR_64, MAKE_PREFIX, LD_SUPPORT_MAKE_LIB_DIR, ! LD_SUPPORT_MAKE_LIB_DIR_64, LD_SUPPORT_MAKE_LIB, ! LD_SUPPORT_MAKE_LIB) + 1; ! newpath64 = (char *) malloc(len); ! sprintf(newpath64, "%s=%s/%s/%s/%s:%s", ! LD_SUPPORT_ENV_VAR_64, MAKE_PREFIX, LD_SUPPORT_MAKE_LIB_DIR, ! LD_SUPPORT_MAKE_LIB_DIR_64, LD_SUPPORT_MAKE_LIB, LD_SUPPORT_MAKE_LIB); ! } else { ! len = snprintf(NULL, 0, "%s=%s:%s/%s/%s/%s:%s", ! LD_SUPPORT_ENV_VAR_64, oldpath64, MAKE_PREFIX, ! LD_SUPPORT_MAKE_LIB_DIR, LD_SUPPORT_MAKE_LIB_DIR_64, ! LD_SUPPORT_MAKE_LIB, LD_SUPPORT_MAKE_LIB) + 1; ! newpath64 = (char *) malloc(len); ! sprintf(newpath64, "%s=%s:%s/%s/%s/%s:%s", ! LD_SUPPORT_ENV_VAR_64, oldpath64, MAKE_PREFIX, ! LD_SUPPORT_MAKE_LIB_DIR, LD_SUPPORT_MAKE_LIB_DIR_64, ! LD_SUPPORT_MAKE_LIB, LD_SUPPORT_MAKE_LIB); } putenv(newpath); if (prev_path) { free(prev_path); } --- 1682,1728 ---- static void set_sgs_support() { int len; char *newpath, *newpath64; ! char *lib32, *lib64; static char *prev_path, *prev_path64; + char *origin = make_install_prefix(); + struct stat st; ! asprintf(&lib32, "%s/%s/%s", origin, "../lib", LD_SUPPORT_MAKE_LIB); + + if (stat(lib32, &st) != 0) { + free(lib32); + // Try the tools path + asprintf(&lib32, "%s/%s/%s/%s", origin, "../../lib/", + LD_SUPPORT_MAKE_ARCH, LD_SUPPORT_MAKE_LIB); + + if (stat(lib32, &st) != 0) { + free(lib32); + lib32 = NULL; + } } ! asprintf(&lib64, "%s/%s/64/%s", origin, "../lib", LD_SUPPORT_MAKE_LIB); ! ! if (stat(lib64, &st) != 0) { ! free(lib64); ! // Try the tools path ! asprintf(&lib64, "%s/%s/%s/64/%s", origin, "../../lib/", ! LD_SUPPORT_MAKE_ARCH, LD_SUPPORT_MAKE_LIB); ! ! if (stat(lib64, &st) != 0) { ! free(lib64); ! lib64 = NULL; } + } + + newpath = add_to_env(LD_SUPPORT_ENV_VAR_32, lib32, LD_SUPPORT_MAKE_LIB); + newpath64 = add_to_env(LD_SUPPORT_ENV_VAR_64, lib64, LD_SUPPORT_MAKE_LIB); putenv(newpath); if (prev_path) { free(prev_path); }
*** 1678,1687 **** --- 1731,1743 ---- putenv(newpath64); if (prev_path64) { free(prev_path64); } prev_path64 = newpath64; + free(lib32); + free(lib64); + free(origin); } /* * read_files_and_state(argc, argv) *