diff --git a/src/gpg-error-config-main.sh b/src/gpg-error-config-main.sh index 37eb193..d7b9c56 100644 --- a/src/gpg-error-config-main.sh +++ b/src/gpg-error-config-main.sh @@ -1,108 +1,123 @@ if echo "$0" | grep gpg-error-config 2>/dev/null >/dev/null; then myname="gpg-error-config" else myname="gpgrt-config" fi usage() { cat <&2 fi if [ "$1" != "--mt" ]; then mt=no else # In future, use --variable=mtcflags or --variable=mtlibs mt=yes shift fi read_config_file ${myname%-config} $PKG_CONFIG_PATH opt_cflags=no opt_libs=no output="" while test $# -gt 0; do case "$1" in -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;; *) optarg= ;; esac case $1 in --prefix) # In future, use --variable=prefix instead. output="$output $(get_var prefix)" ;; --exec-prefix) # In future, use --variable=exec_prefix instead. output="$output $(get_var exec_prefix)" ;; --version) # In future, use --modversion instead. echo "$(get_attr Version)" exit 0 ;; --modversion) echo "$(get_attr Version)" exit 0 ;; --cflags) opt_cflags=yes ;; --libs) opt_libs=yes ;; --variable=*) echo "$(get_var ${1#*=})" exit 0 ;; --host) # In future, use --variable=host instead. echo "$(get_var host)" exit 0 ;; *) usage 1 1>&2 ;; esac shift done -if [ opt_cflags = yes ]; then - output="$output $(get_attr Cflags)" +cflags="$(get_attr Cflags)" +libs="$(get_attr Libs)" + +mtcflags="$(get_var mtcflags)" +mtlibs="$(get_var mtlibs)" + +requires="$(get_attr Requires)" +cleanup_vars_attrs +pkg_list=$(all_required_config_files $requires) + +for p in $pkg_list; do + read_config_file $p $PKG_CONFIG_PATH + cflags="$cflags $(get_attr Cflags)" + libs="$libs $(get_attr Libs)" + cleanup_vars_attrs +done + +if [ $opt_cflags = yes ]; then + output="$output $cflags" # Backward compatibility to old gpg-error-config if [ $mt = yes ]; then - output="$output $(get_var mtcflags)" + output="$output $mtcflags" fi fi -if [ opt_libs = yes ]; then - output="$output $(get_attr Libs)" +if [ $opt_libs = yes ]; then + output="$output $libs" # Backward compatibility to old gpg-error-config if [ $mt = yes ]; then - output="$output $(get_var mtlibs)" + output="$output $mtlibs" fi fi -# cleanup_vars_attrs - echo $output diff --git a/src/pkgconf-funcs.sh b/src/pkgconf-funcs.sh index 38dccf0..a51a8c3 100644 --- a/src/pkgconf-funcs.sh +++ b/src/pkgconf-funcs.sh @@ -1,138 +1,191 @@ #### start of pkgconf-funcs # # 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 () { local 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 () { local name=$1 eval echo \$ATTR_$name } # Remove ${varname} part in the beginning of a string. remove_var_expr () { local varname=$1 shift eval echo \"\${@#\\\$\\\{$varname\\\}}\" } # Given a string, substitute variables. substitute_vars () { local string="$1" local line local varname local 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 () { local line local varname local value local key while read line; do case "$line" in *=*) varname="${line%%=*}" value="${line#*=}" VAR_list="$VAR_list VAR_$varname" read VAR_$varname <&2 exit 1 fi read_config_from_stdin < $config_file } cleanup_vars_attrs () { eval unset $VAR_list VAR_list eval unset $ATTR_list ATTR_list } +not_listed_yet () { + local m=$1 + shift + + for arg; do + if [ $m = $arg ]; then + return 1 + fi + done + + return 0 +} + +list_only_once () { + local result="" + local arg + + for arg; do + if not_listed_yet $arg "$result"; then + result="$result $arg" + fi + done + + echo $result +} + +# +# Recursively solve package dependencies +# +# XXX: version requirement (version comparison) is not yet supported +# +all_required_config_files () { + local list="$1" + local all_list + local new_list + local p + + all_list="$list" + + while [ -n "$list" ]; do + new_list="" + for p in $list; do + read_config_file $p $PKG_CONFIG_PATH + new_list="$new_list $(get_attr Requires)" + cleanup_vars_attrs + done + all_list="$all_list $new_list" + list="$new_list" + done + + echo $(list_only_once $all_list) +} + #### end of pkgconf-funcs