mklib: use a wrapper for ar

This commit is contained in:
Brian Paul
2009-12-28 15:12:14 -07:00
parent 9656177bc0
commit 12039aa7a9

View File

@@ -69,6 +69,38 @@ contents_of_archives() {
} }
# Make static library with 'ar'
# params:
# options to ar
# 1 or 0 to indicate if ranlib should be run
# libname to make
# list of object files
# Return name of library we made
# Example: "make_ar_static_lib -ru 1 libfoo.a foo.o bar.o"
make_ar_static_lib() {
OPTS=$1
shift;
RANLIB=$1
shift;
LIBNAME=$1
shift;
OBJECTS=$@
# remove existing lib, if present
rm -f ${LIBNAME}
# make static lib
ar ${OPTS} ${LIBNAME} ${OBJECTS}
# run ranlib
if [ ${RANLIB} = 1 ] ; then
ranlib ${LIBNAME}
fi
echo ${LIBNAME}
}
# Print usage info. # Print usage info.
usage() { usage() {
echo 'Usage: mklib [options] objects' echo 'Usage: mklib [options] objects'
@@ -331,15 +363,10 @@ case $ARCH in
NEW_OBJECTS=`expand_archives $OBJECTS` NEW_OBJECTS=`expand_archives $OBJECTS`
# make static lib # make static lib
rm -f ${LIBNAME} FINAL_LIBS=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${NEW_OBJECTS}`
ar ${OPTS} ${LIBNAME} ${NEW_OBJECTS}
ranlib ${LIBNAME}
# remove temporary extracted .o files # remove temporary extracted .o files
rm -f `contents_of_archives $OBJECTS` rm -f `contents_of_archives $OBJECTS`
# finish up
FINAL_LIBS=${LIBNAME}
else else
# make dynamic library # make dynamic library
LIBNAME="lib${LIBNAME}" # prefix with "lib" LIBNAME="lib${LIBNAME}" # prefix with "lib"
@@ -402,9 +429,7 @@ case $ARCH in
if [ $STATIC = 1 ] ; then if [ $STATIC = 1 ] ; then
LIBNAME="lib${LIBNAME}.a" LIBNAME="lib${LIBNAME}.a"
echo "mklib: Making SunOS static library: " ${LIBNAME} echo "mklib: Making SunOS static library: " ${LIBNAME}
rm -f ${LIBNAME} FINAL_LIBS=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}`
ar -ruv ${LIBNAME} ${OBJECTS}
FINAL_LIBS=${LIBNAME}
else else
if [ $NOPREFIX = 0 ] ; then if [ $NOPREFIX = 0 ] ; then
LIBNAME="lib${LIBNAME}.so" LIBNAME="lib${LIBNAME}.so"
@@ -530,15 +555,10 @@ case $ARCH in
# expand .a into .o files # expand .a into .o files
NEW_OBJECTS=`expand_archives $OBJECTS` NEW_OBJECTS=`expand_archives $OBJECTS`
# make static lib FINAL_LIBS=`make_ar_static_lib cq 1 ${STLIB} ${NEW_OBJECTS}`
rm -f ${STLIB}
ar cq ${STLIB} ${NEW_OBJECTS}
ranlib ${STLIB}
# remove temporary extracted .o files # remove temporary extracted .o files
rm -f `contents_of_archives $OBJECTS` rm -f `contents_of_archives $OBJECTS`
FINAL_LIBS=${STLIB}
else else
# make dynamic library # make dynamic library
SHLIB="lib${LIBNAME}.so.${MAJOR}" SHLIB="lib${LIBNAME}.so.${MAJOR}"
@@ -558,10 +578,7 @@ case $ARCH in
if [ $STATIC = 1 ] ; then if [ $STATIC = 1 ] ; then
LIBNAME="lib${LIBNAME}_pic.a" LIBNAME="lib${LIBNAME}_pic.a"
echo "mklib: Making NetBSD PIC static library: " ${LIBNAME} echo "mklib: Making NetBSD PIC static library: " ${LIBNAME}
rm -f ${LIBNAME} FINAL_LIBS=`make_ar_static_lib cq 1 ${LIBNAME} ${OBJECTS}`
ar cq ${LIBNAME} ${OBJECTS}
ranlib ${LIBNAME}
FINAL_LIBS=${LIBNAME}
else else
LIBNAME="lib${LIBNAME}.so.${MAJOR}.${MINOR}" LIBNAME="lib${LIBNAME}.so.${MAJOR}.${MINOR}"
echo "mklib: Making NetBSD PIC shared library: " ${LIBNAME} echo "mklib: Making NetBSD PIC shared library: " ${LIBNAME}
@@ -574,9 +591,7 @@ case $ARCH in
'IRIX' | 'IRIX64') 'IRIX' | 'IRIX64')
if [ $STATIC = 1 ] ; then if [ $STATIC = 1 ] ; then
LIBNAME="lib${LIBNAME}.a" LIBNAME="lib${LIBNAME}.a"
rm -f ${LIBNAME} FINAL_LIBS=`make_ar_static_lib rc 0 ${LIBNAME} ${OBJECTS}`
ar rc ${LIBNAME} ${OBJECTS}
FINAL_LIBS=${LIBNAME}
else else
LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so" LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
@@ -627,9 +642,7 @@ case $ARCH in
if [ $STATIC = 1 ] ; then if [ $STATIC = 1 ] ; then
LIBNAME="lib${LIBNAME}.a" LIBNAME="lib${LIBNAME}.a"
echo "mklib: Making HP-UX static library: " ${LIBNAME} echo "mklib: Making HP-UX static library: " ${LIBNAME}
rm -f ${LIBNAME} FINAL_LIBS=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}`
ar -ruv ${LIBNAME} ${OBJECTS}
FINAL_LIBS=${LIBNAME}
else else
# HP uses a .2 for their current GL/GLU libraries # HP uses a .2 for their current GL/GLU libraries
if [ ${LIBNAME} = "GL" -o ${LIBNAME} = "GLU" ] ; then if [ ${LIBNAME} = "GL" -o ${LIBNAME} = "GLU" ] ; then
@@ -659,8 +672,7 @@ case $ARCH in
if [ $STATIC = 1 ] ; then if [ $STATIC = 1 ] ; then
LIBNAME="lib${LIBNAME}.a" LIBNAME="lib${LIBNAME}.a"
echo "mklib: Making AIX static library: " ${LIBNAME} echo "mklib: Making AIX static library: " ${LIBNAME}
ar -ruv ${X64} ${LIBNAME} ${OBJECTS} FINAL_LIBS=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}`
FINAL_LIBS=${LIBNAME}
else else
EXPFILE="lib${LIBNAME}.exp" EXPFILE="lib${LIBNAME}.exp"
LIBNAME="lib${LIBNAME}.a" # shared objects are still stored in the .a libraries LIBNAME="lib${LIBNAME}.a" # shared objects are still stored in the .a libraries
@@ -711,9 +723,7 @@ case $ARCH in
if [ $STATIC = 1 ] ; then if [ $STATIC = 1 ] ; then
LIBNAME="lib${LIBNAME}.a" LIBNAME="lib${LIBNAME}.a"
echo "mklib: Making OSF/1 static library: " ${LIBNAME} echo "mklib: Making OSF/1 static library: " ${LIBNAME}
rm -f ${LIBNAME} FINAL_LIBS=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}`
ar -ruv ${LIBNAME} ${OBJECTS}
FINAL_LIBS=${LIBNAME}
else else
VERSION="${MAJOR}.${MINOR}" VERSION="${MAJOR}.${MINOR}"
LIBNAME="lib${LIBNAME}.so" LIBNAME="lib${LIBNAME}.so"
@@ -800,16 +810,14 @@ case $ARCH in
'LynxOS') 'LynxOS')
LIBNAME="lib${LIBNAME}.a" LIBNAME="lib${LIBNAME}.a"
echo "mklib: Making LynxOS static library: " ${LIBNAME} echo "mklib: Making LynxOS static library: " ${LIBNAME}
rm -f ${LIBNAME} FINAL_LIBS=`make_ar_static_lib -ru 0 ${LIBNAME} ${OBJECTS}`
ar ru ${LIBNAME} ${OBJECTS}
FINAL_LIBS=${LIBNAME}
;; ;;
'BeOS') 'BeOS')
if [ $STATIC = 1 ] ; then if [ $STATIC = 1 ] ; then
LIBNAME="lib${LIBNAME}.a" LIBNAME="lib${LIBNAME}.a"
echo "mklib: Making BeOS static library: " ${LIBNAME} echo "mklib: Making BeOS static library: " ${LIBNAME}
ar -cru "${LIBNAME}" ${OBJECTS} FINAL_LIBS=`make_ar_static_lib -cru 0 ${LIBNAME} ${OBJECTS}`
else else
LIBNAME="lib${LIBNAME}.so" LIBNAME="lib${LIBNAME}.so"
echo "mklib: Making BeOS shared library: " ${LIBNAME} echo "mklib: Making BeOS shared library: " ${LIBNAME}
@@ -888,9 +896,7 @@ case $ARCH in
if [ $STATIC = 1 ] ; then if [ $STATIC = 1 ] ; then
LIBNAME="lib${LIBNAME}.a" LIBNAME="lib${LIBNAME}.a"
echo "mklib: Making AIX GCC static library: " ${LIBNAME} echo "mklib: Making AIX GCC static library: " ${LIBNAME}
rm -f ${LIBNAME} FINAL_LIBS=`make_ar_static_lib ru 0 ${LIBNAME} ${OBJECTS}`
ar ru ${LIBNAME} ${OBJECTS}
FINAL_LIBS=${LIBNAME}
else else
LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so" LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
echo "mklib: Making AIX GCC shared library: " ${LIBNAME} echo "mklib: Making AIX GCC shared library: " ${LIBNAME}
@@ -911,9 +917,7 @@ case $ARCH in
fi fi
LIBNAME="lib${LIBNAME}.a" LIBNAME="lib${LIBNAME}.a"
echo "mklib: Making static library for Ultrix: " ${LIBNAME} echo "mklib: Making static library for Ultrix: " ${LIBNAME}
rm -f ${LIBNAME} FINAL_LIBS=`make_ar_static_lib ru 0 ${LIBNAME} ${OBJECTS}`
ar ru ${LIBNAME} ${OBJECTS}
FINAL_LIBS="${LIBNAME}"
;; ;;
CYGWIN*) CYGWIN*)
@@ -933,17 +937,13 @@ case $ARCH in
LIBNAME="lib${LIBNAME}" # prefix with "lib" LIBNAME="lib${LIBNAME}" # prefix with "lib"
if [ $STATIC = 1 ] ; then if [ $STATIC = 1 ] ; then
echo "mklib: Making" $ARCH "static library: " ${LIBNAME}.a LIBNAME=${LIBNAME}.a
LINK="ar" echo "mklib: Making" $ARCH "static library: " ${LIBNAME}
OPTS="-ru" OPTS="-ru"
if [ "${ALTOPTS}" ] ; then if [ "${ALTOPTS}" ] ; then
OPTS=${ALTOPTS} OPTS=${ALTOPTS}
fi fi
# make lib FINAL_LIBS=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${OBJECTS}`
${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
ranlib ${LIBNAME}.a
# finish up
FINAL_LIBS=${LIBNAME}.a
else else
OPTS="-shared -Wl,--enable-auto-image-base -Wl,-export-all -Wl,--out-implib=${LIBNAME}-${MAJOR}.dll.a" OPTS="-shared -Wl,--enable-auto-image-base -Wl,-export-all -Wl,--out-implib=${LIBNAME}-${MAJOR}.dll.a"
if [ "${ALTOPTS}" ] ; then if [ "${ALTOPTS}" ] ; then
@@ -981,9 +981,7 @@ case $ARCH in
if [ $STATIC = 1 ] ; then if [ $STATIC = 1 ] ; then
LIBNAME="lib${LIBNAME}.a" LIBNAME="lib${LIBNAME}.a"
echo "mklib: Making static library for example arch: " ${LIBNAME} echo "mklib: Making static library for example arch: " ${LIBNAME}
rm -f ${LIBNAME} FINAL_LIBS=`make_ar_static_lib rv 0 ${LIBNAME} ${OBJECTS}`
ar rv ${LIBNAME} ${OBJECTS}
FINAL_LIBS="${LIBNAME}"
else else
LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so" LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
echo "mklib: Making shared library for example arch: " ${LIBNAME} echo "mklib: Making shared library for example arch: " ${LIBNAME}