summaryrefslogtreecommitdiffstats
path: root/x11vnc/misc/enhanced_tightvnc_viewer/build.unix
blob: f84ef78eec81dc6bbced209da1724ea499584d7b (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
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
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
#!/bin/sh

# See the README in this directory for more info on using this script
# (build.unix).  Search for SSVNC_BUILD.
#
# Notes: to customize locations, e.g. for libjpeg, set LDFLAGS_OS and/or
# CPPFLAGS_OS
#
# e.g. on Darwin we did:
#
# env LDFLAGS_OS="-L/Volumes/someplace/common/lib" CPPFLAGS_OS="-I /Volumes/someplace/common/include" ./build.unix
#


# Add useful directories to PATH:
#
PATH=$PATH:/usr/bin:/bin:/usr/local/bin:/usr/X11R6/bin:/usr/bin/X11:/usr/openwin/bin:/opt/SUNWspro/bin:/usr/sfw/bin:/usr/ccs/bin
export PATH

# Check location:
#
thisdir=`dirname "$0"`
if [ ! -d ./bin -o ! -d src/patches -o ! -f ./build.unix ]; then
	echo ""
	echo "You must run this script from: $thisdir"
	echo ""
	echo "Maybe:"
	echo ""
	echo "  cd $thisdir"
	echo "  ./build.unix"
	if [ "X$BUILD_UNIX" != "X" ]; then
		sleep 2
		exit 1
	fi
	echo ""
	sleep 1
	printf "Do you want me to run those for you?  y/[n] "
	read x
	if [ "X$x" = "Xy" ]; then
		BUILD_UNIX=1
		export BUILD_UNIX
		cd "$thisdir" || exit 1
		echo "pwd:"
		pwd
		sleep 1
		./build.unix
	fi
	
	exit $?
fi

pline() {
	echo "------------------------------------------------------------------"
}

# Try to find osname.arch
#
name=$UNAME
if [ "X$name" = "X" ]; then
	name=`uname -sm | sed -e 's/ /./g' -e 's/Linux\.i.86/Linux.i686/'`
fi
if [ "X$name" = "X" ]; then
	echo "cannot determine platform: os.arch, e.g. Linux.i686"
	echo "set \$UNAME manually and retry."
	exit 1
fi

LDD="ldd"
if [ `uname` = "Darwin" ]; then
	LDD="otool -L"
fi

# Create a tmp dir for this build:
#
tmp=./src/tmp/$name.$$
if [ "X$TMPDIR" != "X" ]; then
	tmp="$TMPDIR/$tmp"
fi
mkdir -p $tmp || exit 1

# Do ultraftp Java viewer (only):
#
if [ "X$SSVNC_BUILD_ULTRAFTP" != "X" ]; then
	ultraftp_tar=`ls -td ./src/zips/ultraftp.tar* | head -1`
	if [ ! -f $ultraftp_tar ]; then
		echo "could not locate ultraftp java vnc viewer source"
		exit 1
	fi
	echo ""
	pline
	echo "BUILDING THE ULTRAFTP HELPER JAR"
	echo ""
	sleep 1

	cat $ultraftp_tar | (cd $tmp; tar xvf -) || exit 1
	cd $tmp/ultraftp || exit 1
	pwd
	echo
	make install

	exit 0	# DONE
fi

# Work out main destination:
#
dest=./bin/$name
if [ -d $dest ]; then
	if [ "X$SSVNC_BUILD_FORCE_OVERWRITE" = "X" ]; then
		printf "$dest exists.  overwrite in it? [y]/n "
		read x
		if [ "X$x" = "Xn" ]; then
			exit
		fi
	else
		echo "$dest exists.  overwriting in it."
	fi
	if [ "X$SSVNC_BUILD_SKIP_VIEWER" = "X" ]; then
		if [ `uname` = "Darwin" ]; then
			rm -f $dest/vncviewer.x11*
		else
			rm -f $dest/vncviewer*
		fi
	fi
	if [ "X$SSVNC_BUILD_SKIP_STUNNEL" = "X" ]; then
		rm -f $dest/stunnel*
	fi
fi
mkdir -p $dest || exit 1


# Try to find some static archives of various libraries:
#
libs="$tmp/libs"
mkdir -p $libs || exit 1
for liba in libz.a libjpeg.a libssl.a libcrypto.a
do
	if [ "X$SSVNC_BUILD_STATIC" = "X" ]; then
		break
	fi
	for dir in $SSVNC_STATIC_DIRS /usr/lib /lib /usr/local/lib /usr/pkg/lib /usr/sfw/lib /usr/openwin/lib
	do
		if [ "X$dir" = "X" ]; then
			continue
		fi
		if [ "$name" = "Linux.x86_64" -o "$name" = "Linux.ppc64" ] ; then
			dir64=`echo "$dir" | sed -e 's,lib,lib64,'`
			if [ "X$SSVNC_BUILD_NO_LINUX64" != "X" ]; then
				:
			elif [ -d $dir64 ]; then
				dir=$dir64
			fi
		fi
		try="$dir/$liba"
		if [ -f $try ]; then
			echo cp -p "$try" $libs
			     cp -p "$try" $libs
			break
		fi
	done
done
if [ "X$SSVNC_BUILD_STATIC" != "X" ]; then
	echo "Found these static archive libraries, will try to use them..."
	ls -ld $libs
	ls -l $libs
	echo
fi

have_gcc=""
if type gcc > /dev/null; then
	have_gcc=1
fi
have_cc=""
if type cc > /dev/null; then
	have_cc=1
fi

if [ "X$have_cc" = "X" ]; then
	if [ "X$have_gcc" = "X1" ]; then
		cat > $tmp/cc <<END
#!/bin/sh
gcc "\$@"
END
		chmod 755 $tmp/cc
		PATH=$PATH:`pwd`/$tmp
		type cc
		type gcc
	fi
fi

if [ -d /var/tmp/LIBS -a "X$SSVNC_BUILD_STATIC" != "X" ]; then
	LDFLAGS_OS="$LDFLAGS_OS -L/var/tmp/LIBS"
fi

if [ `uname` = "SunOS" ]; then
	LDFLAGS_OS="$LDFLAGS_OS -L/usr/sfw/lib -R/usr/sfw/lib"
	CPPFLAGS_OS="$CPPFLAGS_OS -I /usr/sfw/include"
elif uname | grep -i bsd > /dev/null; then
	LDFLAGS_OS="$LDFLAGS_OS -L/usr/local/lib -L/usr/pkg/lib"
	CPPFLAGS_OS="$CPPFLAGS_OS -I /usr/local/include -I /usr/pkg/include"
fi

cnt=`ls ./src/patches/*.patch | wc -c`
if [ $cnt -lt 1 ]; then
	echo "Could not find any patches in ./src/patches.  Is your tarball missing them?"
	exit 1
fi

pline() {
	echo "------------------------------------------------------------------"
}

# Do tightvnc viewer:
#
if [ "X$SSVNC_BUILD_SKIP_VIEWER" = "X" ]; then
	tight_src=`ls -td ./src/vnc_unixsrc* | head -1`
	if [ ! -d $tight_src ]; then
		echo "could not locate tight vnc viewer source"
		exit 1
	fi
	echo ""
	pline
	echo "BUILDING THE VNCVIEWER"
	echo ""
	sleep 1

	cp -pR "$tight_src" "$tmp/vnc_unixsrc" || exit 1

	echo "applying tight vnc patches:"
	start=`pwd`
	cd $tmp;
	failed=0
	count=0
	patches="../../patches/tight-vncviewer-full.patch"
	if [ ! -f "$patches" ]; then
		patches=`ls ../../patches/tight* | grep -v 'tight-vncviewer-full.patch'`
	fi
	for patch in $patches
	do
		if [ ! -f "$patch" ]; then
			continue
		fi
		if [ "X$PATCH_FAIL" != "X" ]; then
			failed=1	
			break
		fi
		echo PATCHING WITH: "$patch" 
		ls -l "$patch"
		sleep 1
		patch -p0 < "$patch"
		if [ $? != 0 ]; then
			failed=`expr $failed + 1`
		else
			count=`expr $count + 1`
		fi
	done
	sleep 1
	cd "$start"
	if [ $failed != 0 -o $count = 0 ]; then
		ball=src/zips/vnc_unixsrc_vncviewer.patched.tar
		echo "patches failed, trying to use backup tarball:"
		ls -l $ball
		sleep 2
		cat $ball | (cd $tmp; tar -xvf -)
	fi
	echo


	cd $tmp/vnc_unixsrc
	xmkmf
	make Makefiles
	mv vncviewer/Makefile vncviewer/Makefile.orig
	sed -e "s,EXTRA_LDOPTIONS =,EXTRA_LDOPTIONS = -L$start/$libs $LDFLAGS_OS," \
	    -e "s,CCOPTIONS =,CCOPTIONS = $CPPFLAGS_OS," \
		vncviewer/Makefile.orig > vncviewer/Makefile

	if [ `uname` = "SunOS" ]; then
		for d in vncviewer libvncauth vncconnect vncpasswd
		do
			mv $d/Makefile $d/Makefile.orig
			sed -e "s,CCOPTIONS =.*\$,CCOPTIONS = $CPPFLAGS_OS," \
				$d/Makefile.orig > $d/Makefile
		done
	fi

	make depend
	echo $PATH
	if [ "X$TURBOVNC" = "X" ]; then
		make all
	else
		make CCOPTIONS="-DTURBOVNC $CPPFLAGS_OS" EXTRA_LIBRARIES="$TURBOVNC" all
	fi
	ls -l vncviewer/vncviewer
	cd "$start"
	src=$tmp/vnc_unixsrc/vncviewer/vncviewer
	sync
	sleep 2
	sync
	strip $src
	sync
	sleep 2
	sync
	wc  $src
	sum $src
	sleep 2

	suff=""
	if [ `uname` = "Darwin" ]; then
		suff=".x11"
	fi
	if [ "X$TURBOVNC" != "X" ]; then
		suff="$suff.turbovnc"
	fi
	echo cp -p $src $dest/vncviewer$suff
	sleep 1
	cp -p $src $dest/vncviewer$suff || exit 1

	echo
	pline
	echo "LISTING, HELP, and LDD THE VNCVIEWER:" 
	echo
	sleep 1

	ls -l $src $dest/vncviewer$suff
	echo
	echo $dest/vncviewer$suff -h
	echo
	$dest/vncviewer$suff -h
	echo
	echo $LDD $dest/vncviewer$suff
	echo
	$LDD $dest/vncviewer$suff
	echo ""
fi

# Do stunnel:
#
if [ "X$SSVNC_BUILD_SKIP_STUNNEL" = "X" ]; then
	stunnel_src=`ls -td ./src/stunnel* | head -1`
	if [ ! -d $stunnel_src ]; then
		echo "could not locate stunnel source"
		exit 1
	fi
	echo ""
	pline
	echo "BUILDING THE STUNNEL"
	echo ""
	sleep 1

	cp -pR "$stunnel_src" "$tmp/stunnel" || exit 1

	echo "applying stunnel patches:"
	start=`pwd`
	cd $tmp;
	failed=0
	count=0
	for patch in ../../patches/stunnel*
	do
		if [ ! -f "$patch" ]; then
			continue
		fi
		if [ "X$PATCH_FAIL" != "X" ]; then
			failed=1	
			break
		fi
		echo PATCHING WITH: "$patch" 
		ls -l "$patch"
		sleep 1
		patch -p0 < $patch
		if [ $? != 0 ]; then
			failed=`expr $failed + 1`
		else
			count=`expr $count + 1`
		fi
	done
	sleep 1
	cd "$start"
	if [ $failed != 0 -o $count = 0 ]; then
		ball=src/zips/stunnel.patched.tar
		echo "patches failed, trying to use backup tarball:"
		ls -l $ball
		sleep 2
		cat $ball | (cd $tmp; tar -xvf -)
	fi
	echo


	cd $tmp/stunnel
	if [ `uname` = "SunOS" ]; then
		cp configure configure.orig
		sed -e "s,maindir in,maindir in /usr/sfw," configure.orig > configure
	fi
	env LDFLAGS="-L$start/$libs $LDFLAGS_OS" CPPFLAGS="$CPPFLAGS_OS" ./configure --disable-libwrap --enable-ipv6
	make
	ls -l src/stunnel
	cd "$start"
	src=$tmp/stunnel/src/stunnel
	sync
	sleep 2
	sync
	strip $src
	sync
	sleep 2
	sync
	wc  $src
	sum $src
	sleep 2
	echo cp -p $src $dest/stunnel
	cp -p $src $dest/stunnel || exit 1
	sleep 1
	cp -p $src $dest/stunnel || exit 1

	echo
	pline
	echo "LISTING, HELP, and LDD THE STUNNEL:" 
	echo
	sleep 1

	ls -l $src $dest/stunnel
	echo
	echo $dest/stunnel -help
	echo
	$dest/stunnel -help
	echo
	echo $LDD $dest/stunnel
	echo
	$LDD $dest/stunnel
	echo ""
fi

# Do vncstorepw and ld preload friends:
#
if [ "X$SSVNC_BUILD_SKIP_VNCSTOREPW" = "X" ]; then
	vncpw_tar=`ls -td ./src/zips/vncstorepw* | head -1`
	if [ ! -f $vncpw_tar ]; then
		echo "could not locate vncstorepw source"
		exit 1
	fi
	echo ""
	pline
	echo "BUILDING THE VNCSTOREPW AND FRIENDS"
	echo ""
	sleep 1

	cat "$vncpw_tar" | (cd $tmp; tar xvf -)

	cd $tmp/vncstorepw
	make

	cd "$start"
	cp -p $tmp/vncstorepw/vncstorepw $tmp/vncstorepw/lim_accept.so $dest
	echo ""

	cd $tmp/vncstorepw
	make clean

	env LD_SSL="-L$start/$libs $LDFLAGS_OS $LD_SSL" CPP_SSL="$CPPFLAGS_OS" make ultravnc_dsm_helper

	cd "$start"
	cp -p $tmp/vncstorepw/ultravnc_dsm_helper $dest
	echo ""
fi


if [ "X$SSVNC_BUILD_SKIP_VIEWER" = "X" -a "X$SSVNC_BUILD_SKIP_STUNNEL" = "X" ]; then
	# list the viewer again.

	echo
	pline
	echo "LISTING, HELP, and LDD THE VNCVIEWER (again):" 
	echo
	sleep 1

	ls -l $dest/vncviewer$suff
	echo
	echo $dest/vncviewer$suff -h
	echo
	$dest/vncviewer$suff -h
	echo
	echo $LDD $dest/vncviewer$suff
	echo
	$LDD $dest/vncviewer$suff
fi
OpenPOWER on IntegriCloud