1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
AC_INIT([postgresql-setup], [0.9.2~beta], [praiskup@redhat.com])
AC_CONFIG_AUX_DIR(auxdir)
config_aux_dir=auxdir
AC_SUBST([config_aux_dir])
AM_INIT_AUTOMAKE([-Wall])
AC_CONFIG_FILES([Makefile doc/Makefile])
AM_SILENT_RULES([yes])
AC_ARG_VAR([DISTSUFF], [Append string suffix to all binaries])
AC_SUBST([DISTSUFF])
AC_PATH_PROG([SED], [sed])
test -z "$ac_cv_path_SED" &&
AC_MSG_ERROR([Sed is needed but not found.])
# For SELinux purposes use rather runuser
AC_PATH_PROG([SU], [runuser])
test -z "$ac_cv_path_SU" &&
AC_PATH_PROG([SU], [su])
test -z "$ac_cv_path_SU" &&
AC_MSG_ERROR([Neither 'runuser' nor 'su' program found])
distro_family=redhat
test -r /etc/redhat-release ||
AC_MSG_ERROR([This still works for Red Hat distributions only])
# Check package manager is installed
case "$distro_family" in
redhat)
AC_PATH_PROG([RPM], [rpm])
test -z "$ac_cv_path_RPM" &&
AC_MSG_ERROR([RPM package manager is required])
;;
esac
# Make sure that the variable is in './configure --help' output and that it is
# not empty.
m4_define([subst_required_var], [
AC_ARG_VAR([$1], [$2])
test -z "$[]$1" &&
AC_MSG_ERROR([the \$$1 variable is not set])
])
# Check for main PostgreSQL binaries
# ----------------------------------
AC_ARG_VAR([POSTGRES_BIN], [Full path to postgres binary. Note that based on
package ownership of this file the package names (like
postgresql-server, postgresql, ..) are detected.])
AC_PATH_PROG([POSTGRES_BIN], [postgres])
# Check for main PostgreSQL packages
# ----------------------------------
case "$distro_family" in
redhat)
rpm_pkgname_server=$(rpm -qf $POSTGRES_BIN --qf '%{NAME}')
rpm_pkgname=${rpm_pkgname_server%%-*}
;;
esac
AC_PATH_PROG([POSTGRES_BIN], [postgres])
# PGVERSION & PGMAJORVERSION
# --------------------------
if test -z "$PGVERSION" -a -z "$PGMAJORVERSION"; then
test -z "$ac_cv_path_POSTGRES_BIN" &&
AC_MSG_ERROR([no postgres binary, can not detect version])
AC_MSG_CHECKING([for full version PostgreSQL server])
raw_version=$("$POSTGRES_BIN" --version) ||
AC_MSG_ERROR([command $POSTGRES_BIN --version failed])
PGVERSION=${raw_version##* }
AC_MSG_RESULT($PGVERSION)
PGMAJORVERSION=${PGVERSION%%.[[0-9]]}
fi
# Detect PGENGINE location
# ------------------------
if test -z "$PGENGINE"; then
test -z "$ac_cv_path_POSTGRES_BIN" &&
AC_MSG_ERROR([no postgres binary, can not detect PGENGINE])
PGENGINE=`AS_DIRNAME($POSTGRES_BIN)`
fi
# Detect pg_ctl binary
# --------------------
test -z "$PG_CTL_BIN" &&
PG_CTL_BIN=$PGENGINE/pg_ctl
AC_SUBST([PG_CTL_BIN])
# pg_upgrade binary
# -----------------
AC_PATH_PROG([PG_UPGRADE_BIN], [pg_upgrade])
# Detect PREVMAJORVERSION
# -----------------------
# This sets as a side effect PREV_POSTGRES_BIN, which is used later on.
if test -z "$PREVMAJORVERSION"; then
case "$distro_family" in
redhat)
AC_MSG_CHECKING([for prev major version])
test -z "$ac_cv_path_PG_UPGRADE_BIN" &&
AC_MSG_ERROR([no pg_upgrade found])
PREV_POSTGRES_BIN=$(rpm -ql \
$(rpm -qf "$ac_cv_path_PG_UPGRADE_BIN") \
| grep 'bin/postgres' )
PREVMAJORVERSION=$(echo $PREV_POSTGRES_BIN \
| sed 's/.*postgresql-\([[0-9\.]]\+\).*/\1/')
AC_MSG_RESULT($PREVMAJORVERSION)
;;
esac
fi
# Detect PREVPGENGINE
# -------------------
if test -z "$PREVPGENGINE"; then
PREVPGENGINE=`AS_DIRNAME($PREV_POSTGRES_BIN)`
fi
# Detect where distribution-like README is
# ----------------------------------------
case "$distro_family" in
redhat)
test -z "$README_DIST" &&
README_DIST=`rpm -ql postgresql | grep README | grep dist`
;;
esac
if test -z "$PKGCONFIG_DIR" -a "$distro_family" = redhat; then
PKGCONFIG_DIR=/etc/postgresql
fi
if test -z "$POSTGRES_HOMEDIR" -a "$distro_family" = redhat; then
POSTGRES_HOMEDIR=/var/lib/pgsql
fi
if test -z "$PGDATADIR" -a "$distro_family" = redhat; then
PGDATADIR=/var/lib/pgsql/data
fi
pgdocdir="\${datarootdir}/doc/\${pkgname}"
pgcontribdocdir="\${datarootdir}/doc/\${pkgname}-contrib"
AC_SUBST([pgdocdir])
AC_SUBST([pgcontribdocdir])
# Deal with previous versions
subst_required_var([PGVERSION], [full PG version])
subst_required_var([PGMAJORVERSION], [major PG version])
subst_required_var([PGENGINE], [directory where PG server resides])
subst_required_var([PREVMAJORVERSION], [PG major version to upgrade _from_])
subst_required_var([PREVPGENGINE], [directory where old PG server resides])
subst_required_var([README_DIST], [README file for distribution])
subst_required_var([PKGCONFIG_DIR], [where configuration should be stored])
subst_required_var([POSTGRES_HOMEDIR], [full path to postgres home dir])
subst_required_var([PGDATADIR], [full path to postgres data dir])
AC_OUTPUT
|