summaryrefslogtreecommitdiffstats
path: root/bin/mklib
diff options
context:
space:
mode:
Diffstat (limited to 'bin/mklib')
-rwxr-xr-xbin/mklib183
1 files changed, 149 insertions, 34 deletions
diff --git a/bin/mklib b/bin/mklib
index 031e049c615..d7b740f8e34 100755
--- a/bin/mklib
+++ b/bin/mklib
@@ -34,6 +34,7 @@ MINOR=0
PATCH=""
DEPS=""
LINK=""
+LDFLAGS=""
CPLUSPLUS=0
STATIC=0
DLOPEN=0
@@ -42,7 +43,7 @@ ARCH="auto"
ARCHOPT=""
NOPREFIX=0
EXPORTS=""
-
+ID=""
#
# Parse arguments
@@ -60,17 +61,21 @@ do
echo ' -minor N specifies minor version number (default is 0)'
echo ' -patch N specifies patch version number (default is 0)'
echo ' -lLIBRARY specifies a dependency on LIBRARY'
- echo ' -LDIR search in DIR for library dependencies'
+ echo ' -LDIR search in DIR for library dependencies at build time'
+ echo ' -RDIR search in DIR for library dependencies at run time'
echo ' -linker L explicity specify the linker program to use (eg: gcc, g++)'
echo ' Not observed on all systems at this time.'
+ echo ' -ldflags OPT specify any additional linker flags in OPT'
echo ' -cplusplus link with C++ runtime'
echo ' -static make a static library (default is dynamic/shared)'
echo ' -dlopen make a shared library suitable for dynamic loading'
echo ' -install DIR put resulting library file(s) in DIR'
echo ' -arch ARCH override using `uname` to determine host system'
echo ' -archopt OPT specify an extra achitecture-specific option OPT'
+ echo ' -altopts OPTS alternate options to override all others'
echo " -noprefix don't prefix library name with 'lib' nor add any suffix"
echo ' -exports FILE only export the symbols listed in FILE'
+ echo ' -id NAME Sets the id of the dylib (Darwin)'
echo ' -h, --help display this information and exit'
exit 1
;;
@@ -94,12 +99,22 @@ do
shift 1;
LINK=$1
;;
+ '-ldflags')
+ shift 1;
+ LDFLAGS=$1
+ ;;
-l*)
DEPS="$DEPS $1"
;;
-L*)
DEPS="$DEPS $1"
;;
+ -R*)
+ DEPS="$DEPS $1"
+ ;;
+ -Wl*)
+ DEPS="$DEPS $1"
+ ;;
-pthread)
# this is a special case (see bugzilla 10876)
DEPS="$DEPS $1"
@@ -128,6 +143,10 @@ do
shift 1;
ARCHOPT=$1
;;
+ '-altopts')
+ shift 1;
+ ALTOPTS=$1
+ ;;
'-noprefix')
NOPREFIX=1
;;
@@ -135,6 +154,10 @@ do
shift 1;
EXPORTS=$1
;;
+ '-id')
+ shift 1;
+ ID=$1
+ ;;
-*)
echo "mklib: Unknown option: " $1 ;
exit 1
@@ -178,6 +201,7 @@ if [ ] ; then
echo PATCH is $PATCH
echo DEPS are $DEPS
echo "EXPORTS in" $EXPORTS
+ echo ID is $ID
echo "-----------------"
fi
@@ -187,7 +211,7 @@ fi
#
case $ARCH in
- 'Linux' | 'OpenBSD' | 'GNU' | GNU/*)
+ 'Linux' | 'OpenBSD' | 'DragonFly' | 'GNU' | GNU/*)
# we assume gcc
if [ "x$LINK" = "x" ] ; then
@@ -218,9 +242,13 @@ case $ARCH in
OPTS="-m32 ${OPTS}"
fi
+ if [ "${ALTOPTS}" ] ; then
+ OPTS=${ALTOPTS}
+ fi
+
rm -f ${LIBNAME}
# make lib
- ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
+ ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
# finish up
FINAL_LIBS="${LIBNAME}"
elif [ $STATIC = 1 ] ; then
@@ -228,10 +256,35 @@ case $ARCH in
echo "mklib: Making" $ARCH "static library: " ${LIBNAME}
LINK="ar"
OPTS="-ru"
+ if [ "${ALTOPTS}" ] ; then
+ OPTS=${ALTOPTS}
+ fi
rm -f ${LIBNAME}
+
+ # expand any .a objects into constituent .o files.
+ NEWOBJECTS=""
+ DELETIA=""
+ for OBJ in ${OBJECTS} ; do
+ if [ `expr match $OBJ '.*\.a'` -gt 0 ] ; then
+ # extract the .o files from this .a archive
+ FILES=`ar t $OBJ`
+ ar x $OBJ
+ NEWOBJECTS="$NEWOBJECTS $FILES"
+ # keep track of temporary .o files and delete them below
+ DELETIA="$DELETIA $FILES"
+ else
+ # ordinary .o file
+ NEWOBJECTS="$NEWOBJECTS $OBJ"
+ fi
+ done
+
# make lib
- ${LINK} ${OPTS} ${LIBNAME} ${OBJECTS}
+ ${LINK} ${OPTS} ${LIBNAME} ${NEWOBJECTS}
ranlib ${LIBNAME}
+
+ # remove temporary extracted .o files
+ rm -f ${DELETIA}
+
# finish up
FINAL_LIBS=${LIBNAME}
else
@@ -263,6 +316,9 @@ case $ARCH in
if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then
OPTS="-m32 ${OPTS}"
fi
+ if [ "${ALTOPTS}" ] ; then
+ OPTS=${ALTOPTS}
+ fi
if [ x${PATCH} = "x" ] ; then
VERSION="${MAJOR}.${MINOR}"
@@ -278,7 +334,7 @@ case $ARCH in
rm -f ${LIBNAME}.so
# make lib
- ${LINK} ${OPTS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
+ ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
# make usual symlinks
ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
@@ -312,7 +368,7 @@ case $ARCH in
# use g++
LINK="g++"
else
- echo "mklib: warning: can't find C++ comiler, trying CC."
+ echo "mklib: warning: can't find C++ compiler, trying CC."
LINK="CC"
fi
else
@@ -341,19 +397,23 @@ case $ARCH in
# Check if objects are SPARC v9
# file says: ELF 64-bit MSB relocatable SPARCV9 Version 1
set ${OBJECTS}
- SPARCV9=`file $1 | grep SPARCV9`
- if [ "${SPARCV9}" ] ; then
- OPTS="${OPTS} -xarch=v9"
+ if [ ${LINK} = "cc" -o ${LINK} = "CC" ] ; then
+ SPARCV9=`file $1 | grep SPARCV9`
+ if [ "${SPARCV9}" ] ; then
+ OPTS="${OPTS} -xarch=v9"
+ fi
fi
-
+ if [ "${ALTOPTS}" ] ; then
+ OPTS=${ALTOPTS}
+ fi
# for debug:
#echo "mklib: linker is" ${LINK} ${OPTS}
if [ $NOPREFIX = 1 ] ; then
rm -f ${LIBNAME}
- ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
+ ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
else
rm -f ${LIBNAME}.${MAJOR} ${LIBNAME}
- ${LINK} ${OPTS} -o ${LIBNAME}.${MAJOR} ${OBJECTS} ${DEPS}
+ ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.${MAJOR} -h ${LIBNAME}.${MAJOR} ${OBJECTS} ${DEPS}
ln -s ${LIBNAME}.${MAJOR} ${LIBNAME}
fi
FINAL_LIBS="${LIBNAME}.${MAJOR} ${LIBNAME}"
@@ -376,8 +436,11 @@ case $ARCH in
# No "lib" or ".so" part
echo "mklib: Making FreeBSD shared library: " ${LIBNAME}
OPTS="-shared"
+ if [ "${ALTOPTS}" ] ; then
+ OPTS=${ALTOPTS}
+ fi
rm -f ${LIBNAME}
- ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
+ ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
FINAL_LIBS=${LIBNAME}
elif [ $STATIC = 1 ] ; then
STLIB="lib${LIBNAME}.a"
@@ -389,9 +452,12 @@ case $ARCH in
else
SHLIB="lib${LIBNAME}.so.${MAJOR}"
OPTS="-shared -Wl,-soname,${SHLIB}"
+ if [ "${ALTOPTS}" ] ; then
+ OPTS=${ALTOPTS}
+ fi
echo "mklib: Making FreeBSD shared library: " ${SHLIB}
rm -f ${SHLIB}
- ${LINK} ${OPTS} -o ${SHLIB} ${OBJECTS} ${DEPS}
+ ${LINK} ${OPTS} ${LDFLAGS} -o ${SHLIB} ${OBJECTS} ${DEPS}
ln -sf ${SHLIB} "lib${LIBNAME}.so"
FINAL_LIBS="${SHLIB} lib${LIBNAME}.so"
fi
@@ -442,6 +508,10 @@ case $ARCH in
exit 1
fi
+ if [ "${ALTOPTS}" ] ; then
+ OPTS=${ALTOPTS}
+ fi
+
if [ $CPLUSPLUS = 1 ] ; then
LINK="CC"
else
@@ -449,7 +519,7 @@ case $ARCH in
fi
echo "mklib: Making IRIX " ${ABI} " shared library: " ${LIBNAME}
- ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
+ ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
FINAL_LIBS=${LIBNAME}
fi
;;
@@ -522,12 +592,16 @@ case $ARCH in
}
}' | sort -u >> ${EXPFILE}
+ if [ "${ALTOPTS}" ] ; then
+ OPTS=${ALTOPTS}
+ fi
+
# On AIX a shared library is linked differently when
# you want to dlopen the file
if [ $DLOPEN = "1" ] ; then
- cc -G ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
+ cc -G ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
else
- cc ${OPTS} -o ${OFILE} ${OBJECTS} ${DEPS}
+ cc ${OPTS} ${LDFLAGS} -o ${OFILE} ${OBJECTS} ${DEPS}
ar ${X64} -r ${LIBNAME} ${OFILE}
fi
@@ -573,6 +647,9 @@ case $ARCH in
echo "mklib: Making Darwin static library: " ${LIBNAME}
LINK="ar"
OPTS="-ruvs"
+ if [ "${ALTOPTS}" ] ; then
+ OPTS=${ALTOPTS}
+ fi
${LINK} ${OPTS} ${LIBNAME} ${OBJECTS}
FINAL_LIBS=${LIBNAME}
else
@@ -581,22 +658,46 @@ case $ARCH in
LIBSUFFIX="bundle"
OPTS="${ARCHOPT} -bundle -multiply_defined suppress"
else
- LIBSUFFIX="dylib"
- OPTS="${ARCHOPT} -dynamiclib -multiply_defined suppress -current_version ${MAJOR}.${MINOR}.0 -compatibility_version ${MAJOR}.${MINOR}.0 -install_name lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
+ LIBSUFFIX="dylib"
+ if [ -z "$ID" ] ; then
+ ID="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
+ fi
+ OPTS="${ARCHOPT} -dynamiclib -multiply_defined suppress -current_version ${MAJOR}.${MINOR}.0 -compatibility_version ${MAJOR}.${MINOR}.0 -install_name ${ID}"
fi
- LINKNAME="lib${LIBNAME}.${LIBSUFFIX}"
- LIBNAME="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
+
+ if [ ${EXPORTS} ] ; then
+ if [ -f ${EXPORTS}".darwin" ] ; then
+ EXPORTS=$EXPORTS".darwin"
+ fi
+ OPTS="${OPTS} -exported_symbols_list ${EXPORTS}"
+ fi
+
+ LINKNAME="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
+ LINKNAME2="lib${LIBNAME}.${LIBSUFFIX}"
+ LIBNAME="lib${LIBNAME}.${MAJOR}.${MINOR}.${LIBSUFFIX}"
# examine first object to determine ABI
set ${OBJECTS}
- ABI_PPC=`file $1 | grep 'object ppc'`
- ABI_I386=`file $1 | grep 'object i386'`
- if [ "${ABI_PPC}" ] ; then
- OPTS="${OPTS} -arch ppc"
- fi
- if [ "${ABI_I386}" ] ; then
- OPTS="${OPTS} -arch i386"
- fi
+ ABI_PPC=`file $1 | grep ' ppc'`
+ ABI_I386=`file $1 | grep ' i386'`
+ ABI_PPC64=`file $1 | grep ' ppc64'`
+ ABI_X86_64=`file $1 | grep ' x86_64'`
+ if [ "${ABI_PPC}" ] ; then
+ OPTS="${OPTS} -arch ppc"
+ fi
+ if [ "${ABI_I386}" ] ; then
+ OPTS="${OPTS} -arch i386"
+ fi
+ if [ "${ABI_PPC64}" ] ; then
+ OPTS="${OPTS} -arch ppc64"
+ fi
+ if [ "${ABI_X86_64}" ] ; then
+ OPTS="${OPTS} -arch x86_64"
+ fi
+
+ if [ "${ALTOPTS}" ] ; then
+ OPTS=${ALTOPTS}
+ fi
# XXX can we always add -isysroot /Developer/SDKs/MacOSX10.4u.sdk
# to OPTS here?
@@ -609,9 +710,11 @@ case $ARCH in
fi
echo "mklib: Making Darwin shared library: " ${LIBNAME}
- ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
+
+ ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
ln -s ${LIBNAME} ${LINKNAME}
- FINAL_LIBS="${LIBNAME} ${LINKNAME}"
+ ln -s ${LIBNAME} ${LINKNAME2}
+ FINAL_LIBS="${LIBNAME} ${LINKNAME} ${LINKNAME2}"
fi
;;
@@ -663,6 +766,9 @@ case $ARCH in
echo "mklib: Making Intel ICC static library: " ${LIBNAME}.a
LINK="ar"
OPTS="-ruv"
+ if [ "${ALTOPTS}" ] ; then
+ OPTS=${ALTOPTS}
+ fi
# make lib
${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
# finish up
@@ -673,6 +779,9 @@ case $ARCH in
else
OPTS="-shared"
fi
+ if [ "${ALTOPTS}" ] ; then
+ OPTS=${ALTOPTS}
+ fi
VERSION="${MAJOR}.${MINOR}.${PATCH}"
echo "mklib: Making Intel ICC shared library: " ${LIBNAME}.so.${VERSION}
@@ -686,7 +795,7 @@ case $ARCH in
rm -f ${LIBNAME}.so.${MAJOR}
rm -f ${LIBNAME}.so
# make lib
- ${LINK} ${OPTS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
+ ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
# make usual symlinks
ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
@@ -737,6 +846,9 @@ case $ARCH in
echo "mklib: Making" $ARCH "static library: " ${LIBNAME}.a
LINK="ar"
OPTS="-ru"
+ if [ "${ALTOPTS}" ] ; then
+ OPTS=${ALTOPTS}
+ fi
# make lib
${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
ranlib ${LIBNAME}.a
@@ -744,6 +856,9 @@ case $ARCH in
FINAL_LIBS=${LIBNAME}.a
else
OPTS="-shared -Wl,-export-all -Wl,--out-implib=${LIBNAME}-${MAJOR}.dll.a"
+ if [ "${ALTOPTS}" ] ; then
+ OPTS=${ALTOPTS}
+ fi
echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}-${MAJOR}.dll
if [ $CPLUSPLUS = 1 ] ; then
@@ -758,7 +873,7 @@ case $ARCH in
rm -f ${LIBNAME}.a
# make lib
- ${LINK} ${OPTS} -o ${CYGNAME}-${MAJOR}.dll ${OBJECTS} ${DEPS}
+ ${LINK} ${OPTS} ${LDFLAGS} -o ${CYGNAME}-${MAJOR}.dll ${OBJECTS} ${DEPS}
# make usual symlinks
ln -s ${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a
# finish up