PageRenderTime 28ms CodeModel.GetById 17ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Tools/config/ax_path_generic.m4

#
m4 | 164 lines | 81 code | 12 blank | 71 comment | 0 complexity | 069fda26eeee7317daacd1e6b0a3c213 MD5 | raw file
  1# ===========================================================================
  2#      http://www.gnu.org/software/autoconf-archive/ax_path_generic.html
  3# ===========================================================================
  4#
  5# SYNOPSIS
  6#
  7#   AX_PATH_GENERIC(LIBRARY,[MINIMUM-VERSION,[SED-EXPR-EXTRACTOR]],[ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND],[CONFIG-SCRIPTS],[CFLAGS-ARG],[LIBS-ARG])
  8#
  9# DESCRIPTION
 10#
 11#   Runs the LIBRARY-config script and defines LIBRARY_CFLAGS and
 12#   LIBRARY_LIBS unless the user had predefined them in the environment.
 13#
 14#   The script must support `--cflags' and `--libs' args. If MINIMUM-VERSION
 15#   is specified, the script must also support the `--version' arg. If the
 16#   `--with-library-[exec-]prefix' arguments to ./configure are given, it
 17#   must also support `--prefix' and `--exec-prefix'. Prefereable use
 18#   CONFIG-SCRIPTS as config script, CFLAGS-ARG instead of `--cflags` and
 19#   LIBS-ARG instead of `--libs`, if given.
 20#
 21#   The SED-EXPR-EXTRACTOR parameter representes the expression used in sed
 22#   to extract the version number. Use it if your 'foo-config --version'
 23#   dumps something like 'Foo library v1.0.0 (alfa)' instead of '1.0.0'.
 24#
 25#   The macro respects LIBRARY_CONFIG, LIBRARY_CFLAGS and LIBRARY_LIBS
 26#   variables. If the first one is defined, it specifies the name of the
 27#   config script to use. If the latter two are defined, the script is not
 28#   ran at all and their values are used instead (if only one of them is
 29#   defined, the empty value of the remaining one is still used).
 30#
 31#   Example:
 32#
 33#     AX_PATH_GENERIC(Foo, 1.0.0)
 34#
 35#   would run `foo-config --version' and check that it is at least 1.0.0, if
 36#   successful the following variables would be defined and substituted:
 37#
 38#     FOO_CFLAGS to `foo-config --cflags`
 39#     FOO_LIBS   to `foo-config --libs`
 40#
 41#   Example:
 42#
 43#     AX_PATH_GENERIC([Bar],,,[
 44#        AC_MSG_ERROR([Cannot find Bar library])
 45#     ])
 46#
 47#   would check for bar-config program, defining and substituting the
 48#   following variables:
 49#
 50#     BAR_CFLAGS to `bar-config --cflags`
 51#     BAR_LIBS   to `bar-config --libs`
 52#
 53#   Example:
 54#
 55#     ./configure BAZ_LIBS=/usr/lib/libbaz.a
 56#
 57#   would link with a static version of baz library even if `baz-config
 58#   --libs` returns just "-lbaz" that would normally result in using the
 59#   shared library.
 60#
 61#   This macro is a rearranged version of AC_PATH_GENERIC from Angus Lees.
 62#
 63# LICENSE
 64#
 65#   Copyright (c) 2009 Francesco Salvestrini <salvestrini@users.sourceforge.net>
 66#
 67#   Copying and distribution of this file, with or without modification, are
 68#   permitted in any medium without royalty provided the copyright notice
 69#   and this notice are preserved. This file is offered as-is, without any
 70#   warranty.
 71
 72#serial 11
 73
 74AU_ALIAS([AC_PATH_GENERIC], [AX_PATH_GENERIC])
 75AC_DEFUN([AX_PATH_GENERIC],[
 76  AC_REQUIRE([AC_PROG_SED])
 77
 78  dnl we're going to need uppercase and lowercase versions of the
 79  dnl string `LIBRARY'
 80  pushdef([UP],   translit([$1], [a-z], [A-Z]))dnl
 81  pushdef([DOWN], translit([$1], [A-Z], [a-z]))dnl
 82
 83  AC_ARG_WITH(DOWN-prefix,[AS_HELP_STRING([--with-]DOWN[-prefix=PREFIX], [Prefix where $1 is installed (optional)])],
 84    DOWN[]_config_prefix="$withval", DOWN[]_config_prefix="")
 85  AC_ARG_WITH(DOWN-exec-prefix,[AS_HELP_STRING([--with-]DOWN[-exec-prefix=EPREFIX], [Exec prefix where $1 is installed (optional)])],
 86    DOWN[]_config_exec_prefix="$withval", DOWN[]_config_exec_prefix="")
 87
 88  AC_ARG_VAR(UP[]_CONFIG, [config script used for $1])
 89  AC_ARG_VAR(UP[]_CFLAGS, [CFLAGS used for $1])
 90  AC_ARG_VAR(UP[]_LIBS,   [LIBS used for $1])
 91
 92  AS_IF([test x$UP[]_CFLAGS != x -o x$UP[]_LIBS != x],[
 93    dnl Don't run config script at all, use user-provided values instead.
 94    AC_SUBST(UP[]_CFLAGS)
 95    AC_SUBST(UP[]_LIBS)
 96    :
 97    $4
 98  ],[
 99    AS_IF([test x$DOWN[]_config_exec_prefix != x],[
100      DOWN[]_config_args="$DOWN[]_config_args --exec-prefix=$DOWN[]_config_exec_prefix"
101      AS_IF([test x${UP[]_CONFIG+set} != xset],[
102	UP[]_CONFIG=$DOWN[]_config_exec_prefix/bin/DOWN-config
103      ])
104    ])
105    AS_IF([test x$DOWN[]_config_prefix != x],[
106      DOWN[]_config_args="$DOWN[]_config_args --prefix=$DOWN[]_config_prefix"
107      AS_IF([test x${UP[]_CONFIG+set} != xset],[
108	UP[]_CONFIG=$DOWN[]_config_prefix/bin/DOWN-config
109      ])
110    ])
111
112    AC_PATH_PROGS(UP[]_CONFIG,[$6 DOWN-config],[no])
113    AS_IF([test "$UP[]_CONFIG" == "no"],[
114      :
115      $5
116    ],[
117      dnl Get the CFLAGS from LIBRARY-config script
118      AS_IF([test x"$7" == x],[
119	UP[]_CFLAGS="`$UP[]_CONFIG $DOWN[]_config_args --cflags`"
120      ],[
121	UP[]_CFLAGS="`$UP[]_CONFIG $DOWN[]_config_args $7`"
122      ])
123
124      dnl Get the LIBS from LIBRARY-config script
125      AS_IF([test x"$8" == x],[
126	UP[]_LIBS="`$UP[]_CONFIG $DOWN[]_config_args --libs`"
127      ],[
128	UP[]_LIBS="`$UP[]_CONFIG $DOWN[]_config_args $8`"
129      ])
130
131      AS_IF([test x"$2" != x],[
132	dnl Check for provided library version
133	AS_IF([test x"$3" != x],[
134	  dnl Use provided sed expression
135	  DOWN[]_version="`$UP[]_CONFIG $DOWN[]_config_args --version | $SED -e $3`"
136	],[
137	  DOWN[]_version="`$UP[]_CONFIG $DOWN[]_config_args --version | $SED -e 's/^\ *\(.*\)\ *$/\1/'`"
138	])
139
140	AC_MSG_CHECKING([for $1 ($DOWN[]_version) >= $2])
141	AX_COMPARE_VERSION($DOWN[]_version,[ge],[$2],[
142	  AC_MSG_RESULT([yes])
143
144	  AC_SUBST(UP[]_CFLAGS)
145	  AC_SUBST(UP[]_LIBS)
146	  :
147	  $4
148	],[
149	  AC_MSG_RESULT([no])
150	  :
151	  $5
152	])
153      ],[
154	AC_SUBST(UP[]_CFLAGS)
155	AC_SUBST(UP[]_LIBS)
156	:
157	$4
158      ])
159    ])
160  ])
161
162  popdef([UP])
163  popdef([DOWN])
164])