Source

orange / install-scripts / mac / build-osx-app-template.sh

Full commit
Aleš Erjavec 7db03b5 







Aleš Erjavec 0635b42 


Aleš Erjavec 7db03b5 

Aleš Erjavec 0635b42 

Aleš Erjavec 7db03b5 
Aleš Erjavec 0635b42 








































Aleš Erjavec 7db03b5 



Aleš Erjavec 0635b42 

Aleš Erjavec 7db03b5 


Aleš Erjavec 0635b42 













Aleš Erjavec bb73e85 

Aleš Erjavec 0635b42 
Aleš Erjavec bb73e85 


Aleš Erjavec 0635b42 





Aleš Erjavec 7db03b5 




Aleš Erjavec bb73e85 





Aleš Erjavec 7db03b5 


Aleš Erjavec 0635b42 
Aleš Erjavec 7db03b5 











Aleš Erjavec 0635b42 
Aleš Erjavec 7db03b5 

Aleš Erjavec 0635b42 

Aleš Erjavec 7db03b5 
Aleš Erjavec 0635b42 



Aleš Erjavec 7db03b5 
Aleš Erjavec 0635b42 
Aleš Erjavec 7db03b5 
Aleš Erjavec 0635b42 

Aleš Erjavec 7db03b5 
Aleš Erjavec 0635b42 
Aleš Erjavec 7db03b5 
Aleš Erjavec 0635b42 

Aleš Erjavec c756522 
Aleš Erjavec 7db03b5 
Aleš Erjavec 0635b42 
Aleš Erjavec 7db03b5 
Aleš Erjavec 0635b42 

Aleš Erjavec 7db03b5 




Aleš Erjavec 0635b42 
Aleš Erjavec 7db03b5 
Aleš Erjavec 0635b42 
Aleš Erjavec 7db03b5 














Aleš Erjavec 0635b42 






Aleš Erjavec 7db03b5 

Aleš Erjavec 0635b42 
Aleš Erjavec 7db03b5 
















Aleš Erjavec 0635b42 
Aleš Erjavec 7db03b5 



Aleš Erjavec 0635b42 
Aleš Erjavec 7db03b5 
Aleš Erjavec 0635b42 


Aleš Erjavec 7db03b5 

Aleš Erjavec 0635b42 


Aleš Erjavec 7db03b5 


Aleš Erjavec 0635b42 
Aleš Erjavec 7db03b5 
Aleš Erjavec 0635b42 


Aleš Erjavec 7db03b5 

Aleš Erjavec 0635b42 


Aleš Erjavec 7db03b5 



Aleš Erjavec 0635b42 
Aleš Erjavec 7db03b5 



Aleš Erjavec 0635b42 

Aleš Erjavec bb73e85 


Aleš Erjavec 0635b42 
Aleš Erjavec bb73e85 












Aleš Erjavec 0635b42 

Aleš Erjavec 7db03b5 



















Aleš Erjavec 0635b42 
Aleš Erjavec 7db03b5 

Aleš Erjavec 0635b42 
Aleš Erjavec 7db03b5 




Aleš Erjavec 0635b42 

Aleš Erjavec 7db03b5 




Aleš Erjavec 0635b42 
Aleš Erjavec 7db03b5 


Aleš Erjavec 0635b42 

Aleš Erjavec 7db03b5 
Aleš Erjavec 0635b42 
Aleš Erjavec 7db03b5 
Aleš Erjavec 0635b42 
Aleš Erjavec 7db03b5 

Aleš Erjavec 0635b42 


Aleš Erjavec 7db03b5 



Aleš Erjavec 0635b42 

Aleš Erjavec 7db03b5 
Aleš Erjavec 0635b42 
Aleš Erjavec 7db03b5 
Aleš Erjavec 0635b42 
Aleš Erjavec 7db03b5 

Aleš Erjavec 0635b42 
Aleš Erjavec 7db03b5 
Aleš Erjavec 0635b42 
Aleš Erjavec 7db03b5 


Aleš Erjavec 0635b42 


Aleš Erjavec 7db03b5 




Aleš Erjavec 0635b42 
Aleš Erjavec 7db03b5 
Aleš Erjavec 0635b42 
Aleš Erjavec 7db03b5 


Aleš Erjavec 0635b42 
Aleš Erjavec 7db03b5 



Aleš Erjavec 0635b42 


Aleš Erjavec 7db03b5 


Aleš Erjavec 0635b42 
Aleš Erjavec 7db03b5 
Aleš Erjavec 0635b42 
Aleš Erjavec 7db03b5 



Aleš Erjavec 0635b42 
Aleš Erjavec 7db03b5 
Aleš Erjavec 0635b42 
Aleš Erjavec 7db03b5 

















Aleš Erjavec 0635b42 

Aleš Erjavec 7db03b5 
Aleš Erjavec 0635b42 
Aleš Erjavec 7db03b5 


























Aleš Erjavec 0635b42 
Aleš Erjavec 7db03b5 
Aleš Erjavec 0635b42 
Aleš Erjavec 7db03b5 
Aleš Erjavec 0635b42 


Aleš Erjavec 7db03b5 


Aleš Erjavec 0635b42 



Aleš Erjavec 7db03b5 

Aleš Erjavec 0635b42 




Aleš Erjavec 7db03b5 





















Aleš Erjavec 0635b42 

Aleš Erjavec 7db03b5 

Aleš Erjavec 0635b42 



  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
#!/bin/bash -e
#
# Create (build) an Orange application bundle template
#
# example usage:
#
#   $ build-osx-app-template.sh $HOME/Orange.app
#
# Prerequisites:
#     a working gcc compiler toolchain
#     a working gfortran compiler on PATH


function print_usage () {
echo 'build-osx-app-template.sh [-t] [-k] some_path/Orange.app

Build an Orange application template from scratch.
This will download and build all requirements (Python, Qt4, ...) for a
standalone .app distribution.

Warning: This will take a lot of time.

Options:
    -t --build-temp DIR   A temporary build directory.
    -k --keep-temp        Do not delete the temp directory after build.
    -h --help             Print this help.
'
}

while [[ ${1:0:1} = "-" ]]; do
	case $1 in
		-t|--build-temp)
			BUILD_TEMP=$2
			shift 2
			;;
		-k|--keep-temp)
			KEEP_TEMP=1
			shift 1
			;;
		-h|--help)
			print_usage
			exit 0
			;;
		-*)
			echo "Unknown option $1" >&2
			print_usage
			exit 1
			;;
	esac
done


if [[ $BUILD_TEMP ]]; then
	mkdir -p "$BUILD_TEMP"
else
	BUILD_TEMP=$(mktemp -d -t build-template)
fi

APP=$1

if [[ ! $APP ]]; then
	echo "Target application path must be specified" >&2
	print_usage
	exit 1
fi

mkdir -p "$APP"

# Convert to absolute path
APP=$(cd "$APP"; pwd)

# Get absolute path to the bundle-lite template
SCRIPT_DIR_NAME=$(dirname "$0")
# Convert to absolute path
SCRIPT_DIR_NAME=$(cd "$SCRIPT_DIR_NAME"; pwd)
BUNDLE_LITE=$SCRIPT_DIR_NAME/bundle-lite/Orange.app


# Versions of included 3rd party software

PYTHON_VER=2.7.6
PIP_VER=1.4.1
DISTRIBUTE_VER=0.6.49
NUMPY_VER=1.8.0
SCIPY_VER=0.13.1
QT_VER=4.8.5
SIP_VER=4.14.6
PYQT_VER=4.10.1
PYQWT_VER=5.2.0

# Number of make jobs
MAKE_JOBS=${MAKE_JOBS:-$(sysctl -n hw.physicalcpu)}

PYTHON=$APP/Contents/MacOS/python
EASY_INSTALL=$APP/Contents/MacOS/easy_install
PIP=$APP/Contents/MacOS/pip

export MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET:-10.6}

if [[ $MACOSX_DEPLOYMENT_TARGET < 10.6 ]]; then
	# This is the last Qt version that builds against 10.5 sdk
	QT_VER=4.7.4
fi

SDK=/Developer/SDKs/MacOSX$MACOSX_DEPLOYMENT_TARGET.sdk


function create_template {
	# Create a minimal .app template with the expected dir structure
	# Info.plist and icons.

	mkdir -p "$APP"
	mkdir -p "$APP"/Contents/MacOS
	mkdir -p "$APP"/Contents/Resources

	# Copy icons and Info.plist
	cp "$BUNDLE_LITE"/Contents/Resources/* "$APP"/Contents/Resources
	cp "$BUNDLE_LITE"/Contents/Info.plist "$APP"/Contents/Info.plist

	cp "$BUNDLE_LITE"/Contents/PkgInfo $APP/Contents/PkgInfo

	cat <<-'EOF' > "$APP"/Contents/MacOS/ENV
		# Create an environment for running python from the bundle
		# Should be run as "source ENV"

		BUNDLE_DIR=`dirname "$0"`/../
		BUNDLE_DIR=`perl -MCwd=realpath -e 'print realpath($ARGV[0])' "$BUNDLE_DIR"`/
		FRAMEWORKS_DIR="$BUNDLE_DIR"Frameworks/
		RESOURCES_DIR="$BUNDLE_DIR"Resources/

		PYVERSION="2.7"

		PYTHONEXECUTABLE="$FRAMEWORKS_DIR"Python.framework/Resources/Python.app/Contents/MacOS/Python
		PYTHONHOME="$FRAMEWORKS_DIR"Python.framework/Versions/"$PYVERSION"/

		DYLD_FRAMEWORK_PATH="$FRAMEWORKS_DIR"${DYLD_FRAMEWORK_PATH:+:$DYLD_FRAMEWORK_PATH}

		export PYTHONEXECUTABLE
		export PYTHONHOME
		export PYTHONNOUSERSITE=1

		export DYLD_FRAMEWORK_PATH

		# Some non framework libraries are put in $FRAMEWORKS_DIR by machlib standalone
		export DYLD_LIBRARY_PATH="$FRAMEWORKS_DIR"${DYLD_LIBRARY_PATH:+:$DYLD_LIBRARY_PATH}
EOF

}

function install_python() {
	download_and_extract "http://www.python.org/ftp/python/$PYTHON_VER/Python-$PYTHON_VER.tgz"

	pushd Python-$PYTHON_VER

	# _hashlib import fails with  Symbol not found: _EVP_MD_CTX_md
	# The 10.5 sdk's libssl does not define it (even though it is v 0.9.7)
	patch setup.py -i - <<-'EOF'
		834c834
		<         min_openssl_ver = 0x00907000
		---
		>         min_openssl_ver = 0x00908000
EOF

	./configure --enable-framework="$APP"/Contents/Frameworks \
				--prefix="$APP"/Contents/Resources \
				--with-universal-archs=intel \
				--enable-universalsdk="$SDK"

	make -j $MAKE_JOBS

	# We don't want to install IDLE.app, Python Launcher.app, in /Applications
	# on the build system.
	make install PYTHONAPPSDIR=$(pwd)

	popd

	# PythonAppStart will be used for starting the application GUI.
	# This needs to be symlinked here for Desktop services to read the app's
	# Info.plist and not the contained Python.app's
	ln -fs ../Frameworks/Python.framework/Resources/Python.app/Contents/MacOS/Python "$APP"/Contents/MacOS/PythonAppStart
	ln -fs ../Frameworks/Python.framework/Resources/Python.app "$APP"/Contents/Resources/Python.app

	cat <<-'EOF' > "$APP"/Contents/MacOS/python
		#!/bin/bash

		DIRNAME=$(dirname "$0")

		# Set the proper env variables
		source "$DIRNAME"/ENV

		exec -a "$0" "$PYTHONEXECUTABLE" "$@"
EOF

	chmod +x "$APP"/Contents/MacOS/python

	"$PYTHON" -c"import sys, hashlib"

}

function install_pip() {
	download_and_extract "https://pypi.python.org/packages/source/p/pip/pip-$PIP_VER.tar.gz"

	pushd pip-$PIP_VER

	"$PYTHON" setup.py install
	create_shell_start_script pip

	"$PIP" --version

	popd
}

function install_distribute() {
	download_and_extract "https://pypi.python.org/packages/source/d/distribute/distribute-$DISTRIBUTE_VER.tar.gz"

	pushd distribute-$DISTRIBUTE_VER

	"$PYTHON" setup.py install
	create_shell_start_script easy_install

	"$EASY_INSTALL" --version

	popd
}

function install_ipython {
	# install with easy_install (does not work with pip)
	"$EASY_INSTALL" ipython
	create_shell_start_script ipython
}

function install_qt4 {
	QT_VER_SHORT=${QT_VER%%\.[0-9]}

	# The official releases seem to only include the latest
	# and the archive the rest
	OFFICIAL="http://download.qt-project.org/official_releases/qt/$QT_VER_SHORT/$QT_VER/qt-everywhere-opensource-src-$QT_VER.tar.gz"

	if [[ $QT_VER_SHORT < 4.8 ]]; then
		ARCHIVE="http://download.qt-project.org/archive/qt/$QT_VER_SHORT/qt-everywhere-opensource-src-$QT_VER.tar.gz"
	else
		ARCHIVE="http://download.qt-project.org/archive/qt/$QT_VER_SHORT/$QT_VER/qt-everywhere-opensource-src-$QT_VER.tar.gz"
	fi

	if curl --fail --head --silent -o /dev/null $OFFICIAL ; then
		QT_URL=$OFFICIAL
	else
		QT_URL=$ARCHIVE
	fi

	download_and_extract $QT_URL

	pushd qt-everywhere-opensource-src-$QT_VER

	yes yes | ./configure -prefix "$APP"/Contents/Resources/Qt4 \
				-libdir "$APP"/Contents/Frameworks \
				-framework \
				-release \
				-opensource \
				-no-qt3support \
				-arch x86 -arch x86_64 \
				-no-sql-psql \
				-no-sql-ibase \
				-no-sql-mysql \
				-no-sql-odbc \
				-no-sql-sqlite \
				-no-sql-sqlite2 \
				-nomake examples \
				-nomake demos \
				-nomake docs \
				-nomake translations \
				-sdk "$SDK"

	make -j $MAKE_JOBS
	make install

	# Register plugins with Qt.
	cat <<-EOF > "$APP"/Contents/Resources/qt.conf
		[Paths]
		Plugins = Resources/Qt4/plugins
EOF

	# In case the Python executable is invoked directly (not through
	# Contents/MacOS/python) we also want it to find the plugins.
	cat <<-EOF > "$APP"/Contents/Frameworks/Python.framework/Resources/Python.app/Contents/Resources/qt.conf
		[Paths]
		Plugins = ../../../../../Resources/Qt4/plugins
EOF

	popd
}

function install_sip {
	download_and_extract "http://sourceforge.net/projects/pyqt/files/sip/sip-$SIP_VER/sip-$SIP_VER.tar.gz"
	pushd sip-$SIP_VER

	"$PYTHON" configure.py  --arch i386 --arch x86_64 --sdk "$SDK"

	make -j $MAKE_JOBS
	make install

	"$PYTHON" -c"import sip"

	popd

}

function install_pyqt4 {
	download_and_extract "http://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-$PYQT_VER/PyQt-mac-gpl-$PYQT_VER.tar.gz"
	pushd PyQt-mac-gpl-$PYQT_VER

	yes yes | "$PYTHON" configure.py --qmake "$APP"/Contents/Resources/Qt4/bin/qmake

	make -j $MAKE_JOBS
	make install

	"$PYTHON" -c"from PyQt4 import QtGui, QtWebKit, QtSvg, QtNetwork"

	popd
}

function install_pyqwt5 {
	download_and_extract "http://sourceforge.net/projects/pyqwt/files/pyqwt5/PyQwt-$PYQWT_VER/PyQwt-$PYQWT_VER.tar.gz"

	pushd PyQwt-$PYQWT_VER/configure

	# configure.py fails (with ld: library not found for -lcrt1.10.5.o) trying to
	# build static libraries
	export CPPFLAGS="--shared"

	PYQWT_VER_SHORT=${PYQWT_VER%%\.[0-9]}

	"$PYTHON" configure.py -Q ../qwt-$PYQWT_VER_SHORT \
						--extra-cflags="-arch i386 -arch x86_64" \
						--extra-cxxflags="-arch i386 -arch x86_64" \
						--extra-lflags="-arch i386 -arch x86_64"
	make -j $MAKE_JOBS
	make install

	unset CPPFLAGS

	"$PYTHON" -c"import PyQt4.Qwt5"

	popd
}

function install_numpy {
	"$PIP" install numpy==$NUMPY_VER

	"$PYTHON" -c"import numpy"
}

function install_scipy {
	# This is tricky (req gfortran)
	"$PIP" install scipy==$SCIPY_VER

	"$PYTHON" -c"import scipy"
}

function download_and_extract() {
	# Usage: download_and_extract http://example/source.tar.gz
	#
	# Download the specified .tar source package and extract it in the current dir
	# If the source package is already present only extract it

	URL=$1
	if [[ ! $URL ]]; then
		echo "An url expected"
		exit 1
	fi

	SOURCE_TAR=$(basename "$URL")

	if [[ ! -e $SOURCE_TAR ]]; then
		echo "Downloading $SOURCE_TAR"
		curl --fail -L --max-redirs 3 "$URL" -o "$SOURCE_TAR".part
		mv "$SOURCE_TAR".part "$SOURCE_TAR"
	fi
	tar -xzf "$SOURCE_TAR"
}


function create_shell_start_script() {
	# Usage: create_shell_start_script pip
	#
	# create a start script for the specified script in $APP/Contents/MacOS

	SCRIPT=$1

	cat <<-'EOF' > "$APP"/Contents/MacOS/"$SCRIPT"
		#!/bin/bash

		DIRNAME=$(dirname "$0")
		NAME=$(basename "$0")

		# Set the proper env variables
		source "$DIRNAME"/ENV

		exec -a "$0" "$DIRNAME"/python "$FRAMEWORKS_DIR"/Python.framework/Versions/Current/bin/"$NAME" "$@"
EOF

	chmod +x "$APP"/Contents/MacOS/"$SCRIPT"
}

function cleanup {
	# Cleanup the application bundle by removing unnecesary files.
	find "$APP"/Contents/ \( -name '*~' -or -name '*.bak' -or -name '*.pyc' -or -name '*.pyo' \) -delete

	find "$APP"/Contents/Frameworks -name '*_debug*' -delete

	find "$APP"/Contents/Frameworks -name '*.la' -delete
	find "$APP"/Contents/Frameworks -name '*.a' -delete
	find "$APP"/Contents/Frameworks -name '*.prl' -delete
}

function make_standalone {
	"$PIP" install macholib
	"$PYTHON" -m macholib standalone $APP
	yes y | "$PIP" uninstall altgraph
	yes y | "$PIP" uninstall macholib
}

pushd $BUILD_TEMP

echo "Building template in $BUILD_TEMP"
echo

create_template

install_python

install_distribute

install_pip

install_numpy

install_scipy

install_qt4

install_sip

install_pyqt4

install_pyqwt5

install_ipython

make_standalone

cleanup

popd

if [[ ! $KEEP_TEMP ]]; then
	rm -rf $BUILD_TEMP
fi