Preliminary, but functional, autotoolsification
[proto.git] / config / ax_with_prog.m4
blobba70bcff99108559fa1d6f40b689cfb21c17d8d1
1 # ===========================================================================
2 #              http://autoconf-archive.cryp.to/ax_with_prog.html
3 # ===========================================================================
5 # SYNOPSIS
7 #   AX_WITH_PROG([VARIABLE],[program],[VALUE-IF-NOT-FOUND],[PATH])
9 # DESCRIPTION
11 #   Locates an installed program binary, placing the result in the precious
12 #   variable VARIABLE. Accepts a present VARIABLE, then --with-program, and
13 #   failing that searches for program in the given path (which defaults to
14 #   the system path). If program is found, VARIABLE is set to the full path
15 #   of the binary; if it is not found VARIABLE is set to VALUE-IF-NOT-FOUND
16 #   if provided, unchanged otherwise.
18 #   A typical example could be the following one:
20 #         AX_WITH_PROG(PERL,perl)
22 #   NOTE: This macro is based upon the original AX_WITH_PYTHON macro from
23 #   Dustin J. Mitchell <dustin@cs.uchicago.edu>.
25 # LAST MODIFICATION
27 #   2008-05-05
29 # COPYLEFT
31 #   Copyright (c) 2008 Francesco Salvestrini <salvestrini@users.sourceforge.net>
32 #   Copyright (c) 2008 Dustin J. Mitchell <dustin@cs.uchicago.edu>
34 #   Copying and distribution of this file, with or without modification, are
35 #   permitted in any medium without royalty provided the copyright notice
36 #   and this notice are preserved.
38 AC_DEFUN([AX_WITH_PROG],[
39     AC_PREREQ([2.60])
41     pushdef([VARIABLE],$1)
42     pushdef([EXECUTABLE],$2)
43     pushdef([VALUE_IF_NOT_FOUND],$3)
44     pushdef([PATH_PROG],$4)
46     AC_ARG_VAR(VARIABLE,Absolute path to EXECUTABLE executable)
48     AS_IF(test -z "$VARIABLE",[
49         AC_MSG_CHECKING(whether EXECUTABLE executable path has been provided)
50         AC_ARG_WITH(EXECUTABLE,AS_HELP_STRING([--with-EXECUTABLE=[[[[PATH]]]]],absolute path to EXECUTABLE executable), [
51             AS_IF([test "$withval" != "yes"],[
52                 VARIABLE="$withval"
53                 AC_MSG_RESULT($VARIABLE)
54             ],[
55                 VARIABLE=""
56                 AC_MSG_RESULT([no])
57             ])
58         ],[
59             AC_MSG_RESULT([no])
60         ])
62         AS_IF(test -z "$VARIABLE",[
63             AC_PATH_PROG([]VARIABLE[],[]EXECUTABLE[],[]VALUE_IF_NOT_FOUND[],[]PATH_PROG[])
64         ])
65     ])
67     popdef([PATH_PROG])
68     popdef([VALUE_IF_NOT_FOUND])
69     popdef([EXECUTABLE])
70     popdef([VARIABLE])