全部博文(1159)
分类: C/C++
2015-10-19 12:20:45
因为项目需要在android的NDK开发中使用pcre正则表达式库,而android系统中并没有自带该库,所以就得另外移植了, 下面是移植的详细步骤:
1. 下载pcre源码,可以到。
2. 将pcre-7.8 的源码拷贝至android源码树下的external/pcre目录下。
3. 将下面的Android.mk文件拷贝到external/pcre目录下。
Android.mk:
#---------------------------------------------------------------------------------#
# Android makefile for libpcre
#
# This makefile generates libpcre.a, pcregrep and pcre.h ONLY.
# It should be amended to build libpcreposix.a, libpcrecpp.a
# and tests.
LOCAL_PATH := $(call my-
dir
)
###
### Build libpcre.a and pcre.h
###
include $(CLEAR_VARS)
#step 1:
# to generate the files config.h pcre.h pcre_chartables.c
#
GEN := $(LOCAL_PATH)
/config
.h
$(GEN): $(LOCAL_PATH)
/config
.h.generic
$(hide)
cp
$(LOCAL_PATH)
/config
.h.generic $@
LOCAL_GENERATED_SOURCES += $(GEN)
GEN := $(LOCAL_PATH)
/pcre
.h
$(GEN): $(LOCAL_PATH)
/pcre
.h.generic
$(hide)
cp
$(LOCAL_PATH)
/pcre
.h.generic $@
LOCAL_GENERATED_SOURCES += $(GEN)
GEN := $(LOCAL_PATH)
/pcre_chartables
.c
$(GEN): $(LOCAL_PATH)
/pcre_chartables
.c.dist
$(hide)
cp
$(LOCAL_PATH)
/pcre_chartables
.c.dist $@
LOCAL_GENERATED_SOURCES += $(GEN)
#step 2:
#clear the vars generated by the step 1
#
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
pcre_compile.c \
pcre_config.c \
pcre_dfa_exec.c \
pcre_exec.c \
pcre_fullinfo.c \
pcre_get.c \
pcre_globals.c \
pcre_info.c \
pcre_internal.h \
pcre_maketables.c \
pcre_newline.c \
pcre_ord2utf8.c \
pcre_refcount.c \
pcre_study.c \
pcre_tables.c \
pcre_try_flipped.c \
pcre_ucd.c \
pcre_valid_utf8.c \
pcre_version.c \
pcre_xclass.c \
pcre_chartables.c \
ucp.h \
pcre.h \
config.h
#copy the pcre.h to out/target/product/generic/obj/include/libpcre
#
LOCAL_COPY_HEADERS := pcre.h
LOCAL_COPY_HEADERS_TO := libpcre
LOCAL_CFLAGS += -O3 -I. -DHAVE_CONFIG_H
LOCAL_MODULE := libpcre
LOCAL_MODULE_CLASS := STATIC_LIBRARIES
LOCAL_PRELINK_MODULE :=
false
include $(BUILD_STATIC_LIBRARY)
###
### Build pcregrep
###
include $(CLEAR_VARS)
LOCAL_MODULE := pcregrep
LOCAL_SRC_FILES := pcregrep.c
LOCAL_CFLAGS += -O3 -I. -DHAVE_CONFIG_H
LOCAL_STATIC_LIBRARIES := libpcre
include $(BUILD_EXECUTABLE)
4. cd 到 android的源码树的根目录下,输入命令:
. build/envsetup.sh
chooseproduct
mmm external/pcre
从下面的log可以看到生成了libpcre.a库: