diff options
author | NIIBE Yutaka <gniibe@fsij.org> | 2018-08-31 16:07:12 +0900 |
---|---|---|
committer | NIIBE Yutaka <gniibe@fsij.org> | 2018-08-31 16:07:12 +0900 |
commit | fb1d0cd7105e0603482257e05c559c035b210c9c (patch) | |
tree | a02b07ef34392abd1cbd28a93bea08aa7d653500 | |
parent | e0aecec6d0402bb305aa768656b080c995f781cc (diff) | |
download | libgpg-error-fb1d0cd7105e0603482257e05c559c035b210c9c.tar.gz |
Support module dependency.
-rw-r--r-- | src/gpg-error-config.in | 205 |
1 files changed, 176 insertions, 29 deletions
diff --git a/src/gpg-error-config.in b/src/gpg-error-config.in index d5e2f3b..49451e7 100644 --- a/src/gpg-error-config.in +++ b/src/gpg-error-config.in @@ -92,30 +92,48 @@ substitute_vars () { # For KEY: VALUE, value is stored in the shell variable ATTR_*. # read_config_from_stdin () { + local filename=$1 local line local varname local value local key + local reading_attrs while read line; do - case "$line" in - *=*) - varname="${line%%=*}" - value="${line#*=}" - VAR_list="$VAR_list VAR_$varname" - read VAR_$varname <<EOF1 + 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_$varname" + read VAR_$varname <<EOF1 $(substitute_vars "$value") EOF1 - ;; - *:\ *) - key="${line%%:\ *}" - value="${line#*:\ }" - ATTR_list="$ATTR_list ATTR_$key" - read ATTR_$key <<EOF2 + continue + ;; + *) reading_attrs=yes ;; + esac + fi + if [ -n "$reading_attrs" ]; then + case "$line" in + *:\ *) + key="${line%%:\ *}" + value="${line#*:\ }" + ATTR_list="$ATTR_list ATTR_$key" + read ATTR_$key <<EOF2 $(substitute_vars "$value") EOF2 - ;; - esac + ;; + *:|*:\ ) ;; + *) + echo "Error reading $filename: $line" 1>&2 + exit 1 + ;; + esac + fi done } @@ -145,7 +163,7 @@ read_config_file () { echo "Can't find $1.pc" 1>&2 exit 1 fi - read_config_from_stdin < $config_file + read_config_from_stdin $config_file < $config_file } cleanup_vars_attrs () { @@ -219,32 +237,161 @@ list_only_once_for_libs () { 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 () { + local str1="$1" + local cmp="$2" + local str2="$3" + local char1 char2 + local 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 # -# XXX: version requirement (version comparison) is not yet supported +# Result is in the pkg_list variable # all_required_config_files () { local list local all_list local new_list - local p - - list="$@" - all_list="$list" + local p pkg cmp ver + list=$* while [ -n "$list" ]; do - new_list="" for p in $list; do - read_config_file $p $PKG_CONFIG_PATH + 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 $pkg" + 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 $pkg" + 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 $pkg" new_list="$new_list $(get_attr Requires)" cleanup_vars_attrs - done - all_list="$all_list $new_list" + fi + list="$new_list" + new_list="" done - echo $(list_only_once $all_list) + pkg_list=$(list_only_once $all_list) } #### end of pkgconf-funcs @@ -349,14 +496,14 @@ if [ $myname = "gpg-error-config" -a -z "$modules" ]; then requires="$(get_attr Requires)" cleanup_vars_attrs - pkg_list=$(all_required_config_files $requires) + all_required_config_files $requires else if [ -z "$modules" ]; then modules=${myname%-config} fi cflags="" libs="" - pkg_list=$(all_required_config_files $modules) + all_required_config_files $modules fi for p in $pkg_list; do @@ -374,14 +521,14 @@ done if [ -z "$output_var" -a -z "$output_attr" ]; then if [ $opt_cflags = yes ]; then - output="$output $(list_only_once $cflags)" + output="$output${output:+ }$(list_only_once $cflags)" # Backward compatibility to old gpg-error-config if [ $mt = yes ]; then output="$output $mtcflags" fi fi if [ $opt_libs = yes ]; then - output="$output $(list_only_once_for_libs $libs)" + output="$output${output:+ }$(list_only_once_for_libs $libs)" # Backward compatibility to old gpg-error-config if [ $mt = yes ]; then output="$output $mtlibs" |