Skip to content

Instantly share code, notes, and snippets.

Last active Mar 15, 2018
What would you like to do?
PKGBUILD file for matlab, modified from AUR. Improvement: matlab installer output is NOT redirected to `/dev/null`, so one could see what's going on if fail to create package. And installation folder is changed to `/opt/matlab`
# Maintainer: Grey Christoforo <first name at last name dot net>
# Modified by: Darcy Hu <>
## This PKGBUILD creates an Arch Linux package for the proprietary MATLAB application. A license from The MathWorks is needed in order to both build the package and to run MATLAB once the package is installed. In order to build the package the user must supply a plain text file installation key and the software. For network installations, in addition to the file installation key, a license file needs to be used for the installation. The tar archive file can be generated from an ISO downloaded from The MathWorks, generated from the official DVD, or created by using the interactive installer to download the toolboxes (installation can be made to a temporary directory and canceled once the toolboxes are downloaded). The contents of the tar archive must include: ./archives/ ./bin/ ./etc/ ./help/ ./java/ /sys ./activate.ini ./install ./installer_input.txt
## The default installation behavior is to install all licensed products whether or not they are available in the tar file. To install only a subset of licensed products either provide a $_products array or set $_partialinstall and remove unwanted entries from the provided $_products array. To perform a network install set $_networkinstall.
pkgdesc='A high-level language for numerical computation and visualization'
optdepends=('gcc49: For MEX support')
## For network installations, apparently, a license file needs to be used for the installation.
if [ ! -z ${_networkinstall+isSet} ]; then
prepare() {
msg2 'Creating desktop file'
gendesk -f -n --pkgname "${pkgname}" --pkgdesc "${pkgdesc}" --categories "Development;Education;Science;Mathematics;IDE"
sed -i "/^Exec=/ s,$, -desktop," "${srcdir}/${pkgname}.desktop"
msg2 'Extracting file installation key'
_fik=$(grep -o [0-9-]* ${pkgname}.fik)
msg2 'Modifying the installer settings'
sed -i "s,^# destinationFolder=,destinationFolder=${pkgdir}/${_instdir}," "${srcdir}/${pkgname}/installer_input.txt"
sed -i "s,^# agreeToLicense=,agreeToLicense=yes," "${srcdir}/${pkgname}/installer_input.txt"
sed -i "s,^# mode=,mode=silent," "${srcdir}/${pkgname}/installer_input.txt"
sed -i "s,^# fileInstallationKey=,fileInstallationKey=${_fik}," "${srcdir}/${pkgname}/installer_input.txt"
if [ ! -z ${_networkinstall+isSet} ]; then
sed -i "s,^# licensePath=,licensePath=${srcdir}/license.dat," "${srcdir}/${pkgname}/installer_input.txt"
if [ ! -z ${_products+isSet} ]; then
msg2 'Building a package with a subset of the licensed products.'
for _product in "${_products[@]}"; do
sed -i "/^#product.${_product}$/ s/^#//" "${srcdir}/${pkgname}/installer_input.txt"
package() {
msg2 'Starting MATLAB installer'
"${srcdir}/${pkgname}/install" -inputFile "${srcdir}/${pkgname}/installer_input.txt"
msg2 'Installing license'
install -D -m644 "${pkgdir}/${_instdir}/license_agreement.txt" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
# msg2 'Creating links for license.dat'
# mv "${pkgdir}/${_instdir}/licenses" "${pkgdir}/${_instdir}/licenses.bak"
# if [ ! -z ${_networkinstall+isSet} ]; then
# install -D -m644 "${srcdir}/license.dat" "${pkgdir}/etc/${pkgname}/licenses/license.dat"
# fi
# ln -s "/etc/${pkgname}/licenses/" "${pkgdir}/${_instdir}/licenses"
msg2 'Creating links for executables'
install -d -m755 "${pkgdir}/usr/bin/"
for _executable in deploytool matlab mbuild mcc mex; do
ln -s "/opt/${pkgname}/bin/${_executable}" "${pkgdir}/usr/bin/${_executable}"
msg2 'Installing desktop files'
install -D -m644 "${pkgname}.desktop" "${pkgdir}/usr/share/applications/${pkgname}.desktop"
install -D -m644 "${pkgdir}/opt/${pkgname}/help/matlab/matlab_env/matlab_desktop_icon.png" "${pkgdir}/usr/share/pixmaps/${pkgname}.png"
msg2 'Configuring mex options'
sed -i "s#CC='gcc'#CC='gcc-4.7'#g" "${pkgdir}/opt/${pkgname}/bin/"
sed -i "s#CXX='g++'#CXX='g++-4.7'#g" "${pkgdir}/opt/${pkgname}/bin/"
sed -i "s#FC='gfortran'#FC='gfortran-4.7'#g" "${pkgdir}/opt/${pkgname}/bin/"
## See $MATLABROOT/sys/os/glnxa64/README.libstdc++
msg2 'Removing unused library files'
rm ${pkgdir}/opt/${pkgname}/sys/os/glnxa64/{,,,,,,}
# make sure MATLAB can find
sed -i 's,LD_LIBRARY_PATH="`eval echo $LD_LIBRARY_PATH`",LD_LIBRARY_PATH="`eval echo $LD_LIBRARY_PATH`:/usr/lib/gcc/x86_64-pc-linux-gnu/5.5.0",g' "${pkgdir}/opt/matlab/bin/matlab"
if [ ! -z ${_partialinstall+isSet} ] && [ -z ${_products+isSet} ]; then
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment