%define packagename sqlite3
%define archivename sqlite
%define tclver 8.6
%define build_compat32 %{?_with_compat32:1}%{!?_with_compat32:0}

%define with_check %{?_with_check:1}%{!?_with_check:0}

%define year 2020
%define realver 3310100
%define docver 3310100
%define rpmver 3.31.1


Summary: SQLite is a C library that implements an embeddable SQL database engine
Summary(ja): SQLite は組み込み型SQLデータベースエンジンを実装するCライブラリです。
Name: %{packagename}
Version: %{rpmver}
Release: 1%{?_dist_release}
Group: System Environment/Libraries
Vendor: Project Vine
Distribution: Vine Linux

URL: https://www.sqlite.org
License: Public Domain

Source0: https://www.sqlite.org/%{year}/%{archivename}-src-%{realver}.zip
Source1: https://www.sqlite.org/%{year}/%{archivename}-doc-%{docver}.zip

# Support a system-wide lemon template
Patch1: sqlite-3.6.23-lemon-system-template.patch
# sqlite >= 3.7.10 is buggy if malloc_usable_size() is detected, disable it:
# https://bugzilla.redhat.com/show_bug.cgi?id=801981
# http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=665363
Patch3: sqlite-3.12.2-no-malloc-usable-size.patch
# Temporary workaround for failed percentile test, see patch for details
Patch4: sqlite-3.8.0-percentile-test.patch
# Disable test date-2.2c on i686
Patch7: sqlite-3.16-datetest-2.2c.patch
# Modify sync2.test to pass with DIRSYNC turned off
Patch8: sqlite-3.18.0-sync2-dirsync.patch

BuildRoot: %{_tmppath}/%{name}-%{version}-root
BuildRequires: tcl-devel, libedit-devel, ncurses-devel, zlib-devel


%description
SQLite is a C library that implements an embeddable SQL database engine.
Programs that link with the SQLite library can have SQL database access
without running a separate RDBMS process. The distribution comes with a
standalone command-line access program (sqlite3) that can be used to
administer an SQLite database and which serves as an example of how to
use the SQLite library.

%description -l ja
SQLite は組み込み型SQLデータベースエンジンを実装するCライブラリです。
SQLiteライブラリにリンクされたプログラムではSQLデータベースアクセスが
できるようになります。その際、別のRDBMSプロセスは不要です。

 
%package -n %{name}-devel
Summary: Header files and libraries for developing apps which will use sqlite3
Summary(ja): sqlite3 の開発用ヘッダファイル及びライブラリ
Group: Development/Libraries
Requires: %{name} = %{version}-%{release}

%description -n %{name}-devel
The sqlite3-devel package contains the header files and libraries needed
to develop programs that use the SQLite database library.

%description -n %{name}-devel -l ja
sqlite3-develはSQLiteデータベースライブラリを用いるプログラムの開発に
必要なヘッダファイル及びライブラリを含むパッケージです。

%package -n lemon
Summary: A parser generator
Summary(ja): パーザジェネレータ
Group: Development/Tools

%description -n lemon
Lemon is an LALR(1) parser generator for C or C++. It does the same
job as bison and yacc. But lemon is not another bison or yacc
clone. It uses a different grammar syntax which is designed to reduce
the number of coding errors. Lemon also uses a more sophisticated
parsing engine that is faster than yacc and bison and which is both
reentrant and thread-safe. Furthermore, Lemon implements features
that can be used to eliminate resource leaks, making is suitable for
use in long-running programs such as graphical user interfaces or
embedded controllers.

%description -n lemon -l ja
Lemon は C や C++ 用の LALR(1) パーザジェネレータです。bison や yacc と
同様に機能しますが、これらのクローンではなく、異なる構文を用いることで
コーディング上のエラーを減らすことを狙っています。また Lemon ではより
洗練された構文解析エンジンを使っており、yacc や bison より高速に、かつ
再入可能・スレッドセーフに動作します。さらに Lemon ではリソースのリークを
防ぐ機能も備わっており、GUI や組み込みコントローラといった長期間動作する
プログラムに適しています。


%package -n %{name}-tcl
Summary: Tcl client library for SQLite
Summary(ja): SQLiteのTclクライアントライブラリ
Group: System Environment/Libraries
Requires: %{name} = %{version}-%{release}

%description -n %{name}-tcl
The sqlite3-tcl package contains the libtclsqlite3 client library,
which utilizes SQLite from Tcl.

%description -n %{name}-tcl -l ja
sqlite3-tclはTclからSQLiteデータベースライブラリを扱うために
必要なlibtclsqlite3ライブラリを含むパッケージです。


%package -n compat32-%{name}
Summary: SQLite is a C library that implements an embeddable SQL database engine
Summary(ja): SQLite は組み込み型SQLデータベースエンジンを実装するCライブラリです。
Group: System Environment/Libraries
Requires: %{name} = %{version}-%{release}

%description -n compat32-%{name}
SQLite is a C library that implements an embeddable SQL database engine.
Programs that link with the SQLite library can have SQL database access
without running a separate RDBMS process. The distribution comes with a
standalone command-line access program (sqlite3) that can be used to
administer an SQLite database and which serves as an example of how to
use the SQLite library.

%description -n compat32-%{name} -l ja
SQLite は組み込み型SQLデータベースエンジンを実装するCライブラリです。
SQLiteライブラリにリンクされたプログラムではSQLデータベースアクセスが
できるようになります。その際、別のRDBMSプロセスは不要です。


%package -n compat32-%{name}-devel
Summary: Header files and libraries for developing apps which will use sqlite3
Summary(ja): sqlite3の開発用ヘッダファイル及びライブラリ
Group: Development/Libraries
Requires: compat32-%{name} = %{version}-%{release}

%description -n compat32-%{name}-devel
The sqlite3-devel package contains the header files and libraries needed
to develop programs that use the SQLite database library.

%description -n compat32-%{name}-devel -l ja
sqlite3-develはSQLiteデータベースライブラリを用いるプログラムの開発に
必要なヘッダファイル及びライブラリを含むパッケージです。


%prep
%setup -q -a1 -n%{archivename}-src-%{realver}
%patch1 -p1
%patch3 -p1
%patch4 -p1
%ifarch %{ix86}
%patch7 -p1
%endif
%patch8 -p1

# Remove backup-file
rm -f %{name}-doc-%{docver}/sqlite.css~ || :

%build
autoconf
export CFLAGS="$RPM_OPT_FLAGS 
               -DSQLITE_ENABLE_COLUMN_METADATA=1 
	       -DSQLITE_DISABLE_DIRSYNC=1 
	       -DSQLITE_ENABLE_FTS3=1
	       -DSQLITE_ENABLE_FTS3_PARENTHESIS=1
	       -DSQLITE_ENABLE_JSON1=1
	       -DSQLITE_ENABLE_RTREE=1
	       -DSQLITE_SECURE_DELETE=1
	       -DSQLITE_ENABLE_UNLOCK_NOTIFY=1
	       -DSQLITE_ENABLE_DBSTAT_VTAB=1
	       -Wall -fno-strict-aliasing"
%configure --enable-load-extension \
           --enable-threadsafe \
           --enable-fts5 \
	   --enable-threads-override-locks

%{__make} %{?_smp_mflags}


%install
rm -rf $RPM_BUILD_ROOT

DESTDIR=${RPM_BUILD_ROOT} %{__make} install

## remove unuse files
rm -rf $RPM_BUILD_ROOT%{_libdir}/*.{a,la}

install -D -m0644 sqlite3.1 $RPM_BUILD_ROOT/%{_mandir}/man1/sqlite3.1
install -D -m0755 lemon $RPM_BUILD_ROOT/%{_bindir}/lemon
install -D -m0644 tool/lempar.c $RPM_BUILD_ROOT/%{_datadir}/lemon/lempar.c


%check
%if %{with_check}
%{__make} test
%endif


%clean
%{__rm} -rf $RPM_BUILD_ROOT


%files
%defattr(-, root, root)
%{_bindir}/sqlite3
%{_libdir}/*.so.*
%{_mandir}/*/*


%files -n %{name}-devel
%defattr(-, root, root)
%{_libdir}/*.so
%{_libdir}/pkgconfig/*
%{_includedir}/*
%doc doc/*


%files -n lemon
%defattr(-, root, root)
%{_bindir}/lemon
%{_datadir}/lemon


%files -n %{name}-tcl
%defattr(-, root, root)
%{_datadir}/tcl%{tclver}/%{packagename}/*


%if %{build_compat32}
%files -n compat32-%{name}
%defattr(-, root, root)
%{_libdir}/*.so.*

%files -n compat32-%{name}-devel
%defattr(-, root, root)
%{_libdir}/*.so
%endif


%changelog
* Tue Feb 11 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 3.31.1-1
- new upstream release.

* Sat Oct 05 2019 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 3.30.0-1
- new upstream release.

* Thu Sep 12 2019 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 3.29.0-1
- new upstream release.
- dropped Patch2 and 6.

* Tue May 14 2019 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 3.27.2.0-1
- new upstream release.
- added BR:zlib-devel.

* Sun Mar 19 2017 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 3.17.0.0-1
- new upstream release.
- enabled FTS5 and JSON1 extension.
- built with libedit instead of readline.

* Sun Mar 22 2015 Ryoichi INAGAKI <ryo1@toki.waseda.jp> 3.8.8.2-2
- rebuilt with readline 6.3

* Sun Feb 01 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.8.8.2-1
- new upstream release
- remove Patch2,3
- change BuildRequires: tcl-devel instead of tcl

* Sun Dec 07 2014 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.8.7.3-1
- new upstream release

* Mon Nov 24 2014 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.8.7.2-1
- new upstream release

* Tue Nov 18 2014 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.8.7.1-1
- new upstream release
- update Patch3 (sqlite-3.7.15-no-malloc-usable-size.patch)
- add Patch4 (sqlite-3.8.0-percentile-test.patch) from fedora

* Mon Jan 13 2014 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.7.15.1-2
- rebuild with VineSeed environment

* Thu Nov 29 2012 Daisuke SUZUKI <daisuke@linux.or.jp> 3.7.15.1-1
- new upstream release

* Mon Mar 28 2011 Daisuke SUZUKI <daisuke@linux.or.jp> 3.7.5-1
- new upstream release

* Thu Sep 23 2010 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.7.2-2
- rebuild with rpm-4.8.1 for pkg-config file

* Tue Sep 14 2010 Daisuke SUZUKI <daisuke@linux.or.jp> 3.7.2-1
- new upstream release
- enable SQLITE_SECURE_DELETE, SQLITE_ENABLE_UNLOCK_NOTIFY for firefox

* Sat Apr 17 2010 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 3.6.23.1-2
- new upstream release
- adjust Patch2

* Tue Jan 05 2010 Daisuke SUZUKI <daisuke@linux.or.jp> 3.6.21-1
- new upstream release

* Sun Jun 28 2009 Daisuke SUZUKI <daisuke@linux.or.jp> 3.6.16-1
- new upstream release

* Tue Jun 02 2009 Daisuke SUZUKI <daisuke@linux.or.jp> 3.6.14.2-1
- new upstream release
- remove static library
- add --enable-thereadsafe configure options
- enable RTREE, FTS3 extentions
- dont sync on dirs

* Wed Dec 31 2008 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 3.6.7-1
- new upstream version
- add lemon subpackage
- add Patch1 (upstream ticket #3137) and Patch2 (from Debian)
  - enable loading of external extensions
  - correct snprintf use in lemon.c
- add with_check macro

* Fri Sep 26 2008 Shu KONNO <owa@bg.wakwak.com> 3.5.9-2vl5
- removed *.la
- spec in utf-8

* Sat May 17 2008 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 3.5.9-1vl5
- upstream release

* Sun Apr 27 2008 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 3.5.8-1vl5
- upstream release

* Sun Mar 23 2008 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 3.5.7-1vl5
- upstream release
- drop Patch1 (fixed in upstream source)

* Wed Feb 6 2008 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 3.5.5-0vl1
- upstream release
- add Patch1 to pass tests correctly
- use quick test instead of fulltest (which causes infinite loop)

* Fri Dec 28 2007 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 3.5.4-0vl2
- upstream release
- use full test instead of quick test

* Sun Dec 23 2007 NAKAMURA Kenta <kenta@vinelinux.org> 3.4.2-0vl2
- added compat32-* packages for x86_64 architecture support

* Sat Aug 18 2007 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 3.4.2-0vl1
- upstream release

* Sat Jul 21 2007 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 3.4.1-0vl1
- upstream release
- stop applying Patch0 (problem seems to be fixed in upstream source.
  see http://www.sqlite.org/cvstrac/chngview?cn=4134 )

* Tue Jun 26 2007 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 3.4.0-0vl1
- upstream release

* Sat May 26 2007 NAKAMURA Kenta <kenta@vinelinux.org> 3.3.17-0vl2
- added Patch0: sqlite-3.3.17-types3_test-x86_64.patch

* Wed May  2 2007 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 3.3.17-0vl1
- upstream release

* Wed Apr 11 2007 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 3.3.15-0vl1
- upstream release
- drop Patch0 (merged in upstream source)
- move /usr/lib/libsqlite3.so to -devel package
- add %%check scriptlet

* Tue Apr 3 2007 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 3.3.14-0vl1
- upstream release
- add Patch0 to make test work correctly
  from http://www.sqlite.org/cvstrac/filediff?f=sqlite/Makefile.in&v1=1.164&v2=1.165

* Sun Feb 18 2007 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 3.3.13-0vl1
- upstream release

* Sun Jan 28 2007 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 3.3.12-0vl1
- upstream release

* Fri Jan 26 2007 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 3.3.11-0vl1
- upstream release
- use macros for make and rm

* Wed Jan 17 2007 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 3.3.10-0vl2
- rebuild
- update changelog

* Wed Jan 17 2007 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 3.3.10-0vl1
- upstream release

* Wed Nov 29 2006 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 3.3.8-0vl1
- upstream release
- fix typo in %%changelog

* Sat Jul 22 2006 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 3.3.6-0vl3
- changed devel package's Group to Development/Libraries
- changed tcl package's Group to System Environment/Libraries

* Sun Jun 11 2006 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 3.3.6-0vl2
- upstream release

* Sat Apr 8 2006 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 3.3.5-0vl2
- upstream release
- change Group:

* Wed Feb 15 2006 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 3.3.4-0vl2
- upstream release

* Thu Feb 2 2006 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 3.3.3-0vl2
- upstream release

* Fri Dec 23 2005 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 3.2.8-0vl2
- upstream release

* Sun Sep 25 2005 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 3.2.7-0vl2
- upstream release

* Tue Aug 30 2005 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 3.2.5-0vl2
- upstream release
- drop Patch0 (merged in upstream source)

* Thu Jun 16 2005 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 3.2.2-0vl2
- upstream release

* Tue Apr 5 2005 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 3.2.1-0vl2
- 1st release for VineSeedPlus

* Mon Apr 4 2005 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 3.2.1-0vl1
- upstream release

* Fri Mar 25 2005 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 3.2.0-0vl1
- upstream release

* Mon Mar 21 2005 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 3.1.6-0vl1
- upstream release

* Thu Mar 17 2005 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 3.1.5-0vl1
- upstream release
- modified Patch0 to fit upstream source

* Mon Feb 28 2005 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 3.1.3-0vl1
- upstream release

* Wed Feb 16 2005 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 3.1.2-0vl0.2
- add Requires: ncurses

* Wed Feb 16 2005 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 3.1.2-0vl0.1
- upstream release
- add Patch0 to 'make doc' succeed
- use 'DESTDIR make install' in place of %%makeinstall
- add new package sqlite3-tcl

* Wed Nov 3 2004 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 3.0.8-0vl0.2
- fixed Source URL

* Fri Oct 22 2004 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 3.0.8-0vl0.1
- 1st release for Vine Linux 3.0
- spec file from sqlite(-2.8.15) package
- add BuildRequires: readline-devel
- add Requires: readline
- change configure and makeinstall using macros
- add "rm -rf $RPM_BUILD_ROOT" in %%prep section
