1SUMMARY = "PostgreSQL is a powerful, open source relational database system."
2DESCRIPTION = "\
3    PostgreSQL is an advanced Object-Relational database management system \
4    (DBMS) that supports almost all SQL constructs (including \
5    transactions, subselects and user-defined types and functions). The \
6    postgresql package includes the client programs and libraries that \
7    you'll need to access a PostgreSQL DBMS server.  These PostgreSQL \
8    client programs are programs that directly manipulate the internal \
9    structure of PostgreSQL databases on a PostgreSQL server. These client \
10    programs can be located on the same machine with the PostgreSQL \
11    server, or may be on a remote machine which accesses a PostgreSQL \
12    server over a network connection. This package contains the docs \
13    in HTML for the whole package, as well as command-line utilities for \
14    managing PostgreSQL databases on a PostgreSQL server. \
15    \
16    If you want to manipulate a PostgreSQL database on a local or remote \
17    PostgreSQL server, you need this package. You also need to install \
18    this package if you're installing the postgresql-server package. \
19"
20HOMEPAGE = "http://www.postgresql.com"
21LICENSE = "BSD-0-Clause"
22DEPENDS = "libnsl2 zlib readline tzcode-native"
23
24ARM_INSTRUCTION_SET = "arm"
25
26SRC_URI = "http://ftp.postgresql.org/pub/source/v${PV}/${BP}.tar.bz2 \
27    file://postgresql.init \
28    file://postgresql-profile \
29    file://postgresql.pam \
30    file://postgresql-setup \
31    file://postgresql.service \
32"
33
34LEAD_SONAME = "libpq.so"
35
36# LDFLAGS for shared libraries
37export LDFLAGS_SL = "${LDFLAGS}"
38
39inherit autotools pkgconfig perlnative python3native python3targetconfig useradd update-rc.d systemd gettext cpan-base
40
41CFLAGS += "-I${STAGING_INCDIR}/${PYTHON_DIR} -I${STAGING_INCDIR}/tcl8.6"
42
43SYSTEMD_SERVICE:${PN} = "postgresql.service"
44SYSTEMD_AUTO_ENABLE:${PN} = "disable"
45
46DEPENDS:append = " ${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'systemd-systemctl-native', '', d)}"
47pkg_postinst:${PN} () {
48    if ${@bb.utils.contains('DISTRO_FEATURES', 'systemd sysvinit', 'true', 'false', d)}; then
49        if [ -n "$D" ]; then
50            OPTS="--root=$D"
51        fi
52        systemctl $OPTS mask postgresql-server.service
53    fi
54}
55
56enable_pam = "${@bb.utils.filter('DISTRO_FEATURES', 'pam', d)}"
57PACKAGECONFIG ??= "${enable_pam} openssl python uuid libxml tcl nls libxml perl"
58PACKAGECONFIG[pam] = "--with-pam,--without-pam,libpam,"
59PACKAGECONFIG[openssl] = "--with-openssl,--without-openssl ac_cv_file__dev_urandom=yes,openssl,"
60PACKAGECONFIG[python] = "--with-python,--without-python,python3,python3"
61PACKAGECONFIG[uuid] = "--with-uuid=e2fs,--without-uuid,util-linux,"
62PACKAGECONFIG[tcl] = "--with-tcl --with-tclconfig=${STAGING_BINDIR_CROSS},--without-tcl,tcl tcl-native,"
63PACKAGECONFIG[nls] = "--enable-nls,--disable-nls,,"
64PACKAGECONFIG[libxml] = "--with-libxml,--without-libxml,libxml2,libxml2"
65PACKAGECONFIG[perl] = "--with-perl,--without-perl,perl,perl"
66
67EXTRA_OECONF += "--enable-thread-safety --disable-rpath \
68    --datadir=${datadir}/${BPN} \
69    --sysconfdir=${sysconfdir}/${BPN} \
70"
71EXTRA_OECONF:sh4 += "--disable-spinlocks"
72EXTRA_OECONF:aarch64 += "--disable-spinlocks"
73
74DEBUG_OPTIMIZATION:remove:mips = " -Og"
75DEBUG_OPTIMIZATION:append:mips = " -O"
76BUILD_OPTIMIZATION:remove:mips = " -Og"
77BUILD_OPTIMIZATION:append:mips = " -O"
78
79DEBUG_OPTIMIZATION:remove:mipsel = " -Og"
80DEBUG_OPTIMIZATION:append:mipsel = " -O"
81BUILD_OPTIMIZATION:remove:mipsel = " -Og"
82BUILD_OPTIMIZATION:append:mipsel = " -O"
83
84PACKAGES_DYNAMIC += "^${PN}-plperl \
85    ^${PN}-pltcl \
86    ^${PN}-plpython \
87"
88
89python populate_packages:prepend() {
90
91    def fill_more(name):
92        if name is None or name.strip() == "":
93            return
94
95        fpack=d.getVar('PACKAGES', False) or ""
96        fpack="${PN}-" + name + " " + fpack
97        d.setVar('PACKAGES', fpack)
98
99    conf=(d.getVar('PACKAGECONFIG') or "").split()
100    pack=d.getVar('PACKAGES', False) or ""
101    bb.debug(1, "PACKAGECONFIG=%s" % conf)
102    bb.debug(1, "PACKAGES1=%s" % pack )
103
104    if "perl" in conf :
105        fill_more("plperl")
106
107    if "tcl" in conf:
108        fill_more("pltcl")
109
110    if "python" in conf:
111        fill_more("plpython")
112
113    pack=d.getVar('PACKAGES') or ""
114    bb.debug(1, "PACKAGES2=%s" % pack)
115
116}
117
118# This will make native perl use target settings (for include dirs etc.)
119export PERLCONFIGTARGET = "${@is_target(d)}"
120export PERL_ARCHLIB = "${STAGING_LIBDIR}${PERL_OWN_DIR}/perl5/${@get_perl_version(d)}/${@get_perl_arch(d)}"
121
122do_configure() {
123    # do_configure
124    autotools_do_configure
125
126    # do_configure:append
127    # workaround perl package related bugs
128    sed -i -e "s:-L/usr/local/lib:-L=/usr/local/lib:g" \
129        ${B}/src/Makefile.global
130    LIBPNA="\${STAGING_LIBDIR_NATIVE}/perl-native"
131    LIBNA="\${STAGING_LIBDIR_NATIVE}"
132    BLIBNA="\${STAGING_BASE_LIBDIR_NATIVE}"
133    sed -i -e "/^perl_archlibexp/s:${LIBPNA}:${STAGING_LIBDIR}:g" \
134        ${B}/src/Makefile.global
135    sed -i -e "/^perl_privlibexp/s:${libdir}:${STAGING_LIBDIR}:g" \
136        ${B}/src/Makefile.global
137    # remove the rpath, replace with correct lib path
138    sed -i \
139        -e "/^perl_embed_ldflags/s:-Wl,-rpath,${LIBNA}::g" \
140        -e "/^perl_embed_ldflags/s:-Wl,-rpath,${BLIBNA}::g" \
141        -e "/^perl_embed_ldflags/s:-Wl,-rpath-link,${LIBNA}::g" \
142        -e "/^perl_embed_ldflags/s:-Wl,-rpath-link,${BLIBNA}::g" \
143        -e "/^perl_embed_ldflags/s:${LIBPNA}:${STAGING_LIBDIR}:g" \
144        -e "/^perl_embed_ldflags/s:${LIBNA}:${STAGING_LIBDIR}:g"  \
145        -e "/^perl_embed_ldflags/s:${BLIBNA}:${STAGING_BASELIBDIR}:g" \
146        -e "/^TCLSH/s:=.*:= ${bindir}/tclsh:g" \
147    ${B}/src/Makefile.global
148
149    if ${@bb.utils.contains('PACKAGECONFIG', 'perl', 'true', 'false', d)}; then
150        # workaround perl package's libperl.so problem
151        # we are using perlnative so this perl should have same version
152        perl_version=`perl -v 2>/dev/null | \
153            sed -n 's/This is perl.*v[a-z ]*\([0-9]\.[0-9][0-9.]*\).*$/\1/p'`
154        if [ ! -h "${STAGING_LIBDIR}/perl/$perl_version/CORE/libperl.so" -a \
155             ! -h "${STAGING_LIBDIR}/libperl.so" ]; then
156            ln -sf ../../../libperl.so.5 \
157                ${STAGING_LIBDIR}/perl/$perl_version/CORE/libperl.so
158        fi
159    fi
160}
161
162do_compile:append() {
163    oe_runmake -C contrib all
164}
165
166# server needs to configure user and group
167usernum = "28"
168groupnum = "28"
169USERADD_PACKAGES = "${PN}"
170USERADD_PARAM:${PN} = "-M -g postgres -o -r -d ${localstatedir}/lib/${BPN} \
171    -s /bin/sh -c 'PostgreSQL Server' -u ${usernum} postgres"
172GROUPADD_PARAM:${PN} = "-g ${groupnum} -o -r postgres"
173
174INITSCRIPT_PACKAGES = "${PN}"
175INITSCRIPT_NAME = "${BPN}-server"
176INITSCRIPT_PARAMS = "start 64 . stop 36 0 1 2 3 4 5 6 ."
177
178do_install:append() {
179    # install contrib
180    oe_runmake DESTDIR=${D} -C contrib install
181    # install tutorial
182    install -d -m 0755 ${D}${libdir}/${BPN}/tutorial
183    install ${B}/src/tutorial/* ${D}${libdir}/${BPN}/tutorial
184
185    # install COPYRIGHT README HISTORY
186    install -d -m 0755 ${D}${docdir}/${BPN}
187    for i in ${B}/COPYRIGHT ${B}/README ${B}/HISTORY ${B}/doc/KNOWN_BUGS ${B}/doc/MISSING_FEATURES ${B}/doc/README* ${B}/doc/bug.template; do
188        [ -f $i ] && install $i ${D}${docdir}/${BPN}
189    done
190
191    # install dirs and server init
192    install -d ${D}${sysconfdir}/init.d
193    install -m 0755 ${WORKDIR}/${BPN}.init ${D}${sysconfdir}/init.d/${BPN}-server
194    sed -i -e "s/^PGVERSION=.*$/PGVERSION=${PV}/g" ${D}${sysconfdir}/init.d/${BPN}-server
195    install -m 0755 ${WORKDIR}/${BPN}-setup ${D}${bindir}/${BPN}-setup
196    install -d -m 700 ${D}${localstatedir}/lib/${BPN}/data
197    install -d -m 700 ${D}${localstatedir}/lib/${BPN}/backups
198    install -m 644 ${WORKDIR}/${BPN}-profile ${D}${localstatedir}/lib/${BPN}/.profile
199    chown -R postgres:postgres ${D}${localstatedir}/lib/${BPN}
200    # multiple server config directory
201    install -d -m 700 ${D}${sysconfdir}/default/${BPN}
202
203    if [ "${@d.getVar('enable_pam')}" = "pam" ]; then
204        install -d ${D}${sysconfdir}/pam.d
205        install -m 644 ${WORKDIR}/postgresql.pam ${D}${sysconfdir}/pam.d/postgresql
206    fi
207
208    # Install systemd unit files
209    install -d ${D}${systemd_unitdir}/system
210    install -m 0644 ${WORKDIR}/postgresql.service ${D}${systemd_unitdir}/system
211    sed -i -e 's,@BINDIR@,${bindir},g' \
212        ${D}${systemd_unitdir}/system/postgresql.service
213}
214
215SSTATE_SCAN_FILES += "Makefile.global"
216SSTATE_SCAN_FILES:remove = "*_config"
217
218PACKAGES =+ "${PN}-client ${PN}-server-dev ${PN}-timezone \
219    libecpg-compat libecpg-compat-dev \
220    libecpg libecpg-dev libecpg-staticdev libecpg-doc \
221    libpq libpq-dev libpq-staticdev \
222    libpgtypes libpgtypes-staticdev libpgtypes-dev \
223    ${PN}-contrib \
224"
225
226RPROVIDES:${PN}-dbg += "libecpg-compat-dbg \
227                        libecpg-dbg \
228                        libpq-dbg \
229                        libpgtypes-dbg \
230                        ${PN}-contrib-dbg \
231                        ${PN}-pltcl-dbg \
232                        ${PN}-plpython-dbg \
233                        ${PN}-plperl-dbg \
234                       "
235
236FILES:${PN} += "${sysconfdir}/init.d/${BPN}-server \
237    ${localstatedir}/lib/${BPN}/data ${localstatedir}/lib/${BPN}/backups \
238    ${localstatedir}/lib/${BPN}/.profile ${sysconfdir}/default/${BPN} \
239    ${libdir}/${BPN}/dict_snowball.so ${libdir}/${BPN}/plpgsql.so \
240    ${libdir}/${BPN}/euc2004_sjis2004.so \
241    ${libdir}/${BPN}/libpqwalreceiver.so \
242    ${libdir}/${BPN}/*_and_*.so \
243    ${@'${sysconfdir}/pam.d/postgresql' \
244       if 'pam' == d.getVar('enable_pam') \
245       else ''} \
246"
247
248FILES:${PN}-client = "${bindir}/clusterdb \
249    ${bindir}/createdb \
250    ${bindir}/createuser \
251    ${bindir}/dropdb \
252    ${bindir}/dropuser \
253    ${bindir}/pg_dump \
254    ${bindir}/pg_dumpall \
255    ${bindir}/pg_restore \
256    ${bindir}/psql \
257    ${bindir}/reindexdb \
258    ${bindir}/vacuumdb \
259    ${bindir}/vacuumlo \
260    ${datadir}/${BPN}/psqlrc.sample \
261"
262FILES:${PN}-client-doc = "${mandir}/man1/clusterdb.* \
263    ${mandir}/man1/createdb.*   ${mandir}/man1/createlang.* \
264    ${mandir}/man1/createuser.* ${mandir}/man1/dropdb.* \
265    ${mandir}/man1/droplang.*   ${mandir}/man1/dropuser.* \
266    ${mandir}/man1/pg_dump.*    ${mandir}/man1/pg_dumpall.* \
267    ${mandir}/man1/pg_restore.* ${mandir}/man1/psql.* \
268    ${mandir}/man1/reindexdb.*  ${mandir}/man1/vacuumdb.* \
269    ${mandir}/man7/* \
270"
271FILES:${PN}-doc += "${docdir}/${BPN}/html ${libdir}/${BPN}/tutorial/ \
272    ${mandir}/man1/initdb.* ${mandir}/man1/pg_controldata.* \
273    ${mandir}/man1/pg_ctl.* ${mandir}/man1/pg_resetxlog.* \
274    ${mandir}/man1/postgres.* ${mandir}/man1/postmaster.* \
275"
276FILES:${PN}-timezone = "${datadir}/${BPN}/timezone \
277    ${datadir}/${BPN}/timezonesets \
278"
279RDEPENDS:${PN} += "${PN}-timezone"
280FILES:${PN}-server-dev = "${includedir}/${BPN}/server \
281                          ${libdir}/${BPN}/pgxs \
282"
283
284FILES:libecpg = "${libdir}/libecpg*${SOLIBS}"
285FILES:libecpg-dev = "${libdir}/libecpg*${SOLIBSDEV} \
286    ${libdir}/libpgtypes*${SOLIBSDEV} \
287    ${includedir}/ecpg*.h ${includedir}/${BPN}/ecpg*.h \
288    ${includedir}/pgtypes*.h ${includedir}/${BPN}/informix \
289    ${includedir}/sql3types.h ${includedir}/sqlca.h \
290"
291FILES:libecpg-doc = "${mandir}/man1/ecpg.*"
292FILES:libecpg-staticdev = "${libdir}/libecpg*.a"
293SECTION:libecpg-staticdev = "devel"
294RDEPENDS:libecpg-staticdev = "libecpg-dev (= ${EXTENDPKGV})"
295
296FILES:libpq = "${libdir}/libpq*${SOLIBS}"
297FILES:libpq-dev = "${libdir}/libpq*${SOLIBSDEV} \
298    ${includedir} \
299"
300FILES:libpq-staticdev = "${libdir}/libpq*.a ${libdir}/libpgport.a"
301SECTION:libpq-staticdev = "devel"
302RDEPENDS:libpq-staticdev = "libpq-dev (= ${EXTENDPKGV})"
303
304FILES:libecpg-compat = "${libdir}/libecpg_compat*${SOLIBS}"
305FILES:libecpg-compat-dev = "${libdir}/libecpg_compat*${SOLIBS}"
306FILES:libpgtypes = "${libdir}/libpgtypes*${SOLIBS}"
307FILES:libpgtypes-staticdev = "${libdir}/libpgtypes*.a"
308FILES:libpgtypes-dev = "${libdir}/libpgtypes*${SOLIBS} ${includedir}/pgtypes*.h"
309
310FILES:${PN}-contrib = " ${bindir}/oid2name ${bindir}/pg_standby \
311    ${bindir}/pgbench \
312    ${S}/contrib/spi/*.example \
313    ${libdir}/${BPN}/_int.so ${libdir}/${BPN}/adminpack.so \
314    ${libdir}/${BPN}/autoinc.so ${libdir}/${BPN}/auto_explain.so \
315    ${libdir}/${BPN}/auth_delay.so ${libdir}/${BPN}/btree_gin.so \
316    ${libdir}/${BPN}/btree_gist.so ${libdir}/${BPN}/.so \
317    ${libdir}/${BPN}/chkpass.so ${libdir}/${BPN}/citext.so \
318    ${libdir}/${BPN}/cube.so ${libdir}/${BPN}/dblink.so \
319    ${libdir}/${BPN}/dict_int.so ${libdir}/${BPN}/dict_xsyn.so \
320    ${libdir}/${BPN}/dummy_seclabel.so ${libdir}/${BPN}/earthdistance.so \
321    ${libdir}/${BPN}/file_fdw.so ${libdir}/${BPN}/fuzzystrmatch.so \
322    ${libdir}/${BPN}/hstore.so ${libdir}/${BPN}/insert_username.so \
323    ${libdir}/${BPN}/isn.so ${libdir}/${BPN}/lo.so \
324    ${libdir}/${BPN}/ltree.so ${libdir}/${BPN}/moddatetime.so \
325    ${libdir}/${BPN}/pageinspect.so ${libdir}/${BPN}/pg_buffercache.so \
326    ${libdir}/${BPN}/pg_freespacemap.so ${libdir}/${BPN}/pg_trgm.so \
327    ${libdir}/${BPN}/pgcrypto.so ${libdir}/${BPN}/pgrowlocks.so \
328    ${libdir}/${BPN}/pgstattuple.so ${libdir}/${BPN}/pg_stat_statements.so \
329    ${libdir}/${BPN}/refint.so ${libdir}/${BPN}/seg.so \
330    ${libdir}/${BPN}/sslinfo.so \
331    ${libdir}/${BPN}/tablefunc.so \
332    ${libdir}/${BPN}/test_parser.so ${libdir}/${BPN}/timetravel.so \
333    ${libdir}/${BPN}/uuid-ossp.so \
334    ${libdir}/${BPN}/pgxml.so ${libdir}/${BPN}/passwordcheck.so \
335    ${libdir}/${BPN}/pg_upgrade_support.so ${libdir}/${BPN}/.so \
336    ${libdir}/${BPN}/unaccent.so \
337"
338DESCRIPTION:${PN}-contrib = "The postgresql-contrib package contains \
339    contributed packages that are included in the PostgreSQL distribution."
340
341FILES:${PN}-pltcl = "${libdir}/${BPN}/pltcl.so ${bindir}/pltcl_delmod \
342    ${binddir}/pltcl_listmod ${bindir}/pltcl_loadmod  \
343    ${datadir}/${BPN}/unknown.pltcl"
344SUMMARY:${PN}-pltcl = "The Tcl procedural language for PostgreSQL"
345DESCRIPTION:${PN}-pltcl = "PostgreSQL is an advanced Object-Relational \
346    database management system.  The postgresql-pltcl package contains the PL/Tcl \
347    procedural language for the backend."
348
349FILES:${PN}-plperl = "${libdir}/${BPN}/plperl.so"
350SUMMARY:${PN}-plperl = "The Perl procedural language for PostgreSQL"
351DESCRIPTION:${PN}-plperl = "PostgreSQL is an advanced Object-Relational \
352    database management system.  The postgresql-plperl package contains the \
353    PL/Perl procedural language for the backend."
354
355# In version 8, it will be plpython.so
356# In version 9, it might be plpython{2,3}.so depending on python2 or 3
357FILES:${PN}-plpython = "${libdir}/${BPN}/plpython*.so"
358SUMMARY:${PN}-plpython = "The Python procedural language for PostgreSQL"
359DESCRIPTION:${PN}-plpython = "PostgreSQL is an advanced Object-Relational \
360    database management system.  The postgresql-plpython package contains \
361    the PL/Python procedural language for the backend."
362