set_install_name 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #!/bin/sh
  2. #
  3. # Name: set_install_name
  4. # Purpose: set install_name for wx shared libraries under Mac OS X
  5. # Usage: run with --help option to see the instructions
  6. # Copyright: (c) 2005 Vadim Zeitlin <vadim@wxwindows.org>
  7. # Licence: wxWindows licence
  8. ################################################################################
  9. quiet=0
  10. verbose=0
  11. libdir=
  12. tool_prefix=
  13. install_path=
  14. cmd=
  15. Usage()
  16. {
  17. name=`basename $0`
  18. cat 1>&2 <<EOF
  19. Usage: $name [OPTIONS] [--prefix=PFX] [--libdir=DIR] [install_path]
  20. Change the install name of all wxWidgets libraries in the directory DIR (or
  21. current directory if libdir option is not specified) to correspond to the given
  22. install_path (defaults to the libraries directory if not specified).
  23. If prefix option is given, its value is prefixed to the tool names used. E.g.
  24. to use this script when cross-building, use "--prefix=powerpc-apple-darwin8-".
  25. -n, --dry-run Don't really do anything, just print the commands
  26. -q, --quiet Don't display any non error messages
  27. -v, --verbose Just show the commands being executed, don't run them
  28. -h, --help Show this help screen and exit
  29. Examples:
  30. * do "$name --libdir=MyApp.app/Contents/Frameworks @executable_path/../Frameworks"
  31. when distributing wxWidgets shared libraries with application MyApp
  32. * run "$name" without parameters in the directory containing wxWidgets libraries
  33. to use them without installing
  34. EOF
  35. exit 2
  36. }
  37. Message()
  38. {
  39. if [ $quiet != 1 ]; then
  40. echo "$*"
  41. fi
  42. }
  43. VerboseMessage()
  44. {
  45. if [ $verbose = 1 ]; then
  46. Message "$*"
  47. fi
  48. }
  49. Error()
  50. {
  51. echo "$*" 1>&2
  52. }
  53. GiveUsageErrorAndExit()
  54. {
  55. Error "$@"
  56. Usage
  57. }
  58. ChangeInstallNames()
  59. {
  60. # only change the libs themselves, not symlinks to them
  61. all_libs=`find "$libdir" -type f -name libwx_\*.dylib`
  62. if [ -z "$all_libs" ]; then
  63. Error "No wx libraries found in \"$libdir\"."
  64. exit 1
  65. fi
  66. VerboseMessage "Processing $all_libs\n"
  67. for lib in $all_libs; do
  68. libname=`basename $lib`
  69. oldname=`${tool_prefix}otool -D $lib | tail -1`
  70. Message "Updating install name of and references to $libname:"
  71. for lib2 in $all_libs; do
  72. VerboseMessage " updating $lib2"
  73. eval "$cmd ${tool_prefix}install_name_tool -change "$oldname" $install_path/$libname $lib2"
  74. done
  75. VerboseMessage " updating $libname id"
  76. eval "$cmd ${tool_prefix}install_name_tool -id $install_path/$libname $lib"
  77. done
  78. }
  79. while [ $# -ge 1 ]; do
  80. case "$1" in
  81. --help|-h)
  82. Usage
  83. ;;
  84. --dry-run|-n)
  85. cmd="echo"
  86. ;;
  87. --quiet|-q)
  88. quiet=1
  89. ;;
  90. --verbose|-v)
  91. verbose=1
  92. ;;
  93. --libdir=*)
  94. if [ -n "$libdir" ]; then
  95. GiveUsageErrorAndExit "Multiple --libdir options not allowed."
  96. fi
  97. libdir=`echo $1 | cut -c10-`
  98. ;;
  99. --prefix=*)
  100. if [ -n "$tool_prefix" ]; then
  101. GiveUsageErrorAndExit "At most one --prefix option can be given."
  102. fi
  103. tool_prefix=`echo $1 | cut -c10-`
  104. ;;
  105. -*)
  106. GiveUsageErrorAndExit "Unknown option \"$1\"."
  107. ;;
  108. *)
  109. if [ -n "$install_path" ]; then
  110. GiveUsageErrorAndExit "Too many parameters."
  111. fi
  112. install_path=$1
  113. esac
  114. shift
  115. done
  116. if [ -z $libdir ]; then
  117. libdir=`pwd`
  118. fi
  119. if [ -z $install_path ]; then
  120. install_path=$libdir
  121. fi
  122. ChangeInstallNames
  123. exit 0