From 03e9f8bd359665fdeebc3540ed04d541e4cfa5f4 Mon Sep 17 00:00:00 2001
From: Dan Nicholson <dbn.lists@gmail.com>
Date: Thu, 7 Jan 2010 17:11:37 -0800
Subject: [PATCH] mklib: Extract archives into temporary directories

In order to avoid races when creating multiple archives using the same
dependent archives, extract objects into a temporary subdirectory.

Signed-off-by: Dan Nicholson <dbn.lists@gmail.com>
---
 bin/mklib |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/bin/mklib b/bin/mklib
index 0acaeb9..0507324 100755
--- a/bin/mklib
+++ b/bin/mklib
@@ -28,15 +28,22 @@
 # Given a list of files, look for .a archives and unpack them.
 # Return the original list of files minus the .a files plus the unpacked files.
 expand_archives() {
+    DIR=$1
+    shift
     FILES=$@
     NEWFILES=""
+    ORIG_DIR=`pwd`
+    mkdir -p "$DIR"
+    cd "$DIR"
     for FILE in $FILES ; do
         case $FILE in
             *.a)
                 # extract the .o files from this .a archive
                 MEMBERS=`ar t $FILE`
                 ar x $FILE
-                NEWFILES="$NEWFILES $MEMBERS"
+                for MEMBER in $MEMBERS ; do
+                    NEWFILES="$NEWFILES $DIR/$MEMBERS"
+                done
                 ;;
             *)
                 # other file type, just add to list
@@ -44,6 +51,7 @@ expand_archives() {
                 ;;
         esac
     done
+    cd "$ORIG_DIR"
     echo $NEWFILES
 }
 
@@ -360,13 +368,13 @@ case $ARCH in
             fi
 
 	    # expand .a into .o files
-	    NEW_OBJECTS=`expand_archives $OBJECTS`
+	    NEW_OBJECTS=`expand_archives "${LIBNAME}.obj" $OBJECTS`
 
             # make static lib
 	    FINAL_LIBS=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${NEW_OBJECTS}`
 
 	    # remove temporary extracted .o files
-	    rm -f `contents_of_archives $OBJECTS`
+	    rm -rf "${LIBNAME}.obj"
         else
 	    # make dynamic library
 	    LIBNAME="lib${LIBNAME}"     # prefix with "lib"
-- 
1.6.5.2

