···11+#!/bin/sh
22+# This is based on the script by David T. Lewis posted here:
33+# http://lists.squeakfoundation.org/pipermail/vm-dev/2017-April/024836.html
44+#
55+# VM run utility script
66+# usage: run <myimage>
77+#
88+# Select a VM and run an image based on the image format number
99+1010+# Search for the image filename in the command line arguments
1111+for arg in $*; do
1212+ case ${arg} in
1313+ -*) # ignore
1414+ ;;
1515+ *) # either an option argument or the image name
1616+ if test -f ${arg}; then
1717+ magic=$(file -m @share@/magic "$arg")
1818+ case "$magic" in
1919+ 'Smalltalk image V3 32b*')
2020+ image=${arg}
2121+ vm=@cog-vm@/bin/pharo-cog
2222+ ;;
2323+ 'Smalltalk image Spur 32b*')
2424+ image=${arg}
2525+ vm=@spur-vm@/bin/pharo-spur
2626+ ;;
2727+ 'Smalltalk image Spur 64b*')
2828+ if "@spur64-vm@" == "none"; then
2929+ echo "error: detected 64-bit image but 64-bit VM is not available" >&2
3030+ exit 1
3131+ fi
3232+ image=${arg}
3333+ vm=@spur64-vm@/bin/pharo-spur64
3434+ ;;
3535+ esac
3636+ fi
3737+ ;;
3838+ esac
3939+done
4040+4141+# Extra arguments to pass to the VM
4242+args=""
4343+4444+# Print a message to explain our DWIM'ery.
4545+if -n "$image"; then
4646+ echo "using VM selected by image type."
4747+ echo " image: $image"
4848+ echo " type: $magic"
4949+ echo " vm: $vm"
5050+elif test "$#" == 0; then
5151+ echo "using default vm and image; none specified on command line"
5252+ args="@default-image@"
5353+ # XXX Just assume this is the right VM (for pharo launcher)
5454+ vm=@cog-vm@/bin/pharo-cog
5555+else
5656+ echo "using default vm; image type not detected"
5757+fi
5858+5959+# Run the VM
6060+set -f
6161+exec ${vm} $args "$@"
6262+
+58
pkgs/development/pharo/wrapper/default.nix
···11+{ stdenv, file, makeDesktopItem, cog32, spur32, spur64 ? "none" }:
22+33+stdenv.mkDerivation rec {
44+ name = "pharo-vm";
55+ src = ./.;
66+ inherit cog32 spur32 spur64 file;
77+ magic = ./magic;
88+ desktopItem = makeDesktopItem {
99+ inherit name;
1010+ desktopName = "Pharo VM";
1111+ genericName = "Pharo Virtual Machine";
1212+ exec = "pharo %F";
1313+ icon = "pharo";
1414+ terminal = "false";
1515+ type="Application";
1616+ startupNotify = "false";
1717+ categories = "Development;";
1818+ mimeType = "application/x-pharo-image";
1919+ };
2020+ buildPhase = ''
2121+ substituteAllInPlace ./pharo-vm.sh
2222+ '';
2323+ installPhase = ''
2424+ mkdir -p $out/bin
2525+ cp pharo-vm.sh $out/bin/pharo
2626+ chmod +x $out/bin/pharo
2727+ '';
2828+ meta = {
2929+ description = "Pharo virtual machine (multiple variants)";
3030+3131+ longDescription = ''
3232+ Pharo's goal is to deliver a clean, innovative, free open-source
3333+ Smalltalk-inspired environment. By providing a stable and small core
3434+ system, excellent dev tools, and maintained releases, Pharo is an
3535+ attractive platform to build and deploy mission critical applications.
3636+3737+ This package provides a front-end for starting the virtual
3838+ machine. The command 'pharo-vm' automatically detects the type
3939+ of image and executes a suitable virtual machine: CogV3, Spur,
4040+ or Spur64. This makes it easy to open Pharo images because you
4141+ do not have to worry about which virtual machine variant is
4242+ required.
4343+4444+ More about the Cog family of virtual machines:
4545+ http://www.mirandabanda.org/cogblog/about-cog/
4646+ '';
4747+4848+ homepage = http://pharo.org;
4949+ license = stdenv.lib.licenses.mit;
5050+ maintainers = [ stdenv.lib.maintainers.lukego ];
5151+ # Pharo VM sources are packaged separately for darwin (OS X)
5252+ platforms = with stdenv.lib;
5353+ intersectLists
5454+ platforms.mesaPlatforms
5555+ (subtractLists platforms.darwin platforms.unix);
5656+ };
5757+}
5858+
···11+#!/bin/sh
22+# This is based on the script by David T. Lewis posted here:
33+# http://lists.squeakfoundation.org/pipermail/vm-dev/2017-April/024836.html
44+#
55+# VM run utility script
66+# usage: run <myimage>
77+#
88+# Select a VM and run an image based on the image format number
99+1010+PATH=$PATH:@file@/bin
1111+1212+# Search for the image filename in the command line arguments
1313+for arg in $* $SQUEAK_IMAGE; do
1414+ case ${arg} in
1515+ -*) # ignore
1616+ ;;
1717+ *) # either an option argument or the image name
1818+ if test -e ${arg}; then
1919+ magic=$(file -L -b -m @magic@ "$arg")
2020+ case "$magic" in
2121+ "Smalltalk image V3 32b"*)
2222+ image=${arg}
2323+ vm=@cog32@/bin/pharo-cog
2424+ ;;
2525+ "Smalltalk image Spur 32b"*)
2626+ image=${arg}
2727+ vm=@spur32@/bin/pharo-spur
2828+ ;;
2929+ "Smalltalk image Spur 64b"*)
3030+ if [ "@spur64vm@" == "none" ]; then
3131+ echo "error: detected 64-bit image but 64-bit VM is not available" >&2
3232+ exit 1
3333+ fi
3434+ image=${arg}
3535+ vm=@spur64@/bin/pharo-spur64
3636+ ;;
3737+ esac
3838+ fi
3939+ ;;
4040+ esac
4141+done
4242+4343+# Print a message to explain our DWIM'ery.
4444+if [ -n "$image" ]; then
4545+ echo "using VM selected by image type."
4646+ echo " image: $image"
4747+ echo " type: $magic"
4848+ echo " vm: $vm"
4949+else
5050+ echo "using default vm; image type not detected"
5151+ vm=@cog32@/bin/pharo-cog
5252+fi
5353+5454+# Run the VM
5555+set -f
5656+exec -- ${vm} $@
5757+