From 93d45f7e7e937020c796781705516a4b62e6589a Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Mon, 29 Oct 2018 12:11:05 +0900 Subject: gpgrt-config: Better architecture independent support. * configure.ac: Don't generate gpgrt-config. * src/gpgrt-config: Rename from gpgrt-config.in. (--prefix, --exec-prefix, --libdir): Use --libdir to determine PKG_CONFIG_LIBDIR. * src/Makefile.am (EXTRA_DIST): Remove gpgrt-config.in. * src/gpg-error-config-test.sh: Fix for path to gpgrt-config. * src/gpg-error.m4: Provide --prefix, --exec-prefix, --libdir option from configure. Don't use CC because we have --libdir. Bump version date. * src/gpgrt.m4: Likewise. -- Considering multilib support as well as multiarch support, it is better to provide the information for PKG_CONFIG_LIBDIR by --libdir directly, instead of CC. Difficulty is that configure allows variable reference like: --libdir='${exec_prefix}/i386-linux' So, it should also support --prefix and --exec_prefix options. Signed-off-by: NIIBE Yutaka --- configure.ac | 12 - src/Makefile.am | 2 +- src/gpg-error-config-test.sh | 26 +- src/gpg-error.m4 | 38 +-- src/gpgrt-config | 643 +++++++++++++++++++++++++++++++++++++++++++ src/gpgrt-config.in | 628 ------------------------------------------ src/gpgrt.m4 | 17 +- 7 files changed, 690 insertions(+), 676 deletions(-) create mode 100755 src/gpgrt-config delete mode 100644 src/gpgrt-config.in diff --git a/configure.ac b/configure.ac index 81b72f0..34ea775 100644 --- a/configure.ac +++ b/configure.ac @@ -651,17 +651,6 @@ AC_ARG_ENABLE([tests], AC_HELP_STRING([--disable-tests], build_tests=$enableval, build_tests=yes) AM_CONDITIONAL([BUILD_TESTS], [test "x$build_tests" != xno]) -case "$libdir" in - */*-*-*) - # Looks like it's multiarch, then, - # let the script detect host architecture at runtime - pkg_config_libdir=auto - ;; - *) - pkg_config_libdir=$libdir/pkgconfig - ;; -esac -AC_SUBST(pkg_config_libdir) # # Substitution # @@ -672,7 +661,6 @@ AC_CONFIG_FILES([lang/Makefile lang/cl/Makefile lang/cl/gpg-error.asd]) AC_CONFIG_FILES([src/versioninfo.rc src/gpg-error.w32-manifest]) AC_CONFIG_FILES([src/gpg-error.pc]) AC_CONFIG_FILES([src/gpg-error-config-old:src/gpg-error-config.in], [chmod +x src/gpg-error-config-old]) -AC_CONFIG_FILES([src/gpgrt-config], [chmod +x src/gpgrt-config]) AC_OUTPUT diff --git a/src/Makefile.am b/src/Makefile.am index 6df2d6c..280a673 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -98,7 +98,7 @@ EXTRA_DIST = mkstrtable.awk err-sources.h.in err-codes.h.in \ err-sources.h err-codes.h gpg-error-config.in gpg-error.m4 gpgrt.m4 \ gpg-error.vers gpg-error.def.in \ versioninfo.rc.in gpg-error.w32-manifest.in \ - gpgrt-config.in gpg-error-config-test.sh gpg-error.pc.in \ + gpg-error-config-test.sh gpg-error.pc.in \ $(lock_obj_pub) BUILT_SOURCES = $(srcdir)/err-sources.h $(srcdir)/err-codes.h \ diff --git a/src/gpg-error-config-test.sh b/src/gpg-error-config-test.sh index 2d8b94b..7125e10 100755 --- a/src/gpg-error-config-test.sh +++ b/src/gpg-error-config-test.sh @@ -1,5 +1,7 @@ #!/bin/sh +srcdir=${0%/*} + PKG_CONFIG_PATH="." export PKG_CONFIG_PATH @@ -32,54 +34,54 @@ failure () { rm -f gpg-error-config-test.log OUTPUT_OLD=$(echo $($PKG_CONFIG_CMD --libs)) -OUTPUT_NEW=$(./gpgrt-config --libs) +OUTPUT_NEW=$($srcdir/gpgrt-config --libs) [ "$OUTPUT_OLD" = "$OUTPUT_NEW" ] || failure --libs OUTPUT_OLD=$(echo $($PKG_CONFIG_CMD --cflags)) -OUTPUT_NEW=$(./gpgrt-config --cflags) +OUTPUT_NEW=$($srcdir/gpgrt-config --cflags) [ "$OUTPUT_OLD" = "$OUTPUT_NEW" ] || failure --cflags OUTPUT_OLD=$(echo $($PKG_CONFIG_CMD --cflags --libs)) -OUTPUT_NEW=$(./gpgrt-config --cflags --libs) +OUTPUT_NEW=$($srcdir/gpgrt-config --cflags --libs) [ "$OUTPUT_OLD" = "$OUTPUT_NEW" ] || failure --cflags --libs if [ "$PKG_CONFIG_CMD" = ./gpg-error-config-old ]; then OUTPUT_OLD=$(echo $($PKG_CONFIG_CMD --version)) - OUTPUT_NEW=$(./gpgrt-config --version) + OUTPUT_NEW=$($srcdir/gpgrt-config --version) [ "$OUTPUT_OLD" = "$OUTPUT_NEW" ] || failure --version OUTPUT_OLD=$(echo $($PKG_CONFIG_CMD --mt --libs)) - OUTPUT_NEW=$(./gpgrt-config --mt --libs) + OUTPUT_NEW=$($srcdir/gpgrt-config --mt --libs) [ "$OUTPUT_OLD" = "$OUTPUT_NEW" ] || failure --mt --libs OUTPUT_OLD=$(echo $($PKG_CONFIG_CMD --mt --cflags)) - OUTPUT_NEW=$(./gpgrt-config --mt --cflags) + OUTPUT_NEW=$($srcdir/gpgrt-config --mt --cflags) [ "$OUTPUT_OLD" = "$OUTPUT_NEW" ] || failure --mt --cflags OUTPUT_OLD=$(echo $($PKG_CONFIG_CMD --cflags --libs)) - OUTPUT_NEW=$(./gpgrt-config --cflags --libs) + OUTPUT_NEW=$($srcdir/gpgrt-config --cflags --libs) [ "$OUTPUT_OLD" = "$OUTPUT_NEW" ] || failure --cflags --libs OUTPUT_OLD=$(echo $($PKG_CONFIG_CMD --mt --cflags --libs)) - OUTPUT_NEW=$(./gpgrt-config --mt --cflags --libs) + OUTPUT_NEW=$($srcdir/gpgrt-config --mt --cflags --libs) [ "$OUTPUT_OLD" = "$OUTPUT_NEW" ] || failure --mt --cflags --libs OUTPUT_OLD=$(echo $($PKG_CONFIG_CMD --variable=mtcflags)) - OUTPUT_NEW=$(./gpgrt-config --variable=mtcflags) + OUTPUT_NEW=$($srcdir/gpgrt-config --variable=mtcflags) [ "$OUTPUT_OLD" = "$OUTPUT_NEW" ] || failure --variable=mtcflags OUTPUT_OLD=$(echo $($PKG_CONFIG_CMD --variable=mtlibs)) - OUTPUT_NEW=$(./gpgrt-config --variable=mtlibs) + OUTPUT_NEW=$($srcdir/gpgrt-config --variable=mtlibs) [ "$OUTPUT_OLD" = "$OUTPUT_NEW" ] || failure --variable=mtlibs OUTPUT_OLD=$(echo $($PKG_CONFIG_CMD --variable=host)) - OUTPUT_NEW=$(./gpgrt-config --variable=host) + OUTPUT_NEW=$($srcdir/gpgrt-config --variable=host) [ "$OUTPUT_OLD" = "$OUTPUT_NEW" ] || failure --variable=host fi if [ -n "$test_failed" ]; then OUTPUT_OLD=$($PKG_CONFIG_CMD --version) - OUTPUT_NEW=$(./gpgrt-config --version) + OUTPUT_NEW=$($srcdir/gpgrt-config --version) failure --version exit 99 diff --git a/src/gpg-error.m4 b/src/gpg-error.m4 index 70dc501..0964a26 100644 --- a/src/gpg-error.m4 +++ b/src/gpg-error.m4 @@ -9,7 +9,7 @@ # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # -# Last-changed: 2018-10-26 +# Last-changed: 2018-10-29 dnl AM_PATH_GPG_ERROR([MINIMUM-VERSION, @@ -67,13 +67,16 @@ AC_DEFUN([AM_PATH_GPG_ERROR], use_gpgrt_config="" if test "$GPG_ERROR_CONFIG" = "no"; then AC_PATH_PROG(GPGRT_CONFIG, gpgrt-config, no) - if CC=$CC $GPGRT_CONFIG gpg-error >/dev/null 2>&1; then - GPG_ERROR_CONFIG="$GPGRT_CONFIG gpg-error" - use_gpgrt_config=yes - gpg_error_config_version=`CC=$CC $GPG_ERROR_CONFIG --modversion` + if test "$GPGRT_CONFIG" != "no"; then + GPGRT_CONFIG="$GPGRT_CONFIG --prefix=$prefix --exec-prefix=$exec_prefix --libdir=$libdir" + if $GPGRT_CONFIG gpg-error >/dev/null 2>&1; then + GPG_ERROR_CONFIG="$GPGRT_CONFIG gpg-error" + use_gpgrt_config=yes + gpg_error_config_version=`$GPG_ERROR_CONFIG --modversion` + fi fi else - gpg_error_config_version=`CC=$CC $GPG_ERROR_CONFIG --version` + gpg_error_config_version=`$GPG_ERROR_CONFIG --version` fi if test "$GPG_ERROR_CONFIG" != "no"; then req_major=`echo $min_gpg_error_version | \ @@ -96,30 +99,33 @@ AC_DEFUN([AM_PATH_GPG_ERROR], if test -z "$GPGRT_CONFIG"; then if test "$major" -gt 1 -o "$major" -eq 1 -a "$minor" -ge 33; then AC_PATH_PROG(GPGRT_CONFIG, gpgrt-config, no) - GPG_ERROR_CONFIG="$GPGRT_CONFIG gpg-error" - use_gpgrt_config=yes + if test "$GPGRT_CONFIG" != "no"; then + GPGRT_CONFIG="$GPGRT_CONFIG --prefix=$prefix --exec-prefix=$exec_prefix --libdir=$libdir" + GPG_ERROR_CONFIG="$GPGRT_CONFIG gpg-error" + use_gpgrt_config=yes + fi fi fi fi AC_MSG_CHECKING(for GPG Error - version >= $min_gpg_error_version) if test $ok = yes; then - GPG_ERROR_CFLAGS=`CC=$CC $GPG_ERROR_CONFIG --cflags` - GPG_ERROR_LIBS=`CC=$CC $GPG_ERROR_CONFIG --libs` + GPG_ERROR_CFLAGS=`$GPG_ERROR_CONFIG --cflags` + GPG_ERROR_LIBS=`$GPG_ERROR_CONFIG --libs` if test -z "$use_gpgrt_config"; then - GPG_ERROR_MT_CFLAGS=`CC=$CC $GPG_ERROR_CONFIG $gpg_error_config_args --mt --cflags 2>/dev/null` - GPG_ERROR_MT_LIBS=`CC=$CC $GPG_ERROR_CONFIG $gpg_error_config_args --mt --libs 2>/dev/null` + GPG_ERROR_MT_CFLAGS=`$GPG_ERROR_CONFIG --mt --cflags 2>/dev/null` + GPG_ERROR_MT_LIBS=`$GPG_ERROR_CONFIG --mt --libs 2>/dev/null` else - GPG_ERROR_MT_CFLAGS=`CC=$CC $GPG_ERROR_CONFIG --variable=mtcflags 2>/dev/null` + GPG_ERROR_MT_CFLAGS=`$GPG_ERROR_CONFIG --variable=mtcflags 2>/dev/null` GPG_ERROR_MT_CFLAGS="$GPG_ERROR_CFLAGS${GPG_ERROR_CFLAGS:+ }$GPG_ERROR_MT_CFLAGS" - GPG_ERROR_MT_LIBS=`CC=$CC $GPG_ERROR_CONFIG --variable=mtlibs 2>/dev/null` + GPG_ERROR_MT_LIBS=`$GPG_ERROR_CONFIG --variable=mtlibs 2>/dev/null` GPG_ERROR_MT_LIBS="$GPG_ERROR_LIBS${GPG_ERROR_LIBS:+ }$GPG_ERROR_MT_LIBS" fi AC_MSG_RESULT([yes ($gpg_error_config_version)]) ifelse([$2], , :, [$2]) if test -z "$use_gpgrt_config"; then - gpg_error_config_host=`CC=$CC $GPG_ERROR_CONFIG --host 2>/dev/null || echo none` + gpg_error_config_host=`$GPG_ERROR_CONFIG --host 2>/dev/null || echo none` else - gpg_error_config_host=`CC=$CC $GPG_ERROR_CONFIG --variable=host 2>/dev/null || echo none` + gpg_error_config_host=`$GPG_ERROR_CONFIG --variable=host 2>/dev/null || echo none` fi if test x"$gpg_error_config_host" != xnone ; then if test x"$gpg_error_config_host" != x"$host" ; then diff --git a/src/gpgrt-config b/src/gpgrt-config new file mode 100755 index 0000000..1524677 --- /dev/null +++ b/src/gpgrt-config @@ -0,0 +1,643 @@ +#!/bin/sh +# Copyright (C) 2018 g10 Code GmbH +# +# This file is free software; as a special exception the author gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. +# +# This file is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# SPDX-License-Identifier: FSFULLR + +#### start of functions for this script + +# +# Bourne shell functions for config file in pkg-config style, so that +# we can share such a config file between pkg-config and script +# + +# +# get_var: Get the variable value of NAME +# +# Variables are recorded in the shell variables named "VAR_" +# +get_var () { + ___name=$1 + + eval echo \$VAR_$___name +} + +# +# get_attr: Get the attribute value of KEY +# +# Attributes are recorded in the shell variables named "ATTR_" +# +get_attr () { + ___name=$1 + + eval echo \$ATTR_$___name +} + +# Remove ${varname} part in the beginning of a string. +remove_var_expr () { + ___varname=$1 + shift + + expr "$*" : "\${$___varname}\\(.*\\)" +} + +# Given a string, substitute variables. +substitute_vars () { + __string="$1" + __varname="" + __result="" + + while [ -n "$__string" ]; do + case "$__string" in + \$\$*) + __result="$__result\$" + __string="${__string#\$\$}" + ;; + \${*}*) + __varname="${__string#\$\{}" + __varname="${__varname%%\}*}" + __result="$__result$(get_var $__varname)" + __string=$(remove_var_expr $__varname $__string) + ;; + *) + __result="$__result$(printf %c "$__string")" + __string="${__string#$(printf %c "$__string")}" + ;; + esac + done + + echo "$__result" +} + +# +# Read a config from stdin +# +# Variables: +# For VAR=VALUE, value is stored in the shell variable VAR_*. +# +# Attributes: +# For KEY: VALUE, value is stored in the shell variable ATTR_*. +# +read_config_from_stdin () { + _filename=$1 + _line="" + _varname="" + _value="" + _key="" + _reading_attrs="" + + while read _line; do + if [ -z "$_line" ]; then + _reading_attrs=yes + continue + elif [ -z "$_reading_attrs" ]; then + case "$_line" in + *=*) + _varname="${_line%%=*}" + _value="${_line#*=}" + VAR_list="$VAR_list${VAR_list:+ }VAR_$_varname" + read VAR_$_varname <&2 + exit 1 + ;; + esac + fi + done +} + + +find_file_in_path () { + _f=$1 + _p=$2 + _saved_IFS="$IFS" + _arg="" + IFS=":" # On Windows it should be ";"??? + + for _arg in $_p; do + if [ -r $_arg/$_f ]; then + RESULT="$_arg/$_f" + IFS="$_saved_IFS" + return 0 + fi + done + IFS="$_saved_IFS" + RESULT="" + return 1 +} + +read_config_file () { + if ! find_file_in_path $1.pc $2; then + if [ -z "$want_exists" ]; then + echo "Can't find $1.pc" 1>&2 + fi + exit 1 + fi + read_config_from_stdin $RESULT < $RESULT +} + +cleanup_vars_attrs () { + eval unset $VAR_list VAR_list + eval unset $ATTR_list ATTR_list +} + +not_listed_yet () { + ___m=$1 + ___arg="" + shift + + for ___arg; do + if [ $___m = $___arg ]; then + return 1 + fi + done + + return 0 +} + +list_only_once () { + __result="" + __arg="" + + for __arg; do + if not_listed_yet $__arg $__result; then + __result="$__result${__result:+ }$__arg" + fi + done + + echo $__result +} + +list_only_once_for_libs () { + __result="" + __rev_list="" + __arg="" + + # Scan the list and eliminate duplicates for non-"-lxxx" + # the resulted list is in reverse order + for __arg; do + case "$__arg" in + -l*) + # As-is + __rev_list="$__arg${__rev_list:+ }$__rev_list" + ;; + *) + if not_listed_yet $__arg $__rev_list; then + __rev_list="$__arg${__rev_list:+ }$__rev_list" + fi + ;; + esac + done + + # Scan again + for __arg in $__rev_list; do + case "$__arg" in + -l*) + if not_listed_yet $__arg $__result; then + __result="$__arg${__result:+ }$__result" + fi + ;; + *) + # As-is + __result="$__arg${__result:+ }$__result" + ;; + esac + done + + echo $__result +} + +arg1_is_same () { + [ "$1" = "=" -o "$1" = ">=" -o "$1" = "<=" ] +} + +arg1_is_less () { + [ "$1" = "!=" -o "$1" = "<" -o "$1" = "<=" ] +} + +arg1_is_great () { + [ "$1" = "!=" -o "$1" = ">" -o "$1" = ">=" ] +} + +# +# Evaluate comparison between versions in RPM way +# +eval_compare_version () { + ___str1="$1" + ___cmp="$2" + ___str2="$3" + ___char1="" + ___char2="" + ___chunk1="" + ___chunk2="" + + while [ -n "$___str1" -a -n "$___str2" ]; do + # Trim anything that's not alnum or tilde from the front + ___str1="$(expr "$___str1" : '[^0-9A-Za-z~]*\(.*\)')" + ___str2="$(expr "$___str2" : '[^0-9A-Za-z~]*\(.*\)')" + + # Get the first character + ___char1=${___str1%${___str1#?}} + ___char2=${___str2%${___str2#?}} + + if [ "$___char1" = ~ -o "$___char2" = ~ ]; then + if [ "$___char1" != ~ ]; then + arg1_is_great $___cmp + return + fi + if [ "$___char2" != ~ ]; then + arg1_is_less $___cmp + return + fi + ___str1=${___str1#~} + ___str2=${___str2#~} + continue + fi + + if [ -z "$___char1" -o -z "$___char2" ]; then + break + fi + + case "$___char1$___char2" in + [0-9][A-Za-z]) + arg1_is_great $___cmp + return + ;; + [A-Za-z][0-9]) + arg1_is_less $___cmp + return + ;; + [0-9][0-9]) + ___chunk1="$(expr "$___str1" : '\([0-9]*\)')" + ___chunk2="$(expr "$___str2" : '\([0-9]*\)')" + ;; + [A-Za-z][A-Za-z]) + ___chunk1="$(expr "$___str1" : '\([A-Za-z]*\)')" + ___chunk2="$(expr "$___str2" : '\([A-Za-z]*\)')" + ;; + esac + + # Compare chunks numerically if digits, or lexicographically + if expr "$___chunk1" "!=" "$___chunk2" >/dev/null; then + if expr "$___chunk1" ">" "$___chunk2" >/dev/null; then + arg1_is_great $___cmp + return + else + arg1_is_less $___cmp + return + fi + fi + + # Remove the chunk + ___str1="${___str1#$___chunk1}" + ___str2="${___str2#$___chunk2}" + done + + # Either STR1, STR2 or both is empty here + if [ -n "$___str1" ]; then + case "$___str1" in + ~*) arg1_is_less $___cmp ;; + *) arg1_is_great $___cmp ;; + esac + elif [ -n "$___str2" ]; then + case "$___str2" in + ~*) arg1_is_great $___cmp ;; + *) arg1_is_less $___cmp ;; + esac + else + arg1_is_same $___cmp + fi +} + +# +# Recursively solve package dependencies +# +# Result is in the PKG_LIST variable +# +all_required_config_files () { + all_list="" + new_list="" + p="" + pkg="" + cmp="" + + list=$* + while [ -n "$list" ]; do + for p in $list; do + if [ -z "$pkg" ]; then + pkg=$p + elif [ -z "$cmp" ]; then + case "$p" in + "="|"!="|"<"|">"|"<="|">=") cmp=$p ;; + *) + read_config_file $pkg $PKG_CONFIG_PATH + all_list="$all_list${all_list:+ }$pkg" + new_list="$new_list${new_list:+ }$(get_attr Requires)" + cleanup_vars_attrs + pkg=$p + ;; + esac + else + read_config_file $pkg $PKG_CONFIG_PATH + if ! eval_compare_version "$(get_attr Version)" $cmp $p; then + echo "Version mismatch for $pkg $cmp $p: $(get_attr Version)" 1>&2 + exit 1 + fi + all_list="$all_list${all_list:+ }$pkg" + new_list="$new_list${new_list:+ }$(get_attr Requires)" + cleanup_vars_attrs + pkg="" + cmp="" + fi + done + if [ -n "$cmp" ]; then + echo "No version after comparison operator ($cmp): $pkg" 1>&2 + exit 1 + elif [ -n "$pkg" ]; then + read_config_file $pkg $PKG_CONFIG_PATH + all_list="$all_list${all_list:+ }$pkg" + new_list="$new_list${new_list:+ }$(get_attr Requires)" + cleanup_vars_attrs + fi + + list="$new_list" + new_list="" + done + + PKG_LIST=$(list_only_once $all_list) +} + +# +# Modify -I or -L by PKG_CONFIG_SYSROOT_DIR variable +# +sysroot () { + _opt="$1" + _result="" + shift + + while [ $# -gt 0 ]; do + if [ $1 = $_opt ]; then + _result="$_result${_result:+ }$_opt" + shift + _result="$_result $PKG_CONFIG_SYSROOT_DIR$1" + elif expr "$1" : "^$_opt" >/dev/null; then + _result="$_result${_result:+ }$_opt$PKG_CONFIG_SYSROOT_DIR$(expr "$1" : "^$_opt\(.*\)")" + else + _result="$_result${_result:+ }$1" + fi + shift + done + echo "$_result" +} + +# Show usage +usage () { + cat <&2 + echo "When LIBDIR has variable references for prefix and/or exec_prefix," 1>&2 + echo "you should provide --prefix=PREFIX option and/or" 1>&2 + echo "--exec-prefix=EXEC_PREFIX option, too" 1>&2 + exit 1 +fi + +PKG_CONFIG_PATH="$PKG_CONFIG_PATH${PKG_CONFIG_PATH:+:}$PKG_CONFIG_LIBDIR" +# + +if test $# -eq 0; then + usage 1 1>&2 +fi + + +# Second stage to do the main functionality + +module_list="" +want_var="" +want_attr="" +want_cflags="" +want_libs="" +want_exists="" + +cflags="" +libs="" +mtcflags="" +mtlibs="" + +delimiter=" " +output="" + +mt="no" + +VAR_list=VAR_pc_sysrootdir +if [ -z "$PKG_CONFIG_SYSROOT_DIR" ]; then + VAR_pc_sysrootdir="/" +else + VAR_pc_sysrootdir="$PKG_CONFIG_SYSROOT_DIR" +fi + +while test $# -gt 0; do + case $1 in + #### pkg-config incompatible options: begin + --prefix) + # In future, use --variable=prefix instead. + want_var=prefix + ;; + --exec-prefix) + # In future, use --variable=exec_prefix instead. + want_var=exec_prefix + ;; + --version) + # In future, use --modversion instead. + want_attr=Version + delimiter=" +" + ;; + --api-version) + # In future, use --variable=api_version instead. + want_var=api_version + ;; + --host) + # In future, use --variable=host instead. + want_var=host + ;; + --mt) + # In future, use --variable=mtcflags or --variable=mtlibs. + mt=yes + ;; + #### pkg-config incompatible options: end + --modversion) + want_attr=Version + delimiter=" +" + ;; + --exists) + want_exists=yes + ;; + --cflags) + want_cflags=yes + ;; + --libs) + want_libs=yes + ;; + --variable=*) + want_var=${1#*=} + ;; + --help) + usage 0 + ;; + --*) + usage 1 1>&2 + ;; + *) + # Modules + module_list="$module_list${module_list:+ }$1" + ;; + esac + + shift +done + + +if [ -z "$module_list" ]; then + module_list=$default_module +elif expr match "$module_list" "=\|!=\|<\|>\|<=\|>=" >/dev/null; then + module_list="$default_module $module_list" +fi + +all_required_config_files $module_list + +for p in $PKG_LIST; do + read_config_file $p $PKG_CONFIG_PATH + # For want_var or want_attr, get it from the first package + if [ -n "$want_var" ]; then + output="$(get_var $want_var)" + break + elif [ -n "$want_attr" ]; then + output="$(get_attr $want_attr)" + break + else + cflags="$cflags${cflags:+ }$(get_attr Cflags)" + libs="$libs${libs:+ }$(get_attr Libs)" + + if [ $p = "gpg-error" ]; then + mtcflags="$(get_var mtcflags)" + mtlibs="$(get_var mtlibs)" + fi + fi + cleanup_vars_attrs +done + +if [ -z "$want_var" -a -z "$want_attr" ]; then + if [ -n "$want_cflags" ]; then + output="$output${output:+ }$(sysroot -I $(list_only_once $cflags))" + # Backward compatibility to old gpg-error-config + if [ $mt = yes -a -n "$mtcflags" ]; then + output="$output${output:+ }$mtcflags" + fi + fi + if [ -n "$want_libs" ]; then + output="$output${output:+ }$(sysroot -L $(list_only_once_for_libs $libs))" + # Backward compatibility to old gpg-error-config + if [ $mt = yes -a -n "$mtlibs" ]; then + output="$output${output:+ }$mtlibs" + fi + fi +fi + +if [ -z "$want_exists" ]; then + echo "$output" +fi + +exit 0 diff --git a/src/gpgrt-config.in b/src/gpgrt-config.in deleted file mode 100644 index 9df01b7..0000000 --- a/src/gpgrt-config.in +++ /dev/null @@ -1,628 +0,0 @@ -#!/bin/sh -# Copyright (C) 2018 g10 Code GmbH -# -# This file is free software; as a special exception the author gives -# unlimited permission to copy and/or distribute it, with or without -# modifications, as long as this notice is preserved. -# -# This file is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# SPDX-License-Identifier: FSFULLR - -prefix=@prefix@ -exec_prefix=@exec_prefix@ -pkg_config_libdir=@pkg_config_libdir@ -if [ x"${PKG_CONFIG_LIBDIR+set}" = x ]; then - # If PKG_CONFIG_LIBDIR is not specified, detect the directory. - - # We supports standard cross build with $CC - triplet="" - case "$CC" in - *-*-*) triplet=${CC%-*} ;; - *) ;; - esac - if [ "$pkg_config_libdir" = auto ]; then - # It's multiarch environment. - # It may be standard cross build, native multiarch build, or - # multiarch-cross build - multiarch="" - if [ -n "$triplet" ]; then - triplet1=$triplet - else - triplet1=$(gcc -dumpmachine) - fi - # Follow existing practice for multiarch name - if expr $triplet1 : "^i[4567]86-" >/dev/null; then - multiarch="i386-${triplet1#*-}" - else - multiarch=$triplet1 - fi - if [ -n "$triplet" ]; then - PKG_CONFIG_LIBDIR="@exec_prefix@/$triplet/lib/pkgconfig:@exec_prefix@/lib/$multiarch/pkgconfig" - else - PKG_CONFIG_LIBDIR="@exec_prefix@/lib/$multiarch/pkgconfig" - fi - unset multiarch triplet1 - elif [ -n "$triplet" ]; then - # It's cross build - PKG_CONFIG_LIBDIR="@exec_prefix@/$triplet/lib/pkgconfig" - else - # Native build in standard (non-multiarch) environment - PKG_CONFIG_LIBDIR="$pkg_config_libdir" - fi - unset triplet -fi -PKG_CONFIG_PATH="$PKG_CONFIG_PATH${PKG_CONFIG_PATH:+:}$PKG_CONFIG_LIBDIR" -# - -#### start of functions for this script - -# -# Bourne shell functions for config file in pkg-config style, so that -# we can share such a config file between pkg-config and script -# - -# -# get_var: Get the variable value of NAME -# -# Variables are recorded in the shell variables named "VAR_" -# -get_var () { - ___name=$1 - - eval echo \$VAR_$___name -} - -# -# get_attr: Get the attribute value of KEY -# -# Attributes are recorded in the shell variables named "ATTR_" -# -get_attr () { - ___name=$1 - - eval echo \$ATTR_$___name -} - -# Remove ${varname} part in the beginning of a string. -remove_var_expr () { - ___varname=$1 - shift - - expr "$*" : "\${$___varname}\\(.*\\)" -} - -# Given a string, substitute variables. -substitute_vars () { - __string="$1" - __varname="" - __result="" - - while [ -n "$__string" ]; do - case "$__string" in - \$\$*) - __result="$__result\$" - __string="${__string#\$\$}" - ;; - \${*}*) - __varname="${__string#\$\{}" - __varname="${__varname%%\}*}" - __result="$__result$(get_var $__varname)" - __string=$(remove_var_expr $__varname $__string) - ;; - *) - __result="$__result$(printf %c "$__string")" - __string="${__string#$(printf %c "$__string")}" - ;; - esac - done - - echo "$__result" -} - -# -# Read a config from stdin -# -# Variables: -# For VAR=VALUE, value is stored in the shell variable VAR_*. -# -# Attributes: -# For KEY: VALUE, value is stored in the shell variable ATTR_*. -# -read_config_from_stdin () { - _filename=$1 - _line="" - _varname="" - _value="" - _key="" - _reading_attrs="" - - while read _line; do - if [ -z "$_line" ]; then - _reading_attrs=yes - continue - elif [ -z "$_reading_attrs" ]; then - case "$_line" in - *=*) - _varname="${_line%%=*}" - _value="${_line#*=}" - VAR_list="$VAR_list${VAR_list:+ }VAR_$_varname" - read VAR_$_varname <&2 - exit 1 - ;; - esac - fi - done -} - - -find_file_in_path () { - _f=$1 - _p=$2 - _saved_IFS="$IFS" - _arg="" - IFS=":" # On Windows it should be ";"??? - - for _arg in $_p; do - if [ -r $_arg/$_f ]; then - RESULT="$_arg/$_f" - IFS="$_saved_IFS" - return 0 - fi - done - IFS="$_saved_IFS" - RESULT="" - return 1 -} - -read_config_file () { - if ! find_file_in_path $1.pc $2; then - if [ -z "$want_exists" ]; then - echo "Can't find $1.pc" 1>&2 - fi - exit 1 - fi - read_config_from_stdin $RESULT < $RESULT -} - -cleanup_vars_attrs () { - eval unset $VAR_list VAR_list - eval unset $ATTR_list ATTR_list -} - -not_listed_yet () { - ___m=$1 - ___arg="" - shift - - for ___arg; do - if [ $___m = $___arg ]; then - return 1 - fi - done - - return 0 -} - -list_only_once () { - __result="" - __arg="" - - for __arg; do - if not_listed_yet $__arg $__result; then - __result="$__result${__result:+ }$__arg" - fi - done - - echo $__result -} - -list_only_once_for_libs () { - __result="" - __rev_list="" - __arg="" - - # Scan the list and eliminate duplicates for non-"-lxxx" - # the resulted list is in reverse order - for __arg; do - case "$__arg" in - -l*) - # As-is - __rev_list="$__arg${__rev_list:+ }$__rev_list" - ;; - *) - if not_listed_yet $__arg $__rev_list; then - __rev_list="$__arg${__rev_list:+ }$__rev_list" - fi - ;; - esac - done - - # Scan again - for __arg in $__rev_list; do - case "$__arg" in - -l*) - if not_listed_yet $__arg $__result; then - __result="$__arg${__result:+ }$__result" - fi - ;; - *) - # As-is - __result="$__arg${__result:+ }$__result" - ;; - esac - done - - echo $__result -} - -arg1_is_same () { - [ "$1" = "=" -o "$1" = ">=" -o "$1" = "<=" ] -} - -arg1_is_less () { - [ "$1" = "!=" -o "$1" = "<" -o "$1" = "<=" ] -} - -arg1_is_great () { - [ "$1" = "!=" -o "$1" = ">" -o "$1" = ">=" ] -} - -# -# Evaluate comparison between versions in RPM way -# -eval_compare_version () { - ___str1="$1" - ___cmp="$2" - ___str2="$3" - ___char1="" - ___char2="" - ___chunk1="" - ___chunk2="" - - while [ -n "$___str1" -a -n "$___str2" ]; do - # Trim anything that's not alnum or tilde from the front - ___str1="$(expr "$___str1" : '[^0-9A-Za-z~]*\(.*\)')" - ___str2="$(expr "$___str2" : '[^0-9A-Za-z~]*\(.*\)')" - - # Get the first character - ___char1=${___str1%${___str1#?}} - ___char2=${___str2%${___str2#?}} - - if [ "$___char1" = ~ -o "$___char2" = ~ ]; then - if [ "$___char1" != ~ ]; then - arg1_is_great $___cmp - return - fi - if [ "$___char2" != ~ ]; then - arg1_is_less $___cmp - return - fi - ___str1=${___str1#~} - ___str2=${___str2#~} - continue - fi - - if [ -z "$___char1" -o -z "$___char2" ]; then - break - fi - - case "$___char1$___char2" in - [0-9][A-Za-z]) - arg1_is_great $___cmp - return - ;; - [A-Za-z][0-9]) - arg1_is_less $___cmp - return - ;; - [0-9][0-9]) - ___chunk1="$(expr "$___str1" : '\([0-9]*\)')" - ___chunk2="$(expr "$___str2" : '\([0-9]*\)')" - ;; - [A-Za-z][A-Za-z]) - ___chunk1="$(expr "$___str1" : '\([A-Za-z]*\)')" - ___chunk2="$(expr "$___str2" : '\([A-Za-z]*\)')" - ;; - esac - - # Compare chunks numerically if digits, or lexicographically - if expr "$___chunk1" "!=" "$___chunk2" >/dev/null; then - if expr "$___chunk1" ">" "$___chunk2" >/dev/null; then - arg1_is_great $___cmp - return - else - arg1_is_less $___cmp - return - fi - fi - - # Remove the chunk - ___str1="${___str1#$___chunk1}" - ___str2="${___str2#$___chunk2}" - done - - # Either STR1, STR2 or both is empty here - if [ -n "$___str1" ]; then - case "$___str1" in - ~*) arg1_is_less $___cmp ;; - *) arg1_is_great $___cmp ;; - esac - elif [ -n "$___str2" ]; then - case "$___str2" in - ~*) arg1_is_great $___cmp ;; - *) arg1_is_less $___cmp ;; - esac - else - arg1_is_same $___cmp - fi -} - -# -# Recursively solve package dependencies -# -# Result is in the PKG_LIST variable -# -all_required_config_files () { - all_list="" - new_list="" - p="" - pkg="" - cmp="" - - list=$* - while [ -n "$list" ]; do - for p in $list; do - if [ -z "$pkg" ]; then - pkg=$p - elif [ -z "$cmp" ]; then - case "$p" in - "="|"!="|"<"|">"|"<="|">=") cmp=$p ;; - *) - read_config_file $pkg $PKG_CONFIG_PATH - all_list="$all_list${all_list:+ }$pkg" - new_list="$new_list${new_list:+ }$(get_attr Requires)" - cleanup_vars_attrs - pkg=$p - ;; - esac - else - read_config_file $pkg $PKG_CONFIG_PATH - if ! eval_compare_version "$(get_attr Version)" $cmp $p; then - echo "Version mismatch for $pkg $cmp $p: $(get_attr Version)" 1>&2 - exit 1 - fi - all_list="$all_list${all_list:+ }$pkg" - new_list="$new_list${new_list:+ }$(get_attr Requires)" - cleanup_vars_attrs - pkg="" - cmp="" - fi - done - if [ -n "$cmp" ]; then - echo "No version after comparison operator ($cmp): $pkg" 1>&2 - exit 1 - elif [ -n "$pkg" ]; then - read_config_file $pkg $PKG_CONFIG_PATH - all_list="$all_list${all_list:+ }$pkg" - new_list="$new_list${new_list:+ }$(get_attr Requires)" - cleanup_vars_attrs - fi - - list="$new_list" - new_list="" - done - - PKG_LIST=$(list_only_once $all_list) -} - -# -# Modify -I or -L by PKG_CONFIG_SYSROOT_DIR variable -# -sysroot () { - _opt="$1" - _result="" - shift - - while [ $# -gt 0 ]; do - if [ $1 = $_opt ]; then - _result="$_result${_result:+ }$_opt" - shift - _result="$_result $PKG_CONFIG_SYSROOT_DIR$1" - elif expr "$1" : "^$_opt" >/dev/null; then - _result="$_result${_result:+ }$_opt$PKG_CONFIG_SYSROOT_DIR$(expr "$1" : "^$_opt\(.*\)")" - else - _result="$_result${_result:+ }$1" - fi - shift - done - echo "$_result" -} - -#### end of functions for this script - -myname=${0##*/} -if [ $myname = gpgrt-config ]; then - default_module="gpg-error" -else - default_module=${myname%-config} -fi - -usage() -{ - cat <&2 -fi - - -module_list="" -want_var="" -want_attr="" -want_cflags="" -want_libs="" -want_exists="" - -cflags="" -libs="" -mtcflags="" -mtlibs="" - -delimiter=" " -output="" - -mt="no" - -VAR_list=VAR_pc_sysrootdir -if [ -z "$PKG_CONFIG_SYSROOT_DIR" ]; then - VAR_pc_sysrootdir="/" -else - VAR_pc_sysrootdir="$PKG_CONFIG_SYSROOT_DIR" -fi - -while test $# -gt 0; do - case $1 in - #### pkg-config incompatible options: begin - --prefix) - # In future, use --variable=prefix instead. - want_var=prefix - ;; - --exec-prefix) - # In future, use --variable=exec_prefix instead. - want_var=exec_prefix - ;; - --version) - # In future, use --modversion instead. - want_attr=Version - delimiter=" -" - ;; - --api-version) - # In future, use --variable=api_version instead. - want_var=api_version - ;; - --host) - # In future, use --variable=host instead. - want_var=host - ;; - --mt) - # In future, use --variable=mtcflags or --variable=mtlibs. - mt=yes - ;; - #### pkg-config incompatible options: end - --modversion) - want_attr=Version - delimiter=" -" - ;; - --exists) - want_exists=yes - ;; - --cflags) - want_cflags=yes - ;; - --libs) - want_libs=yes - ;; - --variable=*) - want_var=${1#*=} - ;; - --help) - usage 0 - ;; - --*) - usage 1 1>&2 - ;; - *) - # Modules - module_list="$module_list${module_list:+ }$1" - ;; - esac - - shift -done - - -if [ -z "$module_list" ]; then - module_list=$default_module -elif expr match "$module_list" "=\|!=\|<\|>\|<=\|>=" >/dev/null; then - module_list="$default_module $module_list" -fi - -all_required_config_files $module_list - -for p in $PKG_LIST; do - read_config_file $p $PKG_CONFIG_PATH - # For want_var or want_attr, get it from the first package - if [ -n "$want_var" ]; then - output="$(get_var $want_var)" - break - elif [ -n "$want_attr" ]; then - output="$(get_attr $want_attr)" - break - else - cflags="$cflags${cflags:+ }$(get_attr Cflags)" - libs="$libs${libs:+ }$(get_attr Libs)" - - if [ $p = "gpg-error" ]; then - mtcflags="$(get_var mtcflags)" - mtlibs="$(get_var mtlibs)" - fi - fi - cleanup_vars_attrs -done - -if [ -z "$want_var" -a -z "$want_attr" ]; then - if [ -n "$want_cflags" ]; then - output="$output${output:+ }$(sysroot -I $(list_only_once $cflags))" - # Backward compatibility to old gpg-error-config - if [ $mt = yes -a -n "$mtcflags" ]; then - output="$output${output:+ }$mtcflags" - fi - fi - if [ -n "$want_libs" ]; then - output="$output${output:+ }$(sysroot -L $(list_only_once_for_libs $libs))" - # Backward compatibility to old gpg-error-config - if [ $mt = yes -a -n "$mtlibs" ]; then - output="$output${output:+ }$mtlibs" - fi - fi -fi - -if [ -z "$want_exists" ]; then - echo "$output" -fi - -exit 0 diff --git a/src/gpgrt.m4 b/src/gpgrt.m4 index fab1eb4..7f92a22 100644 --- a/src/gpgrt.m4 +++ b/src/gpgrt.m4 @@ -10,7 +10,7 @@ # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # SPDX-License-Identifier: FSFULLR # -# Last-changed: 2018-10-25 +# Last-changed: 2018-10-29 # Note: This is a kind of duplicate of gpg-error.m4 with uses the # future name of libgpg-error to prepare for a smooth migration in # some distant time. @@ -70,6 +70,9 @@ AC_DEFUN([AM_PATH_GPGRT], fi AC_PATH_PROG(GPGRT_CONFIG, gpgrt-config, no) + if test "$GPGRT_CONFIG" != "no"; then + GPGRT_CONFIG="$GPGRT_CONFIG --prefix=$prefix --exec-prefix=$exec_prefix --libdir=$libdir" + fi min_gpgrt_version=ifelse([$1], ,1.33,$1) AC_MSG_CHECKING(for GPG Runtime - version >= $min_gpgrt_version) ok=no @@ -79,7 +82,7 @@ AC_DEFUN([AM_PATH_GPGRT], sed 's/\([[0-9]]*\)\.\([[0-9]]*\)/\1/'` req_minor=`echo $min_gpgrt_version | \ sed 's/\([[0-9]]*\)\.\([[0-9]]*\)/\2/'` - gpgrt_config_version=`CC=$CC $GPGRT_CONFIG --version` + gpgrt_config_version=`$GPGRT_CONFIG --version` major=`echo $gpgrt_config_version | \ sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'` minor=`echo $gpgrt_config_version | \ @@ -95,15 +98,15 @@ AC_DEFUN([AM_PATH_GPGRT], fi fi if test $ok = yes; then - GPGRT_CFLAGS=`CC=$CC $GPGRT_CONFIG --cflags` - GPGRT_LIBS=`CC=$CC $GPGRT_CONFIG --libs` - GPGRT_MT_CFLAGS=`CC=$CC $GPGRT_CONFIG --variable=mtcflags 2>/dev/null` + GPGRT_CFLAGS=`$GPGRT_CONFIG --cflags` + GPGRT_LIBS=`$GPGRT_CONFIG --libs` + GPGRT_MT_CFLAGS=`$GPGRT_CONFIG --variable=mtcflags 2>/dev/null` GPGRT_MT_CFLAGS="$GPGRT_CFLAGS${GPGRT_CFLAGS:+ }$GPGRT_MT_CFLAGS" - GPGRT_MT_LIBS=`CC=$CC $GPGRT_CONFIG --variable=mtlibs 2>/dev/null` + GPGRT_MT_LIBS=`$GPGRT_CONFIG --variable=mtlibs 2>/dev/null` GPGRT_MT_LIBS="$GPGRT_LIBS${GPGRT_LIBS:+ }$GPGRT_MT_LIBS" AC_MSG_RESULT([yes ($gpgrt_config_version)]) ifelse([$2], , :, [$2]) - gpgrt_config_host=`CC=$CC $GPGRT_CONFIG --variable=host 2>/dev/null || echo none` + gpgrt_config_host=`$GPGRT_CONFIG --variable=host 2>/dev/null || echo none` if test x"$gpgrt_config_host" != xnone ; then if test x"$gpgrt_config_host" != x"$host" ; then AC_MSG_WARN([[ -- cgit v1.2.3