|
因为项目需要在android的NDK开发中使用pcre正则表达式库,而android系统中并没有自带该库,所以就得另外移植了, 下面是移植的详细步骤:
1. 下载pcre源码,可以到http://sourceforge.net/projects/pcre/下载源码。
我这里使用的是pcre-7.8.tar.gz 。
2. 将pcre-7.8 的源码拷贝至android源码树下的external/pcre目录下。
3. 将下面的Android.mk文件拷贝到external/pcre目录下。
Android.mk:
#
02
# Android makefile for libpcre
03
#
04
# This makefile generates libpcre.a, pcregrep and pcre.h ONLY.
05
# It should be amended to build libpcreposix.a, libpcrecpp.a
06
# and tests.
07
08
09
LOCAL_PATH := $(call my-dir)
10
11
###
12
### Build libpcre.a and pcre.h
13
###
14
15
include $(CLEAR_VARS)
16
17
#step 1:
18
# to generate the files config.h pcre.h pcre_chartables.c
19
#
20
GEN := $(LOCAL_PATH)/config.h
21
$(GEN): $(LOCAL_PATH)/config.h.generic
22
$(hide) cp $(LOCAL_PATH)/config.h.generic $@
23
LOCAL_GENERATED_SOURCES += $(GEN)
24
25
GEN := $(LOCAL_PATH)/pcre.h
26
$(GEN): $(LOCAL_PATH)/pcre.h.generic
27
$(hide) cp $(LOCAL_PATH)/pcre.h.generic $@
28
LOCAL_GENERATED_SOURCES += $(GEN)
29
30
GEN := $(LOCAL_PATH)/pcre_chartables.c
31
$(GEN): $(LOCAL_PATH)/pcre_chartables.c.dist
32
$(hide) cp $(LOCAL_PATH)/pcre_chartables.c.dist $@
33
LOCAL_GENERATED_SOURCES += $(GEN)
34
35
#step 2:
36
#clear the vars generated by the step 1
37
#
38
include $(CLEAR_VARS)
39
40
LOCAL_SRC_FILES := \
41
pcre_compile.c \
42
pcre_config.c \
43
pcre_dfa_exec.c \
44
pcre_exec.c \
45
pcre_fullinfo.c \
46
pcre_get.c \
47
pcre_globals.c \
48
pcre_info.c \
49
pcre_internal.h \
50
pcre_maketables.c \
51
pcre_newline.c \
52
pcre_ord2utf8.c \
53
pcre_refcount.c \
54
pcre_study.c \
55
pcre_tables.c \
56
pcre_try_flipped.c \
57
pcre_ucd.c \
58
pcre_valid_utf8.c \
59
pcre_version.c \
60
pcre_xclass.c \
61
pcre_chartables.c \
62
ucp.h \
63
pcre.h \
64
config.h
65
66
#copy the pcre.h to out/target/product/generic/obj/include/libpcre
67
#
68
LOCAL_COPY_HEADERS := pcre.h
69
LOCAL_COPY_HEADERS_TO := libpcre
70
71
LOCAL_CFLAGS += -O3 -I. -DHAVE_CONFIG_H
72
73
LOCAL_MODULE := libpcre
74
LOCAL_MODULE_CLASS := STATIC_LIBRARIES
75
LOCAL_PRELINK_MODULE := false
76
77
include $(BUILD_STATIC_LIBRARY)
78
79
###
80
### Build pcregrep
81
###
82
83
include $(CLEAR_VARS)
84
85
LOCAL_MODULE := pcregrep
86
LOCAL_SRC_FILES := pcregrep.c
87
LOCAL_CFLAGS += -O3 -I. -DHAVE_CONFIG_H
88
LOCAL_STATIC_LIBRARIES := libpcre
89
90
include $(BUILD_EXECUTABLE)
复制代码4. cd 到 android的源码树的根目录下,输入命令: . build/envsetup.sh
chooseproduct
mmm external/pcre
复制代码从下面的log可以看到生成了libpcre.a库: make: Entering directory `/home/braincol/workspace/android/android_build/android_sdk_froyo'
Header: out/target/product/generic/obj/include/libpcre/pcre.h
target thumb C: pcregrep <= external/pcre/pcregrep.c
target thumb C: libpcre <= external/pcre/pcre_compile.c
target thumb C: libpcre <= external/pcre/pcre_config.c
target thumb C: libpcre <= external/pcre/pcre_dfa_exec.c
target thumb C: libpcre <= external/pcre/pcre_exec.c
target thumb C: libpcre <= external/pcre/pcre_fullinfo.c
target thumb C: libpcre <= external/pcre/pcre_get.c
target thumb C: libpcre <= external/pcre/pcre_globals.c
target thumb C: libpcre <= external/pcre/pcre_info.c
target thumb C: libpcre <= external/pcre/pcre_maketables.c
target thumb C: libpcre <= external/pcre/pcre_newline.c
target thumb C: libpcre <= external/pcre/pcre_ord2utf8.c
target thumb C: libpcre <= external/pcre/pcre_refcount.c
target thumb C: libpcre <= external/pcre/pcre_study.c
target thumb C: libpcre <= external/pcre/pcre_tables.c
target thumb C: libpcre <= external/pcre/pcre_try_flipped.c
target thumb C: libpcre <= external/pcre/pcre_ucd.c
target thumb C: libpcre <= external/pcre/pcre_valid_utf8.c
target thumb C: libpcre <= external/pcre/pcre_version.c
target thumb C: libpcre <= external/pcre/pcre_xclass.c
target thumb C: libpcre <= external/pcre/pcre_chartables.c
target StaticLib: libpcre (out/target/product/generic/obj/STATIC_LIBRARIES/libpcre_intermediates/libpcre.a)
target Executable: pcregrep (out/target/product/generic/obj/EXECUTABLES/pcregrep_intermediates/LINKED/pcregrep)
target Non-prelinked: pcregrep (out/target/product/generic/symbols/system/bin/pcregrep)
target Strip: pcregrep (out/target/product/generic/obj/EXECUTABLES/pcregrep_intermediates/pcregrep)
Install: out/target/product/generic/system/bin/pcregrep
make: Leaving directory `/home/braincol/workspace/android/android_build/android_sdk_froyo'
复制代码然后只要把libpcre.a库和头文件pcre.h拷贝到你的android应用工程中,然后就可以在ndk中使用这个pcre库了。 |
|