Adopted SQLite 3.46.1 for DOS based on some tiny code changes and Tcl script. Thanks to Ben Collver!
I hope this 2 files ( `Makefile.cross-djgpp-tcl90` and `sqlite-3.46.1-djgpp.diff` ) will be usefully for SQLite and DOS communities for future SQLite versions.
**sqlite-3.46.1-djgpp.diff**
```
diff -Pur sqlite-src-3460100-orig/src/os_unix.c sqlite-src-3460100/src/os_unix.c
--- sqlite-src-3460100-orig/src/os_unix.c 2024-10-08 14:03:37.579253663 -0700
+++ sqlite-src-3460100/src/os_unix.c 2024-10-08 14:03:53.168253202 -0700
@@ -411,7 +411,9 @@
/* Forward reference */
static int openDirectory(const char*, int*);
+#if LINUX == 1
static int unixGetpagesize(void);
+#endif
/*
** Many system calls are accessed through pointer-to-functions so that
@@ -445,7 +447,7 @@
** that always succeeds. This means that locking does not occur under
** DJGPP. But it is DOS - what did you expect?
*/
-#ifdef __DJGPP__
+#ifdef __DDJGPP__
{ "fstat", 0, 0 },
#define osFstat(a,b,c) 0
#else
@@ -456,8 +458,13 @@
{ "ftruncate", (sqlite3_syscall_ptr)ftruncate, 0 },
#define osFtruncate ((int(*)(int,off_t))aSyscall[6].pCurrent)
+#ifdef __DJGPP__
+ { "fcntl", 0, 0 },
+#define osFcntl(a,b,c) 0
+#else
{ "fcntl", (sqlite3_syscall_ptr)fcntl, 0 },
#define osFcntl ((int(*)(int,int,...))aSyscall[7].pCurrent)
+#endif
{ "read", (sqlite3_syscall_ptr)read, 0 },
#define osRead ((ssize_t(*)(int,void*,size_t))aSyscall[8].pCurrent)
@@ -915,7 +922,9 @@
switch (posixError) {
case EACCES:
case EAGAIN:
+#ifndef __DJGPP__
case ETIMEDOUT:
+#endif
case EBUSY:
case EINTR:
case ENOLCK:
@@ -1502,6 +1511,10 @@
** Return TRUE if pFile has been renamed or unlinked since it was first opened.
*/
static int fileHasMoved(unixFile *pFile){
+#ifdef __DJGPP__
+ // this check returns 'true' in DJGPP enviroments even if the file was not moved --> don't check
+ return 0;
+#else
#if OS_VXWORKS
return pFile->pInode!=0 && pFile->pId!=pFile->pInode->fileId.pId;
#else
@@ -1510,6 +1523,7 @@
(osStat(pFile->zPath, &buf)!=0
|| (u64)buf.st_ino!=pFile->pInode->fileId.ino);
#endif
+#endif
}
@@ -1613,7 +1627,21 @@
** attempt to set the lock.
*/
#ifndef SQLITE_ENABLE_SETLK_TIMEOUT
+#ifdef __DJGPP__
+//# define osSetPosixAdvisoryLock(h,x,t) 0
+static inline int osSetPosixAdvisoryLock(
+ int h, /* The file descriptor on which to take the lock */
+ struct flock *pLock, /* The description of the lock */
+ unixFile *pFile /* Structure holding timeout value */
+){
+ ((void)h);
+ ((void)pLock);
+ ((void)pFile);
+ return 0;
+}
+#else
# define osSetPosixAdvisoryLock(h,x,t) osFcntl(h,F_SETLK,x)
+#endif
#else
static int osSetPosixAdvisoryLock(
int h, /* The file descriptor on which to take the lock */
@@ -6734,6 +6762,11 @@
}
appendAllPathElements(&path, zPath);
zOut[path.nUsed] = 0;
+#ifdef __DJGPP__
+ if (zOut[0] == '/' && zOut[2] == ':') {
+ memmove(zOut, &zOut[1], path.nUsed);
+ }
+#endif
if( path.rc || path.nUsed<2 ) return SQLITE_CANTOPEN_BKPT;
if( path.nSymlink ) return SQLITE_OK_SYMLINK;
return SQLITE_OK;
```
**Makefile.cross-djgpp-tcl90**
```
#!/usr/make
#
# Makefile for SQLITE
#
# This is a template makefile for SQLite. Most people prefer to
# use the autoconf generated "configure" script to generate the
# makefile automatically. But that does not work for everybody
# and in every situation. If you are having problems with the
# "configure" script, you might want to try this makefile as an
# alternative. Create a copy of this file, edit the parameters
# below and type "make".
#
#### The toplevel directory of the source tree. This is the directory
# that contains this "Makefile.in" and the "configure.in" script.
#
TOP = .
#### C Compiler and options for use in building executables that
# will run on the platform that is doing the build.
#
BCC = gcc -g -O0
#BCC = /opt/ancic/bin/c89 -0
#### If the target operating system supports the "usleep()" system
# call, then define the HAVE_USLEEP macro for all C modules.
#
#USLEEP =
USLEEP = -DHAVE_USLEEP=1
#### If you want the SQLite library to be safe for use within a
# multi-threaded program, then define the following macro
# appropriately:
#
#THREADSAFE = -DTHREADSAFE=1
THREADSAFE = -DTHREADSAFE=0
#### Specify any extra linker options needed to make the library
# thread safe
#
#THREADLIB = -lpthread -lm -ldl
THREADLIB =
#### Specify any extra libraries needed to access required functions.
#
#TLIBS = -lrt # fdatasync on Solaris 8
TLIBS =
#### Leave SQLITE_DEBUG undefined for maximum speed. Use SQLITE_DEBUG=1
# to check for memory leaks. Use SQLITE_DEBUG=2 to print a log of all
# malloc()s and free()s in order to track down memory leaks.
#
# SQLite uses some expensive assert() statements in the inner loop.
# You can make the library go almost twice as fast if you compile
# with -DNDEBUG=1
#
#OPTS += -DSQLITE_DEBUG=1
#OPTS += -DSQLITE_ENABLE_WHERETRACE
#OPTS += -DSQLITE_ENABLE_SELECTTRACE
OPTS = -DNDEBUG=1
OPTS += -DHAVE_NANOSLEEP=0
OPTS += -DSQLITE_ENABLE_8_3_NAMES=2
OPTS += -DSQLITE_ENABLE_FTS5=1
OPTS += -DSQLITE_ENABLE_JSON1=1
OPTS += -DSQLITE_ENABLE_LOCKING_STYLE=0
OPTS += -DSQLITE_DEFAULT_MEMSTATUS=0
OPTS += -DSQLITE_MAX_MMAP_SIZE=0
OPTS += -DSQLITE_NO_SYNC=1
OPTS += -DSQLITE_OMIT_WAL=1
OPTS += -DSQLITE_THREADSAFE=0
#### The suffix to add to executable files. ".exe" for windows.
# Nothing for unix.
#
EXE = .exe
#EXE =
#### C Compile and options for use in building executables that
# will run on the target platform. This is usually the same
# as BCC, unless you are cross-compiling.
#
TCC = /home/ben/local/cross-djgpp/bin/i586-pc-msdosdjgpp-gcc -O6
#TCC = gcc -g -O0 -Wall
#TCC = gcc -g -O0 -Wall -fprofile-arcs -ftest-coverage
#TCC = /opt/mingw/bin/i386-mingw32-gcc -O6
#TCC = /opt/ansic/bin/c89 -O +z -Wl,-a,archive
#### Tools used to build a static library.
#
AR = /home/ben/local/cross-djgpp/bin/i586-pc-msdosdjgpp-ar cr
#AR = /opt/mingw/bin/i386-mingw32-ar cr
RANLIB = ranlib
#RANLIB = /opt/mingw/bin/i386-mingw32-ranlib
MKSHLIB = /home/ben/local/cross-djgpp/bin/i586-pc-msdosdjgpp-gcc -shared
SO = so
SHPREFIX = lib
# SO = dll
# SHPREFIX =
#### Extra compiler options needed for programs that use the TCL library.
#
#TCL_FLAGS = -I/home/drh/tcl/include/tcl8.6
TCL_FLAGS = -I/home/ben/local/tcl9.0.0/generic -DSTATIC_BUILD=1 -DCONST=const -DTCL_CHANNEL_VERSION_2=TCL_CHANNEL_VERSION_5
#### Linker options needed to link against the TCL library.
#
#LIBTCL = -ltcl -lm -ldl
LIBTCL = /home/drh/tcl/lib/libtcl9.0.a -lm -lpthread -ldl -lz
#### Additional objects for SQLite library when TCL support is enabled.
#LIBOBJ =
LIBOBJ = tclsqlite.o
#### Compiler options needed for programs that use the readline() library.
#
READLINE_FLAGS =
#READLINE_FLAGS = -DHAVE_READLINE=1 -I/usr/include/readline
#### Linker options needed by programs using readline() must link against.
#
LIBREADLINE =
#LIBREADLINE = -static -lreadline -ltermcap
# You should not have to change anything below this line
###############################################################################
include $(TOP)/main.mk
```