1#!/bin/sh -e
2
3. CI/travis/lib.sh
4
5# Don't prepare a deploy on a Coverity build
6if [ "x${COVERITY_SCAN_PROJECT_NAME}" != "x" ] ; then exit 0; fi
7
8deploy=0
9if [ -z "$TRAVIS_BUILD_DIR" ] ; then
10	t=$(find ./ -name CMakeCache.txt|head -1)
11	if [ -n "${t}" ] ; then
12		cd $(dirname $(dirname ${t}))
13		TRAVIS_BUILD_DIR=$(pwd)
14	else
15		echo "I am confused - can't find CMakeCache.txt"
16		exit
17	fi
18else
19	cd $TRAVIS_BUILD_DIR
20fi
21pwd
22
23if [ -z "${LDIST}" -a -f "build/.LDIST" ] ; then
24	export LDIST="-$(cat build/.LDIST)"
25fi
26if [ -z "${LDIST}" ] ; then
27	export LDIST="-$(get_ldist)"
28fi
29
30check_file()
31{
32temp=""
33for i in $(find ./ -name CMakeCache.txt)
34do
35hit=$(find $(dirname ${i}) -maxdepth 1 -name "libiio*.$1" -a ! -name "*${LDIST}*")
36if [ "$(echo ${hit} | wc -w)" -gt "1"  ] ; then
37	echo "I am confused - more than 2 $1 files!"
38	echo $hit
39	exit 1
40else
41	if [ "$(echo ${hit} | wc -w)" -eq "1" ] ; then
42		if [ -z "${temp}" ] ; then
43			temp=$hit
44		else
45			echo "I am confused - more than 2 $1 files"
46			echo $temp
47			echo $hit
48			exit 1
49		fi
50	fi
51fi
52done
53}
54
55check_file deb
56if [ -n "${temp}" ] ; then
57	deploy=$(expr ${deploy} + 1)
58	if [ -z "${TARGET_DEB}" ] ; then
59		export TARGET_DEB=$(echo ${temp} | \
60			sed -e 's:^./.*/::' -e 's:-Linux::' -e 's:.deb$::')${LDIST}.deb
61	fi
62	echo "deploying ${temp} to nightly $TARGET_DEB"
63	if [ -z "${RELEASE_PKG_FILE_DEB}" ] ; then
64		export RELEASE_PKG_FILE_DEB=$(dirname ${temp})/${TARGET_DEB}
65		cp ${temp} ${RELEASE_PKG_FILE_DEB}
66	fi
67	echo ${TARGET_DEB}
68	ls -lh ${temp}
69	echo ${RELEASE_PKG_FILE_DEB}
70	ls -lh ${RELEASE_PKG_FILE_DEB}
71else
72	echo "Skipping deployment of debian package"
73fi
74
75check_file rpm
76if [ -n "${temp}" ] ; then
77	deploy=$(expr ${deploy} + 1)
78	if [ -z "${TARGET_RPM}" ] ; then
79		export TARGET_RPM=$(echo ${temp} | \
80			sed -e 's:^./.*/::' -e 's:-Linux::' -e 's:.rpm$::')${LDIST}.rpm
81	fi
82	echo "deploying ${temp} to nightly $TARGET_RPM"
83	if [ -z "${RELEASE_PKG_FILE_RPM}" ] ; then
84		export RELEASE_PKG_FILE_RPM=$(dirname ${temp})/${TARGET_RPM}
85		cp ${temp}  ${RELEASE_PKG_FILE_RPM}
86	fi
87	echo ${TARGET_RPM}
88	ls -lh ${temp}
89	echo ${RELEASE_PKG_FILE_RPM}
90	ls -lh ${RELEASE_PKG_FILE_RPM}
91else
92	echo "Skipping deployment of rpm package"
93fi
94
95check_file tar.gz
96if [  -n "${temp}"  ] ; then
97	deploy=$(expr ${deploy} + 1)
98	if [ -z "${TARGET_TGZ}" ] ; then
99		echo Add the MATLAB bindings into the tar file
100		(
101		cd $(dirname ${temp})
102		if [ -d tarball_fixup ] ; then
103			rm -rf tarball_fixup
104		fi
105		mkdir tarball_fixup && cd tarball_fixup
106
107		if [ "$TRAVIS_OS_NAME" = "osx" ] ; then
108			tar --strip-components=1 -xzf ${TRAVIS_BUILD_DIR}/${temp}
109		else
110			tar -xzf ${TRAVIS_BUILD_DIR}/${temp}
111		fi
112
113		mkdir -p usr/include usr/lib/matlab/iio
114		cp ${TRAVIS_BUILD_DIR}/bindings/matlab/iio-wrapper.h usr/include/
115		cp ${TRAVIS_BUILD_DIR}/bindings/matlab/*.m usr/lib/matlab/iio/
116
117		if [ "$TRAVIS_OS_NAME" = "osx" ] ; then
118			cd usr/lib
119			ln -fs ../../Library/Frameworks/iio.framework/iio libiio.dylib
120			install_name_tool -change /usr/local/opt/libusb/lib/libusb-1.0.0.dylib @rpath/libusb-1.0.dylib libiio.dylib
121			install_name_tool -add_rpath @loader_path/../../../../../usr/lib libiio.dylib
122			install_name_tool -add_rpath /usr/local/opt/libusb/lib libiio.dylib
123
124			cd ../include
125			ln -s ../../Library/Frameworks/iio.framework/Headers/iio.h iio.h
126
127			# Update references for tools
128			cd ../..
129			TOOLS=Library/Frameworks/iio.framework/Tools/*
130			for tool in $TOOLS
131			do
132				install_name_tool -add_rpath @loader_path/../../ $tool
133			done
134			cp /usr/local/lib/libusb-1.0.dylib usr/lib/
135			chmod +w usr/lib/libusb-1.0.dylib
136			install_name_tool -id @rpath/libusb-1.0.dylib usr/lib/libusb-1.0.dylib
137
138			tar -czf ${TRAVIS_BUILD_DIR}/${temp} usr Library
139		else
140			tar -czf ${TRAVIS_BUILD_DIR}/${temp} usr lib
141		fi
142		)
143
144		export TARGET_TGZ=$(echo ${temp} | \
145			sed -e 's:^./.*/::' -e 's:-Linux::' -e 's:-Darwin::' -e 's:.tar.gz$::')${LDIST}.tar.gz;
146	fi
147	echo "deploying ${temp} to $TARGET_TGZ"
148	if [ -z "${RELEASE_PKG_FILE_TGZ}" ] ; then
149		export RELEASE_PKG_FILE_TGZ=$(dirname ${temp})/${TARGET_TGZ}
150		cp ${temp} ${RELEASE_PKG_FILE_TGZ}
151	fi
152	echo ${TARGET_TGZ}
153	ls -lh ${temp}
154	echo ${RELEASE_PKG_FILE_TGZ}
155	ls -lh ${RELEASE_PKG_FILE_TGZ}
156else
157	echo "Skipping deployment of tarball"
158fi
159
160check_file pkg
161if [ -n "${temp}" ] ; then
162	deploy=$(expr ${deploy} + 1)
163	if [ -z "${TARGET_PKG}" ] ; then
164		export TARGET_PKG=$(echo ${temp} | \
165			sed -e 's:^./.*/::' -e 's:.pkg$::')${LDIST}.pkg
166	fi
167	echo "deploying ${temp} to nightly $TARGET_PKG"
168	if [ -z "${RELEASE_PKG_FILE_PKG}" ] ; then
169		export RELEASE_PKG_FILE_PKG=$(dirname ${temp})/${TARGET_PKG}
170		cp ${temp} ${RELEASE_PKG_FILE_PKG}
171	fi
172	echo ${TARGET_PKG}
173	ls -lh ${temp}
174	echo ${RELEASE_PKG_FILE_PKG}
175	ls -lh ${RELEASE_PKG_FILE_PKG}
176else
177	echo "Skipping deployment of OS X package"
178fi
179
180if [ "${deploy}" -eq "0" ] ; then
181	echo did not deploy any files
182	exit 1
183fi
184