1#!/bin/sh 2 3# See the README in this directory for more info on using this script 4# (build.unix). Search for SSVNC_BUILD. 5# 6# Notes: to customize locations, e.g. for libjpeg, set LDFLAGS_OS and/or 7# CPPFLAGS_OS 8# 9# e.g. on Darwin we did: 10# 11# env LDFLAGS_OS="-L/Volumes/someplace/common/lib" CPPFLAGS_OS="-I /Volumes/someplace/common/include" ./build.unix 12# 13 14 15# Add useful directories to PATH: 16# 17PATH=$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 18export PATH 19 20# Check location: 21# 22thisdir=`dirname "$0"` 23if [ ! -d ./bin -o ! -d src/patches -o ! -f ./build.unix ]; then 24 echo "" 25 echo "You must run this script from: $thisdir" 26 echo "" 27 echo "Maybe:" 28 echo "" 29 echo " cd $thisdir" 30 echo " ./build.unix" 31 if [ "X$BUILD_UNIX" != "X" ]; then 32 sleep 2 33 exit 1 34 fi 35 echo "" 36 sleep 1 37 printf "Do you want me to run those for you? y/[n] " 38 read x 39 if [ "X$x" = "Xy" ]; then 40 BUILD_UNIX=1 41 export BUILD_UNIX 42 cd "$thisdir" || exit 1 43 echo "pwd:" 44 pwd 45 sleep 1 46 ./build.unix 47 fi 48 49 exit $? 50fi 51 52pline() { 53 echo "------------------------------------------------------------------" 54} 55 56# Try to find osname.arch 57# 58name=$UNAME 59if [ "X$name" = "X" ]; then 60 name=`uname -sm | sed -e 's/ /./g' -e 's/Linux\.i.86/Linux.i686/'` 61fi 62if [ "X$name" = "X" ]; then 63 echo "cannot determine platform: os.arch, e.g. Linux.i686" 64 echo "set \$UNAME manually and retry." 65 exit 1 66fi 67 68LDD="ldd" 69if [ `uname` = "Darwin" ]; then 70 LDD="otool -L" 71fi 72 73# Create a tmp dir for this build: 74# 75tmp=./src/tmp/$name.$$ 76if [ "X$TMPDIR" != "X" ]; then 77 tmp="$TMPDIR/$tmp" 78fi 79mkdir -p $tmp || exit 1 80 81# Do ultraftp Java viewer (only): 82# 83if [ "X$SSVNC_BUILD_ULTRAFTP" != "X" ]; then 84 ultraftp_tar=`ls -td ./src/zips/ultraftp.tar* | head -1` 85 if [ ! -f $ultraftp_tar ]; then 86 echo "could not locate ultraftp java vnc viewer source" 87 exit 1 88 fi 89 echo "" 90 pline 91 echo "BUILDING THE ULTRAFTP HELPER JAR" 92 echo "" 93 sleep 1 94 95 cat $ultraftp_tar | (cd $tmp; tar xvf -) || exit 1 96 cd $tmp/ultraftp || exit 1 97 pwd 98 echo 99 make install 100 101 exit 0 # DONE 102fi 103 104# Work out main destination: 105# 106dest=./bin/$name 107if [ -d $dest ]; then 108 if [ "X$SSVNC_BUILD_FORCE_OVERWRITE" = "X" ]; then 109 printf "$dest exists. overwrite in it? [y]/n " 110 read x 111 if [ "X$x" = "Xn" ]; then 112 exit 113 fi 114 else 115 echo "$dest exists. overwriting in it." 116 fi 117 if [ "X$SSVNC_BUILD_SKIP_VIEWER" = "X" ]; then 118 if [ `uname` = "Darwin" ]; then 119 rm -f $dest/vncviewer.x11* 120 else 121 rm -f $dest/vncviewer* 122 fi 123 fi 124 if [ "X$SSVNC_BUILD_SKIP_STUNNEL" = "X" ]; then 125 rm -f $dest/stunnel* 126 fi 127fi 128mkdir -p $dest || exit 1 129 130 131# Try to find some static archives of various libraries: 132# 133libs="$tmp/libs" 134mkdir -p $libs || exit 1 135for liba in libz.a libjpeg.a libssl.a libcrypto.a 136do 137 if [ "X$SSVNC_BUILD_STATIC" = "X" ]; then 138 break 139 fi 140 for dir in $SSVNC_STATIC_DIRS /usr/lib /lib /usr/local/lib /usr/pkg/lib /usr/sfw/lib /usr/openwin/lib 141 do 142 if [ "X$dir" = "X" ]; then 143 continue 144 fi 145 if [ "$name" = "Linux.x86_64" -o "$name" = "Linux.ppc64" ] ; then 146 dir64=`echo "$dir" | sed -e 's,lib,lib64,'` 147 if [ "X$SSVNC_BUILD_NO_LINUX64" != "X" ]; then 148 : 149 elif [ -d $dir64 ]; then 150 dir=$dir64 151 fi 152 fi 153 try="$dir/$liba" 154 if [ -f $try ]; then 155 echo cp -p "$try" $libs 156 cp -p "$try" $libs 157 break 158 fi 159 done 160done 161if [ "X$SSVNC_BUILD_STATIC" != "X" ]; then 162 echo "Found these static archive libraries, will try to use them..." 163 ls -ld $libs 164 ls -l $libs 165 echo 166fi 167 168have_gcc="" 169if type gcc > /dev/null; then 170 have_gcc=1 171fi 172have_cc="" 173if type cc > /dev/null; then 174 have_cc=1 175fi 176 177if [ "X$have_cc" = "X" ]; then 178 if [ "X$have_gcc" = "X1" ]; then 179 cat > $tmp/cc <<END 180#!/bin/sh 181gcc "\$@" 182END 183 chmod 755 $tmp/cc 184 PATH=$PATH:`pwd`/$tmp 185 type cc 186 type gcc 187 fi 188fi 189 190if [ -d /var/tmp/LIBS -a "X$SSVNC_BUILD_STATIC" != "X" ]; then 191 LDFLAGS_OS="$LDFLAGS_OS -L/var/tmp/LIBS" 192fi 193 194if [ `uname` = "SunOS" ]; then 195 LDFLAGS_OS="$LDFLAGS_OS -L/usr/sfw/lib -R/usr/sfw/lib" 196 CPPFLAGS_OS="$CPPFLAGS_OS -I /usr/sfw/include" 197elif uname | grep -i bsd > /dev/null; then 198 LDFLAGS_OS="$LDFLAGS_OS -L/usr/local/lib -L/usr/pkg/lib" 199 CPPFLAGS_OS="$CPPFLAGS_OS -I /usr/local/include -I /usr/pkg/include" 200fi 201 202cnt=`ls ./src/patches/*.patch | wc -c` 203if [ $cnt -lt 1 ]; then 204 echo "Could not find any patches in ./src/patches. Is your tarball missing them?" 205 exit 1 206fi 207 208pline() { 209 echo "------------------------------------------------------------------" 210} 211 212# Do tightvnc viewer: 213# 214if [ "X$SSVNC_BUILD_SKIP_VIEWER" = "X" ]; then 215 tight_src=`ls -td ./src/vnc_unixsrc* | head -1` 216 if [ ! -d $tight_src ]; then 217 echo "could not locate tight vnc viewer source" 218 exit 1 219 fi 220 echo "" 221 pline 222 echo "BUILDING THE VNCVIEWER" 223 echo "" 224 sleep 1 225 226 cp -pR "$tight_src" "$tmp/vnc_unixsrc" || exit 1 227 228 echo "applying tight vnc patches:" 229 start=`pwd` 230 cd $tmp; 231 failed=0 232 count=0 233 patches="../../patches/tight-vncviewer-full.patch" 234 if [ ! -f "$patches" ]; then 235 patches=`ls ../../patches/tight* | grep -v 'tight-vncviewer-full.patch'` 236 fi 237 for patch in $patches 238 do 239 if [ ! -f "$patch" ]; then 240 continue 241 fi 242 if [ "X$PATCH_FAIL" != "X" ]; then 243 failed=1 244 break 245 fi 246 echo PATCHING WITH: "$patch" 247 ls -l "$patch" 248 sleep 1 249 patch -p0 < "$patch" 250 if [ $? != 0 ]; then 251 failed=`expr $failed + 1` 252 else 253 count=`expr $count + 1` 254 fi 255 done 256 sleep 1 257 cd "$start" 258 if [ $failed != 0 -o $count = 0 ]; then 259 ball=src/zips/vnc_unixsrc_vncviewer.patched.tar 260 echo "patches failed, trying to use backup tarball:" 261 ls -l $ball 262 sleep 2 263 cat $ball | (cd $tmp; tar -xvf -) 264 fi 265 echo 266 267 268 cd $tmp/vnc_unixsrc 269 xmkmf 270 make Makefiles 271 mv vncviewer/Makefile vncviewer/Makefile.orig 272 sed -e "s,EXTRA_LDOPTIONS =,EXTRA_LDOPTIONS = -L$start/$libs $LDFLAGS_OS," \ 273 -e "s,CCOPTIONS =,CCOPTIONS = $CPPFLAGS_OS," \ 274 vncviewer/Makefile.orig > vncviewer/Makefile 275 276 if [ `uname` = "SunOS" ]; then 277 for d in vncviewer libvncauth vncconnect vncpasswd 278 do 279 mv $d/Makefile $d/Makefile.orig 280 sed -e "s,CCOPTIONS =.*\$,CCOPTIONS = $CPPFLAGS_OS," \ 281 $d/Makefile.orig > $d/Makefile 282 done 283 fi 284 285 make depend 286 echo $PATH 287 if [ "X$TURBOVNC" = "X" ]; then 288 make all 289 else 290 make CCOPTIONS="-DTURBOVNC $CPPFLAGS_OS" EXTRA_LIBRARIES="$TURBOVNC" all 291 fi 292 ls -l vncviewer/vncviewer 293 cd "$start" 294 src=$tmp/vnc_unixsrc/vncviewer/vncviewer 295 sync 296 sleep 2 297 sync 298 strip $src 299 sync 300 sleep 2 301 sync 302 wc $src 303 sum $src 304 sleep 2 305 306 suff="" 307 if [ `uname` = "Darwin" ]; then 308 suff=".x11" 309 fi 310 if [ "X$TURBOVNC" != "X" ]; then 311 suff="$suff.turbovnc" 312 fi 313 echo cp -p $src $dest/vncviewer$suff 314 sleep 1 315 cp -p $src $dest/vncviewer$suff || exit 1 316 317 echo 318 pline 319 echo "LISTING, HELP, and LDD THE VNCVIEWER:" 320 echo 321 sleep 1 322 323 ls -l $src $dest/vncviewer$suff 324 echo 325 echo $dest/vncviewer$suff -h 326 echo 327 $dest/vncviewer$suff -h 328 echo 329 echo $LDD $dest/vncviewer$suff 330 echo 331 $LDD $dest/vncviewer$suff 332 echo "" 333fi 334 335# Do stunnel: 336# 337if [ "X$SSVNC_BUILD_SKIP_STUNNEL" = "X" ]; then 338 stunnel_src=`ls -td ./src/stunnel* | head -1` 339 if [ ! -d $stunnel_src ]; then 340 echo "could not locate stunnel source" 341 exit 1 342 fi 343 echo "" 344 pline 345 echo "BUILDING THE STUNNEL" 346 echo "" 347 sleep 1 348 349 cp -pR "$stunnel_src" "$tmp/stunnel" || exit 1 350 351 echo "applying stunnel patches:" 352 start=`pwd` 353 cd $tmp; 354 failed=0 355 count=0 356 for patch in ../../patches/stunnel* 357 do 358 if [ ! -f "$patch" ]; then 359 continue 360 fi 361 if [ "X$PATCH_FAIL" != "X" ]; then 362 failed=1 363 break 364 fi 365 echo PATCHING WITH: "$patch" 366 ls -l "$patch" 367 sleep 1 368 patch -p0 < $patch 369 if [ $? != 0 ]; then 370 failed=`expr $failed + 1` 371 else 372 count=`expr $count + 1` 373 fi 374 done 375 sleep 1 376 cd "$start" 377 if [ $failed != 0 -o $count = 0 ]; then 378 ball=src/zips/stunnel.patched.tar 379 echo "patches failed, trying to use backup tarball:" 380 ls -l $ball 381 sleep 2 382 cat $ball | (cd $tmp; tar -xvf -) 383 fi 384 echo 385 386 387 cd $tmp/stunnel 388 if [ `uname` = "SunOS" ]; then 389 cp configure configure.orig 390 sed -e "s,maindir in,maindir in /usr/sfw," configure.orig > configure 391 fi 392 env LDFLAGS="-L$start/$libs $LDFLAGS_OS" CPPFLAGS="$CPPFLAGS_OS" ./configure --disable-libwrap --enable-ipv6 393 make 394 ls -l src/stunnel 395 cd "$start" 396 src=$tmp/stunnel/src/stunnel 397 sync 398 sleep 2 399 sync 400 strip $src 401 sync 402 sleep 2 403 sync 404 wc $src 405 sum $src 406 sleep 2 407 echo cp -p $src $dest/stunnel 408 cp -p $src $dest/stunnel || exit 1 409 sleep 1 410 cp -p $src $dest/stunnel || exit 1 411 412 echo 413 pline 414 echo "LISTING, HELP, and LDD THE STUNNEL:" 415 echo 416 sleep 1 417 418 ls -l $src $dest/stunnel 419 echo 420 echo $dest/stunnel -help 421 echo 422 $dest/stunnel -help 423 echo 424 echo $LDD $dest/stunnel 425 echo 426 $LDD $dest/stunnel 427 echo "" 428fi 429 430# Do vncstorepw and ld preload friends: 431# 432if [ "X$SSVNC_BUILD_SKIP_VNCSTOREPW" = "X" ]; then 433 vncpw_tar=`ls -td ./src/zips/vncstorepw* | head -1` 434 if [ ! -f $vncpw_tar ]; then 435 echo "could not locate vncstorepw source" 436 exit 1 437 fi 438 echo "" 439 pline 440 echo "BUILDING THE VNCSTOREPW AND FRIENDS" 441 echo "" 442 sleep 1 443 444 cat "$vncpw_tar" | (cd $tmp; tar xvf -) 445 446 cd $tmp/vncstorepw 447 make 448 449 cd "$start" 450 cp -p $tmp/vncstorepw/vncstorepw $tmp/vncstorepw/lim_accept.so $dest 451 echo "" 452 453 cd $tmp/vncstorepw 454 make clean 455 456 env LD_SSL="-L$start/$libs $LDFLAGS_OS $LD_SSL" CPP_SSL="$CPPFLAGS_OS" make ultravnc_dsm_helper 457 458 cd "$start" 459 cp -p $tmp/vncstorepw/ultravnc_dsm_helper $dest 460 echo "" 461fi 462 463 464if [ "X$SSVNC_BUILD_SKIP_VIEWER" = "X" -a "X$SSVNC_BUILD_SKIP_STUNNEL" = "X" ]; then 465 # list the viewer again. 466 467 echo 468 pline 469 echo "LISTING, HELP, and LDD THE VNCVIEWER (again):" 470 echo 471 sleep 1 472 473 ls -l $dest/vncviewer$suff 474 echo 475 echo $dest/vncviewer$suff -h 476 echo 477 $dest/vncviewer$suff -h 478 echo 479 echo $LDD $dest/vncviewer$suff 480 echo 481 $LDD $dest/vncviewer$suff 482fi 483