pg_buildext 4.04 KB
Newer Older
1
#!/bin/sh
2
#
3
# build a PostgreSQL module based on PGXS for given list of supported major
4 5
# versions
#
6 7 8 9 10 11 12 13 14 15 16 17
# (C) 2010 Dimitri Fontaine <dfontaine@hi-media.com>
# (C) 2011-2013 Christoph Berg <myon@debian.org>
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
18

19 20
set -e

21
action="$1"
22 23 24 25 26 27 28 29
if [ -d "$2" ]; then # compat mode: $2 is source directory
    srcdir="$2"
    shift
else
    srcdir="$PWD"
fi
target="$2"
opt="$3"
30

31 32 33 34 35
die() {
    echo "`basename $0`: error: $*" >&2
    exit 1
}

36
prepare_env() {
37
    version=$1
38
    vtarget=`echo $target | sed -e "s:%v:$version:g"`
39
    pgc="/usr/lib/postgresql/$version/bin/pg_config"
40
    [ -e "$pgc" ] || die "$pgc does not exist"
41 42 43 44 45 46 47 48
}

configure() {
    prepare_env $1
    confopts=`echo $opt | sed -e "s:%v:$version:g"`

    mkdir -p $vtarget
    ( echo "calling configure in $vtarget" &&
49
      cd $vtarget && $srcdir/configure $confopts DESTDIR="$srcdir/debian/$package" PG_CONFIG="$pgc" VPATH="$srcdir" )
50 51
}

52
build() {
53
    prepare_env $1
54
    cflags="`$pgc --cflags` `echo $opt | sed -e "s:%v:$version:g"`"
55 56

    mkdir -p $vtarget
57 58
    # if a Makefile was created by configure, use it, else the top level Makefile
    [ -f $vtarget/Makefile ] || makefile="-f $srcdir/Makefile"
59
    make -C $vtarget $makefile CFLAGS="$cflags" DESTDIR="$srcdir/debian/$package" PG_CONFIG="$pgc" VPATH="$srcdir" srcdir="$srcdir" USE_PGXS=1
60 61 62 63 64 65 66 67 68
}

install() {
    prepare_env $1
    package=`echo $opt | sed -e "s:%v:$version:g"`

    mkdir -p $vtarget
    # if a Makefile was created by configure, use it, else the top level Makefile
    [ -f $vtarget/Makefile ] || makefile="-f $srcdir/Makefile"
69
    make -C $vtarget $makefile install DESTDIR="$srcdir/debian/$package" PG_CONFIG="$pgc" VPATH="$srcdir" srcdir="$srcdir" USE_PGXS=1
70 71
}

72
clean() {
73
    prepare_env $1
74 75 76

    # if a Makefile was created by configure, use it, else the top level Makefile
    [ -f $vtarget/Makefile ] || makefile="-f $srcdir/Makefile"
77
    [ -d $vtarget ] && make -C $vtarget clean $makefile DESTDIR="$srcdir/debian/$package" PG_CONFIG="$pgc" VPATH="$srcdir" srcdir="$srcdir" USE_PGXS=1
78 79 80
    rm -rf $vtarget
}

81 82 83 84 85 86 87 88 89 90 91 92 93 94
loop() {
    echo "### $1 ###"
    prepare_env $1
    package=$(echo $target | sed -e "s:%v:$version:g")

    echo "# $1: make clean"
    make clean            DESTDIR="$PWD/debian/$package" PG_CONFIG="$pgc" USE_PGXS=1
    echo "# $1: make"
    make CFLAGS="$cflags" DESTDIR="$PWD/debian/$package" PG_CONFIG="$pgc" USE_PGXS=1
    echo "# $1: make install"
    make install          DESTDIR="$PWD/debian/$package" PG_CONFIG="$pgc" USE_PGXS=1
    echo "### done $1 ###"
}

95
versions() {
96 97
    [ -e /usr/share/postgresql-common/supported-versions ] ||
	die "/usr/share/postgresql-common/supported-versions not found"
98
    [ -e debian/pgversions ] || die "debian/pgversions not found"
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
    supported_versions=$(/usr/share/postgresql-common/supported-versions)
    while read version; do
	case $version in
	    all) echo "$supported_versions" ;;
	    [1-9]*+)
		for sup_version in $supported_versions; do
		    if expr $(echo "$version" | tr -d +) '<=' $sup_version > /dev/null; then echo "$sup_version"; fi
		done ;;
	    [1-9]*)
		for sup_version in $supported_versions; do
		    if [ "$version" = "$sup_version" ]; then echo "$sup_version"; fi
		done ;;
	    '#'*) ;;
	    '') ;;
	    *) echo "Syntax error in debian/pgversions: $version" >&2 ;;
	esac
    done < debian/pgversions
116 117
}

118 119 120
VERSIONS=`versions`

for v in $VERSIONS
121 122 123 124 125 126
do
    case "$action" in
	"supported-versions")
	    echo $v
	    ;;

127
	configure|build|install|clean|loop)
128
	    [ "$target" ] || die "syntax: pg_buildext $action <srcdir> <target> ..."
129 130 131 132 133
	    # be verbose?
	    $action $v
	    ;;

	*)
134
	    die "unsupported $action."
135 136 137
	    ;;
    esac
done