Add license/copyright.

Add -h/--help option for usage.
Minor clean-ups.
This commit is contained in:
Brian Paul 2005-07-25 23:49:50 +00:00
parent 8dcc6736ab
commit 7c1ab40898
1 changed files with 108 additions and 42 deletions

150
bin/mklib
View File

@ -1,36 +1,53 @@
#!/bin/sh #!/bin/sh
# Make a shared library. # Make a shared library.
# Basically do a switch/case depending on the OS and make a shared (or static) # This script should be useful for projects other than Mesa.
# library conforming to that OS. # Improvements/fixes are welcome.
# Usage: # Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
# mklib [options] objects ...
# Options:
# -o LIBRARY specifies the name of resulting library
# ("-o GL" for example, might result in "libGL.so" being made)
# -major N specifies major version number (default is 1)
# -minor N specifies minor version number (default is 0)
# -patch N specifies patch version number (default is 0)
# -lLIBRARY specifies a dependency on LIBRARY
# -LDIR search in DIR for library dependencies
# -linker L explicity specify the linker program to use (ex: gcc, g++)
# Not observed on all systems at this time.
# -cplusplus link with C++ runtime
# -static make a static library (default is dynamic/shared)
# -install DIR pu resulting library file(s) in DIR
# -arch ARCH override using `uname` to determine architecture
# -archopt OPT specify an extra achitecture-specific option OPT
# -noprefix don't prefix library name with "lib" nor add any suffix
# -exports FILE only export the symbols listed in FILE
# #
# The library name should just be "GL" or "GLU", etc. The 'lib' prefix # Permission is hereby granted, free of charge, to any person obtaining a
# will be added here if needed, as well as the ".so" or ".a" suffix, # copy of this software and associated documentation files (the "Software"),
# etc (unless the -noprefix option is used). # to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
# #
# objects should be: foo.o bar.o etc.o # The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
# #
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
function usage()
{
echo 'Usage: mklib [options] objects'
echo 'Create a shared library from object files.'
echo ' -o LIBRARY specifies the name of the resulting library, without'
echo ' the leading "lib" or any suffix.'
echo ' (eg: "-o GL" might result in "libGL.so" being made)'
echo ' -major N specifies major version number (default is 1)'
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 ' -linker L explicity specify the linker program to use (eg: gcc, g++)'
echo ' Not observed on all systems at this time.'
echo ' -cplusplus link with C++ runtime'
echo ' -static make a static library (default is dynamic/shared)'
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 " -noprefix don't prefix library name with 'lib' nor add any suffix"
echo ' -exports FILE only export the symbols listed in FILE'
echo ' -h, --help display this information and exit'
}
# #
@ -57,27 +74,74 @@ EXPORTS=""
while true while true
do do
case $1 in case $1 in
'-o') shift 1; LIBNAME=$1;; '-h' | '--help')
'-major') shift 1; MAJOR=$1;; usage;
'-minor') shift 1; MINOR=$1;; exit 1
'-patch') shift 1; PATCH=$1;; ;;
'-linker') shift 1; LINK=$1;; '-o')
-l*) DEPS="$DEPS $1";; shift 1;
-L*) DEPS="$DEPS $1";; LIBNAME=$1
'-cplusplus') CPLUSPLUS=1;; ;;
'-static') STATIC=1;; '-major')
'-install') shift 1; INSTALLDIR=$1;; shift 1;
'-arch') shift 1; ARCH=$1;; MAJOR=$1
'-archopt') shift 1; ARCHOPT=$1;; ;;
'-noprefix') NOPREFIX=1;; '-minor')
'-exports') shift 1; EXPORTS=$1;; shift 1;
-*) echo "mklib: Unknown option: " $1 ; exit 1;; MINOR=$1
*) break ;;
'-patch')
shift 1;
PATCH=$1
;;
'-linker')
shift 1;
LINK=$1
;;
-l*)
DEPS="$DEPS $1"
;;
-L*)
DEPS="$DEPS $1"
;;
'-cplusplus')
CPLUSPLUS=1
;;
'-static')
STATIC=1
;;
'-install')
shift 1;
INSTALLDIR=$1
;;
'-arch')
shift 1;
ARCH=$1
;;
'-archopt')
shift 1;
ARCHOPT=$1
;;
'-noprefix')
NOPREFIX=1
;;
'-exports')
shift 1;
EXPORTS=$1
;;
-*)
echo "mklib: Unknown option: " $1 ;
exit 1
;;
*)
# This should be the first object file, stop parsing
break
esac esac
shift 1 shift 1
done done
OBJECTS=$@ OBJECTS=$@
if [ ${ARCH} = "auto" ] ; then if [ ${ARCH} = "auto" ] ; then
ARCH=`uname` ARCH=`uname`
fi fi
@ -476,6 +540,8 @@ case $ARCH in
'icc') 'icc')
# Intel C compiler # Intel C compiler
# This should get merged into the Linux code, above, since this isn't
# really a different architecture.
LIBNAME="lib${LIBNAME}" # prefix with "lib" LIBNAME="lib${LIBNAME}" # prefix with "lib"
if [ $STATIC = 1 ] ; then if [ $STATIC = 1 ] ; then
@ -593,7 +659,7 @@ case $ARCH in
ar rv ${LIBNAME} ${OBJECTS} ar rv ${LIBNAME} ${OBJECTS}
FINAL_LIBS="${LIBNAME}" FINAL_LIBS="${LIBNAME}"
else else
LIBNAME="lib${LIBNAME}.so" # prefix with "lib" 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}
ld -o ${LIBNAME} ${OBJECTS} ${DEPS} ld -o ${LIBNAME} ${OBJECTS} ${DEPS}
FINAL_LIBS="${LIBNAME}" FINAL_LIBS="${LIBNAME}"