tar_em_up.sh 10.4 KB
Newer Older
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
1
2
3
4
#!/bin/bash
# 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"
24
	echo "     -n    skip package creation (-bB, -fF)"
Ivica Bukvic's avatar
Ivica Bukvic committed
25
	echo "     -r    build a Raspberry Pi deb (incremental)"
26
27
28
	echo "     -R    build a Raspberry Pi deb (complete recompile)"
	echo "     -t    auto-detect target (incremental)"
	echo "     -T    auto-detect target (complete recompile)"
29
	echo "     -X    build an OSX installer (dmg)"
30
31
	echo "     -z    build a Windows installer (incremental)"
	echo "     -Z    build a Windows installer (complete recompile)"
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
32
	echo
33
	echo "   The incremental options bypass Gem compilation. This saves"
34
35
36
	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."
37
38
	echo
	echo "   The -k (keep) option doesn't clean before compilation,"
39
40
41
	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."
42
	echo
43
44
	echo "   For custom install locations and staged installations"
	echo "   set the inst_dir environment variable as follows:"
45
46
47
	echo
	echo "           export inst_dir=/some/custom/location"
	echo
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
48
49
50
51
52
53
	exit 1
fi

deb=0
core=0
full=0
Ivica Bukvic's avatar
Ivica Bukvic committed
54
rpi=0
55
pkg=1
56
inno=0
57
dmg=0
58
any=0
59
clean=1
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
60

61
while getopts ":bBcfFknRrTtXzZ" Option
62
63
64
65
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;;

		f)		full=1;;

		F)		full=2;;

75
76
		k)		clean=0;;

77
78
79
80
81
82
83
84
85
86
		n)		pkg=0;;

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

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

87
88
89
90
		t)		any=1;;

		T)		any=2;;

91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
		X)		dmg=1
				inst_dir=/usr;;

		z)		inno=1
				inst_dir=/usr;;

		Z)		inno=2
				inst_dir=/usr;;

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

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

export TAR_EM_UP_PREFIX=$inst_dir

108
109
110
111
112
113
# 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
114
elif [[ $os == "darwin" ]]; then
115
116
	os=osx
fi
117

118
119
# Auto-detect the platform and pick an appropriate build target.
if [ $any -gt 0 ]; then
120
121
122
	if [[ $os == "osx" ]]; then
		dmg=1
	elif [[ $os == "win" ]]; then
123
		inno=$any
124
	else
125
126
		deb=$any
		inst_dir=${inst_dir:-/usr}
127
128
129
	fi
fi

130
131
# Automagically disable Debian packaging when the Debian packaging tools are
# not available.
132
133
134
135
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
136

137
# Fetch the nw.js binary if we haven't already. We want to fetch it even
Jonathan Wilkes's avatar
Jonathan Wilkes committed
138
# for building with no libs, so we do it regardless of the options
139
#echo nwjs-sdk-v0.16.0-`uname | tr '[:upper:]' '[:lower:]'`
140
141
142
143
144
145
if [ ! -d "../pd/nw/nw" ]; then
	if [ `getconf LONG_BIT` -eq 32 ]; then
		arch="ia32"
	else
		arch="x64"
	fi
146

147
	# for rpi
148
	if [ `uname -m` == "armv7l" ]; then
149
150
151
		arch="armv7l"
	fi

152
	if [[ $os == "win" || $os == "osx" ]]; then
153
		ext="zip"
154
155
156
157
	else
		ext="tar.gz"
	fi

158
	if [[ $os == "win" || $osx_version == "10.8" ]]; then
159
160
161
162
		# 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
163
		# temporary kluge for rpi-- only 0.15.1 is available atm
164
		if [ `uname -m` == "armv7l" ]; then
Jonathan Wilkes's avatar
Jonathan Wilkes committed
165
			nwjs_version="v0.17.6"
166
		else
167
			nwjs_version="v0.22.1"
168
		fi
169
170
	fi

171
172
173
	nwjs="nwjs-sdk"
	nwjs_dirname=${nwjs}-${nwjs_version}-${os}-${arch}
	nwjs_filename=${nwjs_dirname}.${ext}
174
175
	nwjs_url=https://git.purrdata.net/jwilkes/nwjs-binaries/raw/master
	nwjs_url=${nwjs_url}/$nwjs_filename
176
177
	echo "Fetching the nwjs binary from"
	echo "$nwjs_url"
178
        wget -nv $nwjs_url
179
	if [[ $os == "win" || $os == "osx" ]]; then
180
181
182
183
		unzip $nwjs_filename
	else
		tar -xf $nwjs_filename
	fi
184
185
186
187
188
189
	# 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
190
191
	# make sure the nw binary is executable on GNU/Linux
	if [[ $os != "win" && $dmg == 0 ]]; then
192
193
		chmod 755 ../pd/nw/nw/nw
	fi
194
195
196
	rm $nwjs_filename
fi

197
198
199
200
201
202
203
204
205
206
# 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
207
208
209
210
211
212
213
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/
214
	make clean || true # this may fail on 1st attempt
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
215
	cd ../../
216
	tar -jcf ./Pd-l2ork-`date +%Y%m%d`.tar.bz2 pd
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
217
218
fi

219
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
220
then
221
222
	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..."

223
224
225
	if [ -d .git ]; then
		# check if Gem submodule is empty, and if so do first init
		if [ "$(ls -A Gem)" ]; then
226
227
			git submodule update
			#git submodule foreach git pull origin master
228
		else
229
			# init all submodules (only necessary the first time)
230
			git submodule init
231
232
			git submodule update
			#git submodule foreach git pull origin master
233
		fi
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
234
235
236
	fi


237
	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
238
	then
239
240
241
	        if [ $clean -eq 0 ]; then
		cd externals
		else
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
242
		# clean files that may remain stuck even after doing global make clean (if any)
243
		test $os == "osx" && make -C packages/darwin_app clean || true
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
244
		cd externals/miXed
245
		make clean || true # this may fail on 1st attempt
246
		cd ../
247
		make gem_clean || true # this may fail on 1st attempt
248
		cd ../Gem/src/
249
		make distclean || true # this may fail on 1st attempt
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
250
251
252
		rm -rf ./.libs
		rm -rf ./*/.libs
		cd ../
253
254
255
		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
256
257
		aclocal
		./autogen.sh
258
		fi
259
		export INCREMENTAL=""
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
260
261
	else
		cd Gem/
262
		export INCREMENTAL="yes"
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
263
	fi
264
	cd ../pd/src && aclocal && autoconf
265
266
	if [[ $os == "win" ]]; then
		cd ../../packages/win32_inno
Jonathan Wilkes's avatar
Jonathan Wilkes committed
267
	elif [[ $os == "osx" ]]; then
268
		cd ../../packages/darwin_app
269
270
271
	else
		cd ../../packages/linux_make
	fi
272
	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
273
	then
274
275
276
277
278
279
		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?
		make -C .. git_version
280
281
282
283
		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
284
285
		cp ../../pd/src/s_stuff.h ../../externals/build/include
		cp ../../pd/src/g_all_guis.h ../../externals/build/include
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
286
	fi
287
	rm -rf build/
Ivica Bukvic's avatar
Ivica Bukvic committed
288
289
290
291
	if [ $rpi -eq 0 ]
	then
		echo "installing desktop version..."
		cp -f debian/control.desktop debian/control
292
		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
293
294
295
	else
		echo "installing raspbian version..."
		cp -f debian/control.raspbian debian/control
296
		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
297
298
		cat ../../externals/OSCx/src/Makefile | sed -e s/-lpd//g > ../../externals/OSCx/src/Makefile
	fi
299
300
301
302
	if [[ $os == "win" ]]; then
		echo "Making Windows package..."
		echo `pwd`
		make install && make package
Jonathan Wilkes's avatar
Jonathan Wilkes committed
303
	elif [[ $os == "osx" ]]; then
304
305
306
		echo "Making OSX package (dmg)..."
		echo `pwd`
		make install && make package
307
	else
308
309
		# create images folder
		mkdir -p ../../packages/linux_make/build$inst_dir/lib/pd-l2ork/extra/images
310
311
		make install prefix=$inst_dir
	fi
312
	echo "copying pd-l2ork-specific externals..."
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
313
314
	# patch_name
	# spectdelay
315
316
	if [[ $os == "win" ]]; then
		cd ../../l2ork_addons
Jonathan Wilkes's avatar
Jonathan Wilkes committed
317
	elif [[ $os == "osx" ]]; then
318
		cd ../../l2ork_addons
319
320
321
322
323
324
325
326
327
	else
		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 ../../
	fi
Ivica Bukvic's avatar
Ivica Bukvic committed
328
	# install raspberry pi externals (if applicable)
329
	if [ $inno -eq 0 -a $dmg -eq 0 ]; then
330
331
332
333
334
335
336
337
		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
338

339
	echo "done with l2ork addons."
340
	cd ../
341
	# finish install for deb
342
	if [ $inno -eq 0 -a $dmg -eq 0 ]; then
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
		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
359
			mv *.deb ../../
360
361
362
		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
363
			mv -f build/pd*bz2 ../..
364
365
366
367
368
		fi
		elif [ $deb -gt 0 ]; then
			make debstage prefix=$inst_dir
		fi
		cd ../../
369
370
371
	# move OSX dmg installer
	elif [ $dmg -gt 0 ]; then
		mv packages/darwin_app/Pd*.dmg .
372
	elif [ $inno -gt 0 ]; then
Jonathan Wilkes's avatar
Jonathan Wilkes committed
373
		mv packages/win32_inno/Output/Purr*.exe .
374
	fi
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
375
376
377
378
379
380
381
fi

cd l2ork_addons/

echo "done."

exit 0