finesse.sh 23.3 KB
Newer Older
1 2
#!/bin/bash

3 4 5 6 7 8 9 10 11 12 13 14
###########################################################################
#
#	Finesse Helper Script
#	Andreas Freise & Daniel Brown
#
#	This build helper script has been modified with the permission of 
#	Oliver Bock from the Einstein@Home Project to work with Finesse.
#
#	Usage can be found by typing ./finesse.sh at the terminal
#
###########################################################################

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
###########################################################################
#   Copyright (C) 2008-2009 by Oliver Bock                                #
#   oliver.bock[AT]aei.mpg.de                                             #
#                                                                         #
#   This file is part of Einstein@Home.                                   #
#                                                                         #
#   Einstein@Home is free software: you can redistribute it and/or modify #
#   it under the terms of the GNU General Public License as published     #
#   by the Free Software Foundation, version 2 of the License.            #
#                                                                         #
#   Einstein@Home is distributed in the hope that it will be useful,      #
#   but WITHOUT ANY WARRANTY; without even the implied warranty of        #
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the          #
#   GNU General Public License for more details.                          #
#                                                                         #
#   You should have received a copy of the GNU General Public License     #
#   along with Einstein@Home. If not, see <http://www.gnu.org/licenses/>. #
#                                                                         #
###########################################################################

### globals ###############################################################

ROOT=`pwd`
PATH_ORG="$PATH"
PATH_MINGW="$PATH"
LOGFILE=$ROOT/build.log
Andreas Freise's avatar
Andreas Freise committed
41
CC=gcc
42

43
verbose=0
44

45
TARGET=0
46

47 48 49
TARGET_LINUX=1
TARGET_MAC=2
TARGET_WIN32=3
50
TARGET_WIN64=4
Daniel Brown's avatar
Daniel Brown committed
51
TARGET_CLEAN=6
52
TARGET_NATIVE=7
53 54 55

BRANCH_DEVELOP=1
BRANCH_STABLE=2
56 57 58 59 60

### functions (tools) #############################################################

failure()
{
61 62
    echo "************************************" 
    echo "Error detected! Stopping build!"
63 64 65 66 67
    echo "`date`" | tee -a $LOGFILE

    if [ -f "$LOGFILE" ]; then
        echo "------------------------------------"
        echo "Please check logfile: `basename $LOGFILE`"
68
        #echo "These are the final 20 lines:"
69
        echo "------------------------------------"
70
        #tail -n 14 $LOGFILE | head -n 20
71 72
    fi

73
    echo "************************************"
74 75 76 77 78

    exit 1
}


79
clean()
80 81 82
{
    cd $ROOT || failure

83
    echo "Cleaning Finesse files..." | tee -a $LOGFILE
Daniel Brown's avatar
Daniel Brown committed
84 85
    
    make realclean
Daniel Brown's avatar
Daniel Brown committed
86
    rm kat || failure
87 88 89 90
}

### functions (features) #############################################################

91
check_GSL_architecture()
92 93 94
{
		lib1=$gsl_libpath/libgsl.dylib
		lib2=$gsl_libpath/libgsl.a
95 96
		lib4=$gsl_libpath/libgslcblas.a
		lib3=$gsl_libpath/libgslcblas.dylib
97
        
98
		if [ -f $lib2 ]
99
		then
100 101
				echo "Found libgsl.a, use static linking" 
				export GSL_LIBS="$lib2 $lib4"
102
				
103 104
				echo $CPUARCH
				if [[ $platform == "mac" && -z $CPUARCH ]] 
105
				then
106
						libinfo=`file $lib2`
Andreas Freise's avatar
Andreas Freise committed
107
						if [[  "$libinfo" != *i386* && "$libinfo" != *i686* ]] 
108 109
						then
						    echo "Trying ar -x ..."
110
							 testfile=version.o
111 112 113
							 ar -x $lib2 $testfile
							 libinfo=`file $testfile`
							 echo $libinfo
114 115
							 rm $testfile
						fi
116 117
						if [[ "$libinfo" == *x86_64* ]] 
						then
118
						CPUARCH="x86_64"					       
119 120 121
						elif [[ "$libinfo" == *i386* || "$libinfo" == *i686* ]]
						then
								CPUARCH="i686"
122 123 124
						else 
						echo " ** Could not determne architecture from GSL libraries"
						exit 1
Daniel Brown's avatar
Daniel Brown committed
125

126 127
						fi
						echo "	- setting architecture based on GSL to $CPUARCH " | tee -a $LOGFILE
128
				fi
129
		elif [ -f $lib1 ]
130
		then
131 132
				echo "Found libgsl.dylib, use dynamic linking" 
				export GSL_LIBS="$lib1 $lib3"
133

134
				if [[ $platform == "mac"  && -z $CPUARCH  ]] 
135
				then
136 137 138 139 140 141 142 143 144
						libinfo=`file -L $lib1`
						if [[ "$libinfo" == *x86_64* ]] 
						then
								CPUARCH="x86_64"
						elif [[ "$libinfo" == *i386* || "$libinfo" == *i686* ]]
						then
								CPUARCH="i686"
						fi
						echo "	- setting architecture based on GSL to $CPUARCH " | tee -a $LOGFILE
145 146 147 148 149 150 151
				fi
		else
				echo"  - Could not determine architecture (x86_64 or i686) of GSL library" | tee -a $LOGFILE
		return 1
		fi
}

152 153
check_prerequisites()
{
Andreas Freise's avatar
Andreas Freise committed
154 155 156

  # setting default compiler 
  export CC
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
	# check if the src and lib directories are here
	echo "Required source and library folders exist?"
	if [ ! -d "src" ]; then
		echo "	- Source folder is not present, please run with --checkout before building"
		failure
	else
		echo "	- Source folder exists" | tee -a $LOGFILE
	fi
	
	if [ ! -d "lib" ]; then
		echo "	- Library folder is not present, please run with --checkout before building"
		failure
	else
		echo "	- Library folder exists" | tee -a $LOGFILE
	fi
	
173
    echo "Checking prerequisites..." | tee -a $LOGFILE
174
		
175 176 177
    # required toolchain
    if [[ $target_arch == "win" ]]; then
    	if [[ $platform == "win" ]]; then
Daniel Brown's avatar
Daniel Brown committed
178
		TOOLS="make gcc ar ranlib"
179 180 181 182 183 184 185
	else
	    echo "	- Compiling windows version on non-windows machine"	
            TOOLS="i586-mingw32msvc-gcc i586-mingw32msvc-ar i586-mingw32msvc-ranlib"
    	fi
    else
    	TOOLS="gcc ar ranlib"
    fi
186
		
187
    for tool in $TOOLS; do
Daniel Brown's avatar
Daniel Brown committed
188
		if which ls &> /dev/null; then
189
			echo "	- Found \"$tool\"..." | tee -a $LOGFILE
Daniel Brown's avatar
Daniel Brown committed
190
		else
191
			echo "	- Missing \"$tool\" which is required tool!" | tee -a $LOGFILE
192
            return 1
Daniel Brown's avatar
Daniel Brown committed
193
		fi
194
    done
195
	
Daniel Brown's avatar
Daniel Brown committed
196 197 198 199 200
    if [[ "$platform" == 'win32' ]]; then
        echo "	- GSL found!" | tee -a $LOGFILE
    elif [[ "$platform" == 'win64' ]]; then
        echo "	- GSL found!" | tee -a $LOGFILE
	elif ! (which gsl-config &> /dev/null); then
201
			echo "	- Missing GSL which is a required library" | tee -a $LOGFILE
Daniel Brown's avatar
Daniel Brown committed
202
			return 1
203
	else
204 205 206 207 208 209 210 211 212 213
            if [[ "$platform" == 'win' ]];
            then
		        echo "	- GSL found!" | tee -a $LOGFILE
		    else            
                gsl_libpath=`gsl-config --libs | cut -d " " -f1`
                gsl_libpath=${gsl_libpath#-L}
                gsl_libpath=${gsl_libpath#-l}
                echo "	- GSL found! ($gsl_libpath)" | tee -a $LOGFILE
                check_GSL_architecture
            fi
Daniel Brown's avatar
Daniel Brown committed
214
	fi
215
	
216
  echo "	- Required toolchain found!" | tee -a $LOGFILE
217
				
Daniel Brown's avatar
Daniel Brown committed
218
	return 0
219 220
}

221
build()
222
{
Daniel Brown's avatar
Daniel Brown committed
223
		
224
		pwdbefore=`pwd`
Daniel Brown's avatar
Daniel Brown committed
225 226 227 228
        
        if [[ $platform != "win32" && $platform != "win64" ]] ; then
            echo "Configuring CUBA" | tee -a $LOGFILE
            # configure cuba if needed
Daniel Brown's avatar
Daniel Brown committed
229
            if [ ! -f "./lib/Cuba-3.2/config.h" ] && [ ! -f "./lib/Cuba-3.2/makefile" ] ; then
Daniel Brown's avatar
Daniel Brown committed
230 231
                    cd ./lib/Cuba-3.2
                    chmod 700 ./configure
232

Daniel Brown's avatar
Daniel Brown committed
233 234 235
                    if [[ $platform == "mac" ]]
                    then
                            echo "Configuring Cuba with extra flags (CPUARCH=$CPUARCH)"
236
                            ./configure -q CFLAGS="-O3 -fomit-frame-pointer -ffast-math -Wall -Wextra -arch $CPUARCH"
Daniel Brown's avatar
Daniel Brown committed
237
                    else
238
                            ./configure -q CFLAGS="-O3 -fomit-frame-pointer -ffast-math -Wall -Wextra"
Daniel Brown's avatar
Daniel Brown committed
239 240 241 242 243 244
                    fi
                    rm libcuba.a # removing this to trigger rebuild
                    # These CFLAGS are those generated by the configure script on a clean system
            # We set them here explicitly in order to overwrite the previously exported
            # CFLAGS for the rest of the build (because they cause Cuba to crash with a 
            # segmentation fault).
245

Daniel Brown's avatar
Daniel Brown committed
246 247 248 249 250
                    cd $pwdbefore
            else
                    echo "	- Cuba is already configured"
            fi
        fi
251

252 253 254 255
		#------------ don't know why this is here ---------------------
		#gsl_libpath=`gsl-config --libs | cut -d " " -f1`
		#gsl_libpath=${gsl_libpath#-L}
		#gsl_libpath=${gsl_libpath#-l}
256
		# Setting GSL_LIBS flags to allow static linking
257
    #export GSL_LIBS="$gsl_libpath/libgslcblas.a $gsl_libpath/libgsl.a"
258

259 260
		echo "Calling make file, see make.log for more details..."
		echo ""
Andreas Freise's avatar
Andreas Freise committed
261

262 263
		if [ $verbose == 1 ]
		then
264
				make ARCH=$target_arch BUILD=$platform config 2>&1 | tee make.log || failure
265
				make ARCH=$target_arch BUILD=$platform kat 2>&1 | tee make.log || failure
266
		else
267
				make ARCH=$target_arch BUILD=$platform config 2>&1 1>make.log || failure
268
				make ARCH=$target_arch BUILD=$platform kat 2>&1 1>make.log || failure
269 270 271 272 273 274 275 276 277
		fi

		if grep " Error " make.log 1>/dev/null 2>&1
		then
				#cat make.err > $LOGFILE
				failure
		else
				return 0;
		fi
278 279
}

280 281
make-win-package()
{
282 283
	python getWinDLLs.py
	
Daniel Brown's avatar
Daniel Brown committed
284
    sys=`eval uname --machine`
285
    ver=`eval git describe --abbrev=0`
Daniel Brown's avatar
Daniel Brown committed
286
	echo "Making Windows $sys package..." | tee -a $LOGFILE
287
    rm -rf .windlls
Daniel Brown's avatar
Daniel Brown committed
288
    python getWinDLLs.py
289 290
    
    dir=FINESSE_"$ver"_WIN_"$sys"
Daniel Brown's avatar
Daniel Brown committed
291 292 293 294
    
    rm -rf $dir
	mkdir $dir
	cd $dir
295
	
Daniel Brown's avatar
Daniel Brown committed
296
	cp ../.windlls/*.dll .
297
	cp ../kat.exe .
298
    cp ../kat.ini .
299 300 301 302
	cp ../CHANGES .
	cp ../LICENSES .
	cp ../README .
	cp ../INSTALL .
Daniel Brown's avatar
Daniel Brown committed
303 304 305
	cp ../test.kat .
    cp ../test_plot.kat .
    cp ../install.bat .
306 307 308 309
    cp ../findGnuplot.bat .

    a=`which cygpath`    
    cp $a .
Daniel Brown's avatar
Daniel Brown committed
310
    
311
	echo "Created Windows distribution $dir" | tee -a $LOGFILE
312 313 314 315
	
	cd ..
}

316 317 318 319
print_usage()
{
    cd $ROOT

Daniel Brown's avatar
Daniel Brown committed
320 321
    echo "******************************************************************************"
    echo "Usage: `basename $0` <option> <--checkout: option>"
322
    echo
323 324 325 326
		echo "Run with the checkout command first, this fetches the latest stable"
		echo "version of Finesse source. You can then build it by using the system"
		echo "specific build argument to get the required version."
		echo
327
    echo "Available Arguments:"
328 329 330 331
		echo "  --build"
		echo "       Builds Finesse executable that is native to the system you are running"
		echo ""
		echo "  --build-linux"
332
		echo "  --build-linux32"
Daniel Brown's avatar
Daniel Brown committed
333
    echo "  --build-mac"
334
    echo "  --build-mac32"
Daniel Brown's avatar
Daniel Brown committed
335
    echo "  --build-win32"
336
    echo "  --build-win64"
337 338
		echo "       Choose the system which you would like to build an executable for."
		echo ""
Daniel Brown's avatar
Daniel Brown committed
339
    echo "  --clean"
340 341 342 343
		echo "       This cleans up all the build files. Should be used if you have"
		echo "       swapped branches."
		echo ""
		echo "  --make-win-package"
344 345
		echo "       This creates the binary distribution for win32. Only runs on Cygwin"
    echo "       capable Windows machines."
Daniel Brown's avatar
Daniel Brown committed
346
    echo "******************************************************************************"
347 348 349 350 351 352

    echo "Wrong usage. Stopping!" >> $LOGFILE

    return 0
}

Daniel Brown's avatar
Daniel Brown committed
353
### main control ##########################################################
Daniel Brown's avatar
Daniel Brown committed
354

355 356 357
# crude command line parsing :-)

if [ $# -ne 1 ]; then
358 359 360 361
	if [ $# -ne 2 ]; then
		print_usage
		exit 1
	fi
362 363
fi

Daniel Brown's avatar
Daniel Brown committed
364 365 366 367 368 369
echo "************************************" | tee -a $LOGFILE
echo "Starting new build!" | tee -a $LOGFILE
echo "`date`" | tee -a $LOGFILE
echo "************************************" | tee -a $LOGFILE


370 371
platform='unknown'
unamestr=`uname`
Daniel Brown's avatar
Daniel Brown committed
372
unamem=`uname -m`
373 374 375

if [[ "$unamestr" == 'Linux' ]]; then
   platform='linux'
376 377
elif [[ "$unamestr" == 'Darwin' ]]; then
   platform='mac'
378
elif [[ "$unamestr" == *CYGWIN* ]]; then
Daniel Brown's avatar
Daniel Brown committed
379 380 381 382 383
    if [[ "$unamem" == 'i686' ]]; then
        platform='cygwin32'
    else
        platform='cygwin64'
    fi
Daniel Brown's avatar
Daniel Brown committed
384 385 386 387 388 389
elif [[ "$unamestr" == *MINGW* ]]; then
    if [[ "$unamem" == 'i686' ]]; then
        platform='win32'
    else
        platform='win64'
    fi
Daniel Brown's avatar
Daniel Brown committed
390
else
Daniel Brown's avatar
Daniel Brown committed
391
   echo "Platform could not be determined ($unamestr)" | tee -a $LOGFILE
Daniel Brown's avatar
Daniel Brown committed
392
   failure
393 394
fi

395
echo 'Running on "'$platform'"'
396 397
		
case "$1" in
398
    "--build")
399
		    NATIVE="-march=native"
400 401 402 403
		    CPUARCH=""
		    target_arch=$platform
            
            if [[ "$platform" == 'linux' ]]; then
404 405 406
		       TARGET=$TARGET_LINUX
		    elif [[ "$platform" == 'mac' ]]; then
		       TARGET=$TARGET_MAC
Daniel Brown's avatar
Daniel Brown committed
407 408 409 410 411 412 413 414 415
            elif [[ "$platform" == 'cygwin32' ]]; then
		       TARGET=$TARGET_WIN32
                CPUARCH=
                target_arch=win32
            elif [[ "$platform" == 'cygwin64' ]]; then
		       TARGET=$TARGET_WIN64
                CPUARCH=
                target_arch=win64
		    elif [[ "$platform" == 'win32' ]]; then
416
		       TARGET=$TARGET_WIN32
Daniel Brown's avatar
Daniel Brown committed
417 418 419 420
                CPUARCH=
                target_arch=win64
            elif [[ "$platform" == 'win64' ]]; then
		       TARGET=$TARGET_WIN64
421 422
                CPUARCH=
                target_arch=win64
423 424 425 426
		    else
		       echo "Platform Target could not be determined" | tee -a $LOGFILE
		       failure
		    fi   
Daniel Brown's avatar
Daniel Brown committed
427
		
428 429
        echo "Building native Finesse version:" | tee -a $LOGFILE        
        ;;
Daniel Brown's avatar
Daniel Brown committed
430
    "--build-linux")
431
		    NATIVE=""
432
            TARGET=$TARGET_LINUX   
433
		        ="-m64"
434
		    target_arch="linux"
Daniel Brown's avatar
Daniel Brown committed
435
        echo "Building Linux version    :" | tee -a $LOGFILE        
436
        ;;
437 438
    "--build-linux32")
		    NATIVE=""
439
            TARGET=$TARGET_LINUX   
440 441 442 443
		    CPUARCH="-m32"
		    target_arch="linux"
        echo "Building Linux 32bit version:" | tee -a $LOGFILE        
        ;;
444 445
    "--build-mac32")
		    NATIVE=""
446
            TARGET=$TARGET_MAC        
447
		    CPUARCH="i386"
448 449 450
		    target_arch="mac"
		    echo "Building Mac (Intel) 32bit version:" | tee -a $LOGFILE        
        ;;
Daniel Brown's avatar
Daniel Brown committed
451
    "--build-mac")
452
		    NATIVE=""
453
            TARGET=$TARGET_MAC        
454 455 456
		    CPUARCH=""
		    target_arch="mac"
		    echo "Building Mac (Intel) version:" | tee -a $LOGFILE        
457
        ;;
Daniel Brown's avatar
Daniel Brown committed
458
    "--build-win32")
459
		    NATIVE=""
Daniel Brown's avatar
Daniel Brown committed
460
            TARGET=$TARGET_WIN32
461
		    CPUARCH="i686"
462
		    target_arch="win32"
463
        echo "Building Win32 version:" | tee -a $LOGFILE        
464
        ;;
465 466
    "--build-win64")
		    NATIVE=""
Daniel Brown's avatar
Daniel Brown committed
467
            TARGET=$TARGET_WIN64     
468 469 470 471
		    CPUARCH="x86_64"
		    target_arch="win64"
        echo "Building Win64 version:" | tee -a $LOGFILE        
        ;;
472
    "--checkout")
473 474 475
        echo ""
        echo "ERROR: --checkout is no longer used, use 'git checkout [branch name]' instead." | tee -a $LOGFILE
        echo ""
476 477
        ;;	
    "--remove")
478
		    echo "--remove is no longer used." | tee -a $LOGFILE
479
        ;;
480 481
	  "--clean")
		    TARGET=$TARGET_CLEAN
Daniel Brown's avatar
Daniel Brown committed
482
        ;;
483 484 485
	  "--make-win-package")
		    make-win-package
		    exit 0
486
        ;;
487 488 489 490 491 492 493 494
    *)
        print_usage
        exit 1
        ;;
esac

# here we go...

Andreas Freise's avatar
Andreas Freise committed
495
#export OPTIM_CFLAGS="-mfpmath=sse -O3 -ffast-math -Wall -fexpensive-optimizations -fomit-frame-pointer -funroll-loops -DNDEBUG "
496 497

if ( cc 2>&1 | grep clang >/dev/null ); then
498
		echo "Setting optimisation flags for clang compiler"
499
		export OPTIM_CFLAGS="-mfpmath=sse -O3 -fno-math-errno -ffinite-math-only -fno-trapping-math -fno-signed-zeros -Wall -Wextra -Wno-missing-field-initializers -fomit-frame-pointer -funroll-loops -DNDEBUG "
500
else
501
		echo "Setting optimisation flags for gcc compiler"
502
		export OPTIM_CFLAGS="-mfpmath=sse -O3 -fno-math-errno -ffinite-math-only -fno-signaling-nans -fno-trapping-math -fno-signed-zeros -Wall -Wextra -Wno-missing-field-initializers -fexpensive-optimizations -fomit-frame-pointer -funroll-loops -DNDEBUG "
503
fi
504

505 506 507
case $TARGET in
    $TARGET_LINUX)
        check_prerequisites || failure
508
				export CFLAGS="$OPTIM_CFLAGS $NATIVE $CPUARCH"
509
        build || failure
510 511
        ;;
    $TARGET_MAC)
512
        check_prerequisites || failure
513 514 515
				OSXminor=7
                
                #`sw_vers -productVersion | cut -d'.' -f2`
516 517 518 519
				if [ -z "$OSXminor" ]; then
						echo "Could not determine OSX version"
						failure
				fi
520
                
521
				echo "Building for OSX version: 10.$OSXminor"
522
				# probably should allow custom minor version for build-mac
523
				export MACOSX_DEPLOYMENT_TARGET="10.$OSXminor"
524
                
Andreas Freise's avatar
Andreas Freise committed
525 526 527
        if [ -d /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/ ]; then
            echo "Preparing Mac OS X 10.12 SDK build environment..." | tee -a $LOGFILE
            export OSX_SDK="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/"
528
            export OSX_CFLAGS="$NATIVE $OPTIM_CFLAGS -isysroot $OSX_SDK -arch $CPUARCH -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET -DOSX_BUILD_VER=$MACOSX_DEPLOYMENT_TARGET -DMACOSX_SDK=12"
Andreas Freise's avatar
Andreas Freise committed
529 530 531 532 533
            export OSX_LDFLAGS="-isysroot $OSX_SDK -Wl,-syslibroot,$OSX_SDK -arch $CPUARCH -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET"
            export CFLAGS=$OSX_CFLAGS
            export CXXFLAGS=$OSX_CFLAGS
            export LDFLAGS=$OSX_LDFLAGS
        elif [ -d /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/ ]; then
534
            echo "Preparing Mac OS X 10.11 SDK build environment..." | tee -a $LOGFILE
535
            export OSX_SDK="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/"
536
            export OSX_CFLAGS="$NATIVE $OPTIM_CFLAGS -isysroot $OSX_SDK -arch $CPUARCH -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET -DOSX_BUILD_VER=$MACOSX_DEPLOYMENT_TARGET -DMACOSX_SDK=11"
537 538 539 540 541
            export OSX_LDFLAGS="-isysroot $OSX_SDK -Wl,-syslibroot,$OSX_SDK -arch $CPUARCH -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET"
            export CFLAGS=$OSX_CFLAGS
            export CXXFLAGS=$OSX_CFLAGS
            export LDFLAGS=$OSX_LDFLAGS
       elif [ -d /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/ ]; then
542
            echo "Preparing Mac OS X 10.10 SDK build environment..." | tee -a $LOGFILE
543
            export OSX_SDK="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/"
544
            export OSX_CFLAGS="$NATIVE $OPTIM_CFLAGS -isysroot $OSX_SDK -arch $CPUARCH -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET -DOSX_BUILD_VER=$MACOSX_DEPLOYMENT_TARGET -DMACOSX_SDK=10"
545 546 547 548 549
            export OSX_LDFLAGS="-isysroot $OSX_SDK -Wl,-syslibroot,$OSX_SDK -arch $CPUARCH -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET"
            export CFLAGS=$OSX_CFLAGS
            export CXXFLAGS=$OSX_CFLAGS
            export LDFLAGS=$OSX_LDFLAGS
      elif [ -d /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/ ]; then
550
            echo "Preparing Mac OS X 10.9 SDK build environment..." | tee -a $LOGFILE
551
            export OSX_SDK="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/"
552
            export OSX_CFLAGS="$NATIVE $OPTIM_CFLAGS -isysroot $OSX_SDK -arch $CPUARCH -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET -DOSX_BUILD_VER=$MACOSX_DEPLOYMENT_TARGET -DMACOSX_SDK=9"
553
            export OSX_LDFLAGS="-isysroot $OSX_SDK -Wl,-syslibroot,$OSX_SDK -arch $CPUARCH -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET"
554 555 556
            export CFLAGS=$OSX_CFLAGS
            export CXXFLAGS=$OSX_CFLAGS
            export LDFLAGS=$OSX_LDFLAGS
557
	    elif [ -d /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/ ]; then
558
            echo "Preparing Mac OS X 10.8 SDK build environment..." | tee -a $LOGFILE
559
            export OSX_SDK="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/"
560
            export OSX_CFLAGS="$NATIVE $OPTIM_CFLAGS -isysroot $OSX_SDK -arch $CPUARCH -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET -DOSX_BUILD_VER=$MACOSX_DEPLOYMENT_TARGET -DMACOSX_SDK=8"
561
            export OSX_LDFLAGS=" -isysroot $OSX_SDK -Wl,-syslibroot,$OSX_SDK -arch $CPUARCH -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET"
562 563 564 565
            export CFLAGS=$OSX_CFLAGS
            export CXXFLAGS=$OSX_CFLAGS
            export LDFLAGS=$OSX_LDFLAGS
        elif [ -d /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/ ]; then
566
            echo "Preparing Mac OS X 10.7 SDK build environment..." | tee -a $LOGFILE
567
            export OSX_SDK="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/"
568
            export OSX_CFLAGS="$NATIVE $OPTIM_CFLAGS -isysroot $OSX_SDK -arch $CPUARCH -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET -DOSX_BUILD_VER=$MACOSX_DEPLOYMENT_TARGET -DMACOSX_SDK=7"
569
            export OSX_LDFLAGS="-isysroot $OSX_SDK -Wl,-syslibroot,$OSX_SDK -arch $CPUARCH -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET"
570 571 572
            export CFLAGS=$OSX_CFLAGS
            export CXXFLAGS=$OSX_CFLAGS
            export LDFLAGS=$OSX_LDFLAGS
573
        elif [ -d /Developer/SDKs/MacOSX10.6.sdk ]; then
574
            echo "Preparing Mac OS X 10.6 x86_64 SDK build environment..." | tee -a $LOGFILE
575
            export LDFLAGS="-isysroot /Developer/SDKs/MacOSX10.6.sdk -Wl,-syslibroot,/Developer/SDKs/MacOSX10.6.sdk -arch $CPUARCH $LDFLAGS"
576
            export CPPFLAGS="-isysroot /Developer/SDKs/MacOSX10.6.sdk -arch $CPUARCH $CPPFLAGS -DOSX_BUILD_VER=$MACOSX_DEPLOYMENT_TARGET"
577
            export CFLAGS="$NATIVE $OPTIM_CFLAGS -isysroot /Developer/SDKs/MacOSX10.6.sdk -arch $CPUARCH $CFLAGS -DOSX_BUILD_VER=$MACOSX_DEPLOYMENT_TARGET  -DMACOSX_SDK=6"
578
            export CXXFLAGS="-isysroot /Developer/SDKs/MacOSX10.6.sdk -arch $CPUARCH $CXXFLAGS"
579 580 581
            export SDKROOT="/Developer/SDKs/MacOSX10.6.sdk"
        elif [ -d /Developer/SDKs/MacOSX10.5u.sdk ]; then
            echo "Preparing Mac OS X 10.5 i386 SDK build environment..." | tee -a $LOGFILE
582
            export LDFLAGS="-isysroot /Developer/SDKs/MacOSX10.5.sdk -Wl,-syslibroot,/Developer/SDKs/MacOSX10.5.sdk -arch $CPUARCH $LDFLAGS"
583
            export CPPFLAGS="-isysroot /Developer/SDKs/MacOSX10.5.sdk -arch $CPUARCH $CPPFLAGS -DOSX_BUILD_VER=$MACOSX_DEPLOYMENT_TARGET"
584
            export CFLAGS="$NATIVE $OPTIM_CFLAGS -isysroot /Developer/SDKs/MacOSX10.5.sdk -arch $CPUARCH $CFLAGS -DOSX_BUILD_VER=$MACOSX_DEPLOYMENT_TARGET -DMACOSX_SDK=5"
585
            export CXXFLAGS="-isysroot /Developer/SDKs/MacOSX10.5.sdk -arch $CPUARCH $CXXFLAGS"
586 587 588
            export SDKROOT="/Developer/SDKs/MacOSX10.5.sdk"
        elif [ -d /Developer/SDKs/MacOSX10.4u.sdk ]; then
            echo "Preparing Mac OS X 10.4 i386 SDK build environment..." | tee -a $LOGFILE
589
            export LDFLAGS="-isysroot /Developer/SDKs/MacOSX10.4u.sdk -Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch $CPUARCH $LDFLAGS"
590
            export CPPFLAGS="-isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch $CPUARCH $CPPFLAGS -DOSX_BUILD_VER=$MACOSX_DEPLOYMENT_TARGET"
591
            export CFLAGS="$NATIVE $OPTIM_CFLAGS -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch $CPUARCH $CFLAGS -DOSX_BUILD_VER=$MACOSX_DEPLOYMENT_TARGET -DMACOSX_SDK=4"
592
            export CXXFLAGS="-isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch $CPUARCH $CXXFLAGS"
593 594
            export SDKROOT="/Developer/SDKs/MacOSX10.4u.sdk"
        else
595
            echo "Mac OS X 10.4 - 10.12 SDK required but missing!" | tee -a $LOGFILE
596 597
            failure
        fi
598
        #prepare_tree || failure
599
        build $TARGET_MAC || failure
600 601 602
        ;;
    $TARGET_WIN32)
        check_prerequisites || failure
Daniel Brown's avatar
Daniel Brown committed
603 604 605 606 607 608 609
				export CFLAGS="$CFLAGS -m32 $OPTIM_CFLAGS $NATIVE"
        build || failure
		
        ;;
    $TARGET_WIN64)
        check_prerequisites || failure
				export CFLAGS="$CFLAGS -m64 $OPTIM_CFLAGS $NATIVE"
610
        build || failure
611 612
		
        ;;
613 614 615 616 617 618 619 620 621
    $TARGET_CLEAN)
		    echo "Cleaning up build files, see clean.err and clean.log for more details..."
		    make ARCH=$target_arch BUILD=$platform realclean 2>&1 1>make.log 
        if grep " Error " make.log 1>/dev/null 2>&1
    		then
		  	    #cat make.err > $LOGFILE
			      failure
        fi
	 	    ;;
622 623 624 625 626 627 628
    *)
        # should be unreachable
        print_usage
        exit 1
        ;;
esac

629
echo
Daniel Brown's avatar
Daniel Brown committed
630
echo "************************************	" | tee -a $LOGFILE
631
echo " Finished with no errors              " | tee -a $LOGFILE
632 633 634
echo "`date`" | tee -a $LOGFILE
echo "************************************" | tee -a $LOGFILE

Daniel Brown's avatar
Daniel Brown committed
635 636
cd $ROOT

637
exit 0