1#! /bin/sh
2
3# This script prepares a PostgreSQL build tree.  It is intended
4# to be run by the configure script.
5
6me=`basename $0`
7
8help="\
9Usage: $me sourcetree [buildtree]"
10
11if test -z "$1"; then
12    echo "$help" 1>&2
13    exit 1
14elif test x"$1" = x"--help"; then
15    echo "$help"
16    exit 0
17fi
18
19unset CDPATH
20
21sourcetree=`cd $1 && pwd`
22
23buildtree=`cd ${2:-'.'} && pwd`
24
25# We must not auto-create the subdirectories holding built documentation.
26# If we did, it would interfere with installation of prebuilt docs from
27# the source tree, if a VPATH build is done from a distribution tarball.
28# See bug #5595.
29for item in `find "$sourcetree" -type d \( \( -name CVS -prune \) -o \( -name .git -prune \) -o -print \) | grep -v "$sourcetree/doc/src/sgml/\+"`; do
30    subdir=`expr "$item" : "$sourcetree\(.*\)"`
31    if test ! -d "$buildtree/$subdir"; then
32        mkdir -p "$buildtree/$subdir" || exit 1
33    fi
34done
35
36for item in `find "$sourcetree" -name Makefile -print -o -name GNUmakefile -print`; do
37    filename=`expr "$item" : "$sourcetree\(.*\)"`
38    if test ! -f "${item}.in"; then
39        if cmp "$item" "$buildtree/$filename" >/dev/null 2>&1; then : ; else
40            ln -fs "$item" "$buildtree/$filename" || exit 1
41        fi
42    fi
43done
44
45exit 0
46