File indexing completed on 2024-05-12 04:17:32

0001 #!/bin/bash
0002 
0003 # Script to build a bundle MXE installation with all Exiv2 low level dependencies in a dedicated directory.
0004 #
0005 # SPDX-FileCopyrightText: 2015-2024 by Gilles Caulier, <caulier dot gilles at gmail dot com>
0006 #
0007 # SPDX-License-Identifier: BSD-3-Clause
0008 #
0009 
0010 # Halt and catch errors
0011 set -eE
0012 trap 'PREVIOUS_COMMAND=$THIS_COMMAND; THIS_COMMAND=$BASH_COMMAND' DEBUG
0013 trap 'echo "FAILED COMMAND: $PREVIOUS_COMMAND"' ERR
0014 
0015 #################################################################################################
0016 # Manage script traces to log file
0017 
0018 mkdir -p ./logs
0019 exec > >(tee ./logs/build-mxe.full.log) 2>&1
0020 
0021 #################################################################################################
0022 
0023 echo "build-mxe.sh : build a bundle MXE install with Exiv2 dependencies."
0024 echo "-----------------------------------------------------------------------"
0025 
0026 #################################################################################################
0027 # Configuration
0028 
0029 # Absolute path where are downloaded all tarballs to compile.
0030 DOWNLOAD_DIR="`pwd`/temp.dwnld"
0031 
0032 # Absolute path where are compiled all tarballs
0033 BUILDING_DIR="`pwd`/temp.build"
0034 
0035 #-------------------------------------------------------------------------------------------
0036 
0037 # MXE configuration
0038 
0039 #------------
0040 # IMPORTANT: Target Windows architecture to build installer. Possible values: 32 or 64 bits.
0041 MXE_ARCHBITS=64
0042 #------------
0043 
0044 if [[ $MXE_ARCHBITS == 32 ]]; then
0045     # Windows 32 bits shared
0046     MXE_BUILD_TARGETS="i686-w64-mingw32.shared"
0047     MXE_BUILDROOT="`pwd`/build.win32"
0048 elif [[ $MXE_ARCHBITS == 64 ]]; then
0049     # Windows 64 bits shared
0050     MXE_BUILD_TARGETS="x86_64-w64-mingw32.shared"
0051     MXE_BUILDROOT="`pwd`/build.win64"
0052 else
0053     echo "Unsupported or wrong target Windows architecture: $MXE_ARCHBITS bits."
0054     exit -1
0055 fi
0056 
0057 echo "Target Windows architecture: $MXE_ARCHBITS bits."
0058 
0059 MXE_GIT_URL="https://github.com/mxe/mxe.git"
0060 MXE_GIT_REVISION=master
0061 MXE_INSTALL_PREFIX=${MXE_BUILDROOT}/usr/${MXE_BUILD_TARGETS}/
0062 MXE_TOOLCHAIN=${MXE_INSTALL_PREFIX}/share/cmake/mxe-conf.cmake
0063 
0064 
0065 #################################################################################################
0066 # Macro definitions
0067 
0068 ChecksCPUCores()
0069 {
0070 CPU_CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu)
0071 
0072 if [[ $CPU_CORES -gt 1 ]]; then
0073     CPU_CORES=$((CPU_CORES-1))
0074 fi
0075 
0076 echo "CPU Cores to use : $CPU_CORES"
0077 }
0078 
0079 # For time execution measurement ; startup
0080 StartScript()
0081 {
0082 BEGIN_SCRIPT=$(date +"%s")
0083 }
0084 
0085 # For time execution measurement : shutdown
0086 TerminateScript()
0087 {
0088 TERMIN_SCRIPT=$(date +"%s")
0089 difftimelps=$(($TERMIN_SCRIPT-$BEGIN_SCRIPT))
0090 echo "Elaspsed time for script execution : $(($difftimelps / 3600 )) hours $((($difftimelps % 3600) / 60)) minutes $(($difftimelps % 60)) seconds"
0091 }
0092 
0093 #################################################################################################
0094 
0095 StartScript
0096 ChecksCPUCores
0097 
0098 # Paths rules
0099 ORIG_PATH="$PATH"
0100 ORIG_WD="`pwd`"
0101 
0102 export PATH=$MXE_BUILDROOT/usr/bin:$MXE_INSTALL_PREFIX/qt5/bin:$PATH
0103 
0104 #################################################################################################
0105 # Check if a previous bundle already exist
0106 
0107 CONTINUE_INSTALL=0
0108 
0109 if [ -d "$MXE_BUILDROOT" ] ; then
0110 
0111     read -p "$MXE_BUILDROOT already exist. Do you want to remove it or to continue an aborted previous installation ? [(r)emove/(c)ontinue/(s)top] " answer
0112 
0113     if echo "$answer" | grep -iq "^r" ;then
0114 
0115         echo "---------- Removing existing $MXE_BUILDROOT"
0116 #        chmod +w "$MXE_BUILDROOT/usr/readonly"
0117 #        chattr -i "$MXE_BUILDROOT/usr/readonly/.gitkeep"
0118         rm -rf "$MXE_BUILDROOT"
0119 
0120     elif echo "$answer" | grep -iq "^c" ;then
0121 
0122         echo "---------- Continue aborted previous installation in $MXE_BUILDROOT"
0123         CONTINUE_INSTALL=1
0124 
0125     else
0126 
0127         echo "---------- Aborting..."
0128         exit;
0129 
0130     fi
0131 
0132 fi
0133 
0134 if [[ $CONTINUE_INSTALL == 0 ]]; then
0135 
0136     # Checkout latest MXE from github
0137     git clone $MXE_GIT_URL $MXE_BUILDROOT
0138 
0139 fi
0140 
0141 #################################################################################################
0142 # MXE git revision to use
0143 
0144 cd $MXE_BUILDROOT
0145 
0146 if [[ $MXE_GIT_REVISION == "master" ]]; then
0147     echo -e "\n"
0148     echo "---------- Updating MXE"
0149     git pull
0150 else
0151     echo -e "\n"
0152     echo "---------- Checkout MXE revision to $MXE_GIT_REVISION"
0153     git checkout $MXE_GIT_REVISION
0154 fi
0155 
0156 #################################################################################################
0157 # Dependencies build and installation
0158 
0159 echo -e "\n"
0160 echo "---------- Building Exiv2 low level dependencies with MXE"
0161 
0162 make MXE_TARGETS=$MXE_BUILD_TARGETS \
0163      gcc \
0164      cmake \
0165      libgnurx \
0166      gettext \
0167      libxml2 \
0168      libxslt \
0169      libpng \
0170      expat \
0171      zlib \
0172      mman-win32 \
0173      pthreads
0174 
0175 echo -e "\n"
0176 
0177 #################################################################################################
0178 
0179 export PATH=$ORIG_PATH
0180 
0181 TerminateScript