From c8e0d7a02c3e65f8bbf09bb95f5b413a9a0de865 Mon Sep 17 00:00:00 2001 From: yinshengkai Date: Wed, 21 Feb 2024 13:22:54 +0800 Subject: [PATCH] database: add sqlite support enable UTILS_SQLITE configuration, use the sqlite3 command line tool Signed-off-by: yinshengkai --- database/Make.defs | 21 +++++ database/Makefile | 23 ++++++ database/sqlite/.gitignore | 3 + database/sqlite/Kconfig | 26 +++++++ database/sqlite/Make.defs | 23 ++++++ database/sqlite/Makefile | 68 ++++++++++++++++ database/sqlite/sqlite_cfg.h | 145 +++++++++++++++++++++++++++++++++++ 7 files changed, 309 insertions(+) create mode 100644 database/Make.defs create mode 100644 database/Makefile create mode 100644 database/sqlite/.gitignore create mode 100644 database/sqlite/Kconfig create mode 100644 database/sqlite/Make.defs create mode 100644 database/sqlite/Makefile create mode 100644 database/sqlite/sqlite_cfg.h diff --git a/database/Make.defs b/database/Make.defs new file mode 100644 index 000000000..577407990 --- /dev/null +++ b/database/Make.defs @@ -0,0 +1,21 @@ +############################################################################ +# apps/database/Make.defs +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +include $(wildcard $(APPDIR)/database/*/Make.defs) diff --git a/database/Makefile b/database/Makefile new file mode 100644 index 000000000..3cf46e8e3 --- /dev/null +++ b/database/Makefile @@ -0,0 +1,23 @@ +############################################################################ +# apps/database/Makefile +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +MENUDESC = "Database" + +include $(APPDIR)/Directory.mk diff --git a/database/sqlite/.gitignore b/database/sqlite/.gitignore new file mode 100644 index 000000000..4292e4d3b --- /dev/null +++ b/database/sqlite/.gitignore @@ -0,0 +1,3 @@ +/build +/sqlite +*.zip diff --git a/database/sqlite/Kconfig b/database/sqlite/Kconfig new file mode 100644 index 000000000..fb15805ff --- /dev/null +++ b/database/sqlite/Kconfig @@ -0,0 +1,26 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config LIB_SQLITE + bool "SQLITE library" + depends on CONFIG_FS_LOCK_BUCKET_SIZE > 0 + default n + +if LIB_SQLITE + +config LIB_SQLITE_VERSION + string "SQLITE version" + default "3.45.1" + +config UTILS_SQLITE + tristate "SQLite cmd line tool" + default n + +config UTILS_SQLITE_STACKSIZE + int "SQLite3 cmd line tool stack size" + default 8192 + depends on UTILS_SQLITE + +endif diff --git a/database/sqlite/Make.defs b/database/sqlite/Make.defs new file mode 100644 index 000000000..2b9ff26ce --- /dev/null +++ b/database/sqlite/Make.defs @@ -0,0 +1,23 @@ +############################################################################ +# apps/database/sqlite/Make.defs +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +ifneq ($(CONFIG_LIB_SQLITE),) +CONFIGURED_APPS += $(APPDIR)/database/sqlite +endif diff --git a/database/sqlite/Makefile b/database/sqlite/Makefile new file mode 100644 index 000000000..f178a65a3 --- /dev/null +++ b/database/sqlite/Makefile @@ -0,0 +1,68 @@ +############################################################################ +# apps/database/sqlite/Makefile +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +include $(APPDIR)/Make.defs + +SQLITEDIR=$(APPDIR)/database/sqlite +BUILDDIR=$(SQLITEDIR)/build + +CSRCS += ${BUILDDIR}/sqlite3.c + +CFLAGS += ${INCDIR_PREFIX}$(SQLITEDIR) +CFLAGS += ${DEFINE_PREFIX}_HAVE_SQLITE_CONFIG_H +CFLAGS += ${DEFINE_PREFIX}NDEBUG +CFLAGS += -Wno-unused-variable -Wno-undef -Wno-unused-function -Wno-shadow + +ifneq ($(CONFIG_UTILS_SQLITE),) +PROGNAME = sqlite3 +PRIORITY = 100 +STACKSIZE = ${CONFIG_UTILS_SQLITE_STACKSIZE} +MAINSRC = ${BUILDDIR}/shell.c +endif + + +# Download and unpack tarball if no git repo found + +sqlite.zip: +ifeq ($(wildcard sqlite/.git),) + $(Q) curl -L https://codeload.github.com/sqlite/sqlite/zip/refs/tags/vesion-${CONFIG_LIB_SQLITE_VERSION} -o sqlite.zip + $(Q) unzip -q -o sqlite.zip + $(Q) mv sqlite-vesion-* sqlite + $(call DELFILE, sqlite.zip) +endif + +context:: sqlite.zip + $(Q) mkdir -p ${BUILDDIR} && \ + cd ${BUILDDIR} && \ + echo "Generate SQLite amalgamation version" && \ + ${SQLITEDIR}/sqlite/configure 1> /dev/null && \ + make sqlite3.c -j 1> /dev/null + +clean:: + $(call DELFILE, ${BUILDDIR}/*.o) + +distclean:: + $(call DELDIR, ${BUILDDIR}) +ifeq ($(wildcard sqlite/.git),) + $(call DELDIR, sqlite) +endif + +include $(APPDIR)/Application.mk + diff --git a/database/sqlite/sqlite_cfg.h b/database/sqlite/sqlite_cfg.h new file mode 100644 index 000000000..fcd1d7f07 --- /dev/null +++ b/database/sqlite/sqlite_cfg.h @@ -0,0 +1,145 @@ +/* sqlite_cfg.h. Generated from sqlite_cfg.h.in by configure. */ +/* sqlite_cfg.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the `fdatasync' function. */ +#define HAVE_FDATASYNC 1 + +/* Define to 1 if you have the `gmtime_r' function. */ +#define HAVE_GMTIME_R 1 + +/* Define to 1 if the system has the type `int16_t'. */ +#define HAVE_INT16_T 1 + +/* Define to 1 if the system has the type `int32_t'. */ +#define HAVE_INT32_T 1 + +/* Define to 1 if the system has the type `int64_t'. */ +#define HAVE_INT64_T 1 + +/* Define to 1 if the system has the type `int8_t'. */ +#define HAVE_INT8_T 1 + +/* Define to 1 if the system has the type `intptr_t'. */ +#define HAVE_INTPTR_T 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the `isnan' function. */ +#define HAVE_ISNAN 1 + +/* Define to 1 if you have the `localtime_r' function. */ +#define HAVE_LOCALTIME_R 1 + +/* Define to 1 if you have the `localtime_s' function. */ +/* #undef HAVE_LOCALTIME_S */ + +/* Define to 1 if you have the header file. */ +#define HAVE_MALLOC_H 1 + +/* Define to 1 if you have the `malloc_usable_size' function. */ +#define HAVE_MALLOC_USABLE_SIZE 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the `pread' function. */ +#define HAVE_PREAD 1 + +/* Define to 1 if you have the `pread64' function. */ +#define HAVE_PREAD64 1 + +/* Define to 1 if you have the `pwrite' function. */ +#define HAVE_PWRITE 1 + +/* Define to 1 if you have the `pwrite64' function. */ +#define HAVE_PWRITE64 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the `strchrnul' function. */ +#define HAVE_STRCHRNUL 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if the system has the type `uint16_t'. */ +#define HAVE_UINT16_T 1 + +/* Define to 1 if the system has the type `uint32_t'. */ +#define HAVE_UINT32_T 1 + +/* Define to 1 if the system has the type `uint64_t'. */ +#define HAVE_UINT64_T 1 + +/* Define to 1 if the system has the type `uint8_t'. */ +#define HAVE_UINT8_T 1 + +/* Define to 1 if the system has the type `uintptr_t'. */ +#define HAVE_UINTPTR_T 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to 1 if you have the `usleep' function. */ +#define HAVE_USLEEP 1 + +/* Define to 1 if you have the `utime' function. */ +#define HAVE_UTIME 1 + +/* Define to 1 if you have the header file. */ +#ifdef CONFIG_LIB_ZLIB +# define HAVE_ZLIB_H 1 +#endif + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#define LT_OBJDIR ".libs/" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "sqlite" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "sqlite 3.45.1" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "sqlite" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "3.45.1" + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Enable large inode numbers on Mac OS X 10.5. */ +#ifndef _DARWIN_USE_64_BIT_INODE +# define _DARWIN_USE_64_BIT_INODE 1 +#endif + +/* Number of bits in a file offset, on hosts where this is settable. */ +/* #undef _FILE_OFFSET_BITS */ + +/* Define for large files, on AIX-style hosts. */ +/* #undef _LARGE_FILES */