#!/usr/bin/env bash

gccversion=$(gcc --version | head -n1)
cppversion=$(g++ -dM -E -x c++ /dev/null | grep -F __cplusplus | cut -d' ' -f3)
cmakeversion=$(cmake --version | head -n1)
clangversion=$(clang --version | head -n1)

cat <<EOF
Hello, this is the Sysdig builder container.

How to use.

    The default commands for the Sysdig builder image reports usage and environment info.
    * docker run sysdig/sysdig-builder
    * docker run sysdig/sysdig-builder usage

    It supports bash.
    * docker run -ti sysdig/sysdig-builder bash

    To build it needs:
    - The source directory in /source (ie., the directory containing the sysdig tree)

    Optionally, you can also bind-mount the build directory.
    So, you can execute it from the root directory as follows.

    * docker run -v $PWD/..:/source -v $PWD/build:/build sysdig/sysdig-builder cmake
    * docker run -v $PWD/..:/source -v $PWD/build:/build sysdig/sysdig-builder [<cmake-target-x>, ..., <cmake-target-y>]

    Eg.,
    * docker run -v $PWD/..:/source -v $PWD/build:/build sysdig/sysdig-builder tests
    * docker run -v $PWD/..:/source -v $PWD/build:/build sysdig/sysdig-builder install

How to build.

    * cd docker/builder && DOCKER_BUILDKIT=1 docker build -t sysdig/sysdig-builder .

    In case you want to customise the builder at build time the following build arguments are provided:
    - BUILD_TYPE                whether you want a "release" or "debug" build (defaults to "release").
    - BUILD_DRIVER              whether to build the driver or not (defaults to "OFF")
    - BUILD_BPF                 whether to build the BPF driver or not (defaults to "OFF")
    - BUILD_WARNINGS_AS_ERRORS  whether to intend warnings as errors or not (defaults to "ON")
    - MAKE_JOBS                 the number of jobs to use during make (defaults to "4")
    - BUILD_VERSION             the version to label the build (built from git index in case it is missing)

    It is possible to change these at runtime (in the container) since environment variables with the same names are provided, too.

Environment.

    * ${gccversion}
    * cplusplus ${cppversion}
    * ${cmakeversion}
    * ${clangversion}
EOF
