You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
4.5 KiB

  1. #!/bin/bash
  2. # v 1.1 Supports migration of links (limited to the same directory) - I should add checks..
  3. # usage osx_fixbundle.sh <bundle-name> <bzr_root>
  4. if [[ ! -f version.h ]]; then
  5. echo "**"
  6. echo "** ERROR: $0 doesn't seems to be launched from the kicad's bzr root !!!"
  7. echo "** Go in the bzr root directory and launch: scripts/osx_fixbundle.sh"
  8. echo "**"
  9. exit 1
  10. fi
  11. EXECUTABLES="`find . -name '*.app'`"
  12. #
  13. # Copies libraries under <bzr_root> in the bundle and relocates them in the binary
  14. #
  15. function fixbundle() {
  16. exec="$1"
  17. bzroot="$2"
  18. execpath="$3"
  19. binary="$4"
  20. LIBRARIES="`otool -L ${binary} | cut -d' ' -f1`"
  21. for library in $LIBRARIES; do
  22. mkdir -p ${execpath}${exec}.app/Contents/Frameworks
  23. if [[ "$library" =~ "$bzroot" ]]; then
  24. echo "${exec}: Migrating `basename $library` in the bundle"
  25. if [ ! -f ${exec}.app/Contents/Frameworks/`basename $library` ]; then
  26. if [ ! -L $library ]; then
  27. cp -f $library ${execpath}${exec}.app/Contents/Frameworks
  28. else
  29. resolvelink "$library" "`dirname $library`" "${execpath}/${exec}.app/Contents/Frameworks"
  30. fi
  31. fi
  32. install_name_tool -change $library @executable_path/../Frameworks/`basename $library` ${binary}
  33. fi
  34. done
  35. # Resolve issue in python modules (.so)
  36. cd ${execpath}
  37. MODULES="`find ${exec}.app -name '*.so'`"
  38. for module in $MODULES; do
  39. LIBRARIES="`otool -L $module | cut -d' ' -f1`"
  40. mkdir -p ${exec}.app/Contents/Frameworks
  41. for library in $LIBRARIES; do
  42. if [[ "$library" =~ "$bzroot" ]]; then
  43. if [ ! -f ${exec}.app/Contents/Frameworks/`basename $library` ]; then
  44. if [ ! -L $library ]; then
  45. cp -f $library ${exec}.app/Contents/Frameworks
  46. else
  47. resolvelink "$library" "`dirname $library`" "${execpath}/${exec}.app/Contents/Frameworks"
  48. fi
  49. fi
  50. install_name_tool -change $library @executable_path/../Frameworks/`basename $library` $module
  51. fi
  52. done
  53. echo "${exec}: elaborated module `basename ${module}`"
  54. done
  55. # Resolve issue between DYNLIBS
  56. dynlib_migrate="1";
  57. dynlib_cycle="0";
  58. while [ $dynlib_migrate -gt 0 ]; do
  59. dynlib_migrate="0";
  60. (( dynlib_cycle += 1 ))
  61. DYNLIBS="`find ${exec}.app -name '*.dylib'`"
  62. for dynlib in $DYNLIBS; do
  63. LIBRARIES="`otool -L $dynlib | cut -d' ' -f1`"
  64. mkdir -p ${exec}.app/Contents/Frameworks
  65. for library in $LIBRARIES; do
  66. if [[ "$library" =~ "$bzroot" ]]; then
  67. if [ ! -f ${exec}.app/Contents/Frameworks/`basename $library` ]; then
  68. if [ ! -L $library ]; then
  69. cp -f $library ${exec}.app/Contents/Frameworks
  70. else
  71. resolvelink "$library" "`dirname $library`" "${execpath}/${exec}.app/Contents/Frameworks"
  72. fi
  73. echo "copied `basename $library` into bundle"
  74. (( dynlib_migrate += 1))
  75. fi
  76. install_name_tool -change $library @executable_path/../Frameworks/`basename $library` $dynlib
  77. fi
  78. done
  79. done
  80. echo "${exec}: bundle dynlib dependencies migration Pass $dynlib_cycle: Migrated $dynlib_migrate libraries in bundle"
  81. done
  82. cd - >/dev/null
  83. }
  84. #
  85. # This supports only links on the same dir (TODO ?)
  86. #
  87. function resolvelink() {
  88. local srclib="`basename $1`"
  89. local srcpath="$2"
  90. local destpath="$3"
  91. #if is a file i expect a pointed ""
  92. local pointed="`readlink ${srcpath}/${srclib}`"
  93. if [ ! -f ${pointed} ]; then
  94. resolvelink "${pointed}" "${srcpath}" "${destpath}"
  95. echo "Link ${srclib} -> ${pointed} "
  96. (cd "${destpath}"; ln -s "${pointed}" "${srclib}" )
  97. else
  98. echo "Copy ${srcpath}/${srclib} -> ${destpath} "
  99. cp "${srcpath}/${srclib}" ${destpath}
  100. fi
  101. }
  102. for executable in $EXECUTABLES;
  103. do
  104. myexecpath="`dirname ${executable}`/"
  105. myexec="`basename ${executable}|sed -e 's/\.app//'`"
  106. fixbundle "${myexec}" "$1" "${myexecpath}" "${myexecpath}${myexec}.app/Contents/MacOS/${myexec}"
  107. fixbundle "${myexec}" "$1" "${myexecpath}" "${myexecpath}${myexec}.app/Contents/MacOS/_${myexec}.kiface"
  108. done