X-Git-Url: http://git.pld-linux.org/?a=blobdiff_plain;f=repackage.sh;h=9c92434cfb0b1d099571c18ece886eecb1ebf685;hb=9e3300e3997bbae5e22b1fcee4bd4046326a3589;hp=d39a6bd812c5f80ccba0b42fcc49eec6d9d32bc5;hpb=814db7355bf31ea359bf076cfecf2444a0fa00aa;p=packages%2Frpm-build-tools.git diff --git a/repackage.sh b/repackage.sh old mode 100644 new mode 100755 index d39a6bd..9c92434 --- a/repackage.sh +++ b/repackage.sh @@ -20,22 +20,95 @@ set -e rpmbuild() { + # preprocess args, we must have --target as first arg to rpmbuild + # we need to grab also dir where spec resides + local a spec specdir + while [ $# -gt 0 ]; do + case "$1" in + --target) + shift + TARGET=$1 + ;; + *.spec) + spec="$1" + a="$a $1" + ;; + *) + a="$a $1" + ;; + esac + shift + done + + specdir=$(dirname "$(pwd)/${spec:-.}") + + # use gz payload as time is what we need here, not compress ratio + + # we use %__ldconfig variable to test are we on rpm 4.4.9 + # on 4.4.9 we should not redefine %clean to contain %clean, and redefine %__spec_clean_body instead + # on 4.4.2 we must redefine %clean to contain %clean + set -x + /usr/bin/rpmbuild \ + ${TARGET:+--target $TARGET} \ + --short-circuit \ + --define "_specdir $specdir" --define "_sourcedir $specdir" \ + --define 'clean %%%{!?__ldconfig:clean}%{?__ldconfig:check} \ + exit 0%{nil}' \ + --define 'check %%check \ + exit 0%{nil}' \ + --define '_source_payload w5.gzdio' \ + --define '_binary_payload w5.gzdio' \ + --define '__spec_install_pre %___build_pre' \ + --define '__spec_clean_body %{nil}' \ + --define '_enable_debug_packages 0' \ + $a || exit +} + +specdump() { + local a + while [ $# -gt 0 ]; do + case "$1" in + --target|--with|--without) + a="$a $1 $2" + shift + ;; + --define) + a="$a $1 \"$2\"" + shift + ;; + -*) + ;; + *) + a="$a $1" + ;; + esac + shift + done set -x - /usr/bin/rpmbuild ${TARGET:+--target $TARGET} $BCONDS --short-circuit --define '_source_payload w9.gzdio' --define 'check exit 0; %{nil}' "$@" || exit + eval rpm-specdump $a || echo >&2 $? } -specfile="${1%.spec}.spec"; shift -set -- "$specfile" "$@" +if [ $# = 0 ]; then + # if no spec name passed, glob *.spec + set -- *.spec + if [ ! -f "$1" -o $# -gt 1 ]; then + echo >&2 "ERROR: Too many or too few .spec files found" + echo >&2 "Usage: ${0##*/} PACKAGE.spec" + exit 1 + fi +else + # $1 must be spec, ensure it has .spec ext + spec=$1; shift + set -- ${spec%.spec}.spec "$@" +fi -tmp=$(awk '/^BuildArch:/ { print $NF}' $specfile) +tmp=$(specdump "$@" | awk '$2 == "_target_cpu" {print $3}') if [ "$tmp" ]; then TARGET="$tmp" fi -BCONDS=$(./builder -nn -ncs --show-bcond-args $specfile) - # just create the rpm's if -bb is somewhere in the args if [[ *$@* != *-bb* ]]; then rpmbuild -bi "$@" fi -rpmbuild -bb --define 'clean exit 0; %{nil}' "$@" +rpmbuild -bb "$@"