phoenix-firestorm/scripts/configure_firestorm.sh

559 lines
20 KiB
Bash
Executable File

#!/bin/bash
###
### Constants
###
TRUE=0 # Map the shell's idea of truth to a variable for better documentation
FALSE=1
#echo "DEBUG ARGS: $@"
#echo "DEBUG `pwd`"
# args ../indra
# <string>-DCMAKE_BUILD_TYPE:STRING=Release</string>
# <string>-DADDRESS_SIZE:STRING=32</string>
# <string>-DROOT_PROJECT_NAME:STRING=SecondLife</string>
# <string>-DUSE_KDU=TRUE</string>
# <string>-DFMODSTUDIO:BOOL=ON</string>
# <string>-DOPENSIM:BOOL=ON</string>
# <string>-DUSE_AVX_OPTIMIZATION:BOOL=OFF</string>
# <string>-DUSE_AVX2_OPTIMIZATION:BOOL=OFF</string>
# <string>-DLL_TESTS:BOOL=OFF</string>
# <string>-DPACKAGE:BOOL=OFF></string>
###
### Global Variables
###
WANTS_CLEAN=$FALSE
WANTS_CONFIG=$FALSE
WANTS_PACKAGE=$FALSE
WANTS_VERSION=$FALSE
WANTS_KDU=$FALSE
WANTS_FMODSTUDIO=$FALSE
WANTS_OPENAL=$FALSE
WANTS_OPENSIM=$TRUE
WANTS_SINGLEGRID=$FALSE
WANTS_AVX=$FALSE
WANTS_AVX2=$FALSE
WANTS_TESTBUILD=$FALSE
WANTS_BUILD=$FALSE
WANTS_CRASHREPORTING=$FALSE
PLATFORM="darwin" # darwin, windows, linux
BTYPE="Release"
CHANNEL="" # will be overwritten later with platform-specific values unless manually specified.
LL_ARGS_PASSTHRU=""
JOBS="0"
WANTS_NINJA=$FALSE
WANTS_VSCODE=$FALSE
TESTBUILD_PERIOD="0"
SINGLEGRID_URI=""
###
### Helper Functions
###
showUsage()
{
echo
echo "Usage: "
echo "========================"
echo
echo " --clean : Remove past builds & configuration"
echo " --config : Generate a new architecture-specific config"
echo " --build : Build Firestorm"
echo " --version : Update version number"
echo " --chan [Release|Beta|Private] : Private is the default, sets channel"
echo " --btype [Release|RelWithDebInfo|Debug] : Release is default, whether to use symbols"
echo " --kdu : Build with KDU"
echo " --package : Build installer"
echo " --no-package : Build without installer (Overrides --package)"
echo " --fmodstudio : Build with FMOD Studio"
echo " --openal : Build with OpenAL"
echo " --opensim : Build with OpenSim support (Disables Havok features)"
echo " --no-opensim : Build without OpenSim support (Overrides --opensim)"
echo " --singlegrid <login_uri> : Build for single grid usage (Requires --opensim)"
echo " --avx : Build with Advanced Vector Extensions"
echo " --avx2 : Build with Advanced Vector Extensions 2"
echo " --crashreporting : Build with crash reporting enabled"
echo " --testbuild <days> : Create time-limited test build (build date + <days>)"
echo " --platform <platform> : Build for specified platform (darwin | windows | linux)"
echo " --jobs <num> : Build with <num> jobs in parallel (Linux and Darwin only)"
echo " --ninja : Build using Ninja (Linux only)"
echo " --vscode : Exports compile commands for VSCode (Linux only)"
echo
echo "All arguments not in the above list will be passed through to LL's configure/build."
echo
}
getArgs()
# $* = the options passed in from main
{
if [ $# -gt 0 ]; then
while getoptex "clean build config version package no-package fmodstudio openal ninja vscode jobs: platform: kdu opensim no-opensim singlegrid: avx avx2 crashreporting testbuild: help chan: btype:" "$@" ; do
#ensure options are valid
if [ -z "$OPTOPT" ] ; then
showUsage
exit 1
fi
case "$OPTOPT" in
clean) WANTS_CLEAN=$TRUE;;
config) WANTS_CONFIG=$TRUE;;
version) WANTS_VERSION=$TRUE;;
chan) CHANNEL="$OPTARG";;
btype) if [ \( "$OPTARG" == "Release" \) -o \( "$OPTARG" == "RelWithDebInfo" \) -o \( "$OPTARG" == "Debug" \) ] ; then
BTYPE="$OPTARG"
fi
;;
kdu) WANTS_KDU=$TRUE;;
fmodstudio) WANTS_FMODSTUDIO=$TRUE;;
openal) WANTS_OPENAL=$TRUE;;
opensim) WANTS_OPENSIM=$TRUE;;
no-opensim) WANTS_OPENSIM=$FALSE;;
singlegrid) WANTS_SINGLEGRID=$TRUE
SINGLEGRID_URI="$OPTARG"
;;
avx) WANTS_AVX=$TRUE;;
avx2) WANTS_AVX2=$TRUE;;
crashreporting) WANTS_CRASHREPORTING=$TRUE;;
testbuild) WANTS_TESTBUILD=$TRUE
TESTBUILD_PERIOD="$OPTARG"
;;
package) WANTS_PACKAGE=$TRUE;;
no-package) WANTS_PACKAGE=$FALSE;;
build) WANTS_BUILD=$TRUE;;
platform) PLATFORM="$OPTARG";;
jobs) JOBS="$OPTARG";;
ninja) WANTS_NINJA=$TRUE;;
vscode) WANTS_VSCODE=$TRUE;;
help) showUsage && exit 0;;
-*) showUsage && exit 1;;
*) showUsage && exit 1;;
esac
done
shift $[OPTIND-1]
if [ $OPTIND -le 1 ] ; then
showUsage && exit 1
fi
fi
if [ $WANTS_CLEAN -ne $TRUE ] && [ $WANTS_CONFIG -ne $TRUE ] && \
[ $WANTS_VERSION -ne $TRUE ] && [ $WANTS_BUILD -ne $TRUE ] && \
[ $WANTS_PACKAGE -ne $TRUE ] ; then
# the user didn't say what to do, so assume he wants to do a basic rebuild
WANTS_CONFIG=$TRUE
WANTS_BUILD=$TRUE
WANTS_VERSION=$TRUE
fi
LOG="`pwd`/logs/build_$PLATFORM.log"
if [ -r "$LOG" ] ; then
rm -f `basename "$LOG"`/* #(remove old logfiles)
fi
}
function b2a()
{
if [ $1 -eq $TRUE ] ; then
echo "true"
else
echo "false"
fi
}
function getoptex()
{
let $# || return 1
local optlist="${1#;}"
let OPTIND || OPTIND=1
[ $OPTIND -lt $# ] || return 1
shift $OPTIND
if [ "$1" != "-" -a "$1" != "${1#-}" ]
then OPTIND=$[OPTIND+1]; if [ "$1" != "--" ]
then
local o
o="-${1#-$OPTOFS}"
for opt in ${optlist#;}
do
OPTOPT="${opt%[;.:]}"
unset OPTARG
local opttype="${opt##*[^;:.]}"
[ -z "$opttype" ] && opttype=";"
if [ ${#OPTOPT} -gt 1 ]
then # long-named option
case $o in
"--$OPTOPT")
if [ "$opttype" != ":" ]; then return 0; fi
OPTARG="$2"
if [ -z "$OPTARG" ];
then # error: must have an agrument
let OPTERR && echo "$0: error: $OPTOPT must have an argument" >&2
OPTARG="$OPTOPT";
OPTOPT="?"
return 1;
fi
OPTIND=$[OPTIND+1] # skip option's argument
return 0
;;
"--$OPTOPT="*)
if [ "$opttype" = ";" ];
then # error: must not have arguments
let OPTERR && echo "$0: error: $OPTOPT must not have arguments" >&2
OPTARG="$OPTOPT"
OPTOPT="?"
return 1
fi
OPTARG=${o#"--$OPTOPT="}
return 0
;;
esac
else # short-named option
case "$o" in
"-$OPTOPT")
unset OPTOFS
[ "$opttype" != ":" ] && return 0
OPTARG="$2"
if [ -z "$OPTARG" ]
then
echo "$0: error: -$OPTOPT must have an argument" >&2
OPTARG="$OPTOPT"
OPTOPT="?"
return 1
fi
OPTIND=$[OPTIND+1] # skip option's argument
return 0
;;
"-$OPTOPT"*)
if [ $opttype = ";" ]
then # an option with no argument is in a chain of options
OPTOFS="$OPTOFS?" # move to the next option in the chain
OPTIND=$[OPTIND-1] # the chain still has other options
return 0
else
unset OPTOFS
OPTARG="${o#-$OPTOPT}"
return 0
fi
;;
esac
fi
done
#echo "$0: error: invalid option: $o"
LL_ARGS_PASSTHRU="$LL_ARGS_PASSTHRU $o"
return 0
#showUsage
#exit 1
fi; fi
OPTOPT="?"
unset OPTARG
return 1
}
function optlistex
{
local l="$1"
local m # mask
local r # to store result
while [ ${#m} -lt $[${#l}-1] ]; do m="$m?"; done # create a "???..." mask
while [ -n "$l" ]
do
r="${r:+"$r "}${l%$m}" # append the first character of $l to $r
l="${l#?}" # cut the first charecter from $l
m="${m#?}" # cut one "?" sign from m
if [ -n "${l%%[^:.;]*}" ]
then # a special character (";", ".", or ":") was found
r="$r${l%$m}" # append it to $r
l="${l#?}" # cut the special character from l
m="${m#?}" # cut one more "?" sign
fi
done
echo $r
}
function getopt()
{
local optlist=`optlistex "$1"`
shift
getoptex "$optlist" "$@"
return $?
}
###
### Main Logic
###
getArgs $*
if [ ! -d `dirname "$LOG"` ] ; then
mkdir -p `dirname "$LOG"`
fi
echo -e "configure_firestorm.sh" > $LOG
echo -e " PLATFORM: $PLATFORM" | tee -a $LOG
echo -e " KDU: `b2a $WANTS_KDU`" | tee -a $LOG
echo -e " FMODSTUDIO: `b2a $WANTS_FMODSTUDIO`" | tee -a $LOG
echo -e " OPENAL: `b2a $WANTS_OPENAL`" | tee -a $LOG
echo -e " OPENSIM: `b2a $WANTS_OPENSIM`" | tee -a $LOG
if [ $WANTS_SINGLEGRID -eq $TRUE ] ; then
echo -e " SINGLEGRID: `b2a $WANTS_SINGLEGRID` ($SINGLEGRID_URI)" | tee -a $LOG
else
echo -e " SINGLEGRID: `b2a $WANTS_SINGLEGRID`" | tee -a $LOG
fi
echo -e " AVX: `b2a $WANTS_AVX`" | tee -a $LOG
echo -e " AVX2: `b2a $WANTS_AVX2`" | tee -a $LOG
echo -e " CRASHREPORTING: `b2a $WANTS_CRASHREPORTING`" | tee -a $LOG
if [ $WANTS_TESTBUILD -eq $TRUE ] ; then
echo -e " TESTBUILD: `b2a $WANTS_TESTBUILD` ($TESTBUILD_PERIOD days)" | tee -a $LOG
else
echo -e " TESTBUILD: `b2a $WANTS_TESTBUILD`" | tee -a $LOG
fi
echo -e " PACKAGE: `b2a $WANTS_PACKAGE`" | tee -a $LOG
echo -e " CLEAN: `b2a $WANTS_CLEAN`" | tee -a $LOG
echo -e " BUILD: `b2a $WANTS_BUILD`" | tee -a $LOG
echo -e " CONFIG: `b2a $WANTS_CONFIG`" | tee -a $LOG
echo -e " NINJA: `b2a $WANTS_NINJA`" | tee -a $LOG
echo -e " VSCODE: `b2a $WANTS_VSCODE`" | tee -a $LOG
echo -e " PASSTHRU: $LL_ARGS_PASSTHRU" | tee -a $LOG
echo -e " BTYPE: $BTYPE" | tee -a $LOG
if [ $PLATFORM == "linux" -o $PLATFORM == "darwin" ] ; then
echo -e " JOBS: $JOBS" | tee -a $LOG
fi
echo -e " Logging to $LOG"
if [ $PLATFORM == "windows" ]
then
if [ -z "${AUTOBUILD_VSVER}" ]
then
echo "AUTOBUILD_VSVER not set, this can lead to Autobuild picking a higher VS version than desired."
echo "If you see this happen you should set the variable to e.g. 120 for Visual Studio 2013."
fi
fi
if [ -z "$AUTOBUILD_VARIABLES_FILE" ]
then
echo "AUTOBUILD_VARIABLES_FILE not set."
echo "In order to run autobuild it needs to be set to point to a correct variables file."
exit 1
fi
if [ $PLATFORM == "windows" ] ; then
FIND=/usr/bin/find
else
FIND=find
fi
if [ -z $CHANNEL ] ; then
if [ $PLATFORM == "darwin" ] ; then
CHANNEL="private-`hostname -s` "
else
CHANNEL="private-`hostname`"
fi
else
CHANNEL=`echo $CHANNEL | sed -e "s/[^a-zA-Z0-9\-]*//g"` # strip out difficult characters from channel
fi
CHANNEL="Firestorm-$CHANNEL"
if [ \( $WANTS_CLEAN -eq $TRUE \) -a \( $WANTS_BUILD -eq $FALSE \) ] ; then
echo "Cleaning $PLATFORM...."
wdir=`pwd`
pushd ..
if [ $PLATFORM == "darwin" ] ; then
if [ "${AUTOBUILD_ADDRSIZE}" == "64" ]
then
rm -rf build-darwin-x86_64/*
mkdir -p build-darwin-x86_64/logs
else
rm -rf build-darwin-i386/*
mkdir -p build-darwin-i386/logs
fi
elif [ $PLATFORM == "windows" ] ; then
rm -rf build-vc120-${AUTOBUILD_ADDRSIZE}
mkdir -p build-vc120-${AUTOBUILD_ADDRSIZE}/logs
elif [ $PLATFORM == "linux32" ] ; then
if [ "${AUTOBUILD_ADDRSIZE}" == "64" ]
then
rm -rf build-linux-x86_64/*
mkdir -p build-linux-x86_64/logs
else
rm -rf build-linux-i686/*
mkdir -p build-linux-i686/logs
fi
fi
popd
fi
if [ \( $WANTS_VERSION -eq $TRUE \) -o \( $WANTS_CONFIG -eq $TRUE \) ] ; then
echo "Versioning..."
pushd ..
if [ -d .git ]
then
buildVer=`git rev-list --count HEAD`
else
buildVer=`hg summary | head -1 | cut -d " " -f 2 | cut -d : -f 1 | grep "[0-9]*"`
fi
export revision=${buildVer}
majorVer=`cat indra/newview/VIEWER_VERSION.txt | cut -d "." -f 1`
minorVer=`cat indra/newview/VIEWER_VERSION.txt | cut -d "." -f 2`
patchVer=`cat indra/newview/VIEWER_VERSION.txt | cut -d "." -f 3`
gitHash=`git describe --always --exclude '*'`
echo "Channel : ${CHANNEL}"
echo "Version : ${majorVer}.${minorVer}.${patchVer}.${buildVer} [${gitHash}]"
GITHASH=-DVIEWER_VERSION_GITHASH=\"${gitHash}\"
popd
fi
if [ $WANTS_CONFIG -eq $TRUE ] ; then
echo "Configuring $PLATFORM..."
if [ $WANTS_KDU -eq $TRUE ] ; then
KDU="-DUSE_KDU:BOOL=ON"
else
KDU="-DUSE_KDU:BOOL=OFF"
fi
if [ $WANTS_FMODSTUDIO -eq $TRUE ] ; then
FMODSTUDIO="-DFMODSTUDIO:BOOL=ON"
else
FMODSTUDIO="-DFMODSTUDIO:BOOL=OFF"
fi
if [ $WANTS_OPENAL -eq $TRUE ] ; then
OPENAL="-DOPENAL:BOOL=ON"
else
OPENAL="-DOPENAL:BOOL=OFF"
fi
if [ $WANTS_OPENSIM -eq $TRUE ] ; then
OPENSIM="-DOPENSIM:BOOL=ON"
else
OPENSIM="-DOPENSIM:BOOL=OFF"
fi
if [ $WANTS_SINGLEGRID -eq $TRUE ] ; then
SINGLEGRID="-DSINGLEGRID:BOOL=ON -DSINGLEGRID_URI:STRING=$SINGLEGRID_URI"
else
SINGLEGRID="-DSINGLEGRID:BOOL=OFF"
fi
if [ $WANTS_AVX -eq $TRUE ] ; then
AVX_OPTIMIZATION="-DUSE_AVX_OPTIMIZATION:BOOL=ON"
else
AVX_OPTIMIZATION="-DUSE_AVX_OPTIMIZATION:BOOL=OFF"
fi
if [ $WANTS_AVX2 -eq $TRUE ] ; then
AVX2_OPTIMIZATION="-DUSE_AVX2_OPTIMIZATION:BOOL=ON"
else
AVX2_OPTIMIZATION="-DUSE_AVX2_OPTIMIZATION:BOOL=OFF"
fi
if [ $WANTS_TESTBUILD -eq $TRUE ] ; then
TESTBUILD="-DTESTBUILD:BOOL=ON -DTESTBUILDPERIOD:STRING=$TESTBUILD_PERIOD"
else
TESTBUILD="-DTESTBUILD:BOOL=OFF"
fi
if [ $WANTS_PACKAGE -eq $TRUE ] ; then
PACKAGE="-DPACKAGE:BOOL=ON"
# Also delete easy-to-copy resource files, insuring that we properly refresh resoures from the source tree
if [ -d skins ] ; then
echo "Removing select previously packaged resources, they will refresh at build time"
for subdir in skins app_settings fs_resources ; do
for resourcedir in `$FIND . -type d -name $subdir` ; do
rm -rf $resourcedir ;
done
done
fi
else
PACKAGE="-DPACKAGE:BOOL=OFF"
fi
if [ $WANTS_CRASHREPORTING -eq $TRUE ] ; then
if [ $PLATFORM == "windows" ] ; then
BUILD_DIR=`cygpath -w $(pwd)`
else
BUILD_DIR=`pwd`
fi
# This name is consumed by indra/newview/CMakeLists.txt
if [ $PLATFORM == "linux" ] ; then
VIEWER_SYMBOL_FILE="${BUILD_DIR}/newview/firestorm-symbols-${PLATFORM}-${AUTOBUILD_ADDRSIZE}.tar.bz2"
else
VIEWER_SYMBOL_FILE="${BUILD_DIR}/newview/$BTYPE/firestorm-symbols-${PLATFORM}-${AUTOBUILD_ADDRSIZE}.tar.bz2"
fi
CRASH_REPORTING="-DRELEASE_CRASH_REPORTING:BOOL=ON"
else
CRASH_REPORTING="-DRELEASE_CRASH_REPORTING:BOOL=OFF"
fi
CHANNEL="-DVIEWER_CHANNEL:STRING=$CHANNEL"
#make sure log directory exists.
if [ ! -d "logs" ] ; then
echo "Creating logging dir `pwd`/logs"
mkdir -p "logs"
fi
if [ $PLATFORM == "darwin" ] ; then
TARGET="Xcode"
elif [ \( $PLATFORM == "linux" \) ] ; then
OPENAL="-DOPENAL:BOOL=ON"
if [ $WANTS_NINJA -eq $TRUE ] ; then
TARGET="Ninja"
else
TARGET="Unix Makefiles"
fi
if [ $WANTS_VSCODE -eq $TRUE ] ; then
VSCODE_FLAGS="-DCMAKE_EXPORT_COMPILE_COMMANDS=On"
ROOT_DIR=$(dirname $(dirname $(readlink -f $0)))
if [ -d ${ROOT_DIR}/vscode_template/ ]
then
test -d "${ROOT_DIR}/.vscode" || mkdir "${ROOT_DIR}/.vscode"
cp -n "${ROOT_DIR}/vscode_template/"* "${ROOT_DIR}/.vscode/"
fi
fi
elif [ \( $PLATFORM == "windows" \) ] ; then
TARGET="${AUTOBUILD_WIN_CMAKE_GEN}"
UNATTENDED="-DUNATTENDED=ON"
fi
cmake -G "$TARGET" ../indra $CHANNEL ${GITHASH} $FMODSTUDIO $OPENAL $KDU $OPENSIM $SINGLEGRID $AVX_OPTIMIZATION $AVX2_OPTIMIZATION $TESTBUILD $PACKAGE \
$UNATTENDED -DLL_TESTS:BOOL=OFF -DADDRESS_SIZE:STRING=$AUTOBUILD_ADDRSIZE -DCMAKE_BUILD_TYPE:STRING=$BTYPE \
$CRASH_REPORTING -DVIEWER_SYMBOL_FILE:STRING="${VIEWER_SYMBOL_FILE:-}" -DROOT_PROJECT_NAME:STRING=Firestorm $LL_ARGS_PASSTHRU ${VSCODE_FLAGS:-} | tee $LOG
if [ $PLATFORM == "windows" ] ; then
../indra/tools/vstool/VSTool.exe --solution Firestorm.sln --startup firestorm-bin --workingdir firestorm-bin "..\\..\\indra\\newview" --config $BTYPE
fi
fi
if [ $WANTS_BUILD -eq $TRUE ] ; then
echo "Building $PLATFORM..."
if [ $PLATFORM == "darwin" ] ; then
if [ $JOBS == "0" ] ; then
JOBS=""
else
JOBS="-jobs $JOBS"
fi
xcodebuild -configuration $BTYPE -project Firestorm.xcodeproj $JOBS 2>&1 | tee -a $LOG
elif [ $PLATFORM == "linux" ] ; then
if [ $JOBS == "0" ] ; then
JOBS=`cat /proc/cpuinfo | grep processor | wc -l`
fi
if [ $WANTS_NINJA -eq $TRUE ] ; then
ninja -j $JOBS | tee -a $LOG
else
make -j $JOBS | tee -a $LOG
fi
elif [ $PLATFORM == "windows" ] ; then
msbuild.exe Firestorm.sln /p:Configuration=${BTYPE} /flp:LogFile="logs\\FirestormBuild_win-${AUTOBUILD_ADDRSIZE}.log" \
/flp1:"errorsonly;LogFile=logs\\FirestormBuild_win-${AUTOBUILD_ADDRSIZE}.err" /p:Platform=${AUTOBUILD_WIN_VSPLATFORM} /t:Build /p:useenv=true \
/verbosity:normal /toolsversion:12.0 /p:"VCBuildAdditionalOptions= /incremental"
fi
fi
echo "Finished"