···1+{ stdenv, fetchurl, bash, unzip, glibc, openssl, gcc, mesa, freetype, xorg, alsaLib, cairo, libuuid, autoreconfHook, gcc6, ... }:
23+{ name, src, version, source-date, source-url, ... }:
45+# Build the Pharo VM
6stdenv.mkDerivation rec {
7+ inherit name src;
89+ # Command line invocation name.
10+ # Distinct name for 64-bit builds because they only work with 64-bit images.
11+ cmd = if stdenv.is64bit then "pharo-spur64" else "pharo-spur";
1213+ # Choose desired VM sources. Separate for 32-bit and 64-bit VM.
14+ # (Could extent to building more VM variants e.g. SpurV3, Sista, etc.)
15+ vm = if stdenv.is64bit then "spur64src" else "spursrc";
16+17+ # Choose target platform name in the format used by the vm.
18+ flavor =
19+ if stdenv.isLinux && stdenv.isi686 then "linux32x86"
20+ else if stdenv.isLinux && stdenv.isx86_64 then "linux64x64"
21+ else if stdenv.isDarwin && stdenv.isi686 then "macos32x86"
22+ else if stdenv.isDarwin && stdenv.isx86_64 then "macos64x64"
23+ else abort "Unsupported platform: only Linux/Darwin x86/x64 are supported.";
24+25+ # Shared data (for the sources file)
26 pharo-share = import ./share.nix { inherit stdenv fetchurl unzip; };
2728+ # Note: -fPIC causes the VM to segfault.
00000000000029 hardeningDisable = [ "format" "pic" ];
3031+ # Regenerate the configure script.
32+ # Unnecessary? But the build breaks without this.
33+ autoreconfPhase = ''
34+ (cd opensmalltalk-vm/platforms/unix/config && make)
35 '';
0003637+ # Configure with options modeled on the 'mvm' build script from the vm.
38+ configureScript = "platforms/unix/config/configure";
39+ configureFlags = [ "--without-npsqueak"
40+ "--with-vmversion=5.0"
41+ "--with-src=${vm}" ];
42+ CFLAGS = "-msse2 -D_GNU_SOURCE -DCOGMTVM=0 -g -O2 -DNDEBUG -DDEBUGVM=0";
43+ LDFLAGS = "-Wl,-z,now";
4445+ # VM sources require some patching before build.
46+ prePatch = ''
47+ patchShebangs opensmalltalk-vm/build.${flavor}
48+ # Fix hard-coded path to /bin/rm in a script
49+ sed -i -e 's:/bin/rm:rm:' opensmalltalk-vm/platforms/unix/config/mkmf
50+ # Fill in mandatory metadata about the VM source version
51+ sed -i -e 's!\$Date\$!$Date: ${source-date} $!' \
52+ -e 's!\$Rev\$!$Rev: ${version} $!' \
53+ -e 's!\$URL\$!$URL: ${source-url} $!' \
54+ opensmalltalk-vm/platforms/Cross/vm/sqSCCSVersion.h
55+ '';
5657+ # Note: --with-vmcfg configure option is broken so copy plugin specs to ./
58+ preConfigure = ''
59+ cd opensmalltalk-vm
60+ cp build.${flavor}/pharo.cog.spur/plugins.{ext,int} .
61+ '';
6263+ # (No special build phase.)
06465+ installPhase = ''
66+ # Install in working directory and then copy
67+ make install-squeak install-plugins prefix=$(pwd)/products
6869+ # Copy binaries & rename from 'squeak' to 'pharo'
70+ mkdir -p $out
71+ cp products/lib/squeak/5.0-*/squeak $out/pharo
7273+ cp -r products/lib/squeak/5.0-*/*.so $out
74+ ln -s "${pharo-share}/lib/"*.sources $out
7576+ # Create a shell script to run the VM in the proper environment.
77+ #
78+ # These wrapper puts all relevant libraries into the
79+ # LD_LIBRARY_PATH. This is important because various C code in the VM
80+ # and Smalltalk code in the image will search for them there.
81+ mkdir -p $out/bin
82+ chmod u+w $out/bin
8384+ # Note: include ELF rpath in LD_LIBRARY_PATH for finding libc.
85+ libs=$out:$(patchelf --print-rpath $out/pharo):${cairo}/lib:${mesa}/lib:${freetype}/lib:${openssl}/lib:${libuuid}/lib:${alsaLib}/lib:${xorg.libICE}/lib:${xorg.libSM}/lib
8687+ # Create the script
88+ cat > $out/bin/${cmd} <<EOF
89+ #!/bin/sh
90 set -f
91+ LD_LIBRARY_PATH="\$LD_LIBRARY_PATH:$libs" exec $out/pharo "\$@"
092 EOF
93+ chmod +x $prefix/bin/${cmd}
94+ '';
9596+ enableParallelBuilding = true;
9798+ # Note: Force gcc6 because gcc5 crashes when compiling the VM.
99+ buildInputs = [ bash unzip glibc openssl gcc6 mesa freetype xorg.libX11 xorg.libICE xorg.libSM alsaLib cairo pharo-share libuuid autoreconfHook ];
1000101102 meta = {
103 description = "Clean and innovative Smalltalk-inspired environment";
···116 '';
117 homepage = http://pharo.org;
118 license = stdenv.lib.licenses.mit;
119+ maintainers = [ stdenv.lib.maintainers.lukego ];
120 # Pharo VM sources are packaged separately for darwin (OS X)
121 platforms = with stdenv.lib;
122 intersectLists
···1+#!/bin/sh
2+# This is based on the script by David T. Lewis posted here:
3+# http://lists.squeakfoundation.org/pipermail/vm-dev/2017-April/024836.html
4+#
5+# VM run utility script
6+# usage: run <myimage>
7+#
8+# Select a VM and run an image based on the image format number
9+10+# Search for the image filename in the command line arguments
11+for arg in $*; do
12+ case ${arg} in
13+ -*) # ignore
14+ ;;
15+ *) # either an option argument or the image name
16+ if test -f ${arg}; then
17+ magic=$(file -m @share@/magic "$arg")
18+ case "$magic" in
19+ 'Smalltalk image V3 32b*')
20+ image=${arg}
21+ vm=@cog-vm@/bin/pharo-cog
22+ ;;
23+ 'Smalltalk image Spur 32b*')
24+ image=${arg}
25+ vm=@spur-vm@/bin/pharo-spur
26+ ;;
27+ 'Smalltalk image Spur 64b*')
28+ if "@spur64-vm@" == "none"; then
29+ echo "error: detected 64-bit image but 64-bit VM is not available" >&2
30+ exit 1
31+ fi
32+ image=${arg}
33+ vm=@spur64-vm@/bin/pharo-spur64
34+ ;;
35+ esac
36+ fi
37+ ;;
38+ esac
39+done
40+41+# Extra arguments to pass to the VM
42+args=""
43+44+# Print a message to explain our DWIM'ery.
45+if -n "$image"; then
46+ echo "using VM selected by image type."
47+ echo " image: $image"
48+ echo " type: $magic"
49+ echo " vm: $vm"
50+elif test "$#" == 0; then
51+ echo "using default vm and image; none specified on command line"
52+ args="@default-image@"
53+ # XXX Just assume this is the right VM (for pharo launcher)
54+ vm=@cog-vm@/bin/pharo-cog
55+else
56+ echo "using default vm; image type not detected"
57+fi
58+59+# Run the VM
60+set -f
61+exec ${vm} $args "$@"
62+
···1+#!/bin/sh
2+# This is based on the script by David T. Lewis posted here:
3+# http://lists.squeakfoundation.org/pipermail/vm-dev/2017-April/024836.html
4+#
5+# VM run utility script
6+# usage: run <myimage>
7+#
8+# Select a VM and run an image based on the image format number
9+10+PATH=$PATH:@file@/bin
11+12+# Search for the image filename in the command line arguments
13+for arg in $* $SQUEAK_IMAGE; do
14+ case ${arg} in
15+ -*) # ignore
16+ ;;
17+ *) # either an option argument or the image name
18+ if test -e ${arg}; then
19+ magic=$(file -L -b -m @magic@ "$arg")
20+ case "$magic" in
21+ "Smalltalk image V3 32b"*)
22+ image=${arg}
23+ vm=@cog32@/bin/pharo-cog
24+ ;;
25+ "Smalltalk image Spur 32b"*)
26+ image=${arg}
27+ vm=@spur32@/bin/pharo-spur
28+ ;;
29+ "Smalltalk image Spur 64b"*)
30+ if [ "@spur64vm@" == "none" ]; then
31+ echo "error: detected 64-bit image but 64-bit VM is not available" >&2
32+ exit 1
33+ fi
34+ image=${arg}
35+ vm=@spur64@/bin/pharo-spur64
36+ ;;
37+ esac
38+ fi
39+ ;;
40+ esac
41+done
42+43+# Print a message to explain our DWIM'ery.
44+if [ -n "$image" ]; then
45+ echo "using VM selected by image type."
46+ echo " image: $image"
47+ echo " type: $magic"
48+ echo " vm: $vm"
49+else
50+ echo "using default vm; image type not detected"
51+ vm=@cog32@/bin/pharo-cog
52+fi
53+54+# Run the VM
55+set -f
56+exec -- ${vm} $@
57+