You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by je...@apache.org on 2007/02/01 13:30:18 UTC

svn commit: r502202 - /apr/apr/trunk/build/jlibtool.c

Author: jerenkrantz
Date: Thu Feb  1 04:30:17 2007
New Revision: 502202

URL: http://svn.apache.org/viewvc?view=rev&rev=502202
Log:
Have jlibtool match GNU libtool's behavior when creating a static library that
links against another static library by importing all objects into the new
static library.  Part of this functionality was there, but it was dormant.
Also avoid 'touch'ing a file when we don't want a fake output name.

* build/jlibtool.c
  (pop_count_chars): Make it easy to reduce the number of vals.
  (flatten_count_chars): Make the insertion of the space optional.
  (run_command): Update flatten_count_chars.
  (safe_mkdir): Factor out our mkdir sequence.
  (jlibtool_basename, nameof): Move earlier in file.
  (explode_static_lib): Move earlier and rewrite it so it works.
  (parse_input_file_name): Explode the static lib if we're creating a library.
  (run_mode): Call safe_mkdir.
  (ensure_fake_uptodate): If we don't have a fake output name specified,
  don't call touch.

Modified:
    apr/apr/trunk/build/jlibtool.c

Modified: apr/apr/trunk/build/jlibtool.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/build/jlibtool.c?view=diff&rev=502202&r1=502201&r2=502202
==============================================================================
--- apr/apr/trunk/build/jlibtool.c (original)
+++ apr/apr/trunk/build/jlibtool.c Thu Feb  1 04:30:17 2007
@@ -341,6 +341,11 @@
     cc->vals[cc->num++] = newval;
 }
 
+void pop_count_chars(count_chars *cc)
+{
+    cc->num--;
+}
+
 void insert_count_chars(count_chars *cc, const char *newval, int position)
 {
     int i;
@@ -363,7 +368,7 @@
     }
 }
 
-const char *flatten_count_chars(count_chars *cc)
+const char *flatten_count_chars(count_chars *cc, int space)
 {
     int i, size;
     char *newval;
@@ -372,6 +377,9 @@
     for (i = 0; i < cc->num; i++) {
         if (cc->vals[i]) {
             size += strlen(cc->vals[i]) + 1;
+            if (space) {
+              size++;
+            }
         }
     }
 
@@ -381,7 +389,9 @@
     for (i = 0; i < cc->num; i++) {
         if (cc->vals[i]) {
             strcat(newval, cc->vals[i]);
-            strcat(newval, " ");
+            if (space) {
+                strcat(newval, " ");
+            }
         }
     }
 
@@ -474,7 +484,7 @@
 
     append_count_chars(&tmpcc, cc);
 
-    command = shell_esc(flatten_count_chars(&tmpcc));
+    command = shell_esc(flatten_count_chars(&tmpcc, 1));
 
     spawn_args[0] = SHELL_CMD;
     spawn_args[1] = "-c";
@@ -665,6 +675,20 @@
     return rv; 
 }
 
+void safe_mkdir(const char *path)
+{
+    mode_t old_umask;
+
+    old_umask = umask(0);
+    umask(old_umask);
+
+#ifdef MKDIR_NO_UMASK
+    mkdir(path);
+#else
+    mkdir(path, ~old_umask);
+#endif
+}
+
 /* version_info is in the form of MAJOR:MINOR:PATCH */
 const char *darwin_dynamic_link_function(const char *version_info)
 {
@@ -1106,6 +1130,119 @@
 #endif
 }
 
+/* returns just a file's name without the path */
+const char *jlibtool_basename(const char *fullpath)
+{
+    const char *name = strrchr(fullpath, '/');
+
+    if (name == NULL) {
+        name = strrchr(fullpath, '\\');
+    }
+
+    if (name == NULL) {
+        name = fullpath;
+    } else {
+        name++;
+    }
+
+    return name;
+}
+
+/* returns just a file's name without path or extension */
+const char *nameof(const char *fullpath)
+{
+    const char *name;
+    const char *ext;
+
+    name = jlibtool_basename(fullpath);
+    ext = strrchr(name, '.');
+
+    if (ext) {
+        char *trimmed;
+        trimmed = malloc(ext - name + 1);
+        strncpy(trimmed, name, ext - name);
+        trimmed[ext-name] = 0;
+        return trimmed;
+    }
+
+    return name;
+}
+
+int explode_static_lib(command_t *cmd_data, const char *lib)
+{
+    count_chars tmpdir_cc, libname_cc;
+    const char *tmpdir, *libname;
+    char savewd[PATH_MAX];
+    const char *name;
+    DIR *dir;
+    struct dirent *entry;
+    const char *lib_args[4];
+
+    /* Bah! */
+    if (cmd_data->options.dry_run) {
+        return 0;
+    }
+
+    name = jlibtool_basename(lib);
+
+    init_count_chars(&tmpdir_cc);
+    push_count_chars(&tmpdir_cc, ".libs/");
+    push_count_chars(&tmpdir_cc, name);
+    push_count_chars(&tmpdir_cc, ".exploded/");
+    tmpdir = flatten_count_chars(&tmpdir_cc, 0);
+
+    if (!cmd_data->options.silent) {
+        printf("Making: %s\n", tmpdir);
+    }
+    safe_mkdir(tmpdir);
+
+    push_count_chars(cmd_data->tmp_dirs, tmpdir);
+
+    getcwd(savewd, sizeof(savewd));
+
+    if (chdir(tmpdir) != 0) {
+        if (!cmd_data->options.silent) {
+            printf("Warning: could not explode %s\n", lib);
+        }
+        return 1;
+    }
+
+    if (lib[0] == '/') {
+        libname = lib;
+    }
+    else {
+        init_count_chars(&libname_cc);
+        push_count_chars(&libname_cc, "../../");
+        push_count_chars(&libname_cc, lib);
+        libname = flatten_count_chars(&libname_cc, 0);
+    }
+
+    lib_args[0] = LIBRARIAN;
+    lib_args[1] = "x";
+    lib_args[2] = libname;
+    lib_args[3] = NULL;
+
+    external_spawn(cmd_data, LIBRARIAN, lib_args);
+
+    chdir(savewd);
+    dir = opendir(tmpdir);
+
+    while ((entry = readdir(dir)) != NULL) {
+        if (entry->d_name[0] != '.') {
+            push_count_chars(&tmpdir_cc, entry->d_name);
+            name = flatten_count_chars(&tmpdir_cc, 0);
+            if (!cmd_data->options.silent) {
+                printf("Adding: %s\n", name);
+            }
+            push_count_chars(cmd_data->obj_files, name);
+            pop_count_chars(&tmpdir_cc);
+        }
+    }
+
+    closedir(dir);
+    return 0;
+}
+
 int parse_input_file_name(char *arg, command_t *cmd_data)
 {
     char *ext = strrchr(arg, '.');
@@ -1170,11 +1307,19 @@
 #ifdef ADD_MINUS_L
             if (libtype == type_DYNAMIC_LIB) {
                  add_minus_l(cmd_data->shared_opts.dependencies, newarg);
+            } else if (cmd_data->output == otLibrary &&
+                       libtype == type_STATIC_LIB) {
+                explode_static_lib(cmd_data, newarg);
             } else {
                  push_count_chars(cmd_data->shared_opts.dependencies, newarg);
             }
 #else
-            push_count_chars(cmd_data->shared_opts.dependencies, newarg);
+            if (cmd_data->output == otLibrary && libtype == type_STATIC_LIB) {
+                explode_static_lib(cmd_data, newarg);
+            }
+            else {
+                push_count_chars(cmd_data->shared_opts.dependencies, newarg);
+            }
 #endif
             if (libtype == type_DYNAMIC_LIB) {
                 if (cmd_data->options.no_install) {
@@ -1327,44 +1472,6 @@
     return 0;
 }
 
-/* returns just a file's name without the path */
-const char *jlibtool_basename(const char *fullpath)
-{
-    const char *name = strrchr(fullpath, '/');
-
-    if (name == NULL) {
-        name = strrchr(fullpath, '\\');
-    }
-
-    if (name == NULL) {
-        name = fullpath;
-    } else {
-        name++;
-    }
-
-    return name;
-}
-
-/* returns just a file's name without path or extension */
-const char *nameof(const char *fullpath)
-{
-    const char *name;
-    const char *ext;
-
-    name = jlibtool_basename(fullpath);
-    ext = strrchr(name, '.');
-
-    if (ext) {
-        char *trimmed;
-        trimmed = malloc(ext - name + 1);
-        strncpy(trimmed, name, ext - name);
-        trimmed[ext-name] = 0;
-        return trimmed;
-    }
-
-    return name;
-}
-
 void parse_args(int argc, char *argv[], command_t *cmd_data)
 {
     int a;
@@ -1435,62 +1542,6 @@
 
 }
 
-int explode_static_lib(const char *lib, command_t *cmd_data)
-{
-    char tmpdir[1024];
-    char savewd[1024];
-    char cmd[1024];
-    const char *name;
-    DIR *dir;
-    struct dirent *entry;
-
-    /* Bah! */
-    if (cmd_data->options.dry_run) {
-        return 0;
-    }
-
-    strcpy(tmpdir, lib);
-    strcat(tmpdir, ".exploded");
-
-#ifdef MKDIR_NO_UMASK
-    mkdir(tmpdir);
-#else
-    mkdir(tmpdir, 0);
-#endif
-    push_count_chars(cmd_data->tmp_dirs, strdup(tmpdir));
-    getcwd(savewd, sizeof(savewd));
-
-    if (chdir(tmpdir) != 0)
-        return 1;
-
-    strcpy(cmd, LIBRARIAN " x ");
-    name = strrchr(lib, '/');
-
-    if (name) {
-        name++;
-    } else {
-        name = lib;
-    }
-
-    strcat(cmd, "../");
-    strcat(cmd, name);
-    system(cmd);
-    chdir(savewd);
-    dir = opendir(tmpdir);
-
-    while ((entry = readdir(dir)) != NULL) {
-        if (entry->d_name[0] != '.') {
-            strcpy(cmd, tmpdir);
-            strcat(cmd, "/");
-            strcat(cmd, entry->d_name);
-            push_count_chars(cmd_data->arglist, strdup(cmd));
-        }
-    }
-
-    closedir(dir);
-    return 0;
-}
-
 #ifdef GEN_EXPORTS
 void generate_def_file(command_t *cmd_data)
 {
@@ -1788,16 +1839,7 @@
     case mLink:
         if (!cmd_data->options.dry_run) {
             /* Check first to see if the dir already exists! */
-            mode_t old_umask;
-
-            old_umask = umask(0);
-            umask(old_umask);
-
-#ifdef MKDIR_NO_UMASK
-            mkdir(".libs");
-#else
-            mkdir(".libs", ~old_umask);
-#endif
+            safe_mkdir(".libs");
         }
 
         if (cmd_data->output == otStaticLibraryOnly ||
@@ -1904,6 +1946,9 @@
     const char *touch_args[3];
 
     if (cmd_data->mode == mInstall) {
+        return 0;
+    }
+    if (!cmd_data->fake_output_name) {
         return 0;
     }