generate application ini based on $ISABELLE_JAVA_SYSTEM_OPTIONS $JEDIT_JAVA_OPTIONS $JEDIT_SYSTEM_OPTIONS at build time (see also lib/Tools/java and src/Tools/jEdit/lib/Tools/jedit);
#!/usr/bin/env bash
#
# DESCRIPTION: re-package Isabelle distribution with add-on components
## diagnostics
PRG=$(basename "$0")
function usage()
{
echo
echo "Usage: isabelle $PRG ARCHIVE PLATFORM_FAMILY"
echo
echo " Re-package Isabelle source distribution with add-on components"
echo " and post-hoc patches for platform family linux, macos, windows."
echo
echo " Add-on components are that of the running Isabelle version!"
echo
exit 1
}
function fail()
{
echo "$1" >&2
exit 2
}
## arguments
[ "$#" -ne 2 ] && usage
ARCHIVE="$1"; shift
PLATFORM_FAMILY="$1"; shift
[ -f "$ARCHIVE" ] || fail "Bad source archive: $ARCHIVE"
ARCHIVE_DIR="$(cd $(dirname "$ARCHIVE"); echo "$PWD")"
ISABELLE_NAME="$(basename "$ARCHIVE" .tar.gz)"
## main
export COPYFILE_DISABLE=true
TMP="/var/tmp/isabelle-makedist$$"
mkdir "$TMP" || fail "Cannot create directory $TMP"
ISABELLE_TARGET="$TMP/$ISABELLE_NAME"
tar -C "$TMP" -x -z -f "$ARCHIVE" || exit 2
# bundled components
mkdir -p "$ARCHIVE_DIR/contrib"
echo "#bundled components" >> "$ISABELLE_TARGET/etc/components"
for CATALOG in main "$PLATFORM_FAMILY" bundled "bundled-$PLATFORM_FAMILY"
do
CATALOG_FILE="$ISABELLE_HOME/Admin/components/$CATALOG"
if [ -f "$CATALOG_FILE" ]
then
echo "catalog ${CATALOG}"
{
while { unset REPLY; read -r; test "$?" = 0 -o -n "$REPLY"; }
do
case "$REPLY" in
\#* | "") ;;
*)
COMPONENT="$REPLY"
COMPONENT_DIR="$ISABELLE_TARGET/contrib/$COMPONENT"
case "$COMPONENT" in
jedit_build*) ;;
*)
echo " component $COMPONENT"
CONTRIB="$ARCHIVE_DIR/contrib/${COMPONENT}.tar.gz"
if [ ! -f "$CONTRIB" ]; then
REMOTE="$ISABELLE_COMPONENT_REPOSITORY/${COMPONENT}.tar.gz"
echo " download $REMOTE"
perl -MLWP::Simple -e "getprint '$REMOTE';" > "$CONTRIB"
perl -e "exit((stat('${CONTRIB}'))[7] == 0 ? 0 : 1);" && exit 2
fi
tar -C "$ISABELLE_TARGET/contrib" -x -z -f "$CONTRIB" || exit 2
if [ -f "$COMPONENT_DIR/etc/settings" -o -f "$COMPONENT_DIR/etc/components" ]
then
case "$COMPONENT" in
jdk-*)
mv "$ISABELLE_TARGET/contrib/$COMPONENT" "$ISABELLE_TARGET/contrib/jdk"
echo "contrib/jdk" >> "$ISABELLE_TARGET/etc/components"
;;
*)
echo "contrib/$COMPONENT" >> "$ISABELLE_TARGET/etc/components"
;;
esac
fi
;;
esac
;;
esac
done
} < "$CATALOG_FILE"
fi
done
# purge other platforms
function purge_contrib
{
(
cd "$ISABELLE_TARGET"
for DIR in $(eval find contrib "$@" | sort)
do
echo "removing $DIR"
rm -rf "$DIR"
done
)
}
# platform-specific setup (inside archive)
case "$PLATFORM_FAMILY" in
linux)
purge_contrib '-name "x86*-darwin" -o -name "x86*-cygwin" -o -name "x86*-windows"'
cat "$ISABELLE_HOME/Admin/Linux/Isabelle" | \
perl -p -e "s,{JAVA_ARGS},$JEDIT_JAVA_OPTIONS $JEDIT_SYSTEM_OPTIONS,g;" \
> "$ISABELLE_TARGET/$ISABELLE_NAME"
chmod +x "$ISABELLE_TARGET/$ISABELLE_NAME"
;;
macos)
purge_contrib '-name "x86*-linux" -o -name "x86*-cygwin" -o -name "x86*-windows"'
mv "$ISABELLE_TARGET/contrib/macos_app" "$TMP/."
perl -pi -e "s,lookAndFeel=.*,lookAndFeel=com.apple.laf.AquaLookAndFeel,g;" \
-e "s,delete-line.shortcut=.*,delete-line.shortcut=C+d,g;" \
-e "s,delete.shortcut2=.*,delete.shortcut2=A+d,g;" \
"$ISABELLE_TARGET/src/Tools/jEdit/dist/properties/jEdit.props"
;;
windows)
purge_contrib '-name "x86*-linux" -o -name "x86*-darwin"'
mv "$ISABELLE_TARGET/contrib/windows_app" "$TMP/."
perl -pi -e "s,lookAndFeel=.*,lookAndFeel=com.sun.java.swing.plaf.windows.WindowsLookAndFeel,g;" \
"$ISABELLE_TARGET/src/Tools/jEdit/dist/properties/jEdit.props"
(
cat "$ISABELLE_HOME/Admin/Windows/WinRun4J/Isabelle.ini"
declare -a JAVA_ARGS=()
eval "JAVA_ARGS=($ISABELLE_JAVA_SYSTEM_OPTIONS $JEDIT_JAVA_OPTIONS $JEDIT_SYSTEM_OPTIONS)"
A=2
for ARG in "${JAVA_ARGS[@]}"
do
echo -e "vmarg.$A=$ARG\r"
A=$[ $A + 1 ]
done
) > "$ISABELLE_TARGET/${ISABELLE_NAME}.ini"
cp "$TMP/windows_app/Isabelle.exe" "$ISABELLE_TARGET/${ISABELLE_NAME}.exe"
cp "$ISABELLE_HOME/Admin/Windows/Cygwin/Cygwin-Setup.bat" \
"$ISABELLE_HOME/Admin/Windows/Cygwin/Cygwin-Latex-Setup.bat" \
"$ISABELLE_HOME/Admin/Windows/Cygwin/Cygwin-Terminal.bat" "$ISABELLE_TARGET"
(
cd "$ISABELLE_TARGET"
for NAME in postinstall rebaseall
do
cp -a "$ISABELLE_HOME/Admin/Windows/Cygwin/isabelle/$NAME" \
"contrib/cygwin/isabelle/."
done
find . -type f -not -name '*.exe' -not -name '*.dll' -perm +100 \
-print0 > "contrib/cygwin/isabelle/executables"
find . -type l -exec echo "{}" ";" -exec readlink "{}" ";" \
> "contrib/cygwin/isabelle/symlinks"
touch "contrib/cygwin/isabelle/uninitialized"
)
perl -pi -e "s,/bin/rebaseall.*,/isabelle/rebaseall,g;" \
"$ISABELLE_TARGET/contrib/cygwin/etc/postinstall/autorebase.bat.done"
;;
*)
;;
esac
# archive
BUNDLE_ARCHIVE="${ARCHIVE_DIR}/${ISABELLE_NAME}_${PLATFORM_FAMILY}.tar.gz"
echo "packaging $(basename "$BUNDLE_ARCHIVE")"
tar -C "$TMP" -c -z -f "$BUNDLE_ARCHIVE" "$ISABELLE_NAME" || exit 2
# platform-specific setup (outside archive)
if [ "$ISABELLE_PLATFORM_FAMILY" = linux -a "$PLATFORM_FAMILY" != macos -o "$ISABELLE_PLATFORM_FAMILY" = macos ]
then
case "$PLATFORM_FAMILY" in
macos)
echo "application for $PLATFORM_FAMILY"
(
cd "$TMP"
APP_TEMPLATE="$ISABELLE_HOME/Admin/MacOS/App3"
APP="${ISABELLE_NAME}.app"
for NAME in Java MacOS PlugIns Resources
do
mkdir -p "$APP/Contents/$NAME"
done
cat "$APP_TEMPLATE/Info.plist" | \
perl -p -e "s,{ISABELLE_NAME},${ISABELLE_NAME},g;" > "$APP/Contents/Info.plist"
for NAME in Pure.jar scala-compiler.jar scala-library.jar scala-swing.jar scala-actors.jar scala-reflect.jar
do
ln -sf "../Resources/${ISABELLE_NAME}/lib/classes/ext/$NAME" "$APP/Contents/Java"
done
ln -sf "../Resources/${ISABELLE_NAME}/src/Tools/jEdit/dist/jedit.jar" "$APP/Contents/Java"
cp -R "$APP_TEMPLATE/Resources/." "$APP/Contents/Resources/."
cp "$APP_TEMPLATE/../isabelle.icns" "$APP/Contents/Resources/."
ln -sf "../Resources/${ISABELLE_NAME}/contrib/jdk/x86_64-darwin" \
"$APP/Contents/PlugIns/jdk"
cp macos_app/JavaAppLauncher "$APP/Contents/MacOS/." && \
chmod +x "$APP/Contents/MacOS/JavaAppLauncher"
mv "$ISABELLE_NAME" "$APP/Contents/Resources/."
ln -sf "Contents/Resources/$ISABELLE_NAME" "$APP/Isabelle"
rm -f "${ARCHIVE_DIR}/${ISABELLE_NAME}.dmg"
hdiutil create -srcfolder "$APP" "${ARCHIVE_DIR}/${ISABELLE_NAME}.dmg"
)
;;
windows)
(
cd "$TMP"
rm -f "${ARCHIVE_DIR}/${ISABELLE_NAME}.7z"
7z -y -bd a "$TMP/${ISABELLE_NAME}.7z" "$ISABELLE_NAME" || exit 2
echo "application for $PLATFORM_FAMILY"
(
cat "windows_app/7zsd_All.sfx"
cat "$ISABELLE_HOME/Admin/Windows/Installer/sfx.txt" | \
perl -p -e "s,{ISABELLE_NAME},${ISABELLE_NAME},g;"
cat "$TMP/${ISABELLE_NAME}.7z"
) > "${ARCHIVE_DIR}/${ISABELLE_NAME}.exe"
chmod +x "${ARCHIVE_DIR}/${ISABELLE_NAME}.exe"
)
;;
*)
;;
esac
else
echo "### Cannot build application for $PLATFORM_FAMILY on $ISABELLE_PLATFORM_FAMILY"
fi
# clean up
rm -rf "$TMP"