Merge remote-tracking branch 'github/pr/527'.
[gentoo.git] / dev-db / sqlite / sqlite-3.8.11.1.ebuild
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 EAPI="5"
6
7 inherit autotools eutils flag-o-matic multilib multilib-minimal toolchain-funcs versionator
8
9 SRC_PV="$(printf "%u%02u%02u%02u" $(get_version_components))"
10 DOC_PV="${SRC_PV}"
11 # DOC_PV="$(printf "%u%02u%02u00" $(get_version_components $(get_version_component_range 1-3)))"
12
13 DESCRIPTION="A SQL Database Engine in a C Library"
14 HOMEPAGE="http://sqlite.org/"
15 SRC_URI="doc? ( http://sqlite.org/2015/${PN}-doc-${DOC_PV}.zip )
16         tcl? ( http://sqlite.org/2015/${PN}-src-${SRC_PV}.zip )
17         test? ( http://sqlite.org/2015/${PN}-src-${SRC_PV}.zip )
18         tools? ( http://sqlite.org/2015/${PN}-src-${SRC_PV}.zip )
19         !tcl? ( !test? ( !tools? ( http://sqlite.org/2015/${PN}-autoconf-${SRC_PV}.tar.gz ) ) )"
20
21 LICENSE="public-domain"
22 SLOT="3"
23 KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~ppc-aix ~amd64-fbsd ~sparc-fbsd ~x86-fbsd ~x86-freebsd ~hppa-hpux ~ia64-hpux ~x86-interix ~amd64-linux ~arm-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos ~m68k-mint ~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris"
24 IUSE="debug doc icu +readline secure-delete static-libs tcl test tools"
25
26 RDEPEND="icu? ( dev-libs/icu:0=[${MULTILIB_USEDEP}] )
27         readline? ( sys-libs/readline:0=[${MULTILIB_USEDEP}] )
28         tcl? ( dev-lang/tcl:0=[${MULTILIB_USEDEP}] )
29         abi_x86_32? (
30                 !<=app-emulation/emul-linux-x86-baselibs-20131008-r14
31                 !app-emulation/emul-linux-x86-baselibs[-abi_x86_32(-)]
32         )"
33 DEPEND="${RDEPEND}
34         doc? ( app-arch/unzip )
35         tcl? ( app-arch/unzip )
36         test? (
37                 app-arch/unzip
38                 dev-lang/tcl:0[${MULTILIB_USEDEP}]
39         )
40         tools? ( dev-lang/tcl:0 )"
41
42 amalgamation() {
43         ! use tcl && ! use test && ! use tools
44 }
45
46 pkg_setup() {
47         if amalgamation; then
48                 S="${WORKDIR}/${PN}-autoconf-${SRC_PV}"
49         else
50                 S="${WORKDIR}/${PN}-src-${SRC_PV}"
51         fi
52 }
53
54 src_prepare() {
55         if amalgamation; then
56                 epatch "${FILESDIR}/${PN}-3.8.1-autoconf-dlopen_check.patch"
57         else
58                 epatch "${FILESDIR}/${PN}-3.8.1-src-dlopen_check.patch"
59
60                 # Fix shell1-5.0 test.
61                 # http://mailinglists.sqlite.org/cgi-bin/mailman/private/sqlite-dev/2015-May/002575.html
62                 sed -e "/if {\$i==0x0D /s/\$i==0x0D /&|| (\$i>=0xE0 \&\& \$i<=0xEF) /" -i test/shell1.test
63         fi
64
65         eautoreconf
66
67         # At least ppc-aix, x86-interix and *-solaris need newer libtool.
68         # use prefix && eautoreconf
69
70         # Fix building with Full-Text Search version 5.
71         sed \
72                 -e "/^LIBOBJS1 =/s/$/ fts5.lo/" \
73                 -e "s/\$(LIBOBJ) \$(TLIBS)/& -lm/" \
74                 -e "/^TESTFIXTURE_SRC1 =/s/$/ fts5.c/" \
75                 -e "s/\$(TESTFIXTURE_SRC) \$(LIBTCL) \$(TLIBS)/& -lm/" \
76                 -i Makefile.in || die "sed failed"
77
78         if use icu; then
79                 if amalgamation; then
80                         sed -e "s/LIBS = @LIBS@/& -licui18n -licuuc/" -i Makefile.in || die "sed failed"
81                 else
82                         sed -e "s/TLIBS = @LIBS@/& -licui18n -licuuc/" -i Makefile.in || die "sed failed"
83                 fi
84         fi
85
86         multilib_copy_sources
87 }
88
89 src_configure() {
90         # `configure` from amalgamation tarball does not add -DSQLITE_DEBUG or -DNDEBUG flag.
91         if amalgamation; then
92                 if use debug; then
93                         append-cppflags -DSQLITE_DEBUG
94                 else
95                         append-cppflags -DNDEBUG
96                 fi
97         fi
98
99         # Support detection of misuse of SQLite API.
100         # http://sqlite.org/compile.html#enable_api_armor
101         append-cppflags -DSQLITE_ENABLE_API_ARMOR
102
103         # Support column metadata functions.
104         # http://sqlite.org/c3ref/column_database_name.html
105         append-cppflags -DSQLITE_ENABLE_COLUMN_METADATA
106
107         # Support dbstat virtual table.
108         # http://sqlite.org/dbstat.html
109         append-cppflags -DSQLITE_ENABLE_DBSTAT_VTAB
110
111         # Support Full-Text Search versions 3, 4 and 5.
112         # http://sqlite.org/fts3.html
113         # http://sqlite.org/fts5.html
114         append-cppflags -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5
115
116         # Support Resumable Bulk Update extension.
117         # http://sqlite.org/rbu.html
118         append-cppflags -DSQLITE_ENABLE_RBU
119
120         # Support R*Trees.
121         # http://sqlite.org/rtree.html
122         append-cppflags -DSQLITE_ENABLE_RTREE
123
124         # Support scan status functions.
125         # http://sqlite.org/c3ref/stmt_scanstatus.html
126         # http://sqlite.org/c3ref/stmt_scanstatus_reset.html
127         append-cppflags -DSQLITE_ENABLE_STMT_SCANSTATUS
128
129         # Support unlock notification.
130         # http://sqlite.org/unlock_notify.html
131         append-cppflags -DSQLITE_ENABLE_UNLOCK_NOTIFY
132
133         # Support soundex() function.
134         # http://sqlite.org/lang_corefunc.html#soundex
135         append-cppflags -DSQLITE_SOUNDEX
136
137         if use icu; then
138                 # Support ICU extension.
139                 # http://sqlite.org/compile.html#enable_icu
140                 append-cppflags -DSQLITE_ENABLE_ICU
141         fi
142
143         if use secure-delete; then
144                 # Enable secure_delete pragma by default.
145                 # http://sqlite.org/pragma.html#pragma_secure_delete
146                 append-cppflags -DSQLITE_SECURE_DELETE
147         fi
148
149         if [[ "${CHOST}" == *-mint* ]]; then
150                 append-cppflags -DSQLITE_OMIT_WAL
151         fi
152
153         # Use pread(), pread64(), pwrite(), pwrite64() functions for better performance if they are available.
154         if $(tc-getCC) ${CPPFLAGS} ${CFLAGS} ${LDFLAGS} -Werror=implicit-function-declaration -x c - -o "${T}/pread_pwrite_test" <<< $'#include <unistd.h>\nint main()\n{\n  pread(0, NULL, 0, 0);\n  pwrite(0, NULL, 0, 0);\n  return 0;\n}' &> /dev/null; then
155                 append-cppflags -DUSE_PREAD
156         fi
157         if $(tc-getCC) ${CPPFLAGS} ${CFLAGS} ${LDFLAGS} -Werror=implicit-function-declaration -x c - -o "${T}/pread64_pwrite64_test" <<< $'#include <unistd.h>\nint main()\n{\n  pread64(0, NULL, 0, 0);\n  pwrite64(0, NULL, 0, 0);\n  return 0;\n}' &> /dev/null; then
158                 append-cppflags -DUSE_PREAD64
159         elif $(tc-getCC) ${CPPFLAGS} ${CFLAGS} ${LDFLAGS} -D_LARGEFILE64_SOURCE -Werror=implicit-function-declaration -x c - -o "${T}/pread64_pwrite64_test" <<< $'#include <unistd.h>\nint main()\n{\n  pread64(0, NULL, 0, 0);\n  pwrite64(0, NULL, 0, 0);\n  return 0;\n}' &> /dev/null; then
160                 append-cppflags -DUSE_PREAD64 -D_LARGEFILE64_SOURCE
161         fi
162
163         multilib-minimal_src_configure
164 }
165
166 multilib_src_configure() {
167         # `configure` from amalgamation tarball does not support
168         # --with-readline-inc and --(enable|disable)-tcl options.
169         econf \
170                 --enable-$(amalgamation && echo dynamic-extensions || echo load-extension) \
171                 --enable-threadsafe \
172                 $(use_enable readline) \
173                 $(use_enable static-libs static) \
174                 $(amalgamation || echo --with-readline-inc="-I${EPREFIX}/usr/include/readline") \
175                 $(amalgamation || use_enable debug) \
176                 $(amalgamation || if use tcl || use test; then echo --enable-tcl; else echo --disable-tcl; fi)
177 }
178
179 multilib_src_compile() {
180         emake TCLLIBDIR="${EPREFIX}/usr/$(get_libdir)/${P}"
181
182         if use tools && multilib_is_native_abi; then
183                 emake showdb showjournal showstat4 showwal sqldiff
184         fi
185 }
186
187 multilib_src_test() {
188         if [[ "${EUID}" -eq 0 ]]; then
189                 ewarn "Skipping tests due to root permissions"
190                 return
191         fi
192
193         emake $(use debug && echo fulltest || echo test)
194 }
195
196 multilib_src_install() {
197         emake DESTDIR="${D}" HAVE_TCL="$(usex tcl 1 "")" TCLLIBDIR="${EPREFIX}/usr/$(get_libdir)/${P}" install
198
199         if use tools && multilib_is_native_abi; then
200                 newbin showdb sqlite3-show-db
201                 newbin showjournal sqlite3-show-journal
202                 newbin showstat4 sqlite3-show-stat4
203                 newbin showwal sqlite3-show-wal
204                 newbin sqldiff sqlite3-diff
205         fi
206 }
207
208 multilib_src_install_all() {
209         prune_libtool_files
210
211         doman sqlite3.1
212
213         if use doc; then
214                 dohtml -A ico,odg,pdf,svg -r "${WORKDIR}/${PN}-doc-${DOC_PV}/"
215         fi
216 }