diff --git a/src/gpg-error-config-main.sh b/src/gpg-error-config-main.sh index 637db7d..37eb193 100644 --- a/src/gpg-error-config-main.sh +++ b/src/gpg-error-config-main.sh @@ -1,120 +1,108 @@ if echo "$0" | grep gpg-error-config 2>/dev/null >/dev/null; then myname="gpg-error-config" else myname="gpgrt-config" fi -if find_file_in_path ${myname%-config}.pc $PKG_CONFIG_PATH; then - CONFIG_FILE=$RESULT -else - echo "Can't find ${myname%-config}.pc" 1>&2 - exit 1 -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 < "$CONFIG_FILE" +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)" # Backward compatibility to old gpg-error-config if [ $mt = yes ]; then output="$output $(get_var mtcflags)" fi fi if [ opt_libs = yes ]; then output="$output $(get_attr Libs)" # Backward compatibility to old gpg-error-config if [ $mt = yes ]; then output="$output $(get_var mtlibs)" fi fi -# -# Clean up -# -# eval unset $VAR_list VAR_list -# eval unset $ATTR_list ATTR_list -# +# cleanup_vars_attrs echo $output diff --git a/src/pkgconf-funcs.sh b/src/pkgconf-funcs.sh index fd144c8..38dccf0 100644 --- a/src/pkgconf-funcs.sh +++ b/src/pkgconf-funcs.sh @@ -1,119 +1,138 @@ #### 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 file +# 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_file () { +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 +} + #### end of pkgconf-funcs