2018-03-31 03:05:05 +03:00
#!/bin/bash
2018-09-07 01:07:01 +03:00
export PATH = /usr/local/bin:$PATH
2018-03-31 03:05:05 +03:00
DIR = " $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " && pwd ) "
echo " Current directory: $DIR "
cd $DIR
2019-06-20 00:34:04 +03:00
export NOROOT = $NOROOT
2018-03-31 03:05:05 +03:00
if [ " $1 " = = "clean" ] ; then
2020-09-24 21:00:26 +03:00
rm -f CMakeCache.txt *.cmake
rm -rf out
rm -rf .buildtools
# make clean
2018-03-31 03:05:05 +03:00
fi
2020-09-10 13:13:55 +03:00
if [ " $1 " = = "noroot" ] || [ " $2 " = = "noroot" ] || [ " $3 " = = "noroot" ] ; then
2020-09-24 21:00:26 +03:00
export NOROOT = true
2019-06-20 00:34:04 +03:00
fi
2020-09-10 13:13:55 +03:00
if [ " $1 " = = "release" ] || [ " $2 " = = "release" ] || [ " $3 " = = "release" ] ; then
2020-09-22 11:16:29 +03:00
BUILD_TYPE = "Release"
2019-08-07 01:40:28 +03:00
else
2020-09-22 11:16:29 +03:00
BUILD_TYPE = "Debug"
fi
2020-09-24 21:00:26 +03:00
if [ " $1 " = = "arm64" ] || [ " $2 " = = "arm64" ] || [ " $3 " = = "arm64" ] ; then
MAC_ARCH = "arm64"
elif [ " $1 " = = "universal" ] || [ " $2 " = = "universal" ] || [ " $3 " = = "universal" ] ; then
MAC_ARCH = "universal"
else
MAC_ARCH = "x86_64"
fi
CUSTOM_CMAKE_CXX_FLAG = ""
if [ [ $1 = = CUSTOM_BUILD_FLAGS* ] ] || [ [ $2 = = CUSTOM_BUILD_FLAGS* ] ] || [ [ $3 = = CUSTOM_BUILD_FLAGS* ] ] ; then
if [ [ $1 = = CUSTOM_BUILD_FLAGS* ] ] ; then
CUSTOM_CMAKE_CXX_FLAG = " \" ${ 1 : 19 : 999 } \" "
elif [ [ $2 = = CUSTOM_BUILD_FLAGS* ] ] ; then
CUSTOM_CMAKE_CXX_FLAG = " \" ${ 2 : 19 : 999 } \" "
elif [ [ $3 = = CUSTOM_BUILD_FLAGS* ] ] ; then
CUSTOM_CMAKE_CXX_FLAG = " \" ${ 3 : 19 : 999 } \" "
fi
echo "custom build flags=" $CUSTOM_CMAKE_CXX_FLAG
fi
2020-09-22 11:16:29 +03:00
LINK_TYPE =
2023-09-11 21:10:21 +03:00
CMAKE_OPTS = " ${ CMAKE_OPTS :- -DBUILD_SHARED_LIBS=OFF } "
2020-09-22 11:16:29 +03:00
while getopts "h?vl:D:" opt; do
case " $opt " in
h| \? )
2020-09-24 07:23:33 +03:00
echo "Usage: build.sh [clean] [arm64|universal] [CUSTOM_CMAKE_CXX_FLAGS=x] [noroot] [release] [-h|-?] [-l (static|shared)] [-D CMAKE_OPTION] [-v]"
2020-09-22 11:16:29 +03:00
echo " "
echo "options: "
echo " "
2020-09-24 07:23:33 +03:00
echo "Positional options (1st three arguments): "
echo "[clean] - perform clean build "
echo "[arm64|universal] - Apple platform build type. Not applicable to other OS. "
echo "[CUSTOM_CMAKE_CXX_FLAGS] - custom CXX compiler flags "
echo "[noroot] - custom CXX compiler flags "
echo "[release] - build for Release "
2020-09-22 11:16:29 +03:00
echo " "
2020-09-24 07:23:33 +03:00
echo "Additional parameters: "
echo " -h | -? - this help. "
echo " -l [static|shared] - build static (default) or shared library. "
echo " -D [CMAKE_OPTION] - additional options to pass to cmake. Could be multiple. "
echo " -v - increase build verbosity (reserved for future use) "
2020-09-22 11:16:29 +03:00
echo " "
2020-09-24 07:23:33 +03:00
echo "Environment variables: "
echo "CMAKE_OPTS - any additional cmake options. "
echo "GIT_PULL_TOKEN - authorization token for Microsoft-proprietary modules. "
2023-01-28 10:43:03 +03:00
echo "MACOSX_DEPLOYMENT_TARGET - optional parameter for setting macosx deployment target "
2020-09-24 07:23:33 +03:00
echo "Plus any other environment variables respected by CMake build system. "
2020-09-22 11:16:29 +03:00
exit 0
; ;
:) echo " Invalid option: $OPTARG requires an argument " 1>& 2
exit 0
; ;
v) verbose = 1
; ;
D) CMAKE_OPTS = " $CMAKE_OPTS -D $OPTARG "
; ;
l) LINK_TYPE = $OPTARG
; ;
esac
done
shift $(( OPTIND - 1 ))
if [ " $LINK_TYPE " = = "shared" ] ; then
CMAKE_OPTS = " $CMAKE_OPTS -DBUILD_SHARED_LIBS=ON "
2019-08-07 01:40:28 +03:00
fi
2019-09-12 03:23:28 +03:00
# Set target MacOS minver
2023-01-28 10:43:03 +03:00
default_mac_os_target = $( [ " $MAC_ARCH " = = "arm64" ] && echo "11.10" || echo "10.10" )
[ -z $MACOSX_DEPLOYMENT_TARGET ] && export MACOSX_DEPLOYMENT_TARGET = ${ default_mac_os_target }
echo "macosx deployment target=" $MACOSX_DEPLOYMENT_TARGET
2019-09-12 03:23:28 +03:00
2018-03-31 03:05:05 +03:00
# Install build tools and recent sqlite3
FILE = .buildtools
2018-11-07 09:39:27 +03:00
OS_NAME = ` uname -a`
if [ ! -f $FILE ] ; then
2020-09-22 11:16:29 +03:00
case " $OS_NAME " in
2021-01-16 09:03:39 +03:00
*Darwin*) tools/setup-buildtools-apple.sh $MAC_ARCH ; ;
2020-09-22 11:16:29 +03:00
*Linux*) [ [ -z " $NOROOT " ] ] && sudo tools/setup-buildtools.sh || echo "No root: skipping build tools installation." ; ;
*) echo " WARNING: unsupported OS $OS_NAME , skipping build tools installation.. "
esac
# Assume that the build tools have been successfully installed
echo > $FILE
2018-03-31 03:05:05 +03:00
fi
2018-09-07 01:07:01 +03:00
if [ -f /usr/bin/gcc ] ; then
2020-09-22 11:16:29 +03:00
echo "gcc version: `gcc --version`"
2018-11-07 09:39:27 +03:00
fi
if [ -f /usr/bin/clang ] ; then
2020-09-22 11:16:29 +03:00
echo "clang version: `clang --version`"
2018-09-07 01:07:01 +03:00
fi
2019-03-08 08:24:15 +03:00
# Skip Version.hpp changes
2019-04-23 01:18:05 +03:00
# git update-index --skip-worktree lib/include/public/Version.hpp
2019-03-08 08:24:15 +03:00
2018-03-31 03:05:05 +03:00
#rm -rf out
mkdir -p out
cd out
2018-11-07 09:39:27 +03:00
# .tgz package
CMAKE_PACKAGE_TYPE = tgz
if [ -f /usr/bin/dpkg ] ; then
2020-11-09 19:06:12 +03:00
# .deb package
2020-09-22 11:16:29 +03:00
export CMAKE_PACKAGE_TYPE = deb
2020-11-09 19:06:12 +03:00
elif [ -f /usr/bin/rpmbuild ] ; then
# .rpm package
2020-09-22 11:16:29 +03:00
export CMAKE_PACKAGE_TYPE = rpm
2018-09-07 01:07:01 +03:00
fi
2019-04-16 23:51:09 +03:00
# Fail on error
set -e
2020-09-22 11:16:29 +03:00
# TODO: should this be improved to verify if the platform is Apple? Right now we unconditionally pass -DMAC_ARCH even if building for Windows or Linux.
cmake_cmd = " cmake -DMAC_ARCH= $MAC_ARCH -DCMAKE_BUILD_TYPE= $BUILD_TYPE -DCMAKE_PACKAGE_TYPE= $CMAKE_PACKAGE_TYPE -DCMAKE_CXX_FLAGS= " ${ CUSTOM_CMAKE_CXX_FLAG } " $CMAKE_OPTS .. "
2020-09-10 13:13:55 +03:00
echo $cmake_cmd
eval $cmake_cmd
2019-08-07 01:40:28 +03:00
# TODO: strip symbols to minimize (release-only)
2018-03-31 03:05:05 +03:00
# Build all
2018-11-07 09:39:27 +03:00
# TODO: what are the pros and cons of using 'make' vs 'cmake --build' ?
#make
cmake --build .
2018-03-31 03:05:05 +03:00
2019-04-16 23:51:09 +03:00
# No fail on error
set +e
2018-03-31 03:05:05 +03:00
# Remove old package
2018-09-07 01:07:01 +03:00
rm -f *.deb *.rpm
2018-03-31 03:05:05 +03:00
# Build new package
make package
2020-11-09 19:06:12 +03:00
# Install newly generated package
2018-09-07 01:07:01 +03:00
if [ -f /usr/bin/dpkg ] ; then
2020-11-09 19:06:12 +03:00
# Ubuntu / Debian / Raspbian
2020-09-22 11:16:29 +03:00
[ [ -z " $NOROOT " ] ] && sudo dpkg -i *.deb || echo "No root: skipping package deployment."
2020-11-09 19:06:12 +03:00
elif [ -f /usr/bin/rpmbuild ] ; then
# Redhat / Centos
2020-09-22 11:16:29 +03:00
[ [ -z " $NOROOT " ] ] && sudo rpm -i --force -v *.rpm || echo "No root: skipping package deployment."
2018-09-07 01:07:01 +03:00
fi
2018-03-31 03:05:05 +03:00
# Install SDK headers and lib to /usr/local
#
2018-11-07 09:39:27 +03:00
## TODO: [MG] - fix this section for shared library
2019-03-29 02:40:31 +03:00
## strip --strip-unneeded out/lib/libmat.so
## strip -S --strip-unneeded --remove-section=.note.gnu.gold-version --remove-section=.comment --remove-section=.note --remove-section=.note.gnu.build-id --remove-section=.note.ABI-tag out/lib/libmat.so
2018-11-07 09:39:27 +03:00
if [ " $CMAKE_PACKAGE_TYPE " = = "tgz" ] ; then
2020-09-22 11:16:29 +03:00
cd ..
MATSDK_INSTALL_DIR = " ${ MATSDK_INSTALL_DIR :- /usr/local } "
echo "+-----------------------------------------------------------------------------------+"
echo " This step may prompt for your sudo password to deploy SDK to $MATSDK_INSTALL_DIR "
echo "+-----------------------------------------------------------------------------------+"
[ [ -z " $NOROOT " ] ] && sudo ./install.sh $MATSDK_INSTALL_DIR || echo "No root: skipping package deployment."
2018-11-07 09:39:27 +03:00
fi