build.sh
author Franziskus Kiefer <franziskuskiefer@gmail.com>
Thu, 27 Oct 2016 15:07:07 +0200
changeset 12779 b11a63cc651e65d6452bcf679b4fec8c79e49c05
parent 12778 4bbf5203751e6afc2b45284f8390bc34ebd52a7f
child 12782 4d2e32584eb5f112d679ac4e8da363ca9472e62f
permissions -rwxr-xr-x
Bug 1118245 - clang-format on lib/pki and lib/pkcs7, r=ttaubert try: -b do -p none -t clang-format

#!/bin/bash
# This script builds NSS with gyp and ninja.
#
# This build system is still under development.  It does not yet support all
# the features or platforms that NSS supports.

set -e

# Usage info
show_help() {
cat << EOF

Usage: ${0##*/} [-hcgv] [-j <n>] [--test] [--fuzz] [--scan-build[=output]]

This script builds NSS with gyp and ninja.

This build system is still under development.  It does not yet support all
the features or platforms that NSS supports.

NSS build tool options:

    -h            display this help and exit
    -c            clean before build
    -g            force a rebuild of gyp (and NSPR, because why not)
    -j <n>        run at most <n> concurrent jobs
    -v            verbose build
    --test        ignore map files and export everything we have
    --fuzz        enable fuzzing mode. this always enables test builds
    --scan-build  run the build with scan-build (scan-build has to be in the path)
                  --scan-build=/out/path sets the output path for scan-build
EOF
}

CWD=$(cd $(dirname $0); pwd -P)
OBJ_DIR=$(make -s -C "$CWD" platform)
DIST_DIR="$CWD/../dist/$OBJ_DIR"

if [ -n "$CCC" ] && [ -z "$CXX" ]; then
    export CXX="$CCC"
fi

# parse command line arguments
GYP_PARAMS=()
NINJA_PARAMS=()
SCANBUILD=()
while [ $# -gt 0 ]; do
    case $1 in
        -c) CLEAN=1 ;;
        -g) REBUILD_GYP=1 ;;
        -j) NINJA_PARAMS+=(-j "$2"); shift ;;
        -v) NINJA_PARAMS+=(-v) ;;
        --test) GYP_PARAMS+=(-Dtest_build=1) ;;
        --fuzz) GYP_PARAMS+=(-Dtest_build=1 -Dfuzz=1) ;;
        --scan-build) SCANBUILD=(scan-build) ;;
        --scan-build=?*) SCANBUILD=(scan-build -o "${1#*=}") ;;
        *)
            show_help
            exit
            ;;
    esac
    shift
done

# -c = clean first
if [ "$CLEAN" = 1 ]; then
    rm -rf "$CWD/out"
fi

if [ "$BUILD_OPT" = "1" ]; then
    TARGET=Release
else
    TARGET=Debug
fi
if [ "$USE_64" == "1" ]; then
    TARGET="${TARGET}_x64"
else
    GYP_PARAMS+=(-Dtarget_arch=ia32)
fi
TARGET_DIR="$CWD/out/$TARGET"

# figure out scan-build string
if [ "${#SCANBUILD[@]}" -gt 0 ]; then
    if [ -n "$CC" ]; then
       SCANBUILD+=(--use-cc="$CC")
    fi
    if [ -n "$CCC" ]; then
       SCANBUILD+=(--use-c++="$CCC")
    fi
 fi

# These steps can take a while, so don't overdo them.
# Force a redo with -g.
if [ "$REBUILD_GYP" = 1 -o ! -d "$TARGET_DIR" ]; then
    # Build NSPR.
    make -C "$CWD" NSS_GYP=1 install_nspr

    # Run gyp.
    PKG_CONFIG_PATH="$CWD/../nspr/$OBJ_DIR/config" \
        "${SCANBUILD[@]}" gyp -f ninja "${GYP_PARAMS[@]}" --depth="$CWD" \
          --generator-output="." "$CWD/nss.gyp"
fi

# Run ninja.
if which ninja >/dev/null 2>&1; then
    NINJA=(ninja)
elif which ninja-build >/dev/null 2>&1; then
    NINJA=(ninja-build)
else
    echo "Please install ninja" 1>&2
    exit 1
fi
"${SCANBUILD[@]}" $NINJA -C "$TARGET_DIR" "${NINJA_PARAMS[@]}"