C++ Library containing a lot of needful things: Stack Trace, Command Line Parser, Resource Handling, Configuration Files, Unix Command Execution, Directories, Regular Expressions, Tokenizer, Function Trace, Standard Extensions.
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.

mac-create-app-bundle.sh 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #!/bin/bash -ex
  2. ## @id $Id$
  3. ##
  4. ## Create Mac OS-X App Bundle from built file
  5. ##
  6. ## Parameters:
  7. ## $1: name of the app-target
  8. ## $2: name of the project
  9. ## $3: package installation target
  10. ##
  11. ## 1 2 3 4 5 6 7 8
  12. ## 45678901234567890123456789012345678901234567890123456789012345678901234567890
  13. if test "$(uname -s)" != "Darwin"; then
  14. echo "**** ERROR: run on Mac OS-X: $0"
  15. exit 1
  16. fi
  17. project=${2:-$(sed -n 's/ *m4_define *( *x_package_name, *\(.*\) *).*/\1/p' $(pwd)/configure.ac)}
  18. apptarget=${1:-${project}.app}
  19. sources=${3:-$(pwd)/tmp}
  20. ! test -e "$apptarget" || rm -rf "$apptarget"
  21. test -n "$project"
  22. test -d "$sources"
  23. target="$(pwd)/${apptarget}/Contents/MacOS"
  24. echo "Creating $apptarget for $project from $sources"
  25. # Step 1: create and fill app directory structure
  26. mkdir -p ${apptarget}/Contents/{Resources,MacOS}
  27. ! test -d ${sources}/bin || \
  28. find ${sources}/bin -mindepth 1 -maxdepth 1 -exec cp -a {} ${apptarget}/Contents/MacOS/ \;
  29. ! test -d ${sources}/scripts || \
  30. find ${sources}/scripts -mindepth 1 -maxdepth 1 -exec cp -a {} ${apptarget}/Contents/MacOS/ \;
  31. executablefile=${apptarget}/Contents/MacOS/${project}
  32. test -x $executablefile || executablefile=$(ls -1 ${apptarget}/Contents/MacOS/ | head -1)
  33. ! test -d ${sources}/lib || \
  34. find ${sources}/lib -mindepth 1 -maxdepth 1 -exec cp -a {} ${apptarget}/Contents/MacOS/ \;
  35. ! test -d ${sources}/share/${project} || \
  36. find ${sources}/share/${project} -mindepth 1 -maxdepth 1 -exec cp -a {} ${apptarget}/Contents/Resources/ \;
  37. ! test -d ${sources}/share || \
  38. find ${sources}/share -mindepth 1 -maxdepth 1 -name ${project} -prune -o -exec cp -a {} ${apptarget}/Contents/Resources/ \;
  39. ! test -d ${sources} || \
  40. find ${sources} -mindepth 1 -maxdepth 1 -name share -o -name bin -o -name lib -o -name scripts -prune -o -exec cp -a {} ${apptarget}/Contents/Resources/ \;
  41. # Step 2: copy qt plugins, if necessary
  42. for f in ${QT_PLUGINS}; do
  43. test -d ${target}/${f} \
  44. || cp -r ${QT_PLUGIN_PATH}/${f} ${target}/${f} \
  45. || exit 1
  46. done
  47. # Step 3: resolve all library dependencies
  48. found=1
  49. oldpath="$(pwd)"
  50. while [ $found -ne 0 ]; do
  51. found=0
  52. cd "${target}"
  53. for file in $(find . -type f); do
  54. for lib in $(otool -L ${file} | tail -n +2 \
  55. | egrep '/usr/local/|/opt/local/|/opt/X11/|'"${HOME}" \
  56. | grep -v $file | awk '{print $1}'); do
  57. found=1
  58. test -f ${lib##*/} \
  59. || ( \
  60. cp ${lib} . \
  61. && chmod u+w ${lib##*/} \
  62. ) \
  63. || exit 1
  64. install_name_tool -change ${lib} \
  65. @executable_path/${lib##*/} ${file} \
  66. || exit 1
  67. done
  68. done
  69. done
  70. cd ${oldpath}
  71. # Step 4: if necessary, install qt_menu.nib
  72. if test -n "${QTDIR}"; then
  73. MENU_NIB=$(find ${QTDIR} -name .svn -o -name .git -prune -o -name qt_menu.nib -print \
  74. | head -1)
  75. if test -e "${MENU_NIB}"; then
  76. rsync -r "${MENU_NIB}" ${apptarget}/Contents/Resources/
  77. test -d ${apptarget}/Contents/Resources/qt_menu.nib
  78. fi
  79. fi
  80. # Step 5: copy local or create new info.plist
  81. if test -f Info.plist; then
  82. cp -a Info.plist ${apptarget}/Contents/Info.plist
  83. else
  84. cat > ${apptarget}/Contents/Info.plist <<EOF
  85. <?xml version="1.0" encoding="UTF-8"?>
  86. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  87. <plist version="1.0">
  88. <qdict>
  89. <key>CFBundleIdentifier</key>
  90. <string>${project}</string>
  91. <key>CFBundleExecutable</key>
  92. <string>${executablefile##*/}</string>
  93. </dict>
  94. </plist>
  95. EOF
  96. fi