sl@0: #!/bin/bash sl@0: sl@0: #### Configuration: sl@0: # The name of the executable. It is assumed sl@0: # that it is in the current working directory. sl@0: EXE_NAME=hidapi-testgui sl@0: # Path to the executable directory inside the bundle. sl@0: # This must be an absolute path, so use $PWD. sl@0: EXEPATH=$PWD/TestGUI.app/Contents/MacOS sl@0: # Libraries to explicitly bundle, even though they sl@0: # may not be in /opt/local. One per line. These sl@0: # are used with grep, so only a portion of the name sl@0: # is required. eg: libFOX, libz, etc. sl@0: LIBS_TO_BUNDLE=libFOX sl@0: sl@0: sl@0: function copydeps { sl@0: local file=$1 sl@0: # echo "Copying deps for $file...." sl@0: local BASE_OF_EXE=`basename $file` sl@0: sl@0: # A will contain the dependencies of this library sl@0: local A=`otool -LX $file |cut -f 1 -d " "` sl@0: local i sl@0: for i in $A; do sl@0: local BASE=`basename $i` sl@0: sl@0: # See if it's a lib we specifically want to bundle sl@0: local bundle_this_lib=0 sl@0: local j sl@0: for j in $LIBS_TO_BUNDLE; do sl@0: echo $i |grep -q $j sl@0: if [ $? -eq 0 ]; then sl@0: bundle_this_lib=1 sl@0: echo "bundling $i because it's in the list." sl@0: break; sl@0: fi sl@0: done sl@0: sl@0: # See if it's in /opt/local. Bundle all in /opt/local sl@0: local isOptLocal=0 sl@0: echo $i |grep -q /opt/local sl@0: if [ $? -eq 0 ]; then sl@0: isOptLocal=1 sl@0: echo "bundling $i because it's in /opt/local." sl@0: fi sl@0: sl@0: # Bundle the library sl@0: if [ $isOptLocal -ne 0 ] || [ $bundle_this_lib -ne 0 ]; then sl@0: sl@0: # Copy the file into the bundle if it exists. sl@0: if [ -f $EXEPATH/$BASE ]; then sl@0: z=0 sl@0: else sl@0: cp $i $EXEPATH sl@0: chmod 755 $EXEPATH/$BASE sl@0: fi sl@0: sl@0: sl@0: # echo "$BASE_OF_EXE depends on $BASE" sl@0: sl@0: # Fix the paths using install_name_tool and then sl@0: # call this function recursively for each dependency sl@0: # of this library. sl@0: if [ $BASE_OF_EXE != $BASE ]; then sl@0: sl@0: # Fix the paths sl@0: install_name_tool -id @executable_path/$BASE $EXEPATH/$BASE sl@0: install_name_tool -change $i @executable_path/$BASE $EXEPATH/$BASE_OF_EXE sl@0: sl@0: # Call this function (recursive) on sl@0: # on each dependency of this library. sl@0: copydeps $EXEPATH/$BASE sl@0: fi sl@0: fi sl@0: done sl@0: } sl@0: sl@0: rm -f $EXEPATH/* sl@0: sl@0: # Copy the binary into the bundle. Use ../libtool to do this if it's sl@0: # available beacuse if $EXE_NAME was built with autotools, it will be sl@0: # necessary. If ../libtool not available, just use cp to do the copy, but sl@0: # only if $EXE_NAME is a binary. sl@0: if [ -x ../libtool ]; then sl@0: ../libtool --mode=install cp $EXE_NAME $EXEPATH sl@0: else sl@0: file -bI $EXE_NAME |grep binary sl@0: if [ $? -ne 0 ]; then sl@0: echo "There is no ../libtool and $EXE_NAME is not a binary." sl@0: echo "I'm not sure what to do." sl@0: exit 1 sl@0: else sl@0: cp $EXE_NAME $EXEPATH sl@0: fi sl@0: fi sl@0: copydeps $EXEPATH/$EXE_NAME