From a4c85c3ef297814f1fddd6cf41bcf46baef21fc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= Date: Thu, 11 May 2017 21:48:40 +0200 Subject: [PATCH] Add --bootstrap option If `configure` script is called with `--bootstrap` option, and proper instructions are added to build dep, it will be automatically downloaded & built under `vendor` folder. For example, to build a GIT revision of librd: ``` LIBRD_GIT_VERSION=73fae1cc0ca378669fa09bcda54b408397f80c18 function make_librd { if [[ -d "librd-$LIBRD_GIT_VERSION" && ! -d librd ]]; then mv "librd-$LIBRD_GIT_VERSION" librd fi cd librd make libs } ``` And in `checks` function: ``` ... mkl_meta_set librd bootstrap_url "https://github.com/eugpermar/librd/archive/$LIBRD_GIT_VERSION.zip" mkl_meta_set librd bootstrap_makefn make_librd mkl_meta_set librd bootstrap_cppflags "-I./vendor/librd" mkl_meta_set librd bootstrap_static_lib "vendor/librd/librd/librd.a" mkl_lib_check --static=-lrd \ "librd" "" fail CC "-lrd -lpthread -lrt" \ "#include void f() { rdlog(LOG_ERR, \"TEST\"); }" ... ``` Other configurations could use installation under local folder with --prefix or DESTDIR and include that one. --- modules/configure.base | 102 +++++++++++++++++++++++++++++++++++++- modules/configure.builtin | 1 + 2 files changed, 102 insertions(+), 1 deletion(-) diff --git a/modules/configure.base b/modules/configure.base index b17ca81..0fa3da3 100644 --- a/modules/configure.base +++ b/modules/configure.base @@ -1025,6 +1025,73 @@ function mkl_lib_check_static { } +# Uncompress program that accepts file $1 +function mkl_uncompress_pipe { + case "$1" in + *.tar.xz ) echo -n "tar xJp";; + *.tar.gz|*.tgz ) echo -n "tar xzp";; + *.tar.bz2 ) echo -n "tar xjp";; + *.zip ) echo -n "bsdtar -xf-";; + * ) ;; + esac +} + + +# Download & compile dependency on a dependency folder +# Arguments: +# config name +# define name +# action (fail|disable|cont) +function mkl_lib_bootstrap { + local dep_path="vendor/$1" + local bootstrap_url=$(mkl_meta_get $1 bootstrap_url) + if [[ ! -d $dep_path ]]; then + mkl_info "Downloading missing dep $1 from [$bootstrap_url]" + mkdir -p $dep_path + pushd $dep_path &> /dev/null + + local uncompress_pipe=$(mkl_uncompress_pipe "$bootstrap_url") + + local wget_output + if [[ "x$uncompress_pipe" == "x" ]]; then + wget_output=$(wget -q "$bootstrap_url") + else + wget_output=$(wget -q -O - "$bootstrap_url" | $uncompress_pipe) + fi + + local wget_ret=$? + if [[ $wget_ret != 0 ]]; then + mkl_check_failed "$1" "$2" "$3" "couldn't get sources: $wget_output" + return $wget_ret + fi + else + mkl_info "Using previously downloaded $1 from [$bootstrap_url]" + pushd $dep_path &> /dev/null + fi + + mkl_info "Creating dep $1 in [$dep_path]" + + if mkl_func_exists $(mkl_meta_get $1 bootstrap_makefn); then + local readonly CPPFLAGS_BAK="$(mkl_mkvar_get CPPFLAGS)" + mkl_mkvar_set CPPFLAGS CPPFLAGS "$CPPFLAGS_BAK $(mkl_meta_get $1 bootstrap_cppflags)" + + # filter vendor-specific libraries + local makefn_output=$(CPPFLAGS="" LIBS="" $(mkl_meta_get $1 bootstrap_makefn)) + local make_rc=$? + + if [[ $make_rc != 0 ]]; then + # Fail and restore CPPFLAGS + mkl_check_failed "$1" "$2" "$3" "couldn't make source: makefn_output" + mkl_mkvar_set CPPFLAGS CPPFLAGS "$CPPFLAGS_BAK" + return $make_rc + fi + fi + + popd &> /dev/null + return 0 +} + + # Checks that the specified lib is available through a number of methods. # compiler flags are automatically appended to "LIBS" mkvar on success. # @@ -1061,7 +1128,40 @@ function mkl_lib_check { is_static=1 fi - if ! mkl_compile_check "$1" "$2" "$3" "$4" "$libs" "$6"; then + local do_bootstrap=n + if ([[ "x$MKL_BOOTSTRAP" == "xy" ]] && mkl_meta_exists "$1" bootstrap_url) ; then + do_bootstrap=y + fi + + local action="$3" + if [[ "$action" == "fail" && "x$do_bootstrap" == "xy" ]]; then + # Continue for boostrap + action="cont" + fi + + if ! mkl_compile_check "$1" "$2" "$action" "$4" "$libs" "$6"; then + # Compile did not succeed. Try automatic dependency download + if [[ "x$do_bootstrap" == "xy" ]]; then + MKL_BOOTSTRAP=n # Avoid infinite recursion + local readonly WITH_STATIC_LINKING_BAK="$WITH_STATIC_LINKING" + if mkl_meta_exists $1 bootstrap_static_lib; then + WITH_STATIC_LINKING=y + eval "STATIC_LIB_${staticopt#--static=-l}"=$(mkl_meta_get $1 bootstrap_static_lib) + fi + + mkl_lib_bootstrap "$1" "$2" "$3" + mkl_lib_check $staticopt "$1" "$2" "$3" "$4" "$5" "$6" + local rc=$? + + WITH_STATIC_LINKING="$WITH_STATIC_LINKING_BAK" + MKL_BOOTSTRAP=y + + if [[ $rc != 0 ]]; then + # Boostrap also failed, nothing more to do + return $rc + fi + fi + return 1 fi diff --git a/modules/configure.builtin b/modules/configure.builtin index 546cbb2..ac0ebe6 100644 --- a/modules/configure.builtin +++ b/modules/configure.builtin @@ -38,6 +38,7 @@ mkl_option "Configure tool" "" "--reconfigure" "Rerun configure with same argume mkl_option "Configure tool" env:MKL_NO_DOWNLOAD "--no-download" "Disable downloads of required mklove modules" mkl_option "Configure tool" env:MKL_UPDATE_MODS "--update-modules" "Update modules from global repository" mkl_option "Configure tool" env:MKL_REPO_URL "--repo-url=URL_OR_PATH" "Override mklove modules repo URL" "$MKL_REPO_URL" +mkl_option "Configure tool" env:MKL_BOOTSTRAP "--bootstrap" "Get and compile dependencies" mkl_option "Configure tool" "" "--help" "Show configure usage"