summaryrefslogtreecommitdiffstats
path: root/osx/build/build
blob: 0a2206003ec11fb651949cc6766a8b0d6b8ef187 (plain)
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
#!/bin/bash

pushd $(dirname "$0") > /dev/null
D=$(pwd -P)
popd > /dev/null

BASED="$D/.build"
HOMED="$D/.home"

SOURCED="$HOMED/source"
INSTALLD="$HOMED/.local"

GTK_OSX_BASE_URL="https://git.gnome.org/browse/gtk-osx/plain/"
JHBUILD_SOURCED="$SOURCED/jhbuild"

ME="$0"

if [ -z "$GEDIT_SDK" ]; then
	export GEDIT_SDK=10.7
fi

export PATH="$INSTALLD/bin:$PATH"

function do_exit() {
	printf "$@"
	echo ""
	exit 1
}

if [ ! which git &>/dev/null ]; then
	do_exit "You need to have git installed to build gedit for OS X"
fi

if [ ! xcodebuild -version &>/dev/null ]; then
	do_exit "You need to have Xcode installed to build gedit for OS X"
fi

xcodebase=$(xcode-select -p)
sdkdir="$xcodebase/Platforms/MacOSX.platform/Developer/SDKs/MacOSX$GEDIT_SDK.sdk"

if [ ! -d "$sdkdir" ]; then
	do_exit "SDK base directory for $GEDIT_SDK not found. Please make sure to install the SDK at $sdkdir"
fi

function checkout_jhbuild() {
	#JHBUILD_REVISION=$(curl -ks "$GTK_OSX_BASE_URL/jhbuild-revision")

	#if test x"$JHBUILD_REVISION" = x; then
	#	do_exit "Could not find jhbuild revision to use."
	#fi

	mkdir -p $(dirname "$JHBUILD_SOURCED")

	git clone git://git.gnome.org/jhbuild "$JHBUILD_SOURCED" || do_exit "Failed to clone jhbuild."
	#git --work-tree "$JHBUILD_SOURCED" checkout -b stable $JHBUILD_REVISION || do_exit "Failed to checkout stable jhbuild revision."
}

function build_jhbuild() {
	echo "Building jhbuild..."
	(cd "$JHBUILD_SOURCED" && ./autogen.sh --prefix="$INSTALLD" && make -f Makefile.plain DISABLE_GETTEXT=1 install) >/dev/null || do_exit "Jhbuild installation failed";

	rm -f "$INSTALLD/bin/python2"

	cat << PYTHON2 > "$INSTALLD/bin/python2"
#!/bin/bash

exec /usr/bin/python "\$@"
PYTHON2
	chmod +x "$INSTALLD/bin/python2"
}

function setup_jhbuildrc() {
	echo "Installing jhbuild configuration..."

	mkdir -p "$HOMED"
    curl -ks "$GTK_OSX_BASE_URL/jhbuildrc-gtk-osx" | \
    	sed -e 's/^.*PYTHONPATH.*$//g' -e 's/^.*PYTHON_SITE_PACKAGES.*$//g' > "$HOMED/.jhbuildrc" || do_exit "Failed to get jhbuildrc."

    rm -f "$HOMED/.jhbuildrc-gedit"
    ln -s "$D/config/jhbuildrc-gedit" "$HOMED/.jhbuildrc-gedit" || exit 1
}

function init_help_short() {
	echo "Initialize the in-tree build environment (installs jhbuild)"
}

function cmd_init() {
	mkdir -p "$SOURCED"

	if [ ! -d "$JHBUILD_SOURCED" ]; then
		checkout_jhbuild
	fi

	build_jhbuild
	setup_jhbuildrc

	rm -f "$BASED/$GEDIT_SDK/source/gedit"
	mkdir -p "$BASED/$GEDIT_SDK/source"
	ln -s $(cd "$D/../../" && pwd) "$BASED/$GEDIT_SDK/source/gedit"
}

function bootstrap_help_short() {
	echo "Run jhbuild bootstrap"
}

function cmd_bootstrap() {
	# Built python once
	cmd_jh bootstrap -q python || exit 1

	# Built python twice! There is a bug where python somehow manages to link
	# its main binary to the system framework library, which then doesn't work...
	# Building python again seems to resolve the issue...
	cmd_jh bootstrap -q -f -t python python || exit 1

	# Bootstrap all the rest
	cmd_jh bootstrap -q || exit 1
}

function jh_help_usage() {
	echo "jhbuild-command ..."
}

function jh_help_short() {
	echo "Run jhbuild commands"
}

function cmd_jh() {
	# Setup our jhbuild environment
	export GEDIT_OSX_SOURCE_BASE="$D"
	export GEDIT_OSX_BUILD_BASE="$BASED"
	export __GEDIT_OSX_OLD_HOME="$HOME"
	export HOME="$HOMED"
	export JHB=gedit

	# We set this because without it, GNU gettext intltool or whatever the cause
	# may be, will set DATADIRNAME=lib during configure because gettext is not part
	# of libc on OS X. The result is that translations would be installed in lib/
	# instead of share/ and would not get picked up.
	export DATADIRNAME=share

	"$INSTALLD/bin/jhbuild" -f "$HOMED/.jhbuildrc" "$@"
}

function dbg_help_usage() {
	echo "build command ..."
}

function dbg_help_short() {
	echo "Run remaining build commands in a debug environment"
}

function cmd_dbg() {
	export GEDIT_OSX_DEBUG=1
	_process "$@"
}

function shell_help_short() {
	echo "Start the jhbuild shell (shorthand for jh shell)"
}

function cmd_shell() {
	cmd_jh shell
}

function make_help_usage() {
	echo "module-source-directory"
}

function make_help_short() {
	echo "Run jhbuild make at the provided source directory"
}

function cmd_make() {
	cd "$BASED/$GEDIT_SDK/source/$1" && cmd_jh make
}

function run_help_usage() {
	echo "program ..."
}

function run_help_short() {
	echo "Run the provided program in the jhbuild environment (shorthand for jh run)"
}

function cmd_run() {
	cmd_jh run "$@"
}

function env_help_short() {
	echo "Obtain certain environment paths"
}

function cmd_env() {
	vars=(source inst bin home local-bin)

	case "$1" in
	source)
		echo "$BASED/$GEDIT_SDK/source"
		;;
	inst)
		echo "$BASED/$GEDIT_SDK/inst"
		;;
	bin)
		echo "$BASED/$GEDIT_SDK/inst/bin"
		;;
	home)
		echo "$HOMED"
		;;
	local-bin)
		echo "$HOMED/.local/bin"
		;;
	"")
		for v in "${vars[@]}"; do
			u=$(echo -n "$v" | tr '-' '_')
			echo -n "$u="
			cmd_env "$v"
		done
		;;
	*)
		varnames=$(printf ", \033[1m%s\033[0m" "${vars[@]}")
		varnames=${varnames:2}

		do_exit "Unknown environment variable \033[1m$1\033[0m, available variables are: $varnames"
		;;
	esac
}

function all_help_short() {
	echo "Runs the init, bootstrap and build commands"
}

function cmd_all() {
	if [ ! -d "$JHBUILD_SOURCED" ]; then
		cmd_init || exit 1
	fi

	if [ ! -f "$BASED/$GEDIT_SDK/inst/bin/python" ]; then
		cmd_bootstrap || exit 1
	fi

	cmd_jh build -q
}

function help_help_short() {
	echo "Shows this help message"
}

function cmd_help() {
	if [ -z "$1" ]; then
		echo "Usage: $ME [command]"
		echo ""
		echo "Available commands:"
		echo ""

		for cmd in "${commands[@]}"; do
			printf "  \033[1m$cmd\x1B[0m "

			l=${#cmd}
			let d="$commandsmaxlen - $l + 1"

			printf "%${d}s" ""
			echo -n "- "

			if [[ $(type -t "${cmd}_help_short") = "function" ]]; then
				"${cmd}_help_short"
			else
				echo ""
			fi
		done

		echo ""
	else
		cmd="cmd_$1"

		if [[ $(type -t "$cmd") != "function" ]]; then
			do_exit "Invalid command \033[1m$1\033[0m, available commands are: $cmds"
		fi

		printf "Usage: $ME \033[1m$1\033[0m "

		if [[ $(type -t "$1_help_usage") = "function" ]]; then
			"$1_help_usage"
		else
			echo ""
		fi

		echo ""

		if [[ $(type -t "$1_help_long") != "function" ]]; then
			"$1_help_short"
		else
			"$1_help_long"
		fi
	fi
}

commands=()
commandsmaxlen=0

while read line
do
	cmd=${line#declare -f }

	if [[ "$cmd" = cmd_* ]]; then
		cname=${cmd#cmd_}

		commands+=($cname)

		l=${#cname}

		if [[ $l > $commandsmaxlen ]]; then
			commandsmaxlen=$l
		fi
	fi
done < <(declare -F)

cmds=$(printf ", \033[1m%s\033[0m" "${commands[@]}")
cmds=${cmds:2}

function _process() {
	if [ -z "$1" ]; then
		cmd_help
		exit 0
	fi

	cmd="cmd_$1"

	if [[ $(type -t "$cmd") != "function" ]]; then
		do_exit "Invalid command $1, available commands are: $cmds"
	fi

	shift 1
	"$cmd" "$@"
}

_process "$@"