summaryrefslogtreecommitdiff
path: root/acinclude.m4
blob: 8dc0426f6dc088cd25ac01272ea2ebfa37042517 (plain) (blame)
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
dnl $Id$

dnl @synopsis AC_CHECK_LIB_TMW(
dnl               LIBRARY
dnl               [, MINIMUM-VERSION
dnl               [, LIBRARY-CONFIG-EXE
dnl               [, ACTION-IF-FOUND
dnl               [, ACTION-IF-NOT-FOUND ]]]]
dnl           )
dnl
dnl This function runs a LIBRARY-config script (or LIBRARY-CONFIG-EXE if
dnl specified) and defines LIBRARY_CFLAGS and LIBRARY_LIBS.
dnl
dnl The script must support `--cflags' and `--libs' args.
dnl If MINIMUM-VERSION is specified, the script must also support the
dnl `--version' arg.
dnl If the `--with-library-[exec-]prefix' arguments to ./configure are given,
dnl it must also support `--prefix' and `--exec-prefix'.
dnl (In other words, it must be like gtk-config.)
dnl
dnl Example:
dnl
dnl    AC_CHECK_LIB_TMW(foo, 1.0.0)
dnl
dnl would run `foo-config --version' and check that it is at least 1.0.0.
dnl
dnl If so, the following would then be defined:
dnl
dnl    FOO_CFLAGS to `foo-config --cflags`
dnl    FOO_LIBS   to `foo-config --libs`
dnl
dnl This function is a hack of the original ac_path_generic.m4 written by
dnl Angus Lees <gusl@cse.unsw.edu.au>.
dnl It adds LIBRARY-CONFIG-EXE so that it is possible to define `foo_config`
dnl as the script to execute instead of the default `foo-config`.

m4_include(ax_compare_version.m4)

AC_DEFUN([AC_CHECK_LIB_TMW], [
    dnl define macros to uppercase or lowercase a string.
    pushdef([UP], translit([$1], [a-z], [A-Z]))dnl
    pushdef([DOWN], translit([$1], [A-Z], [a-z]))dnl

    dnl add two options to the configure script to set the prefix and
    dnl the exec-prefix of the library.
    AC_ARG_WITH(
        DOWN-prefix,
        AS_HELP_STRING(
            [--with-DOWN-prefix=PREFIX],
            [prefix where lib$1 is installed (optional)]
        ),
        [DOWN[]_config_prefix="$withval"],
        [DOWN[]_config_prefix=""]
    )

    AC_ARG_WITH(
        DOWN-exec-prefix,
        AS_HELP_STRING(
            [--with-DOWN-exec-prefix=EPREFIX],
            [exec prefix where lib$1 is installed (optional)]
        ),
        [DOWN[]_config_exec_prefix="$withval"],
        [DOWN[]_config_exec_prefix=""]
    )

    dnl set default shell script to execute.
    ifelse(
        [$3],
        [],
        [DOWN[]_config_script="DOWN-config"],
        [DOWN[]_config_script="$3"]
    )

    dnl print an info message if we have detected the environment
    dnl variable LIBRARY_CONFIG.
    if test -n "${UP[]_CONFIG+set}"; then
        AC_MSG_NOTICE(
            [using UP[]_CONFIG=$UP[]_CONFIG found from your environment]
        )
    fi

    if test -n "$DOWN[]_config_prefix"; then
        DOWN[]_config_args=\
            "$DOWN[]_config_args --prefix=$DOWN[]_config_prefix"

        if test -z "${UP[]_CONFIG+set}"; then
            [UP[]_CONFIG=$DOWN[]_config_prefix/bin/$DOWN[]_config_script]
        fi
    fi

    if test -n "$DOWN[]_config_exec_prefix"; then
        DOWN[]_config_args=\
            "$DOWN[]_config_args --exec-prefix=$DOWN[]_config_exec_prefix"

        if test -z "${UP[]_CONFIG+set}"; then
            [UP[]_CONFIG=$DOWN[]_config_exec_prefix/bin/$DOWN[]_config_script]
        fi
    fi

    succeeded=no

    if test -z "$UP[]_CONFIG"; then
        AC_PATH_PROG(UP[]_CONFIG, $DOWN[]_config_script, [no])
    fi

    if test "$UP[]_CONFIG" = "no"; then
        echo "*** The $DOWN[]_config_script script could not be found. Make"
        echo "*** sure it is in your path, or set the UP[]_CONFIG environment"
        echo "*** variable to the full path to $DOWN[]_config_script."
    else
        ifelse(
            [$2], [],
            AC_MSG_CHECKING([for $1]),
            AC_MSG_CHECKING([for $1 - version >= $2])
        )

        if test -x "$UP[]_CONFIG"; then
            ifelse(
                [$2], [], [],
                [DOWN[]_version=`$UP[]_CONFIG $DOWN[]_config_args --version`

                AX_COMPARE_VERSION(
                    [$DOWN[]_version], [ge], [$2],
                    [],
                    [AC_MSG_RESULT([no])

                    UP[]_CFLAGS=""
                    UP[]_LIBS=""

                    echo "***"
                    echo "*** If you have already installed a sufficiently new"
                    echo "*** version, this error probably means that the wrong"
                    echo "*** copy of the $DOWN[]_config_script shell script is"
                    echo "*** being found in your path."
                    echo "***"

                    AC_MSG_ERROR([found $DOWN[]_version])
                    ]
                )]
            )

            AC_MSG_RESULT(yes)
            succeeded="yes"

            AC_MSG_CHECKING(UP[]_CFLAGS)
            UP[]_CFLAGS=`$UP[]_CONFIG $DOWN[]_config_args --cflags`
            AC_MSG_RESULT($UP[]_CFLAGS)

            AC_MSG_CHECKING(UP[]_LIBS)
            UP[]_LIBS=`$UP[]_CONFIG $DOWN[]_config_args --libs`
            AC_MSG_RESULT($UP[]_LIBS)
        else
            AC_MSG_RESULT([could not execute $UP[]_CONFIG])

            echo "***"
            echo "*** The $UP[]_CONFIG shell script does not exist or"
            echo "*** is not executable. Please check if the file exists and"
            echo "*** is executable or update your UP[]_CONFIG environment"
            echo "*** variable so that it points to an existing DOWN-config"
            echo "*** shell script."
            echo "***"
        fi
    fi

    dnl define output variables.
    AC_SUBST(UP[]_CFLAGS)
    AC_SUBST(UP[]_LIBS)

    if test "$succeeded" = "yes"; then
        ifelse([$4], [], :, [$4])
    else
        ifelse(
            [$5],
            [],
            AC_MSG_ERROR([library requirements (>=$2) not met.]),
            [$5]
        )
    fi

    dnl undefine macros.
    popdef([UP])
    popdef([DOWN])
])