Welcome to mirror list, hosted at ThFree Co, Russian Federation.

pcre.m4 « m4 - github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3b5a08d2d24ef976fdc1a2d6336080e9bb3ca386 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# LIBPCRE_CHECK_CONFIG ([DEFAULT-ACTION])
# ----------------------------------------------------------
#
# Checks for pcre.
#
# This macro #defines HAVE_PCRE_H if required header files are
# found, and sets @LIBPCRE_LDFLAGS@ and @LIBPCRE_CFLAGS@ to the necessary
# values.
#
# This macro is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

AC_DEFUN([LIBPCRE_TRY_LINK],
[
AC_TRY_LINK(
[
#include <pcre.h>
],
[
	const char* error = NULL;
	int error_offset = -1;
	pcre *regexp = pcre_compile("test", PCRE_UTF8, &error, &error_offset, NULL);
	pcre_free(regexp);
],
found_libpcre="yes")
])dnl

AC_DEFUN([LIBPCRE_CHECK_CONFIG],
[
	AC_ARG_WITH([libpcre],[
If you want to specify libpcre installation directories:
AC_HELP_STRING([--with-libpcre@<:@=DIR@:>@], [use libpcre from given base install directory (DIR), default is to search through a number of common places for the libpcre files.])],
		[
			if test "$withval" = "yes"; then
				if test -f /usr/local/include/pcre.h; then
					withval="/usr/local"
				else
					withval="/usr"
				fi
			else
				_libpcre_dir_lib="$withval/lib"
			fi
			_libpcre_dir="$withval"
			test "x$withval" = "xyes" && withval=/usr
			LIBPCRE_CFLAGS="-I$withval/include"
			LIBPCRE_LDFLAGS="-L$withval/lib"
			_libpcre_dir_set="yes"
		]
	)

	AC_ARG_WITH([libpcre-include],
		AC_HELP_STRING([--with-libpcre-include@<:@=DIR@:>@],
			[use libpcre include headers from given path.]
		),
		[
			LIBPCRE_CFLAGS="-I$withval"
			_libpcre_dir_set="yes"
		]
	)

	AC_ARG_WITH([libpcre-lib],
		AC_HELP_STRING([--with-libpcre-lib@<:@=DIR@:>@],
			[use libpcre libraries from given path.]
		),
		[
			_libpcre_dir="$withval"
			_libpcre_dir_lib="$withval"
			LIBPCRE_LDFLAGS="-L$withval"
			_libpcre_dir_set="yes"
		]
	)

	if test "x$enable_static_libs" = "xyes"; then
		AC_REQUIRE([PKG_PROG_PKG_CONFIG])
		PKG_PROG_PKG_CONFIG()
		test -z "$PKG_CONFIG" -a -z "$_libpcre_dir_lib" && AC_MSG_ERROR([Not found pkg-config library])
		m4_pattern_allow([^PKG_CONFIG_LIBDIR$])
	fi

	AC_MSG_CHECKING(for libpcre support)

	LIBPCRE_LIBS="-lpcre"

	if test "x$enable_static" = "xyes"; then
		LIBPCRE_LIBS=" $LIBPCRE_LIBS -lpthread"
	elif test "x$enable_static_libs" = "xyes" -a -z "$PKG_CONFIG"; then
		LIBPCRE_LIBS="$_libpcre_dir_lib/libpcre.a"
	elif test "x$enable_static_libs" = "xyes"; then

		test "x$static_linking_support" = "xno" -a -z "$_libpcre_dir_lib" && AC_MSG_ERROR(["Compiler not support statically linked libs from default folders"])

		if test -z "$_libpcre_dir_lib"; then
			PKG_CHECK_EXISTS(libpcre,[
				LIBPCRE_LIBS=`$PKG_CONFIG --static --libs libpcre`
			],[
				AC_MSG_ERROR([Not found libpcre package])
			])
		else
			AC_RUN_LOG([PKG_CONFIG_LIBDIR="$_libpcre_dir_lib/pkgconfig" $PKG_CONFIG --exists --print-errors libpcre]) || AC_MSG_ERROR(["Not found libpcre package in $_libpcre_dir/lib/pkgconfig"])
			LIBPCRE_LIBS=`PKG_CONFIG_LIBDIR="$_libpcre_dir_lib/pkgconfig" $PKG_CONFIG --static --libs libpcre`
			test -z "$LIBPCRE_LIBS" && LIBPCRE_LIBS=`PKG_CONFIG_LIBDIR="$_libpcre_dir_lib/pkgconfig" $PKG_CONFIG --libs libpcre`
		fi

		if test "x$static_linking_support" = "xno"; then
			LIBPCRE_LIBS=`echo "$LIBPCRE_LIBS"|sed "s|-lpcre|$_libpcre_dir_lib/libpcre.a|g"`
		else
			LIBPCRE_LIBS=`echo "$LIBPCRE_LIBS"|sed "s/-lpcre/${static_linking_support}static -lpcre ${static_linking_support}dynamic/g"`
		fi
	fi

	if test -n "$_libpcre_dir_set" -o -f /usr/include/pcre.h; then
		found_libpcre="yes"
	elif test -f /usr/local/include/pcre.h; then
		LIBPCRE_CFLAGS="-I/usr/local/include"
		LIBPCRE_LDFLAGS="-L/usr/local/lib"
		found_libpcre="yes"
	elif test -f /usr/pkg/include/pcre.h; then
		LIBPCRE_CFLAGS="-I/usr/pkg/include"
		LIBPCRE_LDFLAGS="-L/usr/pkg/lib"
		LIBPCRE_LDFLAGS="$LIBPCRE_LDFLAGS -Wl,-R/usr/pkg/lib"
		found_libpcre="yes"
	elif test -f /opt/csw/include/pcre.h; then
		LIBPCRE_CFLAGS="-I/opt/csw/include"
		LIBPCRE_LDFLAGS="-L/opt/csw/lib"
		if $(echo "$CFLAGS"|grep -q -- "-m64") ; then
			LIBPCRE_LDFLAGS="$LIBPCRE_LDFLAGS/64 -Wl,-R/opt/csw/lib/64"
		else
			LIBPCRE_LDFLAGS="$LIBPCRE_LDFLAGS -Wl,-R/opt/csw/lib"
		fi
		found_libpcre="yes"
	else
		found_libpcre="no"
		AC_MSG_RESULT(no)
	fi

	if test "x$found_libpcre" = "xyes"; then
		am_save_CFLAGS="$CFLAGS"
		am_save_LDFLAGS="$LDFLAGS"
		am_save_LIBS="$LIBS"

		CFLAGS="$CFLAGS $LIBPCRE_CFLAGS"
		LDFLAGS="$LDFLAGS $LIBPCRE_LDFLAGS"
		LIBS="$LIBS $LIBPCRE_LIBS"

		found_libpcre="no"
		LIBPCRE_TRY_LINK([no])

		CFLAGS="$am_save_CFLAGS"
		LDFLAGS="$am_save_LDFLAGS"
		LIBS="$am_save_LIBS"
	fi

	if test "x$found_libpcre" = "xyes"; then
		AC_DEFINE([HAVE_PCRE_H], 1, [Define to 1 if you have the 'libpcre' library (-lpcre)])
		AC_MSG_RESULT(yes)
	else
		LIBPCRE_CFLAGS=""
		LIBPCRE_LDFLAGS=""
		LIBPCRE_LIBS=""
	fi

	AC_SUBST(LIBPCRE_CFLAGS)
	AC_SUBST(LIBPCRE_LDFLAGS)
	AC_SUBST(LIBPCRE_LIBS)
])dnl