[Mesa-dev] [PATCH v2 2/6] configure.ac: Add helper to add LLVM components/targets

Emil Velikov emil.l.velikov at gmail.com
Tue Oct 11 12:56:18 UTC 2016


On 11 October 2016 at 02:44, Tobias Droste <tdroste at gmx.de> wrote:
> This adds helper function to add components and/or targets anywhere
> i configure.ac.
> The first driver that calls "llvm_check_version_for()" adds the
> default components.
> This is done so that they only get added and checked for if there
> is a driver that actually needs them.
>
> WARNING: Still a broken build!!!
>
Earlier comment still applies.

Here all we need is to ensure that the functions are defined prior to
using them - which should be trivial.

> Signed-off-by: Tobias Droste <tdroste at gmx.de>
> ---
>  configure.ac | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++-------
>  1 file changed, 57 insertions(+), 7 deletions(-)
>
> diff --git a/configure.ac b/configure.ac
> index a2a7ed1..be802d7 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -929,6 +929,7 @@ if test "x$LLVM_CONFIG" != xno; then
>      LLVM_CXXFLAGS=`strip_unwanted_llvm_flags "$LLVM_CONFIG --cxxflags"`
>      LLVM_INCLUDEDIR=`$LLVM_CONFIG --includedir`
>      LLVM_LIBDIR=`$LLVM_CONFIG --libdir`
> +    LLVM_DEFAULT_COMPONENTS_ADDED="no"
>
>      AC_COMPUTE_INT([LLVM_VERSION_MAJOR], [LLVM_VERSION_MAJOR],
>          [#include "${LLVM_INCLUDEDIR}/llvm/Config/llvm-config.h"])
> @@ -952,12 +953,6 @@ if test "x$LLVM_CONFIG" != xno; then
>          AC_MSG_ERROR([LLVM $LLVM_REQUIRED_VERSION_MAJOR.$LLVM_REQUIRED_VERSION_MINOR or newer is required])
>      fi
>
> -    LLVM_COMPONENTS="engine bitwriter mcjit mcdisassembler"
> -
> -    if $LLVM_CONFIG --components | grep -q inteljitevents ; then
> -        LLVM_COMPONENTS="${LLVM_COMPONENTS} inteljitevents"
> -    fi
> -
>      if test "x$enable_opencl" = xyes; then
>          llvm_check_version_for "3" "6" "0" "opencl"
>
> @@ -993,9 +988,64 @@ AC_SUBST([LLVM_INCLUDEDIR])
>  AC_SUBST([LLVM_VERSION])
>
>  llvm_check_version_for() {
Name needs to be improved if we check and add default components.
Alternatively each user of this can call llvm_add_default_components.

> -    if test "${LLVM_VERSION_INT}${LLVM_VERSION_PATCH}" -lt "${1}0${2}${3}"; then
> +    if test "x$MESA_LLVM" = x0 || test "${LLVM_VERSION_INT}${LLVM_VERSION_PATCH}" -lt "${1}0${2}${3}"; then
>          AC_MSG_ERROR([LLVM $1.$2.$3 or newer is required for $4])
>      fi
> +
> +    if test "x$LLVM_DEFAULT_COMPONENTS_ADDED" = "xno"; then
> +        LLVM_DEFAULT_COMPONENTS_ADDED="yes"
> +        llvm_add_default_components $driver_name
llvm-config will handle any duplication, so we can drop this for the
times being and worry about it later. Be that at the end of the series
or some other time.

> +    fi
> +}
> +
> +llvm_add_default_components() {
> +    driver_name=$1
> +
> +    # Required default components
> +    llvm_add_component "engine" $driver_name
> +    llvm_add_component "bitwriter" $driver_name
> +    llvm_add_component "mcjit" $driver_name
> +    llvm_add_component "mcdisassembler" $driver_name
> +
> +    # Optional default components
> +    llvm_add_component_optional "inteljitevents" $driver_name
If we have a single user lets drop this function.

> +}
> +
> +llvm_add_component_optional() {
> +    new_llvm_component=$1
> +    driver_name=$2
> +
> +    if echo "$LLVM_COMPONENTS" | grep -iqw $new_llvm_component ; then
> +        # Component already added
> +        return
> +    fi
You don't need this check - llvm-config is smart enough.

> +
> +    if $LLVM_CONFIG --components | grep -iqw $new_llvm_component ; then
> +        LLVM_COMPONENTS="${LLVM_COMPONENTS} ${new_llvm_component}"
> +    fi
> +}
> +
> +llvm_add_component() {
> +    new_llvm_component=$1
> +    driver_name=$2
> +
> +    llvm_add_component_optional $new_llvm_component $driver_name
> +
> +    if echo "$LLVM_COMPONENTS" | grep -ivqw $new_llvm_component ; then
> +        # Component was not added
> +        AC_MSG_ERROR([LLVM component '$new_llvm_component' not enabled in your LLVM build. Required by $driver_name.])
> +    fi
> +}
> +
I'm leaning towards naming these
llvm_add_{required,optional}_component - they read more natural and
consistent.
An alternative solution for the helpers can be the following (don't
mind either way really).

add_optional()
    if $LLVM_CONFIG --components | grep -iqw $foo ; then
        LLVM_COMPONENTS="${LLVM_COMPONENTS} ${foo}"
    fi

add_required()
    if $LLVM_CONFIG --components | grep -iqw $foo ; then
        LLVM_COMPONENTS="${LLVM_COMPONENTS} ${foo}"
    else
        AC_MSG_ERROR([...])
    fi

> +llvm_add_target() {
> +    new_llvm_target=$1
> +    driver_name=$2
> +
> +    if $LLVM_CONFIG --targets-built | grep -iqw $new_llvm_target ; then
> +        llvm_add_component $new_llvm_target $fail_if_not_present $driver_name
Left over fail_if_not_present ?

-Emil


More information about the mesa-dev mailing list