#!/bin/bash # Default "configure" args. They will be overridden with the contents of a # CONFIGURE_ARGS file in the source directory. CONFIGURE_ARGS="--enable-debug --enable-depend --enable-cassert --enable-nls --cache-file=/home/alvherre/tmp/pgconfig.@TREE@.cache --enable-thread-safety --with-python --with-perl --with-tcl --with-openssl --with-libxml" # The root directory, where everything lies. Defaults to $HOME/CVS/pgsql, # but can be changed by the PGROOT environment variable. ROOT=${PGROOT-/pgsql} # do we have a diff coloring utility? for prog in cdiff colordiff; do which $prog >/dev/null 2>/dev/null if [ $? == 0 ]; then # COLORDIFF=`which $prog` break fi done # If the first argument is "_commands", return the list of known commands if [ ! -z "$1" -a "$1" == '_commands' ]; then for i in config build install init server client check pcheck tags changelog rmderived update showdiff touchchanged edit; do echo $i done exit fi # If the argument is a file, its contents is the real target. Useful to have # a "default" build, pointing to whatever is the current development tree. if [ -f $ROOT/source/$1 ]; then DIR=`cat $ROOT/source/$1` else DIR=$1 fi SRCDIR=$ROOT/source/$DIR INSTDIR=$ROOT/install/$DIR BUILDDIR=$ROOT/build/$DIR PGDATADIR=$INSTDIR/data export LD_LIBRARY_PATH=$INSTDIR/lib if [ -z "$DIR" ]; then LIST=`cd "$SRCDIR" ; find . -maxdepth 1 -mindepth 1 -type d` echo "I need an argument -- one from:" for i in $LIST; do echo -n " "`basename $i` done | (fmt 2>&1 || true) echo "" exit fi PGPORT=$((55432+$(echo $BUILDDIR | sed -e 's/^[^0-9]*\([0-9]*\).*$/\1/' -e 's/^0*//' -e 's/^$/0/' ))) # Miscelaneous functions check_srcdir() { if [ ! -d $SRCDIR ]; then echo "The first argument must be a source directory" >&2 ls $ROOT/source >&2 exit fi } check_blddir() { if [ ! -d $BUILDDIR ]; then echo "The first argument must be a VPATH build directory" >&2 ls $ROOT/build >&2 exit fi } check_backend() { backend=$BUILDDIR/src/backend/postgres if [ ! -f $backend ]; then echo "The backend must exist at $backend" >&2 exit fi } check_instdir() { if [ ! -x $INSTDIR/bin/postmaster ]; then echo "$DIR debe ser un directorio de instalación" >&2 exit fi } runpg_config() { check_srcdir if [ -d $BUILDDIR ]; then echo -n "Desea eliminar $BUILDDIR (y/n)? " unset removed read answer if [ ! -z "$answer" ]; then if [ "$answer" = 's' -o "$answer" = 'y' ]; then rm -fr $BUILDDIR removed=t fi fi if [ -z "$removed" ]; then exit fi fi mkdir $BUILDDIR if [ -f $SRCDIR/CONFIGURE_ARGS ]; then CONFIGURE_ARGS=`cat $SRCDIR/CONFIGURE_ARGS` fi CONFIGURE_ARGS=${CONFIGURE_ARGS//@TREE@/$DIR} cd $BUILDDIR echo $SRCDIR/configure $CONFIGURE_ARGS --prefix=$INSTDIR --with-pgport=$PGPORT $SRCDIR/configure $CONFIGURE_ARGS --prefix=$INSTDIR --with-pgport=$PGPORT make -C src -s distprep cd "$OLDPWD" } runpg_build() { check_srcdir check_blddir cd $BUILDDIR LC_ALL=C make -j3 2>&1 >> $BUILDDIR/build.out | tee -a $BUILDDIR/build.err LC_ALL=C make -j3 -C contrib 2>&1 >> $BUILDDIR/build.out | tee -a $BUILDDIR/build.err cd "$OLDPWD" } runpg_install() { check_backend cd $BUILDDIR LC_ALL=C make -j3 install 2>&1 >> $BUILDDIR/build.out | tee -a $BUILDDIR/build.err LC_ALL=C make -j3 -C contrib install 2>&1 >> $BUILDDIR/build.out | tee -a $BUILDDIR/build.err cd "$OLDPWD" } # Select the action based on the parameters case "$2" in config) runpg_config exit $? ;; build) runpg_build exit $? ;; install) runpg_install exit $? ;; init) check_instdir rm -fr $PGDATADIR $INSTDIR/bin/initdb -D $PGDATADIR exit $? ;; server) check_instdir if [ ! -z $DISPLAY ]; then echo -ne "\033]0;$1 server\007" fi ulimit -c unlimited PGDATA=$PGDATADIR exec $INSTDIR/bin/postmaster exit ;; client) check_instdir export PATH=$INSTDIR/bin:$PATH export PGDATA=$PGDATADIR if [ ! -f $PGDATA/db_created ]; then createdb && createlang plpgsql && createlang plperl && createlang pltcl && createlang plpythonu && touch $PGDATA/db_created fi PGCMD=psql if [ ! -z "$DISPLAY" ]; then echo -ne "\033]0;$1 client\007" fi psql exit ;; check) check_instdir make -C $BUILDDIR/src/test/regress installcheck ;; contribcheck) check_instdir make -s -C $BUILDDIR/contrib installcheck ;; pcheck) check_instdir cd $BUILDDIR/src/test/regress make -C $BUILDDIR/src/test/regress installcheck-parallel ;; tags) check_srcdir cd "$SRCDIR" echo "getting file list for cscope ..." find $SRCDIR $BUILDDIR \( -name "*.[chly]" -o -iname "*makefile*" -o -name "*.mk" -o -name "*.in" -o -name "*.sgml" -o -name "*.sh" -o -name "*.sql" \) -type f > $SRCDIR/cscope.files echo "building cscope database ..." cscope -b echo "building tags file ..." ctags -R echo "done" ;; changelog) check_srcdir cd "$SRCDIR" if [ ! -d CVS ]; then echo "operation is valid only on CVS trees" 1>&2 exit -1 fi common_args="--revisions --no-indent --no-wrap --separate-header" branch_arg="" branch=$(cvs status configure.in | grep 'Sticky Tag' | awk '{print $3}') if [ $branch != "(none)" ]; then branch_arg="--follow $branch" fi if [ ! -f ChangeLog ]; then cvs2cl $common_args $branch_arg else cvs2cl $common_args $branch_arg --accum fi ;; rmderived) check_srcdir cd "$SRCDIR" find . -name .cvsignore | while read line do dir=$(dirname $line) cd $dir rm -fv `cat .cvsignore` cd "$OLDPWD" done ;; update) check_srcdir cd "$SRCDIR" if [ -d CVS ]; then cvs update -Pd elif [ -d .svn ]; then svn update elif [ -d .git ]; then echo "not supported for git trees" >&2 exit -1 fi ;; showdiff) check_srcdir cd "$SRCDIR" if [ ! -z "$COLORDIFF" ]; then pipe="$COLORDIFF" else pipe=cat fi if [ -d CVS ]; then cvs -q diff | $pipe | less -r elif [ -d .svn ]; then svn diff | $pipe | less -r elif [ -d .git ]; then git diff fi ;; touchchanged) check_srcdir cd "$SRCDIR" if [ -d CVS ]; then cvs -q diff | grep ^Index | cut -d" " -f2 | xargs touch elif [ -d .svn ]; then svn diff | grep ^Index | cut -d" " -f2 | xargs touch fi ;; edit) check_srcdir cd "$SRCDIR" vi -g & ;; *) check_instdir echo "export PATH=$INSTDIR/bin:$PATH" echo "export MANPATH=$INSTDIR/share/man" echo "export PGDATA=`echo $PGDATADIR`" echo "export PGPORT=$PGPORT" echo "export PGLIBS=$INSTDIR/lib" echo "export PGINCLUDE=$INSTDIR/include" ;; esac