Build Script Anatomy

From Second Life Wiki
Revision as of 14:59, 4 April 2011 by Draconis Neurocam (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Because Autobuild does not provide a direct mechanism to configure and build applications and libraries (that's just too big a problem for one tool to solve), we need to provide wrappers that Autobuild can use to perform these tasks for each platform. For Linden projects we have chosen to use shell for scripting builds as we can run these on both UNIX like platforms and Windows (using CYGWIN).

This article provides an annotated example of a build script used along with Autobuild to build a package. While some details obviously will change from library to library, many of the elements seen here are common to the majority of third party packages we build. You may see the original source for this page at Note that build scripts are conventionally named


Build scripts by default are run from the build directory not the directory of this script or the directory of the autobuild.xml configuration file. The first command in the script changes directories to the location of the build script for this library. <bash>

  1. !/bin/bash

cd "$(dirname "$0")"

  1. turn on verbose debugging output for parabuild logs.

set -x

  1. make errors fatal

set -e

ZLIB_VERSION="1.2.5" ZLIB_SOURCE_DIR="zlib-$ZLIB_VERSION" </bash> The Autobuild command should be passed as an environment variable, but we sanity check that. <bash> if [ -z "$AUTOBUILD" ] ; then


fi </bash> On Windows systems, the path contained in the AUTOBUILD environment variable is stored in DOS format. Cygwin isn't smart enough to understand DOS paths so we need to convert the path to a UNIX format with the cygpath command. <bash> if [ "$OSTYPE" = "cygwin" ] ; then

   export AUTOBUILD="$(cygpath -u $AUTOBUILD)"

fi </bash> The autobuild source_environment command returns a string with shell code. This code contains some useful functions that we will use later in the build process. <bash>

  1. load autobuild provided shell functions and variables

set +x eval "$("$AUTOBUILD" source_environment)" set -x </bash> Refer to Autobuild Shell Functions for more details. <bash> stage="$(pwd)/stage" pushd "$ZLIB_SOURCE_DIR" </bash> Now we get to the platform specific build commands. <bash>


</bash> The packagers of zlib included this batch file to build some assembly code. <bash>

           pushd contrib/masmx86

</bash> The packagers of zlib added a VisualStudio project to build this package on windows. We take advantage of this by using the build_sln function defined in the source environment to build the desired projects from the command line. <bash>

           build_sln "contrib/vstudio/vc10/zlibvc.sln" "Debug|Win32" "zlibstat"
           build_sln "contrib/vstudio/vc10/zlibvc.sln" "Release|Win32" "zlibstat"

</bash> The build product is output into the source directory, so we need to manually copy the libraries and headers into the autobuild build directory. Note how the debug and release versions of the library are copied into their respective lib/debug and lib/release directories. The headers are copied into include/zlib <bash>

           mkdir -p "$stage/lib/debug"
           mkdir -p "$stage/lib/release"
           cp "contrib/vstudio/vc10/x86/ZlibStatDebug/zlibstat.lib" \
           cp "contrib/vstudio/vc10/x86/ZlibStatRelease/zlibstat.lib" \
           mkdir -p "$stage/include/zlib"
           cp {zlib.h,zconf.h} "$stage/include/zlib"

</bash> Since Darwin is a UNIX variant, we can use the common configure and make commands. Note how the --prefix option is set to the build directory so the files get installed mostly where we want. <bash>

           ./configure --prefix="$stage"
           make install

</bash> We still need to move the header files into include/zlib. <bash>

           mkdir -p "$stage/include/zlib"
           mv "$stage/include/"*.h "$stage/include/zlib/"

</bash> Linux looks pretty much like Darwin. <bash>

           CFLAGS="-m32" CXXFLAGS="-m32" ./configure --prefix="$stage"
           make install
                       mkdir -p "$stage/include/zlib"
                       mv "$stage/include/"*.h "$stage/include/zlib/"

</bash> Finally we copy the license file into the LICENSES directory regardless of platform. <bash>

   mkdir -p "$stage/LICENSES"
   tail -n 31 README > "$stage/LICENSES/zlib.txt"


pass </bash>