Merge pull request #1518 from dg0yt/static-windows
[openjpeg.git] / tools / travis-ci / install.sh
1 #!/bin/bash
2
3 # This script executes the install step when running under travis-ci
4
5 #if cygwin, check path
6 case ${MACHTYPE} in
7         *cygwin*) OPJ_CI_IS_CYGWIN=1;;
8         *) ;;
9 esac
10
11 if [ "${OPJ_CI_IS_CYGWIN:-}" == "1" ]; then
12         # PATH is not yet set up
13         export PATH=$PATH:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
14 fi
15
16 # Set-up some error handling
17 set -o nounset   ## set -u : exit the script if you try to use an uninitialised variable
18 set -o errexit   ## set -e : exit the script if any statement returns a non-true return value
19 set -o pipefail  ## Fail on error in pipe
20
21 function exit_handler ()
22 {
23         local exit_code="$?"
24         
25         test ${exit_code} == 0 && return;
26
27         echo -e "\nInstall failed !!!\nLast command at line ${BASH_LINENO}: ${BASH_COMMAND}";
28         exit "${exit_code}"
29 }
30 trap exit_handler EXIT
31 trap exit ERR
32
33 # We don't need anything for coverity scan builds. ABI check is managed in abi-check.sh
34 if [ "${COVERITY_SCAN_BRANCH:-}" == "1" ] || [ "${OPJ_CI_ABI_CHECK:-}" == "1" ]; then
35         exit 0
36 fi
37
38 if [ "${OPJ_CI_SKIP_TESTS:-}" != "1" ]; then
39
40         OPJ_SOURCE_DIR=$(cd $(dirname $0)/../.. && pwd)
41
42         # We need test data
43         if [ "${GITHUB_HEAD_REF:-}" != "" ]; then
44                 OPJ_DATA_BRANCH=${GITHUB_HEAD_REF}
45         elif [ "${TRAVIS_BRANCH:-}" != "" ]; then
46                 OPJ_DATA_BRANCH=${TRAVIS_BRANCH}
47         elif [ "${APPVEYOR_REPO_BRANCH:-}" != "" ]; then
48                 OPJ_DATA_BRANCH=${APPVEYOR_REPO_BRANCH}
49         else
50                 OPJ_DATA_BRANCH=$(git -C ${OPJ_SOURCE_DIR} branch | grep '*' | tr -d '*[[:blank:]]') #default to same branch as we're setting up
51         fi
52         OPJ_DATA_HAS_BRANCH=$(git ls-remote --heads https://github.com/uclouvain/openjpeg-data ${OPJ_DATA_BRANCH} | wc -l)
53         if [ ${OPJ_DATA_HAS_BRANCH} -eq 0 ]; then
54                 OPJ_DATA_BRANCH=master #default to master
55         fi
56         echo "Cloning openjpeg-data from ${OPJ_DATA_BRANCH} branch"
57         git clone -v --depth=1 --branch=${OPJ_DATA_BRANCH} https://github.com/uclouvain/openjpeg-data data
58
59         # We need jpylyzer for the test suite
60     JPYLYZER_VERSION="1.17.0"    
61         echo "Retrieving jpylyzer"
62         if [ "${TRAVIS_OS_NAME:-}" == "osx"  -o "${RUNNER_OS:-}" == "macOS" ] || uname -s | grep -i Darwin &> /dev/null; then
63         echo "Skip Retrieving jpylyzer on OSX. Related tests no longer work on CI"
64         elif [ "${APPVEYOR:-}" == "True" -o "${RUNNER_OS:-}" == "Windows" ]; then
65                 wget -q https://github.com/openpreserve/jpylyzer/releases/download/${JPYLYZER_VERSION}/jpylyzer_${JPYLYZER_VERSION}_win32.zip
66                 mkdir jpylyzer
67                 cd jpylyzer
68                 cmake -E tar -xf ../jpylyzer_${JPYLYZER_VERSION}_win32.zip
69                 cd ..
70         else
71                 wget -qO - https://github.com/openpreserve/jpylyzer/archive/${JPYLYZER_VERSION}.tar.gz | tar -xz
72                 mv jpylyzer-${JPYLYZER_VERSION}/jpylyzer ./
73                 chmod +x jpylyzer/jpylyzer.py
74         fi
75
76         # When OPJ_NONCOMMERCIAL=1, kakadu trial binaries are used for testing. Here's the copyright notice from kakadu:
77         # Copyright is owned by NewSouth Innovations Pty Limited, commercial arm of the UNSW Australia in Sydney.
78         # You are free to trial these executables and even to re-distribute them, 
79         # so long as such use or re-distribution is accompanied with this copyright notice and is not for commercial gain.
80         # Note: Binaries can only be used for non-commercial purposes.
81         if [ "${OPJ_NONCOMMERCIAL:-}" == "1" ]; then
82                 if [ "${TRAVIS_OS_NAME:-}" == "linux" -o "${RUNNER_OS:-}" == "Linux" ] || uname -s | grep -i Linux &> /dev/null; then
83                         echo "Retrieving Kakadu"
84                         wget -q http://kakadusoftware.com/wp-content/uploads/KDU841_Demo_Apps_for_Linux-x86-64_231117.zip
85                         cmake -E tar -xf KDU841_Demo_Apps_for_Linux-x86-64_231117.zip
86                         mv KDU841_Demo_Apps_for_Linux-x86-64_231117 kdu
87                 elif [ "${TRAVIS_OS_NAME:-}" == "osx"  -o "${RUNNER_OS:-}" == "macOS" ] || uname -s | grep -i Darwin &> /dev/null; then
88                         echo "Retrieving Kakadu"
89                         wget -v http://kakadusoftware.com/wp-content/uploads/KDU841_Demo_Apps_for_MacOS_231117.dmg_.zip
90                         cmake -E tar -xf KDU841_Demo_Apps_for_MacOS_231117.dmg_.zip
91                         wget -q http://downloads.sourceforge.net/project/catacombae/HFSExplorer/0.23/hfsexplorer-0.23-bin.zip
92                         mkdir hfsexplorer && cmake -E chdir hfsexplorer tar -xf ../hfsexplorer-0.23-bin.zip
93                         ./hfsexplorer/bin/unhfs.sh -o ./ -fsroot Kakadu-demo-apps.pkg  KDU841_Demo_Apps_for_MacOS_231117.dmg
94                         pkgutil --expand Kakadu-demo-apps.pkg ./kdu
95                         cd kdu
96                         cat libkduv84r.pkg/Payload | gzip -d | cpio -id
97                         cat kduexpand.pkg/Payload | gzip -d | cpio -id
98                         cat kducompress.pkg/Payload | gzip -d | cpio -id
99                         install_name_tool -id ${PWD}/libkdu_v84R.dylib libkdu_v84R.dylib 
100                         install_name_tool -change /usr/local/lib/libkdu_v84R.dylib ${PWD}/libkdu_v84R.dylib kdu_compress
101                         install_name_tool -change /usr/local/lib/libkdu_v84R.dylib ${PWD}/libkdu_v84R.dylib kdu_expand
102                 elif [ "${APPVEYOR:-}" == "True" -o "${RUNNER_OS:-}" == "Windows"  ] || uname -s | grep -i MINGW &> /dev/null || uname -s | grep -i CYGWIN &> /dev/null; then
103                         echo "Retrieving Kakadu"
104                         wget -q http://kakadusoftware.com/wp-content/uploads/KDU841_Demo_Apps_for_Win64_231117.msi_.zip
105                         cmake -E tar -xf KDU841_Demo_Apps_for_Win64_231117.msi_.zip
106                         msiexec /i KDU841_Demo_Apps_for_Win64_231117.msi /quiet /qn /norestart
107                         if [ -d "C:/Program Files/Kakadu" ]; then
108                                 cp -r "C:/Program Files/Kakadu" ./kdu
109                         else
110                                 cp -r "C:/Program Files (x86)/Kakadu" ./kdu
111                         fi
112                 fi
113         fi
114 fi
115
116 if [ "${OPJ_CI_CHECK_STYLE:-}" == "1" ]; then
117     pip install --user autopep8
118 fi