1#! /bin/bash 2# Script: build.sh 3# Purpose: Build PhotoFlow, create starter scripts. 4# Call: build.sh <Build-Type> 5# Build-Type: debug for a Debug Build, 6# test for a Test Build, 7# else for a Release Build. 8# Environment Variables: 9# BUILD_TYPE : the Build-Type as above. Optional. 10# INSTALL_PREFIX : the root directory for PhotoFlow's release, debug or test 11# builds. 12# Optional. If omitted, then this is the current directory. 13# CMAKE_EXTRA_PARAMS: extra parameters to control cmake, such as -DBUNDLED_GEVIV2=OFF. 14# LD_LIBRARY_PATH: a colon-separated list of directories where libraries 15# should be searched before the standard directories. 16# If VIPS_INSTALL_PREFIX is set, then this variable will 17# be extended accordingly. 18# PKG_CONFIG_PATH: see "man pkg-config". 19# If VIPS_INSTALL_PREFIX is set, then this variable will 20# be extended accordingly. 21# VIPS_INSTALL_PREFIX: VIPS' install prefix. Optional. 22# If omitted, then the system's libvips is used. 23# Author, License: 24# Copyright (C) 2014, 2016 Ferrero Andrea, Sven Claussner 25# 26# This program is free software: you can redistribute it and/or modify 27# it under the terms of the GNU General Public License as published by 28# the Free Software Foundation, either version 3 of the License, or 29# (at your option) any later version. 30# 31# This program is distributed in the hope that it will be useful, 32# but WITHOUT ANY WARRANTY; without even the implied warranty of 33# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34# GNU General Public License for more details. 35# 36# You should have received a copy of the GNU General Public License 37# along with this program. If not, see <http://www.gnu.org/licenses/>. 38 39# evaluate arguments and environment variables 40## Evaluate BUILD_TYPE and create uppercase and capitalized variants of it. 41## BUILD_TYPE: use environment variable BUILD_TYPE, $1 or Release (in this order) 42BUILD_TYPE=${BUILD_TYPE:-${1:-Release}} 43build_type_upper=$(echo ${BUILD_TYPE} | tr '[:lower:]' '[:upper:]') 44build_type_capital=$(echo ${BUILD_TYPE} | tr '[:upper:]' '[:lower:]' | sed 's/.*/\u&/') 45echo "build_type_upper:" $build_type_upper >log.txt 46echo "build_type_capital:" $build_type_capital >>log.txt 47 48## evaluate INSTALL_PREFIX to determine the installation directory 49export INSTALL_PREFIX=${INSTALL_PREFIX:-$(pwd)} 50phf_install_prefix=${INSTALL_PREFIX}/${build_type_capital} 51 52# set LD_LIBRARY_PATH 53if [ -n "${VIPS_INSTALL_PREFIX}" ]; then 54 export PKG_CONFIG_PATH=${VIPS_INSTALL_PREFIX}/lib/pkgconfig:${PKG_CONFIG_PATH} 55 export LD_LIBRARY_PATH=${VIPS_INSTALL_PREFIX}/lib:${LD_LIBRARY_PATH} 56fi 57 58# clean up before building 59rm CMakeCache.txt 60 61echo "Building PhotoFlow..." 62echo "Install PhotoFlow to: ${phf_install_prefix}" 63echo "Build type: ${build_type_capital}" 64echo "Use VIPS in ${VIPS_INSTALL_PREFIX}" 65echo "PKG_CONFIG_PATH: ${PKG_CONFIG_PATH}" 66echo "LD_LIBRARY_PATH: ${LD_LIBRARY_PATH}" 67 68if [ "${build_type_upper}" = "TEST" ]; then 69# valid values for CMAKE_BUILD_TYPE:[DEBUG|RELEASE|RELWITHDEBINFO|MINSIZEREL] 70 cmake -DCMAKE_BUILD_TYPE=DEBUG \ 71 -DCMAKE_INSTALL_PREFIX=${phf_install_prefix} \ 72 -DINSTALL_PREFIX=${phf_install_prefix} \ 73 ${CMAKE_EXTRA_PARAMS} \ 74 .. && 75 make VERBOSE=1 install 76else 77# make Release, Debug and everything else except Test 78 cmake -DCMAKE_BUILD_TYPE=${build_type_upper} \ 79 -DCMAKE_INSTALL_PREFIX=${phf_install_prefix} \ 80 -DINSTALL_PREFIX=${phf_install_prefix} \ 81 ${CMAKE_EXTRA_PARAMS} \ 82 .. && 83 make VERBOSE=1 install 84fi 85 86# If the build broke, then exit here with a message. 87return_code=$? 88if [ ${return_code} -ne 0 ]; then 89 echo "Building PhotoFlow finished with return code ${return_code}." 90 exit ${return_code} 91fi 92 93printf "Creating starter scripts to ensure Photoflow finds libvips: " 94printf "run_photoflow.sh, " 95cat <<EOF >${phf_install_prefix}/run_photoflow.sh 96#! /bin/bash 97export LD_LIBRARY_PATH=${LD_LIBRARY_PATH} 98echo LD_LIBRARY_PATH=\${LD_LIBRARY_PATH} 99${phf_install_prefix}/bin/photoflow 100echo Photoflow exited with code \$?. 101EOF 102chmod a+x ${phf_install_prefix}/run_photoflow.sh 103 104printf "run_pfbatch.sh.\n" 105cat << EOF >${phf_install_prefix}/run_pfbatch.sh 106#! /bin/bash 107export "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" 108echo LD_LIBRARY_PATH=\${LD_LIBRARY_PATH} 109${phf_install_prefix}/bin/pfbatch 110echo Pfbatch exited with code \$?. 111EOF 112chmod a+x ${phf_install_prefix}/run_pfbatch.sh 113 114echo "Building PhotoFlow finished with return code $?." 115