tar_em_up.sh 11.7 KB
Newer Older
1
#!/bin/bash -euo pipefail
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
2 3 4
# super-simplistic installer for l2ork things by Ivica Ico Bukvic <ico@vt.edu>
# for info on L2Ork visit http://l2ork.music.vt.edu

5 6 7 8 9 10 11 12
cleanup() {
    # maybe we'd want to do some actual cleanup here
    test $2 -ne 0 && echo "$0: $1: command failed with exit code $2, exiting now." && echo "$0: $1: $BASH_COMMAND"
    exit $2
}

trap 'cleanup $LINENO $?' ERR

Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
13 14 15 16 17
if [ $# -eq 0 ] # should check for no arguments
then
	echo
	echo "   Usage: ./tar_em_up.sh -option1 -option2 ..."
	echo "   Options:"
18 19
	echo "     -b    build a Debian package (incremental)"
	echo "     -B    build a Debian package (complete recompile)"
20
	echo "     -c    core Pd source tarball"
21 22
	echo "     -f    full tarball installer (incremental)"
	echo "     -F    full tarball installer (complete recompile)"
23
	echo "     -k    keep previous build products"
Albert Gräf's avatar
Albert Gräf committed
24
	echo "     -l    do a light build (only essential externals)"
25
	echo "     -C    clean folder and temp files before building"
26
	echo "     -n    skip package creation (-bB, -fF)"
Ivica Bukvic's avatar
Ivica Bukvic committed
27
	echo "     -r    build a Raspberry Pi deb (incremental)"
28 29 30
	echo "     -R    build a Raspberry Pi deb (complete recompile)"
	echo "     -t    auto-detect target (incremental)"
	echo "     -T    auto-detect target (complete recompile)"
31
	echo "     -X    build an OSX installer (dmg)"
32 33
	echo "     -z    build a Windows installer (incremental)"
	echo "     -Z    build a Windows installer (complete recompile)"
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
34
	echo
35
	echo "   The incremental options bypass Gem compilation. This saves"
36 37 38
	echo "   (lots of) time, but the generated package will lack Gem"
	echo "   unless it has already been built previously. NOTE: Building"
	echo "   Gem is NOT supported on OSX right now."
39 40
	echo
	echo "   The -k (keep) option doesn't clean before compilation,"
41 42 43
	echo "   preserving the build products from a previous run. This"
	echo "   also saves time if the script has been run previously."
	echo "   Not using this option forces a full recompile."
44
	echo
45 46
	echo "   For custom install locations and staged installations"
	echo "   set the inst_dir environment variable as follows:"
47 48 49
	echo
	echo "           export inst_dir=/some/custom/location"
	echo
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
50 51 52 53
	exit 1
fi

deb=0
54
clean=0
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
55 56
core=0
full=0
Ivica Bukvic's avatar
Ivica Bukvic committed
57
rpi=0
58
pkg=1
59
inno=0
60
dmg=0
61
any=0
62
clean=1
Albert Gräf's avatar
Albert Gräf committed
63
light=0
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
64

65
while getopts ":bBcCfFklnRrTtXzZ" Option
66 67 68 69 70 71 72 73 74
do case $Option in
		b)		deb=1
				inst_dir=${inst_dir:-/usr};;

		B)		deb=2
				inst_dir=${inst_dir:-/usr};;

		c)		core=1;;

75 76
		C)		clean=1;;

77 78 79 80
		f)		full=1;;

		F)		full=2;;

81 82
		k)		clean=0;;

Albert Gräf's avatar
Albert Gräf committed
83 84
		l)		light=1;;

85 86 87 88 89 90 91 92 93 94
		n)		pkg=0;;

		R)		deb=2
				inst_dir=/usr
				rpi=1;;

		r)		deb=1
				inst_dir=/usr
				rpi=1;;

95 96 97 98
		t)		any=1;;

		T)		any=2;;

99 100 101 102 103 104 105 106 107 108 109 110 111
		X)		dmg=1
				inst_dir=/usr;;

		z)		inno=1
				inst_dir=/usr;;

		Z)		inno=2
				inst_dir=/usr;;

		*)		echo "Error: unknown option";;
	esac
done

112 113 114 115 116 117 118 119
if [ $clean -eq 1 ]
then
	rm -rf \
		../pd/src/s_stuff.h \
		../pd/src/config.h \
		../pd/src/makefile
fi

120 121
inst_dir=${inst_dir:-/usr/local}

Albert Gräf's avatar
Albert Gräf committed
122 123 124 125 126 127 128
# configure a light build if requested
if [ $light -gt 0 ]; then
    export LIGHT=yes
else
    export LIGHT=
fi

129 130
export TAR_EM_UP_PREFIX=$inst_dir

131 132 133 134 135 136
# Get the OS we're running under, normalized to names that can be used
# to fetch the nwjs binaries below

os=`uname | tr '[:upper:]' '[:lower:]'`
if [[ $os == *"mingw32"* ]]; then
	os=win
137
elif [[ $os == "darwin" ]]; then
138 139
	os=osx
fi
140

141 142
# Auto-detect the platform and pick an appropriate build target.
if [ $any -gt 0 ]; then
143 144 145
	if [[ $os == "osx" ]]; then
		dmg=1
	elif [[ $os == "win" ]]; then
146
		inno=$any
147
	else
148 149
		deb=$any
		inst_dir=${inst_dir:-/usr}
150 151 152
	fi
fi

153 154 155 156 157 158 159 160 161 162 163 164 165 166
# Make sure that we don't try to build a tarball on Mac or Windows (that's
# part of packages/linux_make and hence only works on Linux), build a regular
# package for the platform instead.
if [ $full -gt 0 ]; then
	if [[ $os == "osx" ]]; then
		dmg=1
		echo "Warning: tarball installer not supported on Mac, building a dmg installer instead."
	elif [[ $os == "win" ]]; then
		inno=$full
		echo "Warning: tarball installer not supported on Windows, building a Windows installer instead."
	fi
	full=0
fi

167 168
# Automagically disable Debian packaging when the Debian packaging tools are
# not available.
169 170 171 172
if test $deb -gt 0 && test $pkg -gt 0 && ! test -x /usr/bin/dpkg-deb; then
    pkg=0;
    echo "Debian toolchain unavailable, Debian packaging disabled"
fi
173

174
# Fetch the nw.js binary if we haven't already. We want to fetch it even
Jonathan Wilkes's avatar
Jonathan Wilkes committed
175
# for building with no libs, so we do it regardless of the options
176
#echo nwjs-sdk-v0.16.0-`uname | tr '[:upper:]' '[:lower:]'`
177 178 179 180 181 182
if [ ! -d "../pd/nw/nw" ]; then
	if [ `getconf LONG_BIT` -eq 32 ]; then
		arch="ia32"
	else
		arch="x64"
	fi
183

184
	# for rpi
185
	if [ `uname -m` == "armv7l" ]; then
186 187 188
		arch="armv7l"
	fi

189
	if [[ $os == "win" || $os == "osx" ]]; then
190
		ext="zip"
191 192 193 194
	else
		ext="tar.gz"
	fi

195
	if [[ $os == "win" || $osx_version == "10.8" ]]; then
196 197 198 199
		# We need the lts version to be able to run on XP. For
                # simplicity we use that same version for 64 bit Windows, too
		nwjs_version="v0.14.7"
	else
200
		# temporary kluge for rpi-- only 0.15.1 is available atm
201
		if [ `uname -m` == "armv7l" ]; then
Jonathan Wilkes's avatar
Jonathan Wilkes committed
202
			nwjs_version="v0.17.6"
203
		else
204
			nwjs_version="v0.22.1"
205
		fi
206 207
	fi

208 209 210
	nwjs="nwjs-sdk"
	nwjs_dirname=${nwjs}-${nwjs_version}-${os}-${arch}
	nwjs_filename=${nwjs_dirname}.${ext}
211 212
	nwjs_url=https://git.purrdata.net/jwilkes/nwjs-binaries/raw/master
	nwjs_url=${nwjs_url}/$nwjs_filename
213 214
	echo "Fetching the nwjs binary from"
	echo "$nwjs_url"
215 216 217
	# delete any existing file with the same name
	rm -rf $nwjs_filename
	wget -nv $nwjs_url
218
	if [[ $os == "win" || $os == "osx" ]]; then
219 220
		# unzip overwriting existing files
		unzip -o $nwjs_filename
221 222 223
	else
		tar -xf $nwjs_filename
	fi
224 225 226 227 228 229
	# Special case for arm binary's inconsistent directory name
	# (It's not the same as the `uname -m` output)
	if [ `uname -m` == "armv7l" ]; then
		nwjs_dirname=`echo $nwjs_dirname | sed 's/armv7l/arm/'`
	fi
        mv $nwjs_dirname ../pd/nw/nw
230 231
	# make sure the nw binary is executable on GNU/Linux
	if [[ $os != "win" && $dmg == 0 ]]; then
232 233
		chmod 755 ../pd/nw/nw/nw
	fi
234 235 236
	rm $nwjs_filename
fi

237 238 239 240 241 242 243 244 245 246
# For Windows, fetch the ASIO SDK if we don't have it already
if [[ $os == "win" ]]; then
	if [ ! -d "../pd/lib" ]; then
		mkdir ../pd/lib
		wget http://www.steinberg.net/sdk_downloads/asiosdk2.3.zip
		unzip asiosdk2.3.zip
		mv ASIOSDK2.3 ../pd/lib
	fi
fi

Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
247 248 249 250 251 252 253
cd ../

if [ $core -eq 1 ]
then
	echo "core Pd..."
	rm -f ../Pd-l2ork-`date +%Y%m%d`.tar.bz2 2> /dev/null
	cd pd/src/
254 255 256
	# make sure that Pd is configured before trying to package it
	test -f config.h || (aclocal && autoconf && make -C ../../packages pd)
	make clean
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
257
	cd ../../
258
	tar -jcf ./Pd-l2ork-`date +%Y%m%d`.tar.bz2 pd
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
259 260
fi

261
if [ $full -gt 0 -o $deb -gt 0 -o $inno -gt 0 -o $dmg -gt 0 ]
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
262
then
263 264
	echo "Pd-L2Ork full installer... IMPORTANT! To ensure you have the most up-to-date submodules, this process requires internet connection to pull sources from various repositories..."

265
	if [ -d .git ]; then
266
		git submodule update --init
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
267 268 269
	fi


270
	if [ $full -eq 2 -o $deb -eq 2 -o $inno -eq 2 -o $dmg -eq 2 ]
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
271
	then
272 273 274 275
		# We bypass -k when doing a full build for the first time, so
		# that things are set up properly in preparation of the build.
		if [ ! -f Gem/configure ]; then clean=1; fi
		if [ $clean -eq 0 ]; then
276 277
		cd externals
		else
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
278
		# clean files that may remain stuck even after doing global make clean (if any)
279
		test $os == "osx" && make -C packages/darwin_app clean || true
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
280
		cd externals/miXed
281
		make clean || true # this may fail on 1st attempt
282
		cd ../
283
		make gem_clean || true # this may fail on 1st attempt
284
		cd ../Gem/src/
285
		make distclean || true # this may fail on 1st attempt
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
286 287 288
		rm -rf ./.libs
		rm -rf ./*/.libs
		cd ../
289 290 291
		make distclean || true # this may fail on 1st attempt
		rm -f gemglutwindow.pd_linux
		rm -f Gem.pd_linux
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
292 293
		aclocal
		./autogen.sh
294
		fi
295
		export INCREMENTAL=""
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
296 297
	else
		cd Gem/
298
		export INCREMENTAL="yes"
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
299
	fi
300
	cd ../pd/src && aclocal && autoconf || false
301 302
	if [[ $os == "win" ]]; then
		cd ../../packages/win32_inno
Jonathan Wilkes's avatar
Jonathan Wilkes committed
303
	elif [[ $os == "osx" ]]; then
304
		cd ../../packages/darwin_app
305 306 307
	else
		cd ../../packages/linux_make
	fi
308
	if [ $full -gt 1 -o $deb -eq 2 -o $inno -eq 2 -o $dmg -eq 2 ]
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
309
	then
310 311 312 313 314
		test $clean -ne 0 && make distclean || true
		# Run `make git_version` *now* so that we already have
		# s_stuff.h when we copy it below. XXXNOTE AG: The build seems
		# to work just fine even when skipping all this, so why again
		# is this needed?
315
		test -f ../../pd/src/s_stuff.h || make -C .. git_version
316 317 318 319
		cp ../../pd/src/g_all_guis.h ../../externals/build/include
		cp ../../pd/src/g_canvas.h ../../externals/build/include
		cp ../../pd/src/m_imp.h ../../externals/build/include
		cp ../../pd/src/m_pd.h ../../externals/build/include
320 321
		cp ../../pd/src/s_stuff.h ../../externals/build/include
		cp ../../pd/src/g_all_guis.h ../../externals/build/include
322
		rm -rf build/
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
323
	fi
Ivica Bukvic's avatar
Ivica Bukvic committed
324 325 326
	if [ $rpi -eq 0 ]
	then
		echo "installing desktop version..."
Albert Gräf's avatar
Albert Gräf committed
327 328
		test -f debian/control.desktop && cp -f debian/control.desktop debian/control
		test -f ../../l2ork_addons/flext/config-lnx-pd-gcc.txt.intel && cp -f ../../l2ork_addons/flext/config-lnx-pd-gcc.txt.intel ../../externals/grill/trunk/flext/buildsys/config-lnx-pd-gcc.txt
Ivica Bukvic's avatar
Ivica Bukvic committed
329 330 331
	else
		echo "installing raspbian version..."
		cp -f debian/control.raspbian debian/control
332
		cp -f ../../l2ork_addons/flext/config-lnx-pd-gcc.txt.rpi ../../externals/grill/trunk/flext/buildsys/config-lnx-pd-gcc.txt
Ivica Bukvic's avatar
Ivica Bukvic committed
333 334
		cat ../../externals/OSCx/src/Makefile | sed -e s/-lpd//g > ../../externals/OSCx/src/Makefile
	fi
335 336 337
	if [[ $os == "win" ]]; then
		echo "Making Windows package..."
		echo `pwd`
Albert Gräf's avatar
Albert Gräf committed
338
		make install INCREMENTAL=$INCREMENTAL LIGHT=$LIGHT && make package
Jonathan Wilkes's avatar
Jonathan Wilkes committed
339
	elif [[ $os == "osx" ]]; then
340 341 342
		echo "Making OSX package (dmg)..."
		echo `pwd`
		make install && make package
343
	else
344 345
		# create images folder
		mkdir -p ../../packages/linux_make/build$inst_dir/lib/pd-l2ork/extra/images
346 347
		make install prefix=$inst_dir
	fi
348
	echo "copying pd-l2ork-specific externals..."
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
349 350
	# patch_name
	# spectdelay
351 352
	if [[ $os == "win" ]]; then
		cd ../../l2ork_addons
Jonathan Wilkes's avatar
Jonathan Wilkes committed
353
	elif [[ $os == "osx" ]]; then
354
		cd ../../l2ork_addons
Albert Gräf's avatar
Albert Gräf committed
355
	elif [ $light -eq 0 ]; then
356 357 358 359 360 361 362
		cd ../../l2ork_addons/spectdelay/spectdelay~
		./linux-install.sh
		cp -f spectdelay~.pd_linux ../../../packages/linux_make/build$inst_dir/lib/pd-l2ork/extra
		cp -f spectdelay~-help.pd ../../../packages/linux_make/build$inst_dir/lib/pd-l2ork/extra
		cp -f array* ../../../packages/linux_make/build$inst_dir/lib/pd-l2ork/extra
		# return to l2ork_addons folder
		cd ../../
Albert Gräf's avatar
Albert Gräf committed
363 364
	else
		cd ../../l2ork_addons
365
	fi
Ivica Bukvic's avatar
Ivica Bukvic committed
366
	# install raspberry pi externals (if applicable)
Albert Gräf's avatar
Albert Gräf committed
367
	if [ $inno -eq 0 -a $dmg -eq 0 -a $light -eq 0 ]; then
368 369 370 371 372 373 374 375
		cd raspberry_pi
		./makeall.sh
		cp -f disis_gpio/disis_gpio.pd_linux ../../packages/linux_make/build$inst_dir/lib/pd-l2ork/extra
		cp -f disis_gpio/disis_gpio-help.pd ../../packages/linux_make/build$inst_dir/lib/pd-l2ork/extra
		cp -f disis_spi/disis_spi.pd_linux ../../packages/linux_make/build$inst_dir/lib/pd-l2ork/extra
		cp -f disis_spi/disis_spi-help.pd ../../packages/linux_make/build$inst_dir/lib/pd-l2ork/extra
		cd ../
	fi
376

377
	echo "done with l2ork addons."
378
	cd ../
379
	# finish install for deb
380
	if [ $inno -eq 0 -a $dmg -eq 0 ]; then
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
		cd packages/linux_make
		rm -f build/usr/local/lib/pd
		if [ $pkg -gt 0 ]; then
		echo "tar full installer..."
		if [ $deb -gt 0 ]
		then
			cd build/
			rm -rf DEBIAN/ etc/
			cd ../
			make deb prefix=$inst_dir
		else
			make tarbz2 prefix=$inst_dir
		fi
		echo "move full installer..."
		if [ $deb -gt 0 ]
		then
397
			mv *.deb ../../
398 399 400
		else
			#rm -f ../../../Pd-l2ork-full-`uname -m`-`date +%Y%m%d`.tar.bz2 2> /dev/null
			#mv build/Pd*bz2 ../../../Pd-l2ork-full-`uname -m`-`date +%Y%m%d`.tar.bz2
401
			mv -f build/pd*bz2 ../..
402 403 404
		fi
		elif [ $deb -gt 0 ]; then
			make debstage prefix=$inst_dir
405
			echo "Debian packaging skipped, build results can be found in packages/linux_make/build/."
406 407
		fi
		cd ../../
408 409 410
	# move OSX dmg installer
	elif [ $dmg -gt 0 ]; then
		mv packages/darwin_app/Pd*.dmg .
411
	elif [ $inno -gt 0 ]; then
Jonathan Wilkes's avatar
Jonathan Wilkes committed
412
		mv packages/win32_inno/Output/Purr*.exe .
413
	fi
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
414 415 416 417 418 419 420
fi

cd l2ork_addons/

echo "done."

exit 0