Merge remote-tracking branch 'github/pr/527'.
[gentoo.git] / dev-db / sqlite / sqlite-3.8.10.2.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
58                 # http://www.sqlite.org/cgi/src/info/85bfa9a67f997084
59                 sed \
60                         -e "s/^sqlite3_SOURCES = shell.c sqlite3.h$/sqlite3_SOURCES = shell.c sqlite3.c sqlite3.h/" \
61                         -e "s/^sqlite3_LDADD = sqlite3.\$(OBJEXT) @READLINE_LIBS@$/sqlite3_LDADD = @READLINE_LIBS@\nsqlite3_CFLAGS = \$(AM_CFLAGS)/" \
62                         -i Makefile.am
63         else
64                 epatch "${FILESDIR}/${PN}-3.8.1-src-dlopen_check.patch"
65                 epatch "${FILESDIR}/${PN}-3.8.1-tests-icu-52.patch"
66
67                 # Fix shell1-5.0 test.
68                 # http://mailinglists.sqlite.org/cgi-bin/mailman/private/sqlite-dev/2015-May/002575.html
69                 sed -e "/if {\$i==0x0D /s/\$i==0x0D /&|| (\$i>=0xE0 \&\& \$i<=0xEF) /" -i test/shell1.test
70         fi
71
72         eautoreconf
73
74         # At least ppc-aix, x86-interix and *-solaris need newer libtool.
75         # use prefix && eautoreconf
76
77         if use icu; then
78                 if amalgamation; then
79                         sed -e "s/LIBS = @LIBS@/& -licui18n -licuuc/" -i Makefile.in || die "sed failed"
80                 else
81                         sed -e "s/TLIBS = @LIBS@/& -licui18n -licuuc/" -i Makefile.in || die "sed failed"
82                 fi
83         fi
84
85         multilib_copy_sources
86 }
87
88 src_configure() {
89         # `configure` from amalgamation tarball does not add -DSQLITE_DEBUG or -DNDEBUG flag.
90         if amalgamation; then
91                 if use debug; then
92                         append-cppflags -DSQLITE_DEBUG
93                 else
94                         append-cppflags -DNDEBUG
95                 fi
96         fi
97
98         # Support detection of misuse of SQLite API.
99         # http://sqlite.org/compile.html#enable_api_armor
100         append-cppflags -DSQLITE_ENABLE_API_ARMOR
101
102         # Support column metadata functions.
103         # http://sqlite.org/c3ref/column_database_name.html
104         append-cppflags -DSQLITE_ENABLE_COLUMN_METADATA
105
106         # Support dbstat virtual table.
107         # http://sqlite.org/dbstat.html
108         append-cppflags -DSQLITE_ENABLE_DBSTAT_VTAB
109
110         # Support Full-Text Search versions 3 and 4.
111         # http://sqlite.org/fts3.html
112         append-cppflags -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_FTS4
113
114         # Support R*Trees.
115         # http://sqlite.org/rtree.html
116         append-cppflags -DSQLITE_ENABLE_RTREE
117
118         # Support scan status functions.
119         # http://sqlite.org/c3ref/stmt_scanstatus.html
120         # http://sqlite.org/c3ref/stmt_scanstatus_reset.html
121         append-cppflags -DSQLITE_ENABLE_STMT_SCANSTATUS
122
123         # Support unlock notification.
124         # http://sqlite.org/unlock_notify.html
125         append-cppflags -DSQLITE_ENABLE_UNLOCK_NOTIFY
126
127         # Support soundex() function.
128         # http://sqlite.org/lang_corefunc.html#soundex
129         append-cppflags -DSQLITE_SOUNDEX
130
131         if use icu; then
132                 # Support ICU extension.
133                 # http://sqlite.org/compile.html#enable_icu
134                 append-cppflags -DSQLITE_ENABLE_ICU
135         fi
136
137         if use secure-delete; then
138                 # Enable secure_delete pragma by default.
139                 # http://sqlite.org/pragma.html#pragma_secure_delete
140                 append-cppflags -DSQLITE_SECURE_DELETE
141         fi
142
143         if [[ "${CHOST}" == *-mint* ]]; then
144                 append-cppflags -DSQLITE_OMIT_WAL
145         fi
146
147         # Use pread(), pread64(), pwrite(), pwrite64() functions for better performance if they are available.
148         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
149                 append-cppflags -DUSE_PREAD
150         fi
151         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
152                 append-cppflags -DUSE_PREAD64
153         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
154                 append-cppflags -DUSE_PREAD64 -D_LARGEFILE64_SOURCE
155         fi
156
157         multilib-minimal_src_configure
158 }
159
160 multilib_src_configure() {
161         # `configure` from amalgamation tarball does not support
162         # --with-readline-inc and --(enable|disable)-tcl options.
163         econf \
164                 --enable-$(amalgamation && echo dynamic-extensions || echo load-extension) \
165                 --enable-threadsafe \
166                 $(use_enable readline) \
167                 $(use_enable static-libs static) \
168                 $(amalgamation || echo --with-readline-inc="-I${EPREFIX}/usr/include/readline") \
169                 $(amalgamation || use_enable debug) \
170                 $(amalgamation || if use tcl || use test; then echo --enable-tcl; else echo --disable-tcl; fi)
171 }
172
173 multilib_src_compile() {
174         emake TCLLIBDIR="${EPREFIX}/usr/$(get_libdir)/${P}"
175
176         if use tools && multilib_is_native_abi; then
177                 emake showdb showjournal showstat4 showwal sqldiff
178         fi
179 }
180
181 multilib_src_test() {
182         if [[ "${EUID}" -eq 0 ]]; then
183                 ewarn "Skipping tests due to root permissions"
184                 return
185         fi
186
187         emake $(use debug && echo fulltest || echo test)
188 }
189
190 multilib_src_install() {
191         emake DESTDIR="${D}" HAVE_TCL="$(usex tcl 1 "")" TCLLIBDIR="${EPREFIX}/usr/$(get_libdir)/${P}" install
192
193         if use tools && multilib_is_native_abi; then
194                 newbin showdb sqlite3-show-db
195                 newbin showjournal sqlite3-show-journal
196                 newbin showstat4 sqlite3-show-stat4
197                 newbin showwal sqlite3-show-wal
198                 newbin sqldiff sqlite3-diff
199         fi
200 }
201
202 multilib_src_install_all() {
203         prune_libtool_files
204
205         doman sqlite3.1
206
207         if use doc; then
208                 dohtml -A ico,odg,pdf,svg -r "${WORKDIR}/${PN}-doc-${DOC_PV}/"
209         fi
210 }