From 5ca0cf7b816f8598da6ef9ec907371f1fd613e89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Batuhan=20Ba=C5=9Ferdem?= Date: Mon, 21 Sep 2020 12:15:55 -0400 Subject: [PATCH] PKGBUILD updated for 2020-a --- PKGBUILD | 399 +++++++++++++++++++++++++++++++------------------- README.md | 69 +++++++++ matlab.script | 9 ++ 3 files changed, 325 insertions(+), 152 deletions(-) create mode 100644 README.md create mode 100644 matlab.script diff --git a/PKGBUILD b/PKGBUILD index f6826a9..0d779b6 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -1,165 +1,260 @@ -# Maintainer: Grey Christoforo - -## This PKGBUILD creates an Arch Linux package for the proprietary MATLAB application. -## In order to build the package, the user must supply: -## 1) a plain text file installation key as file `matlab.fik` -## and -## 2) the software tarball as `matlab.tar` from MATLAB ISO image or as downloaded by the installer -## A typical matlab tarball structure looks like this: -#matlab.tar -#├── activate.ini* -#├── archives/ -#│   ├── common/ -#│   └── glnxa64/ -#│   ├── matlab/ -#│   ├── matlab_code_analyzer/ -#│   ├── matlabconnector/ -#│   ├── matlabdata/ -#│   ├── matlab_desktop_glnxa64_1535004605.enc* -#│   ├── matlab_desktop_glnxa64_1535004605.xml* -#│   ├── ... other toolbox/product files & folders go here -#├── bin/ -#├── help/ -#├── install* -#├── installer_input.txt* -#├── install_guide.pdf* -#├── java/ -#├── license_agreement.txt* -#├── patents.txt* -#├── readme.txt* -#├── sys/ -#├── trademarks.txt* -#├── ui/ -#└── VersionInfo.xml* - -## Maybe you'd create this archive like this: -## 1) download the matlab installer form themathworks, let's imagine that file is ~/Downloads/matlab_R2019b_glnxa64.zip -## 2) extract it: unzip ~/Downloads/matlab_R2019b_glnxa64.zip -d ~/matlab -## 3) run the installer almost completely through manually: ~/matlab/install -downloadFolder ${HOME}/matlab/dl -destinationFolder ${HOME}/matlab/deleteme -## you must enter all your proper license info here, the purpose of this is to get the toolbox files you'll need for the offline install later -## when you see that the installer has finished downloading everything, press the Cancel button in the gui and end the installer early -## you don't really want the installer to extract/decrypt the files it has downloaded -## 4) delete anything that might have started to be installed in the above step: rm -rf ~/matlab/deleteme -## 5) now you can create the tarball you'll need here: tar -cvf matlab.tar -C ~/matlab/ . - -## You can get your file installation key (that you must manually put into matlab.fik) from https://mathworks.com/licensecenter -## Then maybe you could make the matlab.fik file you need for this package like this: -## echo "xxxxx-xxxxx-xxxxx-xxxxx-..." > matlab.fik - -## This PKGBUILD no longer attempts to activate the product. -## The user will be prompted to undertake their activation method of choice when the GUI is first run. -## Activation could be automated by running /opt/matlab/bin/activate_matlab.sh after this package is installed. -## Activation could be further automated in matlab.install (a file that doesn't exist at this time) - -## This package will conflict with /usr/bin/mex from texlive-bin -## You could fix that by installing it with the pacman option --overwrite /usr/bin/mex -## /ust/bin/mex from texlive-bin is just a symlink - -# partial install -_partialinstall=false +# Maintainer: Batuhan Baserdem +# Matlab packaging for archlinux +name=MATLAB +version='2020a' +instdir="/opt/tmw/${name}-${version}" pkgname=matlab -_install_dir="/opt/${pkgname}" -# as of R2019b Update 4, MATLAB's version number is: -pkgver=9.7.0.1296695 +pkgver=9.8.0.1323502 pkgrel=1 pkgdesc='A high-level language for numerical computation and visualization' arch=('x86_64') url='http://www.mathworks.com' license=(custom) -makedepends=('gendesk') -depends=('gconf' - 'glu' - 'gstreamer0.10-base' - 'gtk2' - 'libunwind' - 'libxp' - 'libxpm' - 'libxtst' - 'nss' - 'portaudio' - 'python' - 'qt5-svg' - 'qt5-webkit' - 'qt5-websockets' - 'qt5-x11extras' - 'xerces-c') -optdepends=('gcc6: For MEX support') - -source=("local:///matlab.tar" - "local:///matlab.fik") -md5sums=("SKIP" "SKIP") -#PKGEXT='.pkg.tar' - -OPTIONS=(!strip staticlibs) +makedepends=('gendesk' 'python' 'findutils' 'libselinux') +# For 2020a; from https://hub.docker.com/r/mathworks/matlab-deps/dockerfile +# Some of the dependencies are probably not needed; if in case contact the maintainer +depends=( + 'ca-certificates' + 'lsb-release' + 'alsa-lib' + 'atk' + 'libcap' + 'libcups' + 'libdbus' + 'fontconfig' + 'libgcrypt' + 'gdk-pixbuf2' + 'gst-plugins-base' + 'gstreamer' + 'gtk2' + 'krb5' + 'nspr' + 'nss' + 'pam' + 'pango' + 'cairo' + 'libselinux' + 'libsm' + 'libsndfile' + 'libx11' + 'libxcb' + 'libxcomposite' + 'libxcursor' + 'libxdamage' + 'libxext' + 'libxfixes' + 'libxft' + 'libxi' + 'libxmu' + 'libxrandr' + 'libxrender' + 'libxslt' + 'libxss' + 'libxt' + 'libxtst' + 'libxxf86vm' + 'procps-ng' + 'xorg-server-xvfb' + 'x11vnc' + 'sudo' + 'zlib') +# These I got from arch before and afraid to play around +depends+=( + 'gcc6' + 'gconf' + 'glu' + 'gstreamer0.10-base' + 'libunwind' + 'libxp' + 'libxpm' + 'portaudio' + 'qt5-svg' + 'qt5-webkit' + 'qt5-websockets' + 'qt5-x11extras' + 'xerces-c') +provides=('matlab-licenses' 'matlab-engine-for-python' 'matlab-bin') +source=("matlab.tar.gz" + "matlab.fik" + "matlab.lic" + "matlab.script") +md5sums=(SKIP SKIP SKIP SKIP) + +# Limit products to lower size, set this to true to do a partial install +partialinstall=false +# Example list of products for a partial install; check README.md for details +products=( + "MATLAB" + #---MATLAB Product Family---# + "Curve_Fitting_Toolbox" # Math and Optimization + "Database_Toolbox" # Database Access and Reporting + "Deep_Learning_Toolbox" + "Global_Optimization_Toolbox" + "GPU_Coder" + "MATLAB_Coder" # Code Generation + "MATLAB_Compiler" # Application Deployement + "MATLAB_Compiler_SDK" + "Optimization_Toolbox" + "Parallel_Computing_Toolbox" # Parallel computing + "Partial_Differential_Equation_Toolbox" + "Reinforcement_Learning_Toolbox" + "Statistics_and_Machine_Learning_Toolbox" # AI, Data Science, Statistics + "Symbolic_Math_Toolbox" + "Text_Analytics_Toolbox" + #---Application Products---# + "Audio_Toolbox" + "Bioinformatics_Toolbox" # Computational Biology + "Computer_Vision_Toolbox" + "Image_Processing_Toolbox" # Image Processing and Computer Vision + "Signal_Processing_Toolbox" # Signal Processing + "Wavelet_Toolbox" +) prepare() { - msg2 'Generating .desktop launcher file' - gendesk -f -n --pkgname "${pkgname}" \ - --pkgdesc "${pkgdesc}" \ - --categories "Development;Education;Science;Mathematics;IDE" \ - --exec "${_install_dir}/bin/matlab -desktop" - - msg2 'Reading file installation key from matlab.fik' - _fik=$(grep -o [0-9-]* matlab.fik) - - msg2 'Modifying the installer settings' - sed -i "s,^# destinationFolder=,destinationFolder=${pkgdir}${_install_dir}," installer_input.txt - sed -i "s,^# agreeToLicense=,agreeToLicense=yes," installer_input.txt - sed -i "s,^# mode=,mode=silent," installer_input.txt - sed -i "s,^# outputFile=,outputFile=${srcdir}/installer_output.txt," installer_input.txt - sed -i "s,^# fileInstallationKey=,fileInstallationKey=${_fik}," 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/^#//" installer_input.txt - done - fi + # Extract file installation key + _fik=$(grep -o '[0-9-]*' "${srcdir}/${pkgname}.fik") + + # Modify the installer settings' + _set="${srcdir}/${pkgname}/installer_input.txt" + sed -i "s|^# destinationFolder=|destinationFolder=${srcdir}/build|" "${_set}" + sed -i "s|^# fileInstallationKey=|fileInstallationKey=${_fik}|" "${_set}" + sed -i "s|^# agreeToLicense=|agreeToLicense=yes|" "${_set}" + sed -i "s|^# licensePath=|licensePath=${srcdir}/matlab.lic|" "${_set}" + + # Select products if partialinstall is set + if [ "${partialinstall}" = 'true' ]; then + for _prod in "${products[@]}"; do + sed -i 's|^#\(product.'"${_prod}"'\)|\1|' "${_set}" + done + fi + + # Desktop file + # Implemented a fix for intel gpus with mesa 20; + # https://wiki.archlinux.org/index.php/MATLAB#OpenGL_acceleration + # https://wiki.archlinux.org/index.php/Intel_graphics#Old_OpenGL_Driver_(i965) + gendesk -f -n \ + --pkgname "${pkgname}" \ + --pkgdesc "${pkgdesc}" \ + --categories "Development;Education;Science;Mathematics;IDE" \ + --mimetypes "application/x-matlab-data;text/x-matlab" \ + --exec 'sh -c '\''if [ "${MATLAB_INTEL_OVERRIDE}" = "yes" ] ; then exec env MESA_LOADER_DRIVER_OVERRIDE=i965 matlab -desktop ; else exec matlab -desktop ; fi'\' } -package() { - msg2 'Starting MATLAB installer' - ## I assume it's a bad idea, but I had to unset a few vars to prevent - ## fakeroot from slowing the matlab installer to a crawl (commented out by default) - LDLP=${LD_LIBRARY_PATH} - LDP=${LD_PRELOAD} - unset LD_LIBRARY_PATH - unset LD_PRELOAD - ./install -t -inputFile "${srcdir}/installer_input.txt" - - if [ $? -eq 0 ]; then - msg2 'Matlab installer done without error' - else - meg2 'Error encountered while running matlab installer' - fi - - export LD_LIBRARY_PATH="$LDLP" - export LD_PRELOAD="$LDP" - - msg2 'Installing license agreement file' - install -D -m644 "${pkgdir}${_install_dir}/license_agreement.txt" "${pkgdir}/usr/share/licenses/tmw/${pkgname}/LICENSE" - - #msg2 'Creating links for license.dat' - #mv "${pkgdir}${_install_dir}/licenses" "${pkgdir}${_install_dir}/licenses.bak" - #ln -s "/etc/matlab/licenses/" "${pkgdir}${_install_dir}/licenses" - - msg2 'Creating links for executables' - install -d -m755 "${pkgdir}/usr/bin/" - for _executable in deploytool matlab mbuild mcc mex; do - ln -s "${_install_dir}/bin/${_executable}" "${pkgdir}/usr/bin/${_executable}" - done - - msg2 'Installing .desktop launcher files' - install -D -m644 "${pkgname}.desktop" "${pkgdir}/usr/share/applications/${pkgname}.desktop" - install -D -m644 "${pkgdir}${_install_dir}/help/matlab/matlab_env/matlab_desktop_icon.png" "${pkgdir}/usr/share/pixmaps/${pkgname}.png" +build() { + # Using the installer with the -inputFile parameter will automatically + # cause the installation to be non-interactive + "${srcdir}/${pkgname}/install" -inputFile "${srcdir}/${pkgname}/installer_input.txt" + + # Create spoofing for Python API + # https://aur.archlinux.org/packages/matlab-engine-for-python/ + cd "${srcdir}/build/extern/engines/python" + # Getting appropriate python version for spoofing + _matminor="$(find "${srcdir}/build/extern/engines/python" \ + -name 'matlabengineforpython3*.so' | + sort | + sed 's|.*matlabengineforpython3_\([0-9]\)\.so|\1|g' | + tail -1)" + echo 'import sys' > "${srcdir}/sitecustomize.py" + echo "sys.version_info = (3, ${_matminor}, 0)" >> "${srcdir}/sitecustomize.py" + } -if ${_partialinstall} && [ -z ${_products+isSet} ]; then - _products=( - "MATLAB" - #"Curve_Fitting_Toolbox" - # fill in toolboxes/products here as needed for a partial install - # hint: look in your installer_input.txt file for names to use here - ) -fi +package() { + # Install the python API + # https://www.mathworks.com/help/matlab/matlab_external/install-the-matlab-engine-for-python.html + cd "${srcdir}/build/extern/engines/python" + PYTHONPATH="${srcdir}" python setup.py \ + install --root="${pkgdir}" --optimize 1 + # Spoofing trick to fool matlab into believing 3.8 is supported + _matminor="$(find "${srcdir}/build/extern/engines/python" \ + -name 'matlabengineforpython3*.so' | + sort | + sed 's|.*matlabengineforpython3_\([0-9]\)\.so|\1|g' | + tail -1)" + _prefix="$(python -c 'import sys; print(sys.prefix)')" + _pytminor="$(python -c 'import sys; print(sys.version_info.minor)')" + # Correct file names + if [[ "${_pytminor}" != "${_matminor}" ]]; then + mv "${pkgdir}/${_prefix}/lib/python3".{"${_matminor}","${_pytminor}"} + _egginfo="$(ls "${pkgdir}/${_prefix}/lib/python3.${_pytminor}/site-packages/"*"-py3.${_matminor}.egg-info")" + mv "${_egginfo}" "${_egginfo%py3."${_matminor}".egg-info}py3.${_pytminor}.egg-info" + sed -i "s|sys.version_info|(3, $_matminor, 0)|" \ + "${pkgdir}/${_prefix}/lib/python3.${_pytminor}/site-packages/matlab/engine/__init__.py" + fi + # Fix erronous referances in the _arch.txt files + errstr="${srcdir}/build/extern/engines/python/" + trustr="${instdir}/extern/engines/python/" + for _dir in \ + "${srcdir}/build/extern/engines/python/build/lib/matlab/engine" \ + "${pkgdir}/${_prefix}/lib/python3.${_pytminor}/site-packages/matlab/engine" \ + ; do + sed -i "s|${errstr}|${trustr}|" "${_dir}/_arch.txt" + done + + # Moving files from build area + install -dm 0755 "$(dirname "${pkgdir}/${instdir}")" + mv "${srcdir}/build" "${pkgdir}/${instdir}" + + # Copying license + install -D -m644 "${srcdir}/${pkgname}/license_agreement.txt" \ + "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE" + + # Symlink executables' + install -d -m755 "${pkgdir}/usr/bin/" + for _executable in deploytool matlab mbuild mcc; do + ln -s "${instdir}/bin/${_executable}" "${pkgdir}/usr/bin/${_executable}" + done + # This would otherwise conflict with mixtex + ln -s "${instdir}/bin/mex" "${pkgdir}/usr/bin/mex-${pkgname}" + # Why is this in this directory, I wonder... + ln -s "${instdir}/bin/glnxa64/mlint" "${pkgdir}/usr/bin/mlint" + + # Install desktop files + install -D -m644 "${srcdir}/${pkgname}.desktop" \ + "${pkgdir}/usr/share/applications/${pkgname}.desktop" + + # Create backup directories + mkdir -p "${pkgdir}/${instdir}/backup/bin/glnxa64/mexopts" + mkdir -p "${pkgdir}/${instdir}/backup/sys/os/glnxa64" + + # Link mex options to ancient libraries + sysdir="bin/glnxa64/mexopts" + mkdir -p "${pkgdir}/${instdir}/backup/${sysdir}" + cp "${pkgdir}/${instdir}/${sysdir}/gcc_glnxa64.xml" \ + "${pkgdir}/${instdir}/backup/${sysdir}/" + sed -i "s/gcc/gcc-6/g" "${pkgdir}/${instdir}/${sysdir}/gcc_glnxa64.xml" + cp "${pkgdir}/${instdir}/${sysdir}/g++_glnxa64.xml" \ + "${pkgdir}/${instdir}/backup/${sysdir}/" + sed -i "s/g++/g++-6/g" "${pkgdir}/${instdir}/${sysdir}/g++_glnxa64.xml" + cp "${pkgdir}/${instdir}/${sysdir}/gfortran.xml" \ + "${pkgdir}/${instdir}/backup/${sysdir}/" + sed -i "s/gfortran/gfortran-6/g" "${pkgdir}/${instdir}/${sysdir}/gfortran.xml" + cp "${pkgdir}/${instdir}/${sysdir}/gfortran6.xml" \ + "${pkgdir}/${instdir}/backup/${sysdir}/" + sed -i "s/gfortran/gfortran-6/g" "${pkgdir}/${instdir}/${sysdir}/gfortran6.xml" + + # Remove unused library files + # /sys/os/glnxa64/README.libstdc++ + sysdir="sys/os/glnxa64" + mkdir -p "${pkgdir}/${instdir}/backup/${sysdir}" + mv "${pkgdir}/${instdir}/${sysdir}/"{libstdc++.so.6.0.22,libstdc++.so.6} \ + "${pkgdir}/${instdir}/backup/${sysdir}/" + mv "${pkgdir}/${instdir}/${sysdir}/libgcc_s.so.1" \ + "${pkgdir}/${instdir}/backup/${sysdir}/" + mv "${pkgdir}/${instdir}/${sysdir}/"{libgfortran.so.3.0.0,libgfortran.so.3} \ + "${pkgdir}/${instdir}/backup/${sysdir}/" + mv "${pkgdir}/${instdir}/${sysdir}/"{libquadmath.so.0.0.0,libquadmath.so.0} \ + "${pkgdir}/${instdir}/backup/${sysdir}/" + + # make sure MATLAB can find libgfortran.so.3 + mkdir -p "${pkgdir}/${instdir}/backup/bin" + cp "${pkgdir}/${instdir}/bin/matlab" "${pkgdir}/${instdir}/backup/bin" + 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/'$(pacman -Q gcc6 | awk '{print $2}' | cut -d- -f1)'"|g' "${pkgdir}/${instdir}/bin/matlab" + + # https://bbs.archlinux.org/viewtopic.php?id=236821 + # These steps were deleted cause matlab switched to new freetype + + # Install the script file to make scripting easier with matlab + install -Dm 0755 "${srcdir}/matlab.script" "${pkgdir}/usr/bin/matscript" +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..a892d4b --- /dev/null +++ b/README.md @@ -0,0 +1,69 @@ +# MATLAB: Archlinux integration + +This PKGBUILD creates an Arch Linux package for MATLAB +Additionally; it also builds python engine. + +***WARNING***, this package NEEDS you to obtain the files; as the files are too large to host elsewhere. + +## Tips + +* You probably want to run this locally; since the package will be large. +If you are managing your own repos; depending on bandwidth and size constrants; +exclude this package from your workflow. +(Partial install is around 8 GB; and full install about 16 GB) +* Turn off compression if this package will only be installed on the build machine; +this cuts a fair amount of time from the build and compression is unneccessary on local machines. + +# Requirements + +Besides the dependencies; the source files MUST be present at the directory. +The user MUST supply; + +* **matlab.fik**: Plain text file installation key +* **matlab.lic**: License file +* **matlab.tar**: Software tarball + +Then run `makepkg -s` from the PKGBUILD directory to build the package. + +## File Installation Key & Licence File: + +[Here is the current link to the instructions](https://www.mathworks.com/help/install/ug/install-using-a-file-installation-key.html) + +File installation key identifies this specific installation of matlab. +The license file authorizes that this key can use the toolboxes. +Follow the steps; + +* Go to [License center](https://www.mathworks.com/licensecenter) on mathworks +* On install and activate tab; select (or create) an appropriate license +* Navigate to download the license file and the file installation key +* Download the **license file** and put the file in the repository +* Copy and paste the **file installation key** in a plain text file + +## Tarball + +**To run the installer, libselinux is needed!** + +* [Download the matlab installer](https://www.mathworks.com/downloads) +* Unpack and launch the installer +* After logging in and accepting license; select +`Advanced Options > I want to download without installing` +from the top dropdown menu. +* Select the toolboxes you want in the `PKGBUILD`. +(Alternatively install them all) +* Download the files to an empty directory called `matlab` +* After downloading; from the parent directory; do +`tar --create --verbose --file matlab.tar.gz .../matlab` +to create the tarball. + +# Tips + +## Large files + +To transport large files in fat32 media (most flash drives); use split and cat; +* **Split**: `split --bytes 3G --numeric-suffixes=0 matlab.tar.gz matlab.tar.gz.` +* **Concatenate**: `cat matlab.tar.gz.* > matlab.tar.gz` + +## Modules + +Matlab comes with a [lot of products](https://www.mathworks.com/products.html). +Most are not needed; check PKGBUILD to pick and choose appropriately. diff --git a/matlab.script b/matlab.script new file mode 100644 index 0000000..b9195d2 --- /dev/null +++ b/matlab.script @@ -0,0 +1,9 @@ +#!/bin/dash +# vim:ft=sh + +if [ -n "$1" ] && [ -x "$1" ]; then + matlab -batch "$1" +else + echo 'Need executable file as an argument' + exit 1 +fi