#!/usr/bin/env build build_query_usage() { cat< options: --topdir Builder topdir --toolchain Display the toolchain environ --help Display this help package options: --bdepends Package build dependancies [\$BDEPENDS] --bdeps-all Build dependancies of all packages depended on --category Package category [\$CATEGORY] --description Package Description [\$DESCRIPTION] --destdir Build-time destination directory [\$D] --exists Exit with a non-zero exit-status if pkg does not exist --envdir Package environment directory [unused] --environ Print the package environ --filesdir Package files/ directory [\$F] --logdir Package log directory [\$L] --license Package license [\$LICENSE] --name Package name [\$NAME] --pkgname Full package name [\$CATEGORY/\$NAME] --patches Patches used by a package [\$PATCHES] --pkgdir Path to package metadata --rulesfile Path to package Buildrules file [\$RULESFILE] --release Package release number [\$RELEASE] --rdepends Package runtime dependancies [\$RDEPENDS] --rdeps-all Runtime dependancies of all packages depended on --srcdir Package source directory [\$S] --summary Display package summary in specfile format --tmpdir Package temporary directory [\$T] --src-uri URI to package source(s) [\$SOURCE_URI] --version Package version [\$VERSION] --var Query specific variable from package --workdir Package work directory [\$W] END_OF_HELP } RECURSE_RDEPENDS='false' recurse_bdeps() { test "$#" -eq '0' && return if ${RECURSE_RDEPENDS}; then set -- "${@}" $(build query -R "${1}") else set -- "${@}" $(build query -B "${1}") fi eval query_recursive_var="$(echo "${1}"|sed -e 's,[_-/],_,g')" eval query_recursive_val="\$${query_recursive_var}" if ! test -z "${query_recursive_val}"; then unset query_recursive_val unset query_recursive_var return fi unset query_recursive_val echo "${1}" eval "${query_recursive_var}='${*}'" unset query_recursive_var shift for query_recursive_pkg; do recurse_bdeps "${query_recursive_pkg}" done unset unset query_recursive_pkg } recurse_rdeps() { test "$#" -eq '0' && return RECURSE_RDEPENDS='true' recurse_bdeps "${@}" } # Look for cries for --help in the cmdline for arg; do case "${arg}" in (-h|-help|--help) build_query_usage; exit 0;; esac done QUERY_ACTION="summary" while [ "$#" -gt "0" ]; do case "${1}" in (-B|-bdepends|--bdepends) QUERY_ACTION="bdepends";; (-bdeps-all|--bdeps-all) QUERY_ACTION="bdeps_all";; (-c|-category|--category) QUERY_ACTION="category";; (-d|-description|--description) QUERY_ACTION="descr";; (-D|-destdir|--destdir) QUERY_ACTION="destdir";; (--exists) test -e "${BUILDER_PKGDIR}/${2}/Buildrules" && exit 0 || exit 1;; (-e|-envdir|--envdir) QUERY_ACTION="envdir";; (-E|-environ|--environ) QUERY_ACTION="environ";; (-f|-filesdir|--filesdir) QUERY_ACTION="filesdir";; (-l|-logdir|--logdir) QUERY_ACTION="logdir";; (-L|-license|--license) QUERY_ACTION="license";; (-n|-name|--name) QUERY_ACTION="name";; (-N|-pkgname|--pkgname) QUERY_ACTION="pkgname";; (-p|-patches|--patches) QUERY_ACTION="patches";; (-P|-pkgdir|--pkgdir) QUERY_ACTION="pkgdir";; (-r|-rulefile|--rulesfile) QUERY_ACTION="rulesfile";; (--release) QUERY_ACTION="release";; (-R|-rdepends|--rdepends) QUERY_ACTION="rdepends";; (-rdeps-all|--rdeps-all) QUERY_ACTION="rdeps_all";; (-s|-srcdir|--srcdir) QUERY_ACTION="srcdir";; (-S|-summary|--summary) QUERY_ACTION="summary";; (-toolchain|--toolchain) QUERY_ACTION="toolchain";; (-t|-topdir|--topdir) QUERY_ACTION="topdir";; (-T|-tmpdir|--tmpdir) QUERY_ACTION="tmpdir";; (-u|-source-uri|--src-uri) QUERY_ACTION="src_uri";; (-v|-version|--version) QUERY_ACTION="version";; (-V|-var|--var) shift if [ "$#" -lt "1" ]; then error "no variable specified" echo "try '${##*//} --help'" >&2 exit 1 fi QUERY_ACTION="var" QUERY_VAR="${1}" ;; (-w|-workdir|--workdir) QUERY_ACTION="workdir";; (-*) error "unknown query '${1}'" echo "try '${0##*/} --help'" >&2 exit 1 ;; (*) break;; esac shift done # FIXME move these to 'build-config'. 'build-query' is for package data case "${QUERY_ACTION}" in (topdir) echo "${BUILDER_TOPDIR}" exit 0;; (toolchain) if [ "$#" -gt "0" ] && [ "${1}" != "${CHOST}" ]; then CROSS_COMPILE="${1}-" shift else CROSS_COMPILE="${CHOST}-" fi CC="${CROSS_COMPILE}gcc" CXX="${CROSS_COMPILE}g++" cat<<-EOF CC="${CC}" export CC CXX="${CXX}" export CXX CROSS_COMPILE="${CROSS_COMPILE}" export CROSS_COMPILE EOF # Note: we do not set AS since we often use gcc as the assembler for cmd in ar ld strip ranlib autom4te autoconf autoheader automake \ aclocal autopoint libtool libtoolize; do var="$(echo "${cmd}"|tr '[a-z]' '[A-Z]')" if command -v "${CROSS_COMPILE}${cmd}" > /dev/null 2>&1; then echo "${var}=\"${CROSS_COMPILE}${cmd}\"" else echo "${var}=\"${cmd}\"" fi echo "export ${var}" done exit 0;; esac if test "$#" -eq "0"; then die "no package specified" fi load_rules "${1}" # Allow the developer to hijack the SRC_URI with a checked out repository # FIXME this causes problems for various dep targets if [ -d "${BUILDER_PKGDIR}/${CATEGORY}/${NAME}/source" ]; then SOURCE_URI="file://${BUILDER_PKGDIR}/${CATEGORY}/${NAME}/source" fi case "${QUERY_ACTION}" in (name) echo "${NAME}";exit 0;; (category) echo "${CATEGORY}";exit 0;; (pkgname) echo "${CATEGORY}/${NAME}";exit 0;; (pkgdir) echo "${BUILDER_PKGDIR}/${CATEGORY}/${NAME}";exit 0;; (rulesfile) echo "${RULESFILE}";exit 0;; (filesdir) echo "${F}";exit 0;; (workdir) echo "${W}";exit 0;; (logdir) echo "${L}";exit 0;; (envdir) echo "${E}";exit 0;; (tmpdir) echo "${T}";exit 0;; (destdir) echo "${D}";exit 0;; (srcdir) echo "${S}";; (src_uri) echo "${SOURCE_URI}";; (bdepends) echo "$(echo ${BDEPENDS})";; (bdeps_all) recurse_bdeps ${BDEPENDS};; (rdepends) echo "$(echo ${RDEPENDS})";; (rdeps_all) recurse_rdeps ${RDEPENDS};; (descr) echo "${DESCRIPTION}";; (version) echo "${VERSION}";; (release) echo "${RELEASE}";; (patches) echo "${PATCHES}";; (license) echo "${LICENSE}";; # Allow the caller to specify the variable to report. # FIXME may need to protect our existing environ from being poked. (var) if [ -z "${QUERY_VAR}" ]; then die "no variable specified" fi eval "echo \"\$${QUERY_VAR}\"";; # All the fun environ data necessary for grabbing a single package. We ALWAYS # report all the variables, even if unset. This allows a caller to use this # command to set their own environ and automagically clear any variables which # are already set in their environment. (environ) cat<<-EOF TARGET="${TARGET}" TOPDIR="${BUILDER_TOPDIR}" SYSROOT="${SYSROOT}" CBUILD="${CBUILD}" CHOST="${CHOST}" ARCH="${ARCH}" NAME="${NAME}" CATEGORY="${CATEGORY}" RULESFILE="${RULESFILE}" VERSION="${VERSION}" RELEASE="${RELEASE}" DESCRIPTION="${DESCRIPTION}" LICENSE="${LICENSE}" SOURCE_URI="${SOURCE_URI}" EOF if [ ! -z "${NOCLEAN}" ]; then echo "NOCLEAN=\"${NOCLEAN}\"" else echo "NOCLEAN=" fi if [ ! -z "${PATCHES}" ]; then echo "PATCHES=\"${PATCHES}\"" else echo "PATCHES=" fi if [ ! -z "${RDEPENDS}" ]; then echo "RDEPENDS=\"${RDEPENDS}\"" else echo "RDEPENDS=" fi if [ ! -z "${BDEPENDS}" ]; then echo "BDEPENDS=\"${BDEPENDS}\"" else echo "BDEPENDS=" fi cat<<-EOF F="${F}" W="${W}" L="${L}" E="${E}" T="${T}" D="${D}" S="${S}" EOF ;; # Basic summary command (summary) echo "Name: ${CATEGORY}/${NAME}" echo "Version: ${VERSION}" echo "Release: ${RELEASE}" echo "License: ${LICENSE}" echo "Source: ${SOURCE_URI}" if [ ! -z "${RDEPENDS}" ]; then echo "Depends: ${RDEPENDS}" fi if [ ! -z "${BDEPENDS}" ]; then echo "BuildDeps: ${BDEPENDS}" fi cat <<-EOF ${DESCRIPTION} EOF ;; (*) die "unhandled query action '${QUERY_ACTION}'";; esac # vim: filetype=sh