# # $Id: frontend.in,v 1.14 2003/09/30 18:51:57 jmmv Exp $ # bt_pkgflags's frontend. # # buildtool # Copyright (c) 2003 Julio M. Merino Vidal. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the # distribution. # 3. Neither the name of the author nor the names of contributors may # be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # set -w usage() { local exitstatus=$1 detailed=${2:-no} [ ${detailed} = yes ] && echo "@PACKAGE@ version @VERSION@" 1>&2 echo "usage: ${ProgName} [options] pkg1[,op,ver] .. pkgN[,op,ver]" 1>&2 if [ ${detailed} = yes ]; then cat 1>&2 <= or ge, > or gt pkgconfig files are searched in the following path: \${PKG_CONFIG_PATH}:@DIR_PKGCONFIG@ pkgflags files are searched in the following path: \${BT_PATH_PKGFLAGS}:@DIR_PKGFLAGS@ See buildtool(1) for more information. EOF fi exit ${exitstatus} } compare_versions() { local v1=$1 op=$2 v2=$3 local v1_major v1_minor v1_micro local v2_major v2_minor v2_micro local ret # Fill missing numbers in version strings with zeros. v1_major=$(echo ${v1} | cut -d . -f 1); : ${v1_major:=0} v1_minor=$(echo ${v1} | cut -d . -f 2); : ${v1_minor:=0} v1_micro=$(echo ${v1} | cut -d . -f 3); : ${v1_micro:=0} v1=${v1_major}.${v1_minor}.${v1_micro} v2_major=$(echo ${v2} | cut -d . -f 1); : ${v2_major:=0} v2_minor=$(echo ${v2} | cut -d . -f 2); : ${v2_minor:=0} v2_micro=$(echo ${v2} | cut -d . -f 3); : ${v2_micro:=0} v2=${v2_major}.${v2_minor}.${v2_micro} ret=1 case ${op} in lt|'<') [ ${v1} '<' ${v2} ] && ret=0 ;; le|'<=') [ ${v1} '<' ${v2} -o ${v1} = ${v2} ] && ret=0 ;; eq|'=') [ ${v1} = ${v2} ] && ret=0 ;; ne|'!=') [ ${v1} != ${v2} ] && ret=0 ;; ge|'>=') [ ${v1} '>' ${v2} -o ${v1} = ${v2} ] && ret=0 ;; gt|'>') [ ${v1} '>' ${v2} ] && ret=0 ;; *) btcmn_err "unknown version operator \`${op}'" ;; esac return ${ret} } parse() { local fmt="$1" pkgname="$2" pkgop="$3" pkgver="$4" if [ "\\${pkgop}" = "\\" ] || [ "\\${pkgver}" = "\\" ] || \ compare_versions $(${fmt}_get_version) ${pkgop} ${pkgver} then [ ${show_cflags} = yes ] && output+=$(${fmt}_get_cflags) [ ${show_libs} = yes ] && output+=$(${fmt}_get_libs) else btcmn_warn "version mismatch for \`${pkgname}'" return 1 fi return 0 } main() { local show_cflags show_libs local output pkgname pkgop pkgver ret btcmn_req_runtime show_cflags=no show_libs=no while [ $# -gt 0 ]; do echo $1 | grep ^- >/dev/null || break case $1 in -c|--cflags) show_cflags=yes ;; -h|--help) usage 0 yes ;; -l|--libs) show_libs=yes ;; --) shift; break ;; *) btcmn_warn "unknown option \`$1'" usage 1 no ;; esac shift done [ $# -eq 0 ] && usage 1 no ret=0 output= while [ $# -gt 0 ]; do if echo $1 | grep , >/dev/null; then pkgname=$(echo $1 | cut -d , -f 1) pkgop=$(echo $1 | cut -d , -f 2) pkgver=$(echo $1 | cut -d , -f 3) elif echo $1 | grep ' ' >/dev/null; then pkgname=$(echo $1 | cut -d ' ' -f 1) pkgop=$(echo $1 | cut -d ' ' -f 2) pkgver=$(echo $1 | cut -d ' ' -f 3) else pkgname=$1 pkgop= pkgver= fi if pkgflags_open ${pkgname}; then parse pkgflags ${pkgname} ${pkgop} ${pkgver} || ret=1 pkgflags_close elif pkgconfig_open ${pkgname}; then parse pkgconfig ${pkgname} ${pkgop} ${pkgver} || ret=1 pkgconfig_close else btcmn_warn "cannot locate flags information for \`${pkgname}'" ret=1 fi shift done [ -n "${output}" ] && echo ${output} return ${ret} } # Local Variables: *** # mode: shell-script *** # End: *** # vim: syntax=sh