#!/bin/bash export PATH=$HOME/bin:$HOME/Qt5.5/5.5/clang_64/bin:$PATH swipl=$HOME/bin/swipl app=swipl-win.app copy_files=true done=false while [ $done = false ]; do case $1 in --no-copy) copy_files=false shift ;; *) done=true ;; esac done eval `$swipl --dump-runtime-variables` VMAJOR=$(($PLVERSION/10000)) VMINOR=$(($PLVERSION%10000/100)) VPATCH=$(($PLVERSION%100)) version="$VMAJOR.$VMINOR.$VPATCH" if [ ! -z "$PLVERSIONTAG" ]; then version="$version-$PLVERSIONTAG" fi echo "$version" > VERSION if [ $copy_files = true ]; then printf "Deploying Qt ..." macdeployqt $app printf "done\n" printf "Copying $PLBASE ..." rsync -a $PLBASE $app/Contents rm -rf $app/Contents/swipl/pack printf "ok\n" fi abs_libswipl=$PLBASE/lib/$PLARCH/libswipl.dylib rel_lib=@executable_path/../swipl/lib/$PLARCH rel_libswipl=$rel_lib/libswipl.dylib echo old: $abs_libswipl echo new: $rel_libswipl cd $app/Contents if [ $(basename $PLBASE) != swipl ]; then ln -s $(basename $PLBASE) swipl fi # Make SWI-Prolog find its home echo swipl > swipl.home # Install the tradional binaries too cp swipl/bin/$PLARCH/swipl* MacOS # Install icon and bundle meta-data cp ../../swipl.icns Resources cp ../../../../man/macosx/macosx.html Resources/swipl-macosx.html cp ../../../../man/macosx/License.html Resources/ cp ../../../../man/macosx/SWIapp.html Resources/ cat > Info.plist << _EOF_ NSPrincipalClass NSApplication CFBundleShortVersionString $version CFBundleIconFile swipl CFBundleDisplayName SWI-Prolog CFBundlePackageType APPL CFBundleGetInfoString Created by the SWI-Prolog project NSHumanReadableCopyright LGPL CFBundleSignature swpl CFAppleHelpAnchor swipl-macosx.html CFBundleExecutable swipl-win CFBundleIdentifier org.swi-prolog.swipl-win CFBundleDocumentTypes CFBundleTypeExtensions pl prolog CFBundleTypeName Prolog source CFBundleTypeIconFile swipl CFBundleTypeRole Shell LSHandlerRank Default _EOF_ printf "Fixing path to libswipl.dylib " for f in MacOS/* swipl/bin/$PLARCH/* swipl/lib/$PLARCH/*; do case "$(file $f)" in *Mach-O*) old_libswipl=$(otool -L $f | grep libswipl.dylib | awk '{print $1}') if [ ! -z "$old_libswipl" -a $(basename $f) != libswipl.dylib ]; then printf "." install_name_tool -change $old_libswipl $rel_libswipl $f fi ;; *) #printf "Skipped $f: $(file $f)\n" esac done printf 'ok\n' # Getting dependencies from the Macport project into the bundle. # Note that we could consider turning these into a Macports framework. printf "Adding Macport dylibs to the bundle\n" changeset="$(echo swipl/lib/$PLARCH/*)" while [ ! -z "$changeset" ]; do newchanges= for f in $changeset; do case "$(file $f)" in *Mach-O*) opt_dep=$(otool -L $f | grep /opt/local | awk '{print $1}') if [ ! -z "$opt_dep" ]; then change="" for dep in $opt_dep; do file="swipl/lib/$PLARCH/$(basename $dep)" if [ ! -f $file ]; then printf " Adding $dep ... " cp $dep swipl/lib/$PLARCH chmod 755 $file newchanges="$newchanges $file" printf 'ok\n' fi change="$change -change $dep $rel_lib/$(basename $dep)" done if [ ! -z "$change" ]; then install_name_tool $change $f fi fi ;; *) esac done changeset="$newchanges" done # final naming. Hack cd ../.. rm -rf SWI-Prolog.app mv $app SWI-Prolog.app