# define LD_LIBRARY_PATH_LOCAL "DYLD_FALLBACK_LIBRARY_PATH"
#endif
-#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
+#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || (defined(__sun) && defined(__GNUC__))
# define SHELL_CMD "/bin/sh"
# define DYNAMIC_LIB_EXT "so"
# define MODULE_LIB_EXT "so"
# define SHARED_OPTS "-shared"
# define MODULE_OPTS "-shared"
# define LINKER_FLAG_PREFIX "-Wl,"
+#if !defined(__sun)
# define DYNAMIC_LINK_OPTS LINKER_FLAG_PREFIX "-export-dynamic"
+#else
+# define DYNAMIC_LINK_OPTS ""
+#endif
# define ADD_MINUS_L
# define LD_RUN_PATH "LD_RUN_PATH"
# define LD_LIBRARY_PATH "LD_LIBRARY_PATH"
# define LD_LIBRARY_PATH_LOCAL LD_LIBRARY_PATH
#endif
-#if defined(sun)
+#if defined(__sun) && !defined(__GNUC__)
# define SHELL_CMD "/bin/sh"
# define DYNAMIC_LIB_EXT "so"
# define MODULE_LIB_EXT "so"
# define LIBRARIAN "ar"
# define LIBRARIAN_OPTS "cr"
# define RANLIB "ranlib"
-# define PIC_FLAG "-KPIC"
+# define PIC_FLAG "-fPIC"
# define RPATH "-R"
# define SHARED_OPTS "-G"
# define MODULE_OPTS "-G"
va_list ap;
int res;
- va_start( ap, fmt );
- res = vsnprintf( str, n, fmt, ap );
- va_end( ap );
+ va_start(ap, fmt);
+ res = vsnprintf(str, n, fmt, ap);
+ va_end(ap);
return res;
}
#endif
cc->num = 0;
}
-static count_chars *alloc_countchars()
+static count_chars *alloc_countchars(void)
{
count_chars *out;
out = lt_malloc(sizeof(count_chars));
cc->vals[cc->num++] = newval;
}
-static void pop_count_chars(count_chars *cc)
+static char const *pop_count_chars(count_chars *cc)
{
- cc->num--;
+ if (!cc->num) {
+ return NULL;
+ }
+ return cc->vals[--cc->num];
}
static void insert_count_chars(count_chars *cc, char const *newval, int position)
}
}
-static char const *flatten_count_chars(count_chars *cc, int space)
+static char const *flatten_count_chars(count_chars *cc, char delim)
{
int i, size;
char *newval;
for (i = 0; i < cc->num; i++) {
if (cc->vals[i]) {
size += strlen(cc->vals[i]) + 1;
- if (space) {
- size++;
+ if (delim) {
+ size++;
}
}
}
newval = (char*)lt_malloc(size + 1);
- newval[0] = 0;
+ newval[0] = '\0';
for (i = 0; i < cc->num; i++) {
if (cc->vals[i]) {
strcat(newval, cc->vals[i]);
- if (space) {
- strcat(newval, " ");
+ if (delim) {
+ size_t len = strlen(newval);
+ newval[len] = delim;
+ newval[len + 1] = '\0';
}
}
}
return execvp(argv[0], (char**)argv);
}
else {
- int statuscode;
- waitpid(pid, &statuscode, 0);
- if (WIFEXITED(statuscode)) {
- return WEXITSTATUS(statuscode);
+ int status;
+ waitpid(pid, &status, 0);
+
+ /*
+ * Exited via exit(status)
+ */
+ if (WIFEXITED(status)) {
+ return WEXITSTATUS(status);
}
- return 0;
+
+#ifdef WTERMSIG
+ if (WIFSIGNALED(status)) {
+ return WTERMSIG(status);
+ }
+#endif
+
+ /*
+ * Some other failure.
+ */
+ return 1;
}
}
#endif
append_count_chars(&tmpcc, cc);
- raw = flatten_count_chars(&tmpcc, 1);
+ raw = flatten_count_chars(&tmpcc, ' ');
command = shell_esc(raw);
memcpy(&tmp, &raw, sizeof(tmp));
if (equal_pos) {
strncpy(var, arg, equal_pos - arg);
var[equal_pos - arg] = 0;
- if (strlen(equal_pos + 1) >= sizeof(var)) return 0;
+ if (strlen(equal_pos + 1) >= sizeof(var)) {
+ return 0;
+ }
strcpy(value, equal_pos + 1);
} else {
strncpy(var, arg, sizeof(var) - 1);
var[sizeof(var) - 1] = '\0';
- value[0] = '\0';
+ value[0] = '\0';
}
if (strcmp(var, "silent") == 0) {
* 1 - .libs suffix
*/
static char *check_library_exists(command_t *cmd, char const *arg, int pathlen,
- int libdircheck, enum lib_type*libtype)
+ int libdircheck, enum lib_type *libtype)
{
char *newarg, *ext;
int pass, rv, newpathlen;
return path;
}
-static char * load_noinstall_path(char const *arg, int pathlen)
+static char *load_noinstall_path(char const *arg, int pathlen)
{
char *newarg, *expanded_path;
int newpathlen;
char const *name;
char const *ext;
char *newarg = NULL;
- int pathlen;
+ size_t pathlen;
cmd->fake_output_name = arg;
strcpy(libpath, cmd->arglist->vals[0]);
add_dotlibs(libpath);
- l = strrchr(libpath, '/');
- if (!l) l = strrchr(libpath, '\\');
- if (l) {
- *l = '\0';
- l = libpath;
- } else {
- l = ".libs/";
- }
+ l = strrchr(libpath, '/');
+ if (!l) l = strrchr(libpath, '\\');
+ if (l) {
+ *l = '\0';
+ l = libpath;
+ } else {
+ l = ".libs/";
+ }
- l = "./build/lib/.libs";
- setenv(LD_LIBRARY_PATH_LOCAL, l, 1);
- rv = run_command(cmd, cmd->arglist);
+ l = "./build/lib/.libs";
+ setenv(LD_LIBRARY_PATH_LOCAL, l, 1);
+#ifdef __APPLE__
+ setenv("DYLD_FALLBACK_LIBRARY_PATH", l, 1);
+#endif
+ setenv("FR_LIBRARY_PATH", "./build/lib/local/.libs", 1);
+ rv = run_command(cmd, cmd->arglist);
if (rv) goto finish;
}
- break;
+ break;
default:
break;
arg = argv[a];
arg_used = 1;
+ if (cmd->mode == MODE_EXECUTE) {
+ push_count_chars(cmd->arglist, arg);
+ continue;
+ }
+
if (arg[0] == '-') {
/*
* Double dashed (long) single dash (short)
if (arg_used) continue;
/*
+ * Ignore all options after the '--execute'
+ */
+ if (cmd->mode == MODE_EXECUTE) continue;
+
+ /*
* We haven't done anything with it yet, but
* there are still some arg/value pairs.
*