Subject: matlab on NetBSD/i386: success
To: None <netbsd-users@netbsd.org>
From: Emmanuel Dreyfus <manu@netbsd.org>
List: netbsd-users
Date: 08/13/2002 18:41:15
Hi all

More about running Linux Matlab on NetBSD/i386: I have been able to run it 
with the full GUI on NetBSD-1.6_BETA5. I've tried a few demos, nothing seems 
broken.

But, this needs a lot of tweaks. Obviously we have a bug in Linux emulation
that plagues all the JVM part of Matlab. Matlab ships with a jdk118_v3 from
Blackdown. This version does not work on NetBSD (at all). 

As a proof, you can download jdk118_v3 from www.blackdown.org and try 
running anything with it, it will always fail with a SIGSEGV, even for a dummy
Hello world program. What is interesting is that jdk118_v1 runs okay.

The sad story is that Matlab won't work with any of the JVM from pkgsrc. I 
tried replacing the JVM bundled with Matlab by sun-jdk-1.3.0 and 1.4.0, it 
fails (more SIGSEGV). It does work a bit better with jdk118_v1 from blackdown,
but a lot of things are broken at runtime.

The solution is to hybrid jdk118_v3 and jdk118_v1: 118_v1 JVM with 118_v3 
classes. This seems to be okay.

Here is my step by step how-to for Linux Matlab on NetBSD/i386. Most steps 
before 7 are probably not mandatory, let me know if you are able to install 
it without running all the shell scripts in Linux emulation.

1) Make sure your kernel has COMPAT_LINUX, Install pkgsrc/emulation/suse_base 
and pkgsrc/emulation/suse_x11

2) Mount the matlab CD with an union MFS mount on it so that you will be
able to modify the scripts stored on the CD
mkdir /tmp/cdrom
mount -tmfs swap /tmp/cdrom
mount -tcd9660 /dev/cd0a /mnt
mount -tunion /tmp/cdrom /mnt

3) Try the install script from the CD. Each time you get a failure, change the 
#!/bin/sh into #!/emul/linux/bin/sh. Painful, but finnally it works.

4) Let's say you installed it in <matlab> (I'm not sure you can avoid
having it somewhere in /emul/linux). Run <matlab>/install_matlab. Again
you will have to adjust a lot of #!/bin/sh

5) ktrace -di matlab, then kdump|grep 'EMUL  "netbsd"' to see all the shell 
commands that run in NetBSD emulation. get the Linux version on your system. 
There are many: rm, tr, sed, awk, expr... 

6) Create a Linux arch command that returns i686:
cat > /emul/linux/bin/arch
#!/emul/linux/bin/sh
echo "i686"
^D
chmod uog+rx /emul/linux/bin/arch

7) Get jdk118_v1 and jdk118_v3 from www.blackdown.org. let us say you unpack
them in <jdk118_v1> and <jdk18_v3>

8) Tell Matlab to use jdk118_v1
cd <matlab>/sys/java/jre/glnx86/
rm jre
ln -sf <jdk118_v1> ./jre

9) Be brave! Use jdk118_v3 classes with jdk118_v1.
mkdir <matlab>/java/patch
cd <matlab>/java/patch
unzip <jdk118_v3>/lib/classes.zip

10) Start the license server (probably /emul/linux/etc/lmboot_TMW12)

11) Attempt to start matlab, it should work without any warning.

It's worth mentionning that it's only the jvm part of matlab that does not
work well under emulation yet. stock matlab will work with "matlab -nojvm",
(well not exaclty stock matlab, there are always some shell scripts to adjust)
but you loose most of the GUI front-ends.

I'm not sure, but I think that fixing this problem with jdk118_v3 would enable
us to run Oracle for Linux... I have seen a page of the FreeBSD handbook that
talks about this, but I cannot find it anymore. 

-- 
Emmanuel Dreyfus
manu@netbsd.org