dev-db/sqlite: stable 3.24.0 for ppc, bug #664304
[gentoo.git] / dev-db / sqlite / sqlite-3.24.0.ebuild
1 # Copyright 1999-2018 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI="6"
5
6 inherit autotools eutils flag-o-matic multilib multilib-minimal toolchain-funcs versionator
7
8 SRC_PV="$(printf "%u%02u%02u%02u" $(get_version_components))"
9 DOC_PV="${SRC_PV}"
10 # DOC_PV="$(printf "%u%02u%02u00" $(get_version_components $(get_version_component_range 1-3)))"
11
12 DESCRIPTION="SQL database engine"
13 HOMEPAGE="https://sqlite.org/"
14 SRC_URI="doc? ( https://sqlite.org/2018/${PN}-doc-${DOC_PV}.zip )
15         tcl? ( https://sqlite.org/2018/${PN}-src-${SRC_PV}.zip )
16         test? ( https://sqlite.org/2018/${PN}-src-${SRC_PV}.zip )
17         tools? ( https://sqlite.org/2018/${PN}-src-${SRC_PV}.zip )
18         !tcl? ( !test? ( !tools? ( https://sqlite.org/2018/${PN}-autoconf-${SRC_PV}.tar.gz ) ) )"
19
20 LICENSE="public-domain"
21 SLOT="3"
22 KEYWORDS="~alpha amd64 ~arm arm64 ~hppa ia64 ~m68k ~mips ppc ~ppc64 ~s390 ~sh sparc x86 ~ppc-aix ~x64-cygwin ~amd64-fbsd ~x86-fbsd ~amd64-linux ~arm-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos ~m68k-mint ~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris"
23 IUSE="debug doc icu +readline secure-delete static-libs tcl test tools"
24
25 RDEPEND="sys-libs/zlib:0=[${MULTILIB_USEDEP}]
26         icu? ( dev-libs/icu:0=[${MULTILIB_USEDEP}] )
27         readline? ( sys-libs/readline:0=[${MULTILIB_USEDEP}] )
28         tcl? ( dev-lang/tcl:0=[${MULTILIB_USEDEP}] )
29         tools? ( dev-lang/tcl:0=[${MULTILIB_USEDEP}] )"
30 DEPEND="${RDEPEND}
31         doc? ( app-arch/unzip )
32         tcl? ( app-arch/unzip )
33         test? (
34                 app-arch/unzip
35                 >=dev-lang/tcl-8.6:0[${MULTILIB_USEDEP}]
36         )
37         tools? ( app-arch/unzip )"
38
39 full_archive() {
40         use tcl || use test || use tools
41 }
42
43 pkg_setup() {
44         if full_archive; then
45                 S="${WORKDIR}/${PN}-src-${SRC_PV}"
46         else
47                 S="${WORKDIR}/${PN}-autoconf-${SRC_PV}"
48         fi
49 }
50
51 src_prepare() {
52         if full_archive; then
53                 eapply "${FILESDIR}/${PN}-3.24.0-full_archive-build.patch"
54                 eapply "${FILESDIR}/${PN}-3.24.0-full_archive-archive_command_paths_handling.patch"
55
56                 eapply_user
57
58                 # Fix AC_CHECK_FUNCS.
59                 # https://mailinglists.sqlite.org/cgi-bin/mailman/private/sqlite-dev/2016-March/002762.html
60                 sed -e "s/AC_CHECK_FUNCS(.*)/AC_CHECK_FUNCS([fdatasync fullfsync gmtime_r isnan localtime_r localtime_s malloc_usable_size posix_fallocate pread pread64 pwrite pwrite64 strchrnul usleep utime])/" -i configure.ac || die "sed failed"
61         else
62                 eapply "${FILESDIR}/${PN}-3.21.0-nonfull_archive-build.patch"
63                 eapply "${FILESDIR}/${PN}-3.24.0-nonfull_archive-archive_command_paths_handling.patch"
64
65                 eapply_user
66
67                 # Fix AC_CHECK_FUNCS.
68                 # https://mailinglists.sqlite.org/cgi-bin/mailman/private/sqlite-dev/2016-March/002762.html
69                 sed \
70                         -e "s/AC_CHECK_FUNCS(\[fdatasync.*/AC_CHECK_FUNCS([fdatasync fullfsync gmtime_r isnan localtime_r localtime_s malloc_usable_size posix_fallocate pread pread64 pwrite pwrite64 strchrnul usleep utime])/" \
71                         -e "/AC_CHECK_FUNCS(posix_fallocate)/d" \
72                         -i configure.ac || die "sed failed"
73         fi
74
75         eautoreconf
76
77         multilib_copy_sources
78 }
79
80 multilib_src_configure() {
81         local CPPFLAGS="${CPPFLAGS}" CFLAGS="${CFLAGS}" options=()
82
83         options+=(
84                 --enable-$(full_archive && echo load-extension || echo dynamic-extensions)
85                 --enable-threadsafe
86         )
87         if ! full_archive; then
88                 options+=(--disable-static-shell)
89         fi
90
91         # Support detection of misuse of SQLite API.
92         # https://sqlite.org/compile.html#enable_api_armor
93         append-cppflags -DSQLITE_ENABLE_API_ARMOR
94
95         # Support column metadata functions.
96         # https://sqlite.org/c3ref/column_database_name.html
97         append-cppflags -DSQLITE_ENABLE_COLUMN_METADATA
98
99         # Support sqlite_dbpage virtual table.
100         # https://sqlite.org/compile.html#enable_dbpage_vtab
101         append-cppflags -DSQLITE_ENABLE_DBPAGE_VTAB
102
103         # Support dbstat virtual table.
104         # https://sqlite.org/dbstat.html
105         append-cppflags -DSQLITE_ENABLE_DBSTAT_VTAB
106
107         # Support sqlite3_serialize() and sqlite3_deserialize() functions.
108         # https://sqlite.org/compile.html#enable_deserialize
109         # https://sqlite.org/c3ref/serialize.html
110         # https://sqlite.org/c3ref/deserialize.html
111         append-cppflags -DSQLITE_ENABLE_DESERIALIZE
112
113         # Support comments in output of EXPLAIN.
114         # https://sqlite.org/compile.html#enable_explain_comments
115         append-cppflags -DSQLITE_ENABLE_EXPLAIN_COMMENTS
116
117         # Support Full-Text Search versions 3, 4 and 5.
118         # https://sqlite.org/fts3.html
119         # https://sqlite.org/fts5.html
120         append-cppflags -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_FTS4
121         options+=(--enable-fts5)
122
123         # Support hidden columns.
124         append-cppflags -DSQLITE_ENABLE_HIDDEN_COLUMNS
125
126         # Support JSON1 extension.
127         # https://sqlite.org/json1.html
128         append-cppflags -DSQLITE_ENABLE_JSON1
129
130         # Support memsys5 memory allocator.
131         # https://sqlite.org/malloc.html#memsys5
132         append-cppflags -DSQLITE_ENABLE_MEMSYS5
133
134         # Support sqlite_offset() function.
135         # https://sqlite.org/lang_corefunc.html#sqlite_offset
136         append-cppflags -DSQLITE_ENABLE_OFFSET_SQL_FUNC
137
138         # Support pre-update hook functions.
139         # https://sqlite.org/c3ref/preupdate_count.html
140         append-cppflags -DSQLITE_ENABLE_PREUPDATE_HOOK
141
142         # Support Resumable Bulk Update extension.
143         # https://sqlite.org/rbu.html
144         append-cppflags -DSQLITE_ENABLE_RBU
145
146         # Support R*Trees.
147         # https://sqlite.org/rtree.html
148         append-cppflags -DSQLITE_ENABLE_RTREE
149
150         # Support scan status functions.
151         # https://sqlite.org/c3ref/stmt_scanstatus.html
152         # https://sqlite.org/c3ref/stmt_scanstatus_reset.html
153         append-cppflags -DSQLITE_ENABLE_STMT_SCANSTATUS
154
155         # Support sqlite_stmt virtual table.
156         # https://sqlite.org/stmt.html
157         append-cppflags -DSQLITE_ENABLE_STMTVTAB
158
159         # Support Session extension.
160         # https://sqlite.org/sessionintro.html
161         options+=(--enable-session)
162
163         # Support unknown() function.
164         # https://sqlite.org/compile.html#enable_unknown_sql_function
165         append-cppflags -DSQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
166
167         # Support unlock notification.
168         # https://sqlite.org/unlock_notify.html
169         append-cppflags -DSQLITE_ENABLE_UNLOCK_NOTIFY
170
171         # Support LIMIT and ORDER BY clauses on DELETE and UPDATE statements.
172         # https://sqlite.org/compile.html#enable_update_delete_limit
173         append-cppflags -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT
174
175         # Support PRAGMA function_list, PRAGMA module_list and PRAGMA pragma_list statements.
176         # https://sqlite.org/pragma.html#pragma_function_list
177         # https://sqlite.org/pragma.html#pragma_module_list
178         # https://sqlite.org/pragma.html#pragma_pragma_list
179         append-cppflags -DSQLITE_INTROSPECTION_PRAGMAS
180
181         # Support soundex() function.
182         # https://sqlite.org/lang_corefunc.html#soundex
183         append-cppflags -DSQLITE_SOUNDEX
184
185         # debug USE flag.
186         if full_archive; then
187                 options+=($(use_enable debug))
188         else
189                 if use debug; then
190                         append-cppflags -DSQLITE_DEBUG
191                 else
192                         append-cppflags -DNDEBUG
193                 fi
194         fi
195
196         # icu USE flag.
197         if use icu; then
198                 # Support ICU extension.
199                 # https://sqlite.org/compile.html#enable_icu
200                 append-cppflags -DSQLITE_ENABLE_ICU
201                 if full_archive; then
202                         sed -e "s/^TLIBS = @LIBS@/& -licui18n -licuuc/" -i Makefile.in || die "sed failed"
203                 else
204                         sed -e "s/^LIBS = @LIBS@/& -licui18n -licuuc/" -i Makefile.in || die "sed failed"
205                 fi
206         fi
207
208         # readline USE flag.
209         options+=(
210                 --disable-editline
211                 $(use_enable readline)
212         )
213         if full_archive && use readline; then
214                 options+=(--with-readline-inc="-I${EPREFIX}/usr/include/readline")
215         fi
216
217         # secure-delete USE flag.
218         if use secure-delete; then
219                 # Enable secure_delete pragma by default.
220                 # https://sqlite.org/pragma.html#pragma_secure_delete
221                 append-cppflags -DSQLITE_SECURE_DELETE
222         fi
223
224         # static-libs USE flag.
225         options+=($(use_enable static-libs static))
226
227         # tcl, test, tools USE flags.
228         if full_archive; then
229                 options+=(--enable-tcl)
230         fi
231
232         if [[ "${CHOST}" == *-mint* ]]; then
233                 append-cppflags -DSQLITE_OMIT_WAL
234         fi
235
236         if [[ "${ABI}" == "x86" ]]; then
237                 if $(tc-getCC) ${CPPFLAGS} ${CFLAGS} -E -P -dM - < /dev/null 2> /dev/null | grep -q "^#define __SSE__ 1$"; then
238                         append-cflags -mfpmath=sse
239                 else
240                         append-cflags -ffloat-store
241                 fi
242         fi
243
244         econf "${options[@]}"
245 }
246
247 multilib_src_compile() {
248         emake HAVE_TCL="$(usex tcl 1 "")" TCLLIBDIR="${EPREFIX}/usr/$(get_libdir)/${P}"
249
250         if use tools && multilib_is_native_abi; then
251                 emake changeset dbdump dbhash rbu scrub showdb showjournal showshm showstat4 showwal sqldiff sqlite3_analyzer sqlite3_checker sqlite3_expert sqltclsh
252         fi
253 }
254
255 multilib_src_test() {
256         if [[ "${EUID}" -eq 0 ]]; then
257                 ewarn "Skipping tests due to root permissions"
258                 return
259         fi
260
261         emake HAVE_TCL="$(usex tcl 1 "")" $(use debug && echo fulltest || echo test)
262 }
263
264 multilib_src_install() {
265         emake DESTDIR="${D}" HAVE_TCL="$(usex tcl 1 "")" TCLLIBDIR="${EPREFIX}/usr/$(get_libdir)/${P}" install
266
267         if use tools && multilib_is_native_abi; then
268                 install_tool() {
269                         if [[ -f ".libs/${1}" ]]; then
270                                 newbin ".libs/${1}" "${2}"
271                         else
272                                 newbin "${1}" "${2}"
273                         fi
274                 }
275
276                 install_tool changeset sqlite3-changeset
277                 install_tool dbdump sqlite3-db-dump
278                 install_tool dbhash sqlite3-db-hash
279                 install_tool rbu sqlite3-rbu
280                 install_tool scrub sqlite3-scrub
281                 install_tool showdb sqlite3-show-db
282                 install_tool showjournal sqlite3-show-journal
283                 install_tool showshm sqlite3-show-shm
284                 install_tool showstat4 sqlite3-show-stat4
285                 install_tool showwal sqlite3-show-wal
286                 install_tool sqldiff sqlite3-diff
287                 install_tool sqlite3_analyzer sqlite3-analyzer
288                 install_tool sqlite3_checker sqlite3-checker
289                 install_tool sqlite3_expert sqlite3-expert
290                 install_tool sqltclsh sqlite3-tclsh
291
292                 unset -f install_tool
293         fi
294 }
295
296 multilib_src_install_all() {
297         prune_libtool_files
298
299         doman sqlite3.1
300
301         if use doc; then
302                 rm "${WORKDIR}/${PN}-doc-${DOC_PV}/"*.{db,txt}
303                 (
304                         docinto html
305                         dodoc -r "${WORKDIR}/${PN}-doc-${DOC_PV}/"*
306                 )
307         fi
308 }