.gitignore: ignore binaries and generated files
[libtar.git] / autoconf / ac_path_generic.m4
blob401a29187cca3f0a4cadb4ae69351a1efacb1d0e
1 dnl @synopsis AC_PATH_GENERIC(LIBRARY [, MINIMUM-VERSION [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
2 dnl
3 dnl Runs a LIBRARY-config script and defines LIBRARY_CFLAGS and LIBRARY_LIBS
4 dnl
5 dnl The script must support `--cflags' and `--libs' args.
6 dnl If MINIMUM-VERSION is specified, the script must also support the
7 dnl `--version' arg.
8 dnl If the `--with-library-[exec-]prefix' arguments to ./configure are given,
9 dnl it must also support `--prefix' and `--exec-prefix'.
10 dnl (In other words, it must be like gtk-config.)
11 dnl
12 dnl For example:
13 dnl
14 dnl    AC_PATH_GENERIC(Foo, 1.0.0)
15 dnl
16 dnl would run `foo-config --version' and check that it is at least 1.0.0
17 dnl
18 dnl If so, the following would then be defined:
19 dnl
20 dnl    FOO_CFLAGS to `foo-config --cflags`
21 dnl    FOO_LIBS   to `foo-config --libs`
22 dnl
23 dnl At present there is no support for additional "MODULES" (see AM_PATH_GTK)
24 dnl (shamelessly stolen from gtk.m4 and then hacked around a fair amount)
25 dnl
26 dnl @author Angus Lees <gusl@cse.unsw.edu.au>
27 dnl @version $Id: ac_path_generic.m4,v 1.1.4.1 2002/09/06 19:43:55 roth Exp $
29 AC_DEFUN([AC_PATH_GENERIC],
30 [dnl
31 dnl we're going to need uppercase, lowercase and user-friendly versions of the
32 dnl string `LIBRARY'
33 pushdef([UP], translit([$1], [a-z], [A-Z]))dnl
34 pushdef([DOWN], translit([$1], [A-Z], [a-z]))dnl
36 dnl
37 dnl Get the cflags and libraries from the LIBRARY-config script
38 dnl
39 AC_ARG_WITH(DOWN-prefix,[  --with-]DOWN[-prefix=PFX       Prefix where $1 is installed (optional)],
40         DOWN[]_config_prefix="$withval", DOWN[]_config_prefix="")
41 AC_ARG_WITH(DOWN-exec-prefix,[  --with-]DOWN[-exec-prefix=PFX Exec prefix where $1 is installed (optional)],
42         DOWN[]_config_exec_prefix="$withval", DOWN[]_config_exec_prefix="")
44   if test x$DOWN[]_config_exec_prefix != x ; then
45      DOWN[]_config_args="$DOWN[]_config_args --exec-prefix=$DOWN[]_config_exec_prefix"
46      if test x${UP[]_CONFIG+set} != xset ; then
47        UP[]_CONFIG=$DOWN[]_config_exec_prefix/bin/DOWN-config
48      fi
49   fi
50   if test x$DOWN[]_config_prefix != x ; then
51      DOWN[]_config_args="$DOWN[]_config_args --prefix=$DOWN[]_config_prefix"
52      if test x${UP[]_CONFIG+set} != xset ; then
53        UP[]_CONFIG=$DOWN[]_config_prefix/bin/DOWN-config
54      fi
55   fi
57   AC_PATH_PROG(UP[]_CONFIG, DOWN-config, no)
58   ifelse([$2], ,
59      AC_MSG_CHECKING(for $1),
60      AC_MSG_CHECKING(for $1 - version >= $2)
61   )
62   no_[]DOWN=""
63   if test "$UP[]_CONFIG" = "no" ; then
64      no_[]DOWN=yes
65   else
66      UP[]_CFLAGS="`$UP[]_CONFIG $DOWN[]_config_args --cflags`"
67      UP[]_LIBS="`$UP[]_CONFIG $DOWN[]_config_args --libs`"
68      ifelse([$2], , ,[
69         DOWN[]_config_major_version=`$UP[]_CONFIG $DOWN[]_config_args \
70          --version | sed 's/[[^0-9]]*\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
71         DOWN[]_config_minor_version=`$UP[]_CONFIG $DOWN[]_config_args \
72          --version | sed 's/[[^0-9]]*\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
73         DOWN[]_config_micro_version=`$UP[]_CONFIG $DOWN[]_config_args \
74          --version | sed 's/[[^0-9]]*\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
75         DOWN[]_wanted_major_version="regexp($2, [\<\([0-9]*\)], [\1])"
76         DOWN[]_wanted_minor_version="regexp($2, [\<\([0-9]*\)\.\([0-9]*\)], [\2])"
77         DOWN[]_wanted_micro_version="regexp($2, [\<\([0-9]*\).\([0-9]*\).\([0-9]*\)], [\3])"
79         # Compare wanted version to what config script returned.
80         # If I knew what library was being run, i'd probably also compile
81         # a test program at this point (which also extracted and tested
82         # the version in some library-specific way)
83         if test "$DOWN[]_config_major_version" -lt \
84                         "$DOWN[]_wanted_major_version" \
85           -o \( "$DOWN[]_config_major_version" -eq \
86                         "$DOWN[]_wanted_major_version" \
87             -a "$DOWN[]_config_minor_version" -lt \
88                         "$DOWN[]_wanted_minor_version" \) \
89           -o \( "$DOWN[]_config_major_version" -eq \
90                         "$DOWN[]_wanted_major_version" \
91             -a "$DOWN[]_config_minor_version" -eq \
92                         "$DOWN[]_wanted_minor_version" \
93             -a "$DOWN[]_config_micro_version" -lt \
94                         "$DOWN[]_wanted_micro_version" \) ; then
95           # older version found
96           no_[]DOWN=yes
97           echo -n "*** An old version of $1 "
98           echo -n "($DOWN[]_config_major_version"
99           echo -n ".$DOWN[]_config_minor_version"
100           echo    ".$DOWN[]_config_micro_version) was found."
101           echo -n "*** You need a version of $1 newer than "
102           echo -n "$DOWN[]_wanted_major_version"
103           echo -n ".$DOWN[]_wanted_minor_version"
104           echo    ".$DOWN[]_wanted_micro_version."
105           echo "***"
106           echo "*** If you have already installed a sufficiently new version, this error"
107           echo "*** probably means that the wrong copy of the DOWN-config shell script is"
108           echo "*** being found. The easiest way to fix this is to remove the old version"
109           echo "*** of $1, but you can also set the UP[]_CONFIG environment to point to the"
110           echo "*** correct copy of DOWN-config. (In this case, you will have to"
111           echo "*** modify your LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf"
112           echo "*** so that the correct libraries are found at run-time)"
113         fi
114      ])
115   fi
116   if test "x$no_[]DOWN" = x ; then
117      AC_MSG_RESULT(yes)
118      ifelse([$3], , :, [$3])
119   else
120      AC_MSG_RESULT(no)
121      if test "$UP[]_CONFIG" = "no" ; then
122        echo "*** The DOWN-config script installed by $1 could not be found"
123        echo "*** If $1 was installed in PREFIX, make sure PREFIX/bin is in"
124        echo "*** your path, or set the UP[]_CONFIG environment variable to the"
125        echo "*** full path to DOWN-config."
126      fi
127      UP[]_CFLAGS=""
128      UP[]_LIBS=""
129      ifelse([$4], , :, [$4])
130   fi
131   AC_SUBST(UP[]_CFLAGS)
132   AC_SUBST(UP[]_LIBS)
134   popdef([UP])
135   popdef([DOWN])