**Contents** [[!toc levels=3]] # Things needed the latest stable NetBSD/i386 installation. The archivers/{zip,unzip} packages. The linux emulation packages suse_base and suse_compat. If you want to run binary modules (MEX), you also need the suse_devel-7.3 package; that is not (yet?) available as suse9.x version. Matlab 14.3 ships with a JDK 1.5 which runs nicely on netbsd-3, so no additional JRE needed. The three Matlab 7 / R14 Unix installation CDROMs. The patches listed below. A few GBytes of diskspace. # Work to do # A Short Cut While the following steps are kept for documentation and your own experiments, there is a [tar-ball](http://www.spg.tu-darmstadt.de/~hf/notes/patch_matlabcd.tar.gz) available with the patches and a shell script to apply them. Unpack, change to the patch_matlabcd directory, call sh patch-matlab.sh -m /path/to/cdcontent, optionally add '-v' for verbose output. # Footwork * Copy the three CDROMs to the harddisk (directories CD1, CD2, CD3). * mount_union(8) a scratch directory on top of the directory that contains CD[123]. This scratch directory will contain all the changes that you make to the content of the CDs. * chdir to CD1 * Apply the patch
--- /u/software/payware/unix/matlab-r14/CD1/install 2004-09-13 14:56:28.000000000 +0200
+++ install 2004-09-14 11:04:26.000000000 +0200
@@ -516,6 +516,19 @@
Darwin) # Mac OS X
ARCH="mac"
;;
+ NetBSD) # NetBSD (Linux emul)
+ case "`/usr/bin/uname -m`" in
+ i*86)
+ ARCH="glnx86"
+ ;;
+ ia64)
+ ARCH="glnxi64"
+ ;;
+ x86_64)
+ ARCH="glnxa64"
+ ;;
+ esac
+ ;;
esac
fi
return 0
@@ -730,6 +743,19 @@
Darwin) # Mac OS X
ver=`/usr/bin/uname -r | awk '{print $1}'`
;;
+ NetBSD) # NetBSD (Linux emul)
+ case $Arch in
+ glnx86)
+ ver=`/emul/linux/lib/libc.so.6 | head -1 | sed -e "s/^[^0-9]*//" -e "s/[ ,].*$//"`
+ ;;
+ glnxi64)
+ ver=2.2.4
+ ;;
+ glnxa64)
+ ver=`/emul/linux/lib64/libc.so.6 | head -1 | sed -e "s/^[^0-9]*//" -e "s/[ ,].*$//"`
+ ;;
+ esac
+ ;;
esac
fi
#
to the ./install script (assuming /emul/linux is a symlink to the root of the linux emulation setup). Apply equally to CD2 and CD3. Apply the patch
--- /u/software/payware/unix/matlab-r14/CD1/update/install/arch.sh 2004-09-13 14:54:55.000000000 +0200
+++ update/install/arch.sh 2004-09-14 11:38:19.000000000 +0200
@@ -185,6 +185,19 @@
Darwin) # Mac OS X
ARCH="mac"
;;
+ NetBSD) # NetBSD (Linux emul)
+ case "`/usr/bin/uname -m`" in
+ i*86)
+ ARCH="glnx86"
+ ;;
+ ia64)
+ ARCH="glnxi64"
+ ;;
+ x86_64)
+ ARCH="glnxa64"
+ ;;
+ esac
+ ;;
esac
fi
return 0
to ./update/install/arch.sh. Apply equally to CD2 and CD3. Pick the ./update/pd/install/tar.cmp zip archive from CD1, and unpack it.
Archive: tar.cmp
Length Date Time Name
-------- ---- ---- ----
41864 09-14-04 13:10 install_matlab
0 09-14-04 13:08 update/
0 09-14-04 13:08 update/install/
0 09-14-04 13:08 update/install/scripts/
676 07-10-97 05:11 update/install/scripts/abort.sh
2575 01-11-99 20:24 update/install/scripts/actualp.sh
6230 09-14-04 13:11 update/install/scripts/arch.sh
7329 07-27-00 21:42 update/install/scripts/batch1.sh
2597 01-11-99 20:24 update/install/scripts/batch4.sh
6985 01-29-03 21:28 update/install/scripts/bld_lbin.sh
9466 12-11-03 19:21 update/install/scripts/bld_sbin.sh
789 10-23-95 19:07 update/install/scripts/center.sh
530 12-11-03 19:21 update/install/scripts/cleanup.sh
486 01-11-99 20:24 update/install/scripts/clearsc.sh
848 01-11-99 20:24 update/install/scripts/cont.sh
449 01-11-99 20:24 update/install/scripts/echon.sh
2167 11-01-02 03:33 update/install/scripts/fin.sh
4590 03-22-04 06:07 update/install/scripts/genpathdef.sh
3256 12-11-03 19:21 update/install/scripts/intro_l.sh
5376 12-11-03 19:21 update/install/scripts/intro_s.sh
20832 01-09-04 18:30 update/install/scripts/lm.sh
6718 12-11-03 19:21 update/install/scripts/local.sh
3590 12-11-03 19:21 update/install/scripts/main.sh
1115 12-11-03 19:21 update/install/scripts/mapname.sh
1502 01-11-99 20:24 update/install/scripts/netruser.sh
1754 10-23-98 20:50 update/install/scripts/oldname.sh
5267 11-01-02 03:33 update/install/scripts/options.sh
6853 08-31-00 18:09 update/install/scripts/perm.sh
6585 06-12-02 22:21 update/install/scripts/ruser.sh
784 01-11-99 20:24 update/install/scripts/searchp.sh
3303 12-11-03 19:21 update/install/scripts/ucleanpe.sh
3295 12-11-03 19:21 update/install/scripts/update.sh
5395 12-11-03 19:21 update/install/scripts/util.sh
8565 12-11-03 19:21 update/install/scripts/verifyp.sh
-------- -------
171771 34 files
Apply the patch
--- install_matlab.orig 2005-08-12 10:23:52.000000000 +0200
+++ install_matlab 2005-09-30 14:27:23.000000000 +0200
@@ -552,6 +552,19 @@
Darwin) # Mac OS X
ARCH="mac"
;;
+ NetBSD) # NetBSD (Linux emul)
+ case "`/usr/bin/uname -m`" in
+ i*86)
+ ARCH="glnx86"
+ ;;
+ ia64)
+ ARCH="glnxi64"
+ ;;
+ x86_64)
+ ARCH="glnxa64"
+ ;;
+ esac
+ ;;
esac
fi
return 0
@@ -795,6 +808,19 @@
Darwin) # Mac OS X
ver=`/usr/bin/uname -r | awk '{print $1}'`
;;
+ NetBSD) # NetBSD (Linux emul)
+ case $Arch in
+ glnx86)
+ ver=`/emul/linux/lib/libc.so.6 | head -1 | sed -e "s/^[^0-9]*//" -e "s/[ ,].*$//"`
+ ;;
+ glnxi64)
+ ver=2.2.4
+ ;;
+ glnxa64)
+ ver=`/emul/linux/lib64/libc.so.6 | head -1 | sed -e "s/^[^0-9]*//" -e "s/[ ,].*$//"`
+ ;;
+ esac
+ ;;
esac
fi
#
to install_matlab, and the patch
--- orig/update/install/scripts/arch.sh 2004-04-04 10:20:31.000000000 +0200
+++ update/install/scripts/arch.sh 2004-09-14 13:11:17.000000000 +0200
@@ -185,6 +185,19 @@
Darwin) # Mac OS X
ARCH="mac"
;;
+ NetBSD) # NetBSD (Linux emul)
+ case "`/usr/bin/uname -m`" in
+ i*86)
+ ARCH="glnx86"
+ ;;
+ ia64)
+ ARCH="glnxi64"
+ ;;
+ x86_64)
+ ARCH="glnxa64"
+ ;;
+ esac
+ ;;
esac
fi
return 0
(same as above) to update/install/scripts/arch.sh. Re-zip the contents of the archive
[hf@venediger] /var/tmp # zip -r tar.cmp install_matlab update
adding: install_matlab (deflated 77%)
adding: update/ (stored 0%)
adding: update/install/ (stored 0%)
adding: update/install/scripts/ (stored 0%)
adding: update/install/scripts/abort.sh (deflated 53%)
adding: update/install/scripts/actualp.sh (deflated 63%)
adding: update/install/scripts/arch.sh (deflated 69%)
adding: update/install/scripts/batch1.sh (deflated 70%)
adding: update/install/scripts/batch4.sh (deflated 60%)
adding: update/install/scripts/bld_lbin.sh (deflated 75%)
adding: update/install/scripts/bld_sbin.sh (deflated 80%)
adding: update/install/scripts/center.sh (deflated 55%)
adding: update/install/scripts/cleanup.sh (deflated 42%)
adding: update/install/scripts/clearsc.sh (deflated 41%)
adding: update/install/scripts/cont.sh (deflated 53%)
adding: update/install/scripts/echon.sh (deflated 39%)
adding: update/install/scripts/fin.sh (deflated 78%)
adding: update/install/scripts/genpathdef.sh (deflated 66%)
adding: update/install/scripts/intro_l.sh (deflated 80%)
adding: update/install/scripts/intro_s.sh (deflated 85%)
adding: update/install/scripts/lm.sh (deflated 81%)
adding: update/install/scripts/local.sh (deflated 78%)
adding: update/install/scripts/main.sh (deflated 68%)
adding: update/install/scripts/mapname.sh (deflated 54%)
adding: update/install/scripts/netruser.sh (deflated 62%)
adding: update/install/scripts/oldname.sh (deflated 53%)
adding: update/install/scripts/options.sh (deflated 72%)
adding: update/install/scripts/perm.sh (deflated 74%)
adding: update/install/scripts/ruser.sh (deflated 82%)
adding: update/install/scripts/searchp.sh (deflated 47%)
adding: update/install/scripts/ucleanpe.sh (deflated 63%)
adding: update/install/scripts/update.sh (deflated 70%)
adding: update/install/scripts/util.sh (deflated 70%)
adding: update/install/scripts/verifyp.sh (deflated 78%)
to the same name. Copy to CD1, CD2 and CD3. Rinse and repeat.
* And that's about it. Provide a proper license.dat, and you are ready for installation. chdir to the installation directory, call the /path/to/install script from CD1, and click OK a few times.
At the end of the installation, there is a spurious rm -f with empty argument that can safely be ignored. If you find out where it hides, please tell me.
* OK, there's still the license manager...
FlexLM comes with a byzantine set of shell script tools. Of course, there is one more arch.sh to patch, this time under {MATLABHOME}/etc/util/arch.sh. Then create /usr/tmp, preferably as a symlink to /var/tmp, because FlexLM and the MLM backend have that hard-coded for logs, locks, preferences. Make sure you have got a proper license file in place - the procedure is well-documented. After that, you can either start the flexlm daemon from /etc/rc.local by using {MATLABHOME}/etc/rc.lm.glnx86 start|stop, or with the following rc.d script :
#!/bin/sh
#
# $Id: how_to_run_matlab_r14.3_on_netbsd__92__i386.mdwn,v 1.2 2012/02/05 07:14:36 schmonz Exp $
#
# PROVIDE: flexlm
# REQUIRE: DAEMON
. /etc/rc.subr
name="flexlm"
rcvar=$name
flexlm_user="flexlm"
matlabroot="/path/to/matlabr14"
lm_license="${matlabroot}/etc/license.dat"
required_files="${lm_license}"
command="${matlabroot}/etc/glnx86/lmgrd"
command_args="-c ${lm_license} -2 -p -l +/var/log/flexlmlog"
load_rc_config $name
run_rc_command "$1"
-- you need to create a user to run flexlm as, and own the logfile to him.
# Other patches
# arch.sh
For whatever reason there may be, a Matlab 14 installation has three instances of the arch.sh script that works out what platform Matlab is running on:
> find . -name arch.sh -print
./bin/util/arch.sh
./etc/util/arch.sh
./update/install/scripts/arch.sh
And (of course) the one that is sourced by {MATLABROOT}/bin/matlab is the original version which you should replace by e.g. {MATLABROOT}/etc/util/arch.sh once you get tired of adding -glnx86 to every matlab invocation.
# MEX
If you want to build binary modules with mex you need to make sure those modules (libraries) are linux libraries since you cannot use native NetBSD libraries with a program running in emulation. Make sure you install the suse_devel package as listed above, and apply this patch to {MATLABROOT}/toolbox/matlab/general/mex.m. It makes sure the mex shell-script (which calls the compiler) is executed by the linux shell.
# Sound
Add a symlink to the native /dev/sound like
[hf@dreispitz] /<1>linux/dev > pwd
/usr/pkg/emul/linux/dev
[hf@dreispitz] /<1>linux/dev > ll audio
0 lrwx------ 1 root wheel 13 Sep 10 03:25 audio -> /../dev/sound
# Linux pthread libs
Matlab 13, at least, expects the pthread shared library under /usr/lib whereas NetBSD's suse*_base package installs it under /lib. You need to manually add
[hf@dreispitz] /<2>usr/lib > ll libpthread.so*
0 lrwxr-xr-x 1 root wheel 25 Jul 22 17:35 libpthread.so -> ../../lib/libpthread.so.0
0 lrwxr-xr-x 1 root wheel 25 Jul 22 17:35 libpthread.so.0 -> ../../lib/libpthread.so.0
# LD_LIBRARY_PATH
As a Linux binary, Matlab makes heavy use of the LD_LIBRARY_PATH environment variable to access shared libraries. For a shell exit, it populates LD_LIBRARY_PATH like
>> !echo $LD_LIBRARY_PATH
/opt/matlabr14/sys/os/glnx86:/opt/matlabr14/bin/glnx86:/opt/matlabr14/extern/lib/glnx86:/opt/matlabr14/sys/java/jre/glnx86/jre1.5.0/lib/i386/native_threads:/opt/matlabr14/sys/java/jre/glnx86/jre1.5.0/lib/i386/client:/opt/matlabr14/sys/java/jre/glnx86/jre1.5.0/lib/i386
>>
[NetBSD ELF](http://www.netbsd.org/Documentation/elf.html) binaries do not normally use LD_LIBRARY_PATH; instead, NetBSD compiles fixed library paths into shared libraries and applications. Nevertheless, non-setuid NetBSD binaries still look at LD_LIBRARY_PATH. The above path apparently confuses complex NetBSD binaries like NEdit, XEmacs, Mozilla, which try to pick up Linux libraries instead of the native ones. As a workaround, unset LD_LIBRARY_PATH before calling the application, either with per-application wrapper scripts, or a generic wrapper script like
#!/bin/sh
unset LD_LIBRARY_PATH
exec "$@"
# OpenGL
Commands like bench that use OpenGL result in a [kernel panic](http://mail-index.netbsd.org/port-i386/2005/10/07/0004.html) . Christos Zoulas has provided a [kernel patch](http://www.spg.tu-darmstadt.de/~hf/notes/matlab7_opengl.patch). It is against 2005-10-10 NetBSD-current source and applies with offsets to the netbsd-3 branch; apply from within sys/arch/i386/.
The patch avoids the panic; what functionality exactly is missing remains to be seen.
_Workaround_: The Matlab command opengl software enforces software rendering which is slower than using hardware support - but appears to work, unlike the latter. You still need the kernel patch, though, as any OpenGL operation will panic otherwise.
# Issues left
Why Mathworks duplicate their set of install scripts everywhere and still keep a zipped copy around to drop on top of the installation is beyond me. The diffs above are clean and minimal - it's just that you have to have five instances of each.
--Hauke Fath