📄 uclinux-sqlite.txt
字号:
本文讨论的是比较流行的嵌入式开发组合ARM+uclinux,即目标开发板为三星S3C4510,完成sqlite在其uclinux上的移植。
本文假设你已经具备正确编译uclinux的kernel的能力,即有能力完成make menuconfig;make dep;make lib_only;make user_only;make romfs;make image;make。而且还能将自己写的类似helloworld程序加到“用户自定义应用程序”中,即你能完成“uClinux-dist/Documentation/Adding-User-Apps-HOWTO”中所描述的“用户程序的订制”。
大多数需要移植sqlite到uclinux的开发者,应该已经具备上面的能力,而只是不清楚怎么样修改sqlite来完成其在uclinux下的编译。如果你还不能完成上面的要求,那么请先做一定的准备工作,因为本范例所涉及到的内容主要是跟sqlite在uclinux下的移植有关,其他的在这个过程中出现的问题,开发者需要自行处理。
本范例使用的uclinux是uClinux-dist-20030522.tar.gz,你可以从www.uclinux.org得到适合你的软件包。
交叉编译工具是arm-elf-tools-20030314.sh,你也可以在http://www.uclinux.org找到它。
本范例使用的sqlite是sqlite-2.8.15.tar.gz,本文的方法也适合于2.8.x系列的sqlite;可能有部分内容不适用于3.0.x系列的sqlite,因为3.0.x中源代码有较大的变化。
1、 下载sqlite:你可以到www.sqlite.org/download.html,下载sqlite-2.8.15.tar.gz软件包;
2、 将下载的软件包解压缩到uClinux-dist/user目录下;
命令:
$tar zxvf sqlite-2.8.15.tar.gz -C uClinux-dist/user/
现在在uclinux的user目录下,你应该可以看到sqlite目录了。解压缩到这个user目录主要是要将sqlite编译成一个普通的用户应用程序。
3、 用户应用程序的有关设置:
按uClinux-dist/Documentation/Adding-User-Apps-HOWTO文档中说提到的,来添加sqlite作为一个用户应用程序,将其做成一个shell,这样就类似于uclinux自己的ps命令。
编辑文件
uClinux-dist/user/Makefile
uClinux-dist/config/Configure.help
uClinux-dist/config/config.in
我是在这些文件里查找“cpu”有关的项,然后在它的下面,加上自己的sqlite项,这个过程并不复杂。
通过上面的修改后,你现在就可以运行uclinux的make menuconfig,选中“CustomizeVendor/User Settings”,再选中“Miscellaneous Applications”,可以看到它现在出现了一个新的“sqlite (NEW)”,这个就是我们刚添加进去的sqlite项。
在稍后的make romfs中,uclinux会将你的sqlite编译进来,做成romfs的一部分,因为你在uClinux-dist/user/Makefile中已经加上要编译sqlite项了。这样在移植后的uclinux的/bin中将会有sqlite命令可以让你来执行。
好,现在我们就要对sqlite进行修改,来做移植工作。
在下面的描述中,我们将对以下几个文件进行一定的添加、修改,从而来完成sqlite在uclinux下的编译:
sqlite/main.mk 修改
sqlite/Makefile 添加
sqlite/src/os.c 修改
sqlite/src/shell.c 修改
对这几个文件进行修改时,请自己做好这些文件的备份,比如你可以将它们拷贝一份,改名成文件名后面带.bak。这个很重要,可以避免你在修改的过程出现问题而无法还原。
一、修改sqlite/main.mk
1、TCCX
将
TCCX = $(TCC) $(OPTS) $(THREADSAFE) $(USLEEP) -I. -I$(TOP)/src
修改为
TCCX = $(TCC) $(OPTS) $(THREADSAFE) $(USLEEP) -I. -I$(TOP)/src $(CFLAGS)
即加上$(CFLAGS)标记。
2、 LIBOBJ
找到 # Object files for the SQLite library.
将其中的tclsqlite.o去掉。即去掉tcl有关的东西。
如果没有tclsqlite.o,那么不用处理它。
3、 sqlite$(EXE)
找到类似sqlite$(EXE)的一句,将:
sqlite$(EXE): $(TOP)/src/shell.c libsqlite.a sqlite.h
$(TCCX) $(READLINE_FLAGS) -o sqlite$(EXE) $(TOP)/src/shell.c \
libsqlite.a $(LIBREADLINE) $(THREADLIB)
替换为:
shell.o: $(TOP)/src/shell.c sqlite.h
$(TCCX) $(READLINE_FLAGS) -c $(TOP)/src/shell.c
sqlite$(EXE): shell.o libsqlite.a
$(TCC) $(LDFLAGS) -o $@ shell.o \
libsqlite.a $(LIBREADLINE) $(THREADLIB) $(LDLIBS)
即在sqlite$(EXE)上一行加上shell.o,及在其后加上$(LDLIBS)标记。这个是对/src/shell.c的编译方法的修改。
4、romfs
将:
install: sqlite libsqlite.a sqlite.h
mv sqlite /usr/bin
mv libsqlite.a /usr/lib
mv sqlite.h /usr/include
替换为:
romfs: sqlite
$(ROMFSINST) /bin/sqlite
即去掉make install项,加上make romfs项。 这个很重要,这将在romfs的/bin目录下生成sqlite。
5、clean
将:
clean:
rm -f *.o sqlite libsqlite.a sqlite.h opcodes.*
rm -f lemon lempar.c parse.* sqlite*.tar.gz
rm -f $(PUBLISH)
rm -f *.da *.bb *.bbg gmon.out
rm -rf tsrc
替换为:
clean:
rm -f *.o sqlite libsqlite.a sqlite.h opcodes.* sqlite.gdb
rm -f $(PUBLISH)
rm -f *.da *.bb *.bbg gmon.out
rm -rf tsrc
distclean: clean
rm -f lemon lempar.c parse.* sqlite*.tar.gz
rm -f config.h
即增加make distclean项。
二、在sqlite下增加Makefile文件
在sqlite目录下应该没有Makefile文件,而只是有一个sqlite/Makefile.linux-gcc文件。我们要移植sqlite到uclinux,那么就要自己写一个合适的Makefile。
内容如下:
===========Makefile内容开始===========
#!/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 -O2
#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
THREADLIB =
#### Leave MEMORY_DEBUG undefined for maximum speed. Use MEMORY_DEBUG=1
# to check for memory leaks. Use MEMORY_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 = -DMEMORY_DEBUG=2
#OPTS = -DMEMORY_DEBUG=1
#OPTS = -DNDEBUG=1
OPTS = -DMEMORY_DEBUG=1
#### 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 = $(CROSS)gcc
FLTFLAGS += -s 12000
#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 = $(CROSS)ar cr
#AR = /opt/mingw/bin/i386-mingw32-ar cr
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -