1# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
2# vim: set filetype=python:
3# This Source Code Form is subject to the terms of the Mozilla Public
4# License, v. 2.0. If a copy of the MPL was not distributed with this
5# file, You can obtain one at http://mozilla.org/MPL/2.0/.
6NoVisibilityFlags()
7
8EXPORTS += [
9    'sqlite3.h',
10]
11
12# We allow warnings for third-party code that can be updated from upstream.
13AllowCompilerWarnings()
14
15if CONFIG['MOZ_FOLD_LIBS']:
16    # When folding libraries, sqlite is actually in the nss library.
17    FINAL_LIBRARY = 'nss'
18else:
19    # The final library is in config/external/sqlite
20    FINAL_LIBRARY = 'sqlite'
21
22SOURCES += [
23    'sqlite3.c',
24]
25
26# -DSQLITE_SECURE_DELETE=1 will cause SQLITE to 0-fill delete data so we
27# don't have to vacuum to make sure the data is not visible in the file.
28# -DSQLITE_ENABLE_FTS3=1 enables the full-text index module.
29# -DSQLITE_CORE=1 statically links that module into the SQLite library.
30# -DSQLITE_DEFAULT_PAGE_SIZE=32768 and SQLITE_MAX_DEFAULT_PAGE_SIZE=32768
31# increases the page size from 1k, see bug 416330.  It must be kept in sync with
32# the value of PREF_TS_PAGESIZE_DEFAULT in mozStorageService.cpp.  The value can
33# be overridden on a per-platform basis through the use of the PREF_TS_PAGESIZE
34# hidden preference.  If that preference is missing or invalid then this value
35# will be used.
36# Note: Be sure to update the configure.in checks when these change!
37for var in ('SQLITE_SECURE_DELETE', 'SQLITE_THREADSAFE', 'SQLITE_CORE',
38            'SQLITE_ENABLE_FTS3', 'SQLITE_ENABLE_UNLOCK_NOTIFY',
39            'SQLITE_ENABLE_DBSTAT_VTAB'):
40    DEFINES[var] = 1
41
42DEFINES['SQLITE_DEFAULT_PAGE_SIZE'] = 32768
43DEFINES['SQLITE_MAX_DEFAULT_PAGE_SIZE'] = 32768
44
45# -DSQLITE_WIN32_GETVERSIONEX=0 avoids using deprecated functions.
46# SQLite will just assume we are running on NT kinds of Windows. That's fine
47# because we don't support Win9x.
48# -DSQLITE_ALLOW_URI_AUTHORITY=1 enables uri authorities. See bug 879133.
49if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
50    DEFINES['SQLITE_WIN32_GETVERSIONEX'] = 0
51    DEFINES['SQLITE_ALLOW_URI_AUTHORITY'] = 1
52
53# -DSQLITE_ENABLE_LOCKING_STYLE=1 to help with AFP folders
54if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
55    DEFINES['SQLITE_ENABLE_LOCKING_STYLE'] = 1
56
57# sqlite defaults this to on on __APPLE_ but it breaks on newer iOS SDKs
58if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'uikit':
59    DEFINES['SQLITE_ENABLE_LOCKING_STYLE'] = 0
60
61# Turn on SQLite's assertions in debug builds.
62if CONFIG['MOZ_DEBUG']:
63    DEFINES['SQLITE_DEBUG'] = 1
64    DEFINES['SQLITE_ENABLE_API_ARMOR'] = True
65
66if CONFIG['OS_TARGET'] == 'Android':
67    # default to user readable only to fit Android security model
68    DEFINES['SQLITE_DEFAULT_FILE_PERMISSIONS'] = '0600'
69
70# Force using _msize on mingw, as sqlite3 only enables it with MSVC.
71if CONFIG['OS_TARGET'] == 'WINNT' and CONFIG['CC_TYPE'] != 'clang-cl':
72    DEFINES['SQLITE_USE_MALLOC_H'] = True
73    DEFINES['SQLITE_USE_MSIZE'] = True
74
75# Omit unused functions to save some library footprint.
76DEFINES['SQLITE_OMIT_DEPRECATED'] = True
77DEFINES['SQLITE_OMIT_BUILTIN_TEST'] = True
78
79# Try to use a MEMORY temp store when possible. That allows for better
80# performance and doesn't suffer from a full separate tmp partition.
81# Exclude 32bit platforms due to address space fragmentation issues.
82if CONFIG['OS_TARGET'] == 'Android':
83    # On Android there's no tmp partition, so always use a MEMORY temp store.
84    DEFINES['SQLITE_TEMP_STORE'] = 3
85elif CONFIG['HAVE_64BIT_BUILD']:
86    # On 64bit platforms default to a MEMORY temp store for performance.
87    DEFINES['SQLITE_TEMP_STORE'] = 2
88
89# Change the default temp files prefix, to easily distinguish files we created
90# vs files created by other Sqlite instances in the system.
91DEFINES['SQLITE_TEMP_FILE_PREFIX'] = '"mz_etilqs_"'
92
93# Enabling sqlite math functions
94DEFINES['SQLITE_ENABLE_MATH_FUNCTIONS'] = True
95if CONFIG["OS_TARGET"] == "Linux" or CONFIG["OS_TARGET"] == "Android" or \
96        CONFIG["OS_TARGET"] == "FreeBSD":
97    OS_LIBS += [
98        "m"
99    ]
100
101# Suppress warnings in third-party code.
102if CONFIG['CC_TYPE'] in ('clang', 'gcc'):
103    CFLAGS += [
104        '-Wno-sign-compare',
105        '-Wno-type-limits',
106    ]
107