?? 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 + -