1#!/bin/bash
2
3case "$1" in
4    "before_install")
5	;;
6    "install")
7	case "${TRAVIS_OS_NAME}" in
8	    "osx")
9		brew update >/dev/null
10		brew install binutils
11
12		case "${CC}" in
13		    "gcc-"*)
14			which ${CC} || brew install $(echo "${CC}" | sed 's/\-/@/') || brew link --overwrite $(echo "${CC}" | sed 's/\-/@/')
15			;;
16		esac
17
18		case "${BUILD_SYSTEM}" in
19		    "bazel")
20			brew cask install homebrew/cask-versions/adoptopenjdk8
21			brew install bazel
22			;;
23		esac
24		;;
25	    "linux")
26		case "${CC}" in
27		    "pgcc")
28			wget 'https://raw.githubusercontent.com/nemequ/pgi-travis/de6212d94fd0e7d07a6ef730c23548c337c436a7/install-pgi.sh'
29			echo 'acd3ef995ad93cfb87d26f65147395dcbedd4c3c844ee6ec39616f1a347c8df5  install-pgi.sh' | sha256sum -c --strict || exit 1
30			/bin/sh install-pgi.sh
31			;;
32		esac
33		;;
34	esac
35	;;
36    "script")
37	case "${BUILD_SYSTEM}" in
38	    "cmake")
39		mkdir builddir && cd builddir
40		CMAKE_FLAGS=
41		if [ "${CROSS_COMPILE}" = "yes" ]; then
42		    CMAKE_FLAGS="-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_RC_COMPILER=${RC_COMPILER}"
43		fi
44		cmake ${CMAKE_FLAGS} -DCMAKE_C_COMPILER="$CC" -DCMAKE_CXX_COMPILER="$CXX" -DENABLE_SANITIZER="${SANITIZER}" -DCMAKE_C_FLAGS="${CFLAGS}" .. || exit 1
45		make VERBOSE=1 || exit 1
46		ctest -V || exit 1
47		;;
48	    "python")
49		python setup.py test
50		;;
51	    "maven")
52		cd java/org/brotli
53		mvn install && cd integration && mvn verify
54		;;
55	    "autotools")
56		./bootstrap && ./configure && make
57		;;
58	    "fuzz")
59		./c/fuzz/test_fuzzer.sh
60		;;
61	    "bazel")
62		bazel build -c opt ...:all &&
63		cd go && bazel test -c opt ...:all && cd .. &&
64		cd java && bazel test -c opt ...:all && cd .. &&
65		cd js && bazel test -c opt ...:all && cd .. &&
66		cd research && bazel build -c opt ...:all && cd ..
67		;;
68	esac
69	;;
70    "after_success")
71	;;
72    "before_deploy")
73	case "${BUILD_SYSTEM}" in
74	    "bazel")
75		export RELEASE_DATE=`date +%Y-%m-%d`
76		perl -p -i -e 's/\$\{([^}]+)\}/defined $ENV{$1} ? $ENV{$1} : $&/eg' scripts/.bintray.json
77		zip -j9 brotli.zip bazel-bin/libbrotli*.a bazel-bin/libbrotli*.so bazel-bin/brotli
78		;;
79	esac
80	;;
81esac
82