tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nspr.sh (2549B)


      1 #!/usr/bin/env bash
      2 # This script builds NSPR for NSS.
      3 #
      4 # This build system is still under development.  It does not yet support all
      5 # the features or platforms that the regular NSPR build supports.
      6 
      7 # variables
      8 nspr_cflags=
      9 nspr_cxxflags=
     10 nspr_ldflags=
     11 
     12 # Try to avoid bmake on OS X and BSD systems
     13 if hash gmake 2>/dev/null; then
     14    make() { command gmake "$@"; }
     15 fi
     16 
     17 nspr_set_flags()
     18 {
     19    nspr_cflags="$CFLAGS $@"
     20    nspr_cxxflags="$CXXFLAGS $@"
     21    nspr_ldflags="$LDFLAGS $@"
     22 }
     23 
     24 nspr_build()
     25 {
     26    local nspr_dir="$cwd"/../nspr/$target
     27    mkdir -p "$nspr_dir"
     28 
     29    # These NSPR options are directory-specific, so they don't need to be
     30    # included in nspr_opt and changing them doesn't force a rebuild of NSPR.
     31    extra_params=(--prefix="$dist_dir"/$target)
     32    if [ "$opt_build" = 1 ]; then
     33        extra_params+=(--disable-debug --enable-optimize)
     34    fi
     35    if [ "$target_arch" = "x64" ]; then
     36        extra_params+=(--enable-64bit)
     37    fi
     38 
     39    if [[ -n "$CC" && -n "$build_tools_cc" && "$CC" != "$build_tools_cc" ]]; then
     40        # If build_tools_cc is specified, we expect CC to include a target
     41        # triple e.g. "CC=powerpc-linux-gnu-gcc". NSPR, confusingly, uses
     42        # "HOST_CC" to build tools like nsinstall that are called during the
     43        # build process and it uses the parameter "--host" to specify the
     44        # target triple for the build.
     45        HOST_CC="$build_tools_cc"
     46        extra_params+=(--host="${CC%-*}")
     47    fi
     48 
     49    echo "NSPR [1/5] configure ..."
     50    pushd "$nspr_dir" >/dev/null
     51 
     52    CFLAGS="$nspr_cflags" CXXFLAGS="$nspr_cxxflags" \
     53          LDFLAGS="$nspr_ldflags" HOST_CC="$HOST_CC" CC="$CC" CXX="$CCC" \
     54          run_verbose ../configure "${extra_params[@]}" "$@"
     55    popd >/dev/null
     56    echo "NSPR [2/5] make ..."
     57    run_verbose make -C "$nspr_dir"
     58 
     59    if [ "$build_nspr_tests" = 1 ]; then
     60      echo "NSPR [3/5] build tests ..."
     61      run_verbose make -C "$nspr_dir/pr/tests"
     62    else
     63        echo "NSPR [3/5] NOT building tests"
     64    fi
     65 
     66    if [[ "$build_nspr_tests" = 1 && "$run_nspr_tests" = 1 ]]; then
     67      echo "NSPR [4/5] run tests ..."
     68      run_verbose make -C "$nspr_dir/pr/tests" runtests
     69    else
     70        echo "NSPR [4/5] NOT running tests"
     71    fi
     72 
     73    echo "NSPR [5/5] install ..."
     74    run_verbose make -C "$nspr_dir" install
     75 }
     76 
     77 nspr_clean()
     78 {
     79    rm -rf "$cwd"/../nspr/$target
     80 }
     81 
     82 set_nspr_path()
     83 {
     84    local include=$(echo "$1" | cut -d: -f1)
     85    local lib=$(echo "$1" | cut -d: -f2)
     86    gyp_params+=(-Dnspr_include_dir="$include")
     87    gyp_params+=(-Dnspr_lib_dir="$lib")
     88 }