summaryrefslogtreecommitdiff
path: root/macros2/gnome-pkgconfig.m4
blob: 628cdcec420b7fc59fc6d6566d150a0a6b3296e3 (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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
dnl GNOME_PKGCONFIG_CHECK_VERSION() extracts up to 6 decimal numbers out of given-version
dnl and required-version, using any non-number letters as delimiters. it then
dnl compares each of those 6 numbers in order 1..6 to each other, requirering
dnl all of the 6 given-version numbers to be greater than, or at least equal
dnl to the corresponding number of required-version.
dnl GNOME_PKGCONFIG_CHECK_VERSION(given-version, required-version [, match-action] [, else-action])
AC_DEFUN([GNOME_PKGCONFIG_CHECK_VERSION],[
[eval `echo "$1:0:0:0:0:0:0" | sed -e 's/^[^0-9]*//' -e 's/[^0-9]\+/:/g' \
 -e 's/\([^:]*\):\([^:]*\):\([^:]*\):\([^:]*\):\([^:]*\):.*/ac_v1=\1 ac_v2=\2 ac_v3=\3 ac_v4=\4 ac_v5=\5 ac_v6=\6/' \
`]
[eval `echo "$2:0:0:0:0:0:0" | sed -e 's/^[^0-9]*//' -e 's/[^0-9]\+/:/g' \
 -e 's/\([^:]*\):\([^:]*\):\([^:]*\):\([^:]*\):\([^:]*\):.*/ac_r1=\1 ac_r2=\2 ac_r3=\3 ac_r4=\4 ac_r5=\5 ac_r6=\6/' \
`]
ac_vm=[`expr \( $ac_v1 \> $ac_r1 \) \| \( \( $ac_v1 \= $ac_r1 \) \& \(          \
              \( $ac_v2 \> $ac_r2 \) \| \( \( $ac_v2 \= $ac_r2 \) \& \(         \
               \( $ac_v3 \> $ac_r3 \) \| \( \( $ac_v3 \= $ac_r3 \) \& \(        \
                \( $ac_v4 \> $ac_r4 \) \| \( \( $ac_v4 \= $ac_r4 \) \& \(       \
                 \( $ac_v5 \> $ac_r5 \) \| \( \( $ac_v5 \= $ac_r5 \) \& \(      \
                  \( $ac_v6 \>= $ac_r6 \)                                       \
                 \) \)  \
                \) \)   \
               \) \)    \
              \) \)     \
             \) \)      `]
case $ac_vm in
[1)]
        [$3]
        ;;
*[)]
        [$4]
        ;;
esac
])

dnl
dnl GNOME_CHECK_PKGCONFIG (script-if-enabled, [failflag])
dnl
AC_DEFUN([GNOME_CHECK_PKGCONFIG],[
	AC_PATH_PROG(PKG_CONFIG, pkg-config)
	have_pkgconfig=no
	if test -x "$PKG_CONFIG" ; then
	    have_pkgconfig=yes
	else
	    PKG_CONFIG=
	fi
	AC_MSG_CHECKING(for pkg-config)
	if test x$have_pkgconfig = xyes ; then
	    pkgconfig_required_version=0.4.1
	    pkgconfig_version=`pkg-config --version`
	    GNOME_PKGCONFIG_CHECK_VERSION($pkgconfig_version, $pkgconfig_required_version, [have_pkgconfig=yes], [have_pkgconfig=no])
	fi
	if test x$have_pkgconfig = xyes ; then
	    AC_MSG_RESULT(yes)
	else
	    PKG_CONFIG=
	    AC_MSG_RESULT(not found)
 	    if test x$2 = xfail; then
		AC_MSG_ERROR([
*** You need the latest pkg-config (at least $pkgconfig_required_version).
*** Get the latest version of pkg-config from
*** http://pkgconfig.sourceforce.net.])
	    fi
	fi
	AC_SUBST(PKG_CONFIG)

	AC_PROVIDE([GNOME_REQUIRE_PKGCONFIG])
])

dnl
dnl GNOME_REQUIRE_PKGCONFIG
dnl
AC_DEFUN([GNOME_REQUIRE_PKGCONFIG],[
	GNOME_CHECK_PKGCONFIG([], fail)
])

dnl Check if the C compiler accepts a certain C flag, and if so adds it to
dnl CFLAGS
AC_DEFUN([GNOME_PKGCONFIG_CHECK_CFLAG], [
  AC_REQUIRE([GNOME_REQUIRE_PKGCONFIG])

  AC_MSG_CHECKING(if C compiler accepts $1)
  save_CFLAGS="$CFLAGS"

  dnl make sure we add it only once
  dnl this one doesn't seem to work: *[\ \	]$1[\ \ ]*) ;;
  case " $CFLAGS " in
  *\ $1\ *) echo $ac_n "(already in CFLAGS) ... " ;;
  *\ $1\	*) echo $ac_n "(already in CFLAGS) ... " ;;
  *\	$1\ *) echo $ac_n "(already in CFLAGS) ... " ;;
  *\	$1\	*) echo $ac_n "(already in CFLAGS) ... " ;;
  *) CFLAGS="$CFLAGS $1" ;;
  esac

  AC_TRY_COMPILE([#include <stdio.h>], [printf("hello");],
	         [ AC_MSG_RESULT(yes)],dnl
	         [ CFLAGS="$save_CFLAGS" AC_MSG_RESULT(no) ])
])

dnl add $ACLOCAL_FLAGS (and optionally more dirs) to the aclocal
dnl commandline, so make can work even if it needs to rerun aclocal
AC_DEFUN([GNOME_PKGCONFIG_ACLOCALFLAGS],
[
  AC_REQUIRE([GNOME_REQUIRE_PKGCONFIG])

  test -n "$ACLOCAL_FLAGS" && ACLOCAL="$ACLOCAL $ACLOCAL_FLAGS"

  for i in "$1"; do
    ACLOCAL="$ACLOCAL -I $i"
  done
])

AC_DEFUN([GNOME_PKGCONFIG_CHECK_OPTIONAL_MODULES],
[
    AC_REQUIRE([GNOME_REQUIRE_PKGCONFIG])

    name=$1
    depvar=$3

    AC_MSG_CHECKING(for libraries)
    pkg_list=""
    for module in $2 ""; do
	if test -n "$module"; then
	    if `echo $module |grep -q ":"`; then
		dnl has version requirement
		pkg_module_name=`echo $module |sed 's/\(.*\):.*/\1/'`
		test_version=`echo $module |sed 's/.*:\(.*\)/\1/'`

		msg=`$PKG_CONFIG $pkg_module_name 2>&1`
		if test -z "$msg"; then
		    dnl module exists
		    pkg_version=`$PKG_CONFIG --modversion $pkg_module_name`
		    GNOME_PKGCONFIG_CHECK_VERSION($pkg_version, $test_version,
			dnl has the right version
			echo $ac_n "$pkg_module_name "
			pkg_list="$pkg_list $pkg_module_name"
		    ,
			AC_MSG_RESULT([($pkg_module_name)])
			if test x$4 = xfail ; then
				AC_MSG_ERROR([An old version of $pkg_module_name (version $pkg_version) was found. You need at least version $test_version])
			else
				AC_MSG_WARN([An old version of $pkg_module_name (version $pkg_version) was found. You need at least version $test_version])
			fi
		    )
		else
		    dnl doesn't exist
		    AC_MSG_RESULT([($pkg_module_name)])
		    if test x$4 = xfail ; then
			AC_MSG_ERROR([$msg])
		    else
			AC_MSG_WARN([$msg])
		    fi
		fi
	    else
		msg=`$PKG_CONFIG $module 2>&1`
		if test -z "$msg"; then
		    echo $ac_n "$module "
		    pkg_list="$pkg_list $module"
		else
		    AC_MSG_RESULT([($module)])
		    if test x$4 = xfail ; then
			AC_MSG_ERROR([$msg])
		    else
			AC_MSG_WARN([$msg])
		    fi
		fi
	    fi
	fi
    done
    AC_MSG_RESULT([])
    if test -n "$pkg_list"; then
	eval $name'_CFLAGS'=\"`$PKG_CONFIG --cflags $pkg_list`\"
	eval $name'_LIBS'=\"`$PKG_CONFIG --libs $pkg_list`\"
	if test -n "$depvar"; then
	    eval $depvar'_DEPENDS'=\"\$$depname'_DEPENDS' $pkg_list\"
	else
	    eval $name'_DEPENDS'=\"$pkg_list\"
	fi
	if test -z "$4" ; then
	    eval 'HAVE_'$name=yes
	fi
    fi
])

AC_DEFUN([GNOME_PKGCONFIG_CHECK_MODULES],
[
	GNOME_PKGCONFIG_CHECK_OPTIONAL_MODULES($1,$2,$3,fail)
])