Skip to content

Commit dbe15b0

Browse files
authored
Merge pull request #339 from brauner/2016-10-17/fix_libsqlite3_build
actually link to <sqlite3.h> when -tags libsqlite3
2 parents 955dae4 + 420dc66 commit dbe15b0

File tree

4 files changed

+39
-5
lines changed

4 files changed

+39
-5
lines changed

sqlite3-binding.c

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
** language. The code for the "sqlite3" command-line shell is also in a
1818
** separate file. This file contains only code for the core SQLite library.
1919
*/
20+
#ifndef USE_LIBSQLITE3
2021
#define SQLITE_CORE 1
2122
#define SQLITE_AMALGAMATION 1
2223
#ifndef SQLITE_PRIVATE
@@ -197846,5 +197847,9 @@ static int sqlite3Fts5VocabInit(Fts5Global *pGlobal, sqlite3 *db){
197846197847

197847197848

197848197849
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS5) */
197850+
#else // USE_LIBSQLITE3
197851+
// If users really want to link against the system sqlite3 we
197852+
// need to make this file a noop.
197853+
#endif
197849197854

197850197855
/************** End of fts5.c ************************************************/

sqlite3-binding.h

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
** the version number) and changes its name to "sqlite3.h" as
3131
** part of the build process.
3232
*/
33+
#ifndef USE_LIBSQLITE3
3334
#ifndef SQLITE3_H
3435
#define SQLITE3_H
3536
#include <stdarg.h> /* Needed for the definition of va_list */
@@ -10338,5 +10339,9 @@ struct fts5_api {
1033810339
#endif
1033910340

1034010341
#endif /* _FTS5_H */
10342+
#else // USE_LIBSQLITE3
10343+
// If users really want to link against the system sqlite3 we
10344+
// need to make this file a noop.
10345+
#endif
1034110346

1034210347
/******** End of fts5.h *********/

sqlite3ext.h

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#ifndef USE_LIBSQLITE3
12
/*
23
** 2006 June 7
34
**
@@ -12,7 +13,7 @@
1213
** This header file defines the SQLite interface for use by
1314
** shared libraries that want to be imported as extensions into
1415
** an SQLite instance. Shared libraries that intend to be loaded
15-
** as extensions by SQLite should #include this file instead of
16+
** as extensions by SQLite should #include this file instead of
1617
** sqlite3.h.
1718
*/
1819
#ifndef SQLITE3EXT_H
@@ -543,18 +544,22 @@ typedef int (*sqlite3_loadext_entry)(
543544
#endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
544545

545546
#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
546-
/* This case when the file really is being compiled as a loadable
547+
/* This case when the file really is being compiled as a loadable
547548
** extension */
548549
# define SQLITE_EXTENSION_INIT1 const sqlite3_api_routines *sqlite3_api=0;
549550
# define SQLITE_EXTENSION_INIT2(v) sqlite3_api=v;
550551
# define SQLITE_EXTENSION_INIT3 \
551552
extern const sqlite3_api_routines *sqlite3_api;
552553
#else
553-
/* This case when the file is being statically linked into the
554+
/* This case when the file is being statically linked into the
554555
** application */
555556
# define SQLITE_EXTENSION_INIT1 /*no-op*/
556557
# define SQLITE_EXTENSION_INIT2(v) (void)v; /* unused parameter */
557558
# define SQLITE_EXTENSION_INIT3 /*no-op*/
558559
#endif
559560

560561
#endif /* SQLITE3EXT_H */
562+
#else // USE_LIBSQLITE3
563+
// If users really want to link against the system sqlite3 we
564+
// need to make this file a noop.
565+
#endif

tool/upgrade.go

+21-2
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,21 @@ func main() {
3737
if err != nil {
3838
log.Fatal(err)
3939
}
40-
defer resp.Body.Close()
4140

4241
b, err := ioutil.ReadAll(resp.Body)
4342
if err != nil {
43+
resp.Body.Close()
4444
log.Fatal(err)
4545
}
4646

4747
fmt.Printf("extracting %v\n", path.Base(url))
4848
r, err := zip.NewReader(bytes.NewReader(b), resp.ContentLength)
4949
if err != nil {
50+
resp.Body.Close()
5051
log.Fatal(err)
5152
}
53+
resp.Body.Close()
54+
5255
for _, zf := range r.File {
5356
var f *os.File
5457
switch path.Base(zf.Name) {
@@ -68,11 +71,27 @@ func main() {
6871
if err != nil {
6972
log.Fatal(err)
7073
}
74+
75+
_, err = io.WriteString(f, "#ifndef USE_LIBSQLITE3\n")
76+
if err != nil {
77+
zr.Close()
78+
f.Close()
79+
log.Fatal(err)
80+
}
7181
_, err = io.Copy(f, zr)
72-
f.Close()
7382
if err != nil {
83+
zr.Close()
84+
f.Close()
7485
log.Fatal(err)
7586
}
87+
_, err = io.WriteString(f, "#else // USE_LIBSQLITE3\n // If users really want to link against the system sqlite3 we\n// need to make this file a noop.\n #endif")
88+
if err != nil {
89+
zr.Close()
90+
f.Close()
91+
log.Fatal(err)
92+
}
93+
zr.Close()
94+
f.Close()
7695
fmt.Printf("extracted %v\n", filepath.Base(f.Name()))
7796
}
7897
}

0 commit comments

Comments
 (0)