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