前言
之前的文章提到如何使用NDK编译Android上的sqlite3的动态库文件,今天因为第一天上班,人还有点恍惚。早上因为要送老婆去火车站,所以很早便出门了,后来到单位才7点一刻左右,悲催的是单位竟然断网了,不知道是不是台风搞的。静下心来,要不就把之前说的sqlite在iOS上编译下。事实证明,我对MAC下的编译还是懵懵懂懂,很大原因是因为makefile文件不是我亲自写的,而是通过configure工具生成的。
准备工作
可以参考之前的文章:编译iOS上的libevent库
然后只需要一个脚本即可搞定了
编译脚本
#!/bin/bash # Builds libevent for all three current iPhone targets: iPhoneSimulator-i386, # iPhoneOS-armv6, iPhoneOS-armv7. # # Copyright 2013 sosoayaen <sosoayaen@gmail.com> # # Licensed 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. # ########################################################################### # Choose your libevent version and your currently-installed iOS SDK version: # VERSION="3080002" SDKVERSION="6.0" # # ########################################################################### # # Don't change anything under this line! # ########################################################################### # No need to change this since xcode build will only compile in the # necessary bits from the libraries we create ARCHS="i386 armv7 armv7s" DEVELOPER=`xcode-select -print-path` cd "`dirname \"$0\"`" REPOROOT=$(pwd) # Where we'll end up storing things in the end OUTPUTDIR="${REPOROOT}/dependencies" mkdir -p ${OUTPUTDIR}/include mkdir -p ${OUTPUTDIR}/lib BUILDDIR="${REPOROOT}/build" # where we will keep our sources and build from. SRCDIR="${BUILDDIR}/src" mkdir -p $SRCDIR # where we will store intermediary builds INTERDIR="${BUILDDIR}/built" mkdir -p $INTERDIR # Copy source file into src directory # cp -f sqlite3.h sqlite3ext.h sqlite3.c $SRCDIR #unzip -j sqlite-amalgamation-3080002.zip -x sqlite-amalgamation-3080002/shell.c -d ${SRCDIR} ######################################## cd $SRCDIR if [ ! -e "${SRCDIR}/sqlite-autoconf-${VERSION}.tar.gz" ]; then echo "Downloading sqlite-autoconf-${VERSION}.tar.gz" curl -LO http://sqlite.org/2013/sqlite-autoconf-${VERSION}.tar.gz else echo "Using sqlite-autoconf-3080002.tar.gz" fi tar zxf sqlite-autoconf-${VERSION}.tar.gz -C $SRCDIR cd "${SRCDIR}/sqlite-autoconf-${VERSION}" set +e CCACHE=`which ccache` if [ $? == "0" ]; then echo "Building with cache: $CCACHE" CCACHE="${CCACHE} " else echo "Building without ccache" CCACHE="" fi set -e for ARCH in ${ARCHS} do echo ARCH:${ARCH} if [ "${ARCH}" == "i386" ]; then PLATFORM="iPhoneSimulator" EXTRA_CONFIG="" else PLATFORM="iPhoneOS" EXTRA_CONFIG="--host=arm-apple-darwin11" fi mkdir -p "${INTERDIR}/${PLATFORM}${SDKVERSION}-${ARCH}.sdk" ./configure --disable-shared --enable-static --disable-debug-mode ${EXTRA_CONFIG} \ --prefix="${INTERDIR}/${PLATFORM}${SDKVERSION}-${ARCH}.sdk" \ CC="${CCACHE}${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer/usr/bin/gcc -arch ${ARCH}" \ LDFLAGS="$LDFLAGS -L${OUTPUTDIR}/lib" \ CFLAGS="$CFLAGS -I${OUTPUTDIR}/include -isysroot ${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDKVERSION}.sdk" \ CPPFLAGS="$CPPFLAGS -I${OUTPUTDIR}/include -isysroot ${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDKVERSION}.sdk" # Build the application and install it to the fake SDK intermediary dir # we have set up. Make sure to clean up afterward because we will re-use # this source tree to cross-compile other targets. make -j4 make install make clean done ######################################## echo "Build library..." # These are the libs that comprise sqlite3. # may not be compiled if those dependencies aren't available. OUTPUT_LIBS="libsqlite3.a" for OUTPUT_LIB in ${OUTPUT_LIBS}; do INPUT_LIBS="" for ARCH in ${ARCHS}; do if [ "${ARCH}" == "i386" ]; then PLATFORM="iPhoneSimulator" else PLATFORM="iPhoneOS" fi INPUT_ARCH_LIB="${INTERDIR}/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/lib/${OUTPUT_LIB}" if [ -e $INPUT_ARCH_LIB ]; then INPUT_LIBS="${INPUT_LIBS} ${INPUT_ARCH_LIB}" fi done # Combine the three architectures into a universal library. if [ -n "$INPUT_LIBS" ]; then lipo -create $INPUT_LIBS \ -output "${OUTPUTDIR}/lib/${OUTPUT_LIB}" else echo "$OUTPUT_LIB does not exist, skipping (are the dependencies installed?)" fi done for ARCH in ${ARCHS}; do if [ "${ARCH}" == "i386" ]; then PLATFORM="iPhoneSimulator" else PLATFORM="iPhoneOS" fi cp -R ${INTERDIR}/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/include/* ${OUTPUTDIR}/include/ if [ $? == "0" ]; then # We only need to copy the headers over once. (So break out of forloop # once we get first success.) break fi done #################### echo "Building done." echo "Cleaning up..." rm -fr ${INTERDIR} rm -fr "${SRCDIR}/sqlite-autoconf-${VERSION}" echo "Done."
OK,如果编译不了搞不定的话,我也提供了下载文件:请猛击我进入下载界面
这里编译出来的文件是采用默认的configure文件,如果需要sqlite的特殊功能,请自己修改对应头文件中的宏定义后重新编译即可。