autoconfを使って。
開発環境
- Linux Mint 17.3 MATE 32bit
まとめ
コンパイル手順まとめ。
- ソースコードsqlite-autoconf-3170000.tar.gzをダウンロードする
- 1を解凍する
- ターミナルを起動する
cd /{some_path}/sqlite-autoconf-3170000/
で2のディレクトリに移動する./configure --enable-fts5
コマンドを実行するMakefile
が生成されたことを確認するmake
コマンドを実行する- 約7分後、
sqlite3
実行ファイルが生成されたことを確認する(4のディレクトリ配下に)
SQLiteソースコード取得
type | size | desctiption |
---|---|---|
sqlite-amalgamation-3170000.zip | 1.93 MiB | C source code as an amalgamation, version 3.17.0. |
sqlite-autoconf-3170000.tar.gz | 2.40 MiB | C source code as an amalgamation. Also includes a "configure" script and TEA makefiles for the TCL Interface. |
sqlite-src-3170000.zip | 9.65 MiB | Snapshop of the complete (raw) source tree for SQLite version 3.17.0. See How To Compile SQLite for usage details. |
sqlite-preprocessed-3170000.zip | 2.06 MiB | Preprocessed C sources for SQLite version 3.17.0. |
今回はsqlite-autoconf-3170000.tar.gzを使う。
参考
https://sqlite.org/fts5.html
sqlite3, pdo_sqlite モジュールの全文検索(FTS)対応コンパイル手順 – セルティスラボ
autoconf
autoconfやm4などのキーワードが出てくる。これはかつてGTKmmをWindowsXPでコンパイルした時に見覚えがある。
gtkmm3のコンパイルができたっぽい - やってみる
GTKmm3を再コンパイルする - やってみる
autoconfはMakefileを作成するツールらしい。GNU製。Linuxにはインストールされている可能性が高そう。
autoconfを使ってconfigureを作って配布 - nullnull7の日記
以下のようにするとMakefileを作成するツール。そのための入力ファイルはsqlite-autoconf-3170000.tar.gzに含まれている。
$ ./configure
拡張機能ソースコード取得
2. Compiling and Using FTS5
の項を参照。
上記にあった以下のURLからソースコードをダウンロードできた。
http://www.sqlite.org/src/tarball/SQLite-trunk.tgz
参考先ではURLの末尾に?uuid=trunk
もついていたが、それだとダウンロードできなかった。8.9MB。展開後は70.4MB。
見てみる
./SQLite-trunk/ext/
が拡張機能のコードがあるパス。配下にfts5
ディレクトリなどがある。
http://charlesleifer.com/blog/building-the-sqlite-fts5-search-extension/
Sqlite で全文検索 - Qiita
このコードは必要なのか?
FTS5を有効にする方法
SQLite FTS5 Extension
Google 翻訳
FTS5はSQLiteの合併の一部として含まれています。
たぶん拡張機能のコードも含まれているのだろう。と都合よく解釈しておく。
デフォルトでは無効になっています。 2つのautoconfビルドシステムを使用している場合は、configureスクリプトの実行時に "--enable-fts5" オプションを指定することで有効になります。
たぶんコンパイルオプション--enable-fts5
を付与してコンパイルすることでFTS5機能が有効になるという意味だろう。
sqlite3, pdo_sqlite モジュールの全文検索(FTS)対応コンパイル手順 – セルティスラボによると、autoconfでやるには以下のようにすると思われる。
CPPFLAGS="--enable-fts5" ./configure
$ CPPFLAGS="--enable-fts5" ./configure --with-sqlite3=shared
これでMakefileができるのか?
そのつぎはmakeコマンドでMakefileを実行する。
make
これで実行ファイルができるはず。
やってみる
1回目
エラーが出た。
$ CPPFLAGS="--enable-fts5" ./configure --with-sqlite3=shared
configure: WARNING: unrecognized options: --with-sqlite3 checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... /bin/mkdir -p checking for gawk... gawk checking whether make sets $(MAKE)... yes checking whether make supports nested variables... yes checking for style of include used by make... GNU checking for gcc... gcc checking whether the C compiler works... no configure: error: in `{some_path}/sqlite-autoconf-3170000': configure: error: C compiler cannot create executables See `config.log' for more details
checking whether the C compiler works... no
とあるので、gccを確認。存在している。バージョンが古いのだろうか?
$ gcc --version gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4 Copyright (C) 2013 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See `config.log' for more details
config.logファイルの中身を覗いてみる。
configure:3275: gcc -V >&5 gcc: error: unrecognized command line option '-V' gcc: fatal error: no input files
configure:3275: gcc -qversion >&5 gcc: error: unrecognized command line option '-qversion' gcc: fatal error: no input files
configure:3328: gcc --enable-fts5 conftest.c >&5 cc1: error: unknown pass fts5 specified in -fenable
gccコマンドを打ってみたら、そんなオプション認識できないと怒られた。
$ gcc -V gcc: error: unrecognized command line option ‘-V’ gcc: fatal error: no input files compilation terminated.
$ gcc -qversion gcc: error: unrecognized command line option ‘-qversion’ gcc: fatal error: no input files compilation terminated.
http://superuser.com/questions/846768/gcc-unrecognized-command-line-options-v-and-qversion-with-autoconf
Google 翻訳
古いバージョンのgccは-Vオプションがあったらしい。そのコマンドで結果が得られたらバージョンも特定できるという意味だろうか。
2回目
$ ./configure --enable-fts5
もしかして、上記のコマンドかもしれない。やってみたら動いた。Makefile
が生成されたことを確認した。
$ ./configure --enable-fts5 checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... /bin/mkdir -p checking for gawk... gawk checking whether make sets $(MAKE)... yes checking whether make supports nested variables... yes checking for style of include used by make... GNU checking for gcc... gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking whether gcc understands -c and -o together... yes checking dependency style of gcc... gcc3 checking for special C compiler options needed for large files... no checking for _FILE_OFFSET_BITS value needed for large files... 64 checking for gcc... (cached) gcc checking whether we are using the GNU C compiler... (cached) yes checking whether gcc accepts -g... (cached) yes checking for gcc option to accept ISO C89... (cached) none needed checking whether gcc understands -c and -o together... (cached) yes checking dependency style of gcc... (cached) gcc3 checking build system type... i686-pc-linux-gnu checking host system type... i686-pc-linux-gnu checking how to print strings... printf checking for a sed that does not truncate output... /bin/sed checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E checking for fgrep... /bin/grep -F checking for ld used by gcc... /usr/bin/ld checking if the linker (/usr/bin/ld) is GNU ld... yes checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B checking the name lister (/usr/bin/nm -B) interface... BSD nm checking whether ln -s works... yes checking the maximum length of command line arguments... 1572864 checking how to convert i686-pc-linux-gnu file names to i686-pc-linux-gnu format... func_convert_file_noop checking how to convert i686-pc-linux-gnu file names to toolchain format... func_convert_file_noop checking for /usr/bin/ld option to reload object files... -r checking for objdump... objdump checking how to recognize dependent libraries... pass_all checking for dlltool... no checking how to associate runtime and link libraries... printf %s\n checking for ar... ar checking for archiver @FILE support... @ checking for strip... strip checking for ranlib... ranlib checking command to parse /usr/bin/nm -B output from gcc object... ok checking for sysroot... no checking for a working dd... /bin/dd checking how to truncate binary pipes... /bin/dd bs=4096 count=1 checking for mt... mt checking if mt is a manifest tool... no checking how to run the C preprocessor... gcc -E checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking for dlfcn.h... yes checking for objdir... .libs checking if gcc supports -fno-rtti -fno-exceptions... no checking for gcc option to produce PIC... -fPIC -DPIC checking if gcc PIC flag -fPIC -DPIC works... yes checking if gcc static flag -static works... yes checking if gcc supports -c -o file.o... yes checking if gcc supports -c -o file.o... (cached) yes checking whether the gcc linker (/usr/bin/ld) supports shared libraries... yes checking whether -lc should be explicitly linked in... no checking dynamic linker characteristics... GNU/Linux ld.so checking how to hardcode library paths into programs... immediate checking whether stripping libraries is possible... yes checking if libtool supports shared libraries... yes checking whether to build shared libraries... yes checking whether to build static libraries... yes checking for fdatasync... yes checking for usleep... yes checking for fullfsync... no checking for localtime_r... yes checking for gmtime_r... yes checking whether strerror_r is declared... yes checking for strerror_r... yes checking whether strerror_r returns char *... no checking editline/readline.h usability... no checking editline/readline.h presence... no checking for editline/readline.h... no checking readline/readline.h usability... yes checking readline/readline.h presence... yes checking for readline/readline.h... yes checking for library containing tgetent... -ltermcap checking for library containing readline... -lreadline checking for library containing pthread_create... -lpthread checking for library containing pthread_mutexattr_init... none required checking for library containing dlopen... -ldl checking for whether to support dynamic extensions... yes checking for library containing log... -lm checking for posix_fallocate... yes checking that generated files are newer than configure... done configure: creating ./config.status config.status: creating Makefile config.status: creating sqlite3.pc config.status: executing depfiles commands config.status: executing libtool commands
Makeコマンド実行
$ make
Makefileに従ってコンパイルする。コンパイルには7分間くらいかかった。
sqlite3
実行ファイルができあがる。また、.libs
ディレクトリにlibsqlite3.a
,libsqlite3.so
などのファイルができる。
mint@mint-CF-T5AW1AXS /media/mint/85f78c06-a96e-4020-ac36-9419b7e456db/mint/download/sqlite-autoconf-3170000 $ make /bin/bash ./libtool --tag=CC --mode=compile gcc -DPACKAGE_NAME=\"sqlite\" -DPACKAGE_TARNAME=\"sqlite\" -DPACKAGE_VERSION=\"3.17.0\" -DPACKAGE_STRING=\"sqlite\ 3.17.0\" -DPACKAGE_BUGREPORT=\"http://www.sqlite.org\" -DPACKAGE_URL=\"\" -DPACKAGE=\"sqlite\" -DVERSION=\"3.17.0\" -D_FILE_OFFSET_BITS=64 -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DHAVE_FDATASYNC=1 -DHAVE_USLEEP=1 -DHAVE_LOCALTIME_R=1 -DHAVE_GMTIME_R=1 -DHAVE_DECL_STRERROR_R=1 -DHAVE_STRERROR_R=1 -DHAVE_READLINE_READLINE_H=1 -DHAVE_READLINE=1 -DHAVE_POSIX_FALLOCATE=1 -I. -D_REENTRANT=1 -DSQLITE_THREADSAFE=1 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_RTREE -g -O2 -MT sqlite3.lo -MD -MP -MF .deps/sqlite3.Tpo -c -o sqlite3.lo sqlite3.c libtool: compile: gcc -DPACKAGE_NAME=\"sqlite\" -DPACKAGE_TARNAME=\"sqlite\" -DPACKAGE_VERSION=\"3.17.0\" "-DPACKAGE_STRING=\"sqlite 3.17.0\"" -DPACKAGE_BUGREPORT=\"http://www.sqlite.org\" -DPACKAGE_URL=\"\" -DPACKAGE=\"sqlite\" -DVERSION=\"3.17.0\" -D_FILE_OFFSET_BITS=64 -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DHAVE_FDATASYNC=1 -DHAVE_USLEEP=1 -DHAVE_LOCALTIME_R=1 -DHAVE_GMTIME_R=1 -DHAVE_DECL_STRERROR_R=1 -DHAVE_STRERROR_R=1 -DHAVE_READLINE_READLINE_H=1 -DHAVE_READLINE=1 -DHAVE_POSIX_FALLOCATE=1 -I. -D_REENTRANT=1 -DSQLITE_THREADSAFE=1 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_RTREE -g -O2 -MT sqlite3.lo -MD -MP -MF .deps/sqlite3.Tpo -c sqlite3.c -fPIC -DPIC -o .libs/sqlite3.o libtool: compile: gcc -DPACKAGE_NAME=\"sqlite\" -DPACKAGE_TARNAME=\"sqlite\" -DPACKAGE_VERSION=\"3.17.0\" "-DPACKAGE_STRING=\"sqlite 3.17.0\"" -DPACKAGE_BUGREPORT=\"http://www.sqlite.org\" -DPACKAGE_URL=\"\" -DPACKAGE=\"sqlite\" -DVERSION=\"3.17.0\" -D_FILE_OFFSET_BITS=64 -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DHAVE_FDATASYNC=1 -DHAVE_USLEEP=1 -DHAVE_LOCALTIME_R=1 -DHAVE_GMTIME_R=1 -DHAVE_DECL_STRERROR_R=1 -DHAVE_STRERROR_R=1 -DHAVE_READLINE_READLINE_H=1 -DHAVE_READLINE=1 -DHAVE_POSIX_FALLOCATE=1 -I. -D_REENTRANT=1 -DSQLITE_THREADSAFE=1 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_RTREE -g -O2 -MT sqlite3.lo -MD -MP -MF .deps/sqlite3.Tpo -c sqlite3.c -o sqlite3.o >/dev/null 2>&1 mv -f .deps/sqlite3.Tpo .deps/sqlite3.Plo /bin/bash ./libtool --tag=CC --mode=link gcc -D_REENTRANT=1 -DSQLITE_THREADSAFE=1 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_RTREE -g -O2 -no-undefined -version-info 8:6:8 -o libsqlite3.la -rpath /usr/local/lib sqlite3.lo -lm -ldl -lpthread libtool: link: gcc -shared -fPIC -DPIC .libs/sqlite3.o -lm -ldl -lpthread -g -O2 -Wl,-soname -Wl,libsqlite3.so.0 -o .libs/libsqlite3.so.0.8.6 libtool: link: (cd ".libs" && rm -f "libsqlite3.so.0" && ln -s "libsqlite3.so.0.8.6" "libsqlite3.so.0") libtool: link: (cd ".libs" && rm -f "libsqlite3.so" && ln -s "libsqlite3.so.0.8.6" "libsqlite3.so") libtool: link: ar cru .libs/libsqlite3.a sqlite3.o libtool: link: ranlib .libs/libsqlite3.a libtool: link: ( cd ".libs" && rm -f "libsqlite3.la" && ln -s "../libsqlite3.la" "libsqlite3.la" ) gcc -DPACKAGE_NAME=\"sqlite\" -DPACKAGE_TARNAME=\"sqlite\" -DPACKAGE_VERSION=\"3.17.0\" -DPACKAGE_STRING=\"sqlite\ 3.17.0\" -DPACKAGE_BUGREPORT=\"http://www.sqlite.org\" -DPACKAGE_URL=\"\" -DPACKAGE=\"sqlite\" -DVERSION=\"3.17.0\" -D_FILE_OFFSET_BITS=64 -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DHAVE_FDATASYNC=1 -DHAVE_USLEEP=1 -DHAVE_LOCALTIME_R=1 -DHAVE_GMTIME_R=1 -DHAVE_DECL_STRERROR_R=1 -DHAVE_STRERROR_R=1 -DHAVE_READLINE_READLINE_H=1 -DHAVE_READLINE=1 -DHAVE_POSIX_FALLOCATE=1 -I. -D_REENTRANT=1 -DSQLITE_THREADSAFE=1 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_EXPLAIN_COMMENTS -g -O2 -MT sqlite3-shell.o -MD -MP -MF .deps/sqlite3-shell.Tpo -c -o sqlite3-shell.o `test -f 'shell.c' || echo './'`shell.c mv -f .deps/sqlite3-shell.Tpo .deps/sqlite3-shell.Po gcc -DPACKAGE_NAME=\"sqlite\" -DPACKAGE_TARNAME=\"sqlite\" -DPACKAGE_VERSION=\"3.17.0\" -DPACKAGE_STRING=\"sqlite\ 3.17.0\" -DPACKAGE_BUGREPORT=\"http://www.sqlite.org\" -DPACKAGE_URL=\"\" -DPACKAGE=\"sqlite\" -DVERSION=\"3.17.0\" -D_FILE_OFFSET_BITS=64 -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DHAVE_FDATASYNC=1 -DHAVE_USLEEP=1 -DHAVE_LOCALTIME_R=1 -DHAVE_GMTIME_R=1 -DHAVE_DECL_STRERROR_R=1 -DHAVE_STRERROR_R=1 -DHAVE_READLINE_READLINE_H=1 -DHAVE_READLINE=1 -DHAVE_POSIX_FALLOCATE=1 -I. -D_REENTRANT=1 -DSQLITE_THREADSAFE=1 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_EXPLAIN_COMMENTS -g -O2 -MT sqlite3-sqlite3.o -MD -MP -MF .deps/sqlite3-sqlite3.Tpo -c -o sqlite3-sqlite3.o `test -f 'sqlite3.c' || echo './'`sqlite3.c mv -f .deps/sqlite3-sqlite3.Tpo .deps/sqlite3-sqlite3.Po /bin/bash ./libtool --tag=CC --mode=link gcc -D_REENTRANT=1 -DSQLITE_THREADSAFE=1 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_EXPLAIN_COMMENTS -g -O2 -o sqlite3 sqlite3-shell.o sqlite3-sqlite3.o -lreadline -ltermcap -lm -ldl -lpthread libtool: link: gcc -D_REENTRANT=1 -DSQLITE_THREADSAFE=1 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_EXPLAIN_COMMENTS -g -O2 -o sqlite3 sqlite3-shell.o sqlite3-sqlite3.o -lreadline -ltermcap -lm -ldl -lpthread mint@mint-CF-T5AW1AXS /media/mint/85f78c06-a96e-4020-ac36-9419b7e456db/mint/download/sqlite-autoconf-3170000 $
動作確認
$ /{some_dir}/sqlite-autoconf-3170000/sqlite3 test_db.sqlite3 SQLite version 3.17.0 2017-02-13 16:02:40 Enter ".help" for usage hints.
実行できた。バージョンも3.17.0になっている。絶対パスでSQLite3実行ファイルを指定しないとapt-getでインストールした3.8.2が起動してしまう。
virtual table
FTS5用テーブルを作成してみる。
sqlite> create virtual table fts5_test_table using fts5(EntryId, Title, Summary, Content);
何のエラーも表示されない。OK。
sqlite> .tables
fts5_test_table fts5_test_table_content fts5_test_table_docsize
fts5_test_table_config fts5_test_table_data fts5_test_table_idx
なんかテーブルが沢山ある。1つのvirtual tableを作成すると、FTS5関連のテーブルが色々と自動で作成されるらしい。
sqlite> select * from sqlite_master; table|fts5_test_table|fts5_test_table|0|CREATE VIRTUAL TABLE fts5_test_table using fts5(EntryId, Title, Summary, Content) table|fts5_test_table_data|fts5_test_table_data|2|CREATE TABLE 'fts5_test_table_data'(id INTEGER PRIMARY KEY, block BLOB) table|fts5_test_table_idx|fts5_test_table_idx|3|CREATE TABLE 'fts5_test_table_idx'(segid, term, pgno, PRIMARY KEY(segid, term)) WITHOUT ROWID table|fts5_test_table_content|fts5_test_table_content|4|CREATE TABLE 'fts5_test_table_content'(id INTEGER PRIMARY KEY, c0, c1, c2, c3) table|fts5_test_table_docsize|fts5_test_table_docsize|5|CREATE TABLE 'fts5_test_table_docsize'(id INTEGER PRIMARY KEY, sz BLOB) table|fts5_test_table_config|fts5_test_table_config|6|CREATE TABLE 'fts5_test_table_config'(k PRIMARY KEY, v) WITHOUT ROWID
ちなみに、FTS5が実装されていない3.8.2でやると以下のエラーになった。
$ sqlite3 test_db.sqlite3 SQLite version 3.8.2 2013-12-06 14:53:30 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> create virtual table fts5_test_table using fts5(EntryId, Title, Summary, Content); Error: no such module: fts5
所感
FTS5が有効なバイナリファイルの作成に成功した。次は半角スペース区切りの単語での完全一致、前方一致ができるか確認してみるか。それができたら日本語も検索できるようトークナイザの独自実装について調べる。