Difference between revisions of "Build Script Anatomy"

From Second Life Wiki
Jump to navigation Jump to search
(Created page with "<pre> #!/bin/bash </pre> Build scripts by default are run from the build directory. This command will change directories to the location of the build script which is useful for …")
 
Line 33: Line 33:
eval "$("$AUTOBUILD" source_environment)"
eval "$("$AUTOBUILD" source_environment)"
set -x
set -x
 
</pre>
Now we get to the platform specific build commands.
<pre>
stage="$(pwd)/stage"
stage="$(pwd)/stage"
pushd "$ZLIB_SOURCE_DIR"
pushd "$ZLIB_SOURCE_DIR"
Line 39: Line 41:
         "windows")
         "windows")
             load_vsvars
             load_vsvars
           
</pre>
The packagers of '''zlib''' included this batch file to build some assembly  code.
<pre>           
             pushd contrib/masmx86
             pushd contrib/masmx86
                 ./bld_ml32.bat
                 ./bld_ml32.bat
             popd
             popd
           
</pre>
The packagers of '''zlib''' added a VisualStudio project to build this package on windows.  We take advantage of this by using the ''biulld_sln'' function defined in the source environment to build the desired projects from the command line.
<pre>           
             build_sln "contrib/vstudio/vc10/zlibvc.sln" "Debug|Win32" "zlibstat"
             build_sln "contrib/vstudio/vc10/zlibvc.sln" "Debug|Win32" "zlibstat"
             build_sln "contrib/vstudio/vc10/zlibvc.sln" "Release|Win32" "zlibstat"
             build_sln "contrib/vstudio/vc10/zlibvc.sln" "Release|Win32" "zlibstat"
</pre>
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''
<pre>
             mkdir -p "$stage/lib/debug"
             mkdir -p "$stage/lib/debug"
             mkdir -p "$stage/lib/release"
             mkdir -p "$stage/lib/release"
Line 56: Line 65:
         ;;
         ;;
         "darwin")
         "darwin")
</pre>
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.  We still need to move the header files into ''include/zlib''.
<pre>
             ./configure --prefix="$stage"
             ./configure --prefix="$stage"
             make
             make
Line 63: Line 75:
         ;;
         ;;
         "linux")
         "linux")
</pre>
Linux looks pretty much like Darwin.
<pre>
             CFLAGS="-m32" CXXFLAGS="-m32" ./configure --prefix="$stage"
             CFLAGS="-m32" CXXFLAGS="-m32" ./configure --prefix="$stage"
             make
             make
Line 70: Line 85:
         ;;
         ;;
     esac
     esac
</pre>
Finally we copy the license file into the '''LICENSES''' directory regardless of platform.
<pre>
     mkdir -p "$stage/LICENSES"
     mkdir -p "$stage/LICENSES"
     tail -n 31 README > "$stage/LICENSES/zlib.txt"
     tail -n 31 README > "$stage/LICENSES/zlib.txt"

Revision as of 17:44, 15 February 2011

#!/bin/bash

Build scripts by default are run from the build directory. This command will change directories to the location of the build script which is useful for this library.

cd "$(dirname "$0")"
# turn on verbose debugging output for parabuild logs.
set -x
# make errors fatal
set -e

ZLIB_VERSION="1.2.5"
ZLIB_SOURCE_DIR="zlib-$ZLIB_VERSION"

The autobuild command should be passed as an environment variable.

if [ -z "$AUTOBUILD" ] ; then 
    fail
fi

On windows systems, the path contained in the AUTOBUILD environment variable

if [ "$OSTYPE" = "cygwin" ] ; then
    export AUTOBUILD="$(cygpath -u $AUTOBUILD)"
fi

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.

# load autbuild provided shell functions and variables
set +x
eval "$("$AUTOBUILD" source_environment)"
set -x

Now we get to the platform specific build commands.

stage="$(pwd)/stage"
pushd "$ZLIB_SOURCE_DIR"
    case "$AUTOBUILD_PLATFORM" in
        "windows")
            load_vsvars

The packagers of zlib included this batch file to build some assembly code.

            
            pushd contrib/masmx86
                ./bld_ml32.bat
            popd

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

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

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

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

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. We still need to move the header files into include/zlib.

            ./configure --prefix="$stage"
            make
            make install
                        mkdir -p "$stage/include/zlib"
                        mv "$stage/include/"*.h "$stage/include/zlib/"
        ;;
        "linux")

Linux looks pretty much like Darwin.

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

Finally we copy the license file into the LICENSES directory regardless of platform.

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

pass