autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: checking whether a list of commands exists (e.g. gawk mail rcp) all


From: Jason Curl
Subject: Re: checking whether a list of commands exists (e.g. gawk mail rcp) all with one macro, how?
Date: Thu, 08 Nov 2007 19:10:21 +0100
User-agent: Thunderbird 2.0.0.6 (Windows/20070728)

linuxjetaime wrote:
Hi all,
first of all,
i need to check if one command exists in the path, find its path (unless the
user specified --with-xxx)
so i write(in configure.in) for the command 'gawk'

AC_ARG_WITH(gawk, [  --with-gawk=FULLPATH       set full path to gawk
(default /usr/bin/gawk)],[GAWKPATH="$withval"])
I see in my built configure files, without even specifying [GN]AWK it looks for it in anycase. Is the result of that good enough?

$ ./configure
checking build system type... i686-pc-cygwin
checking host system type... i686-pc-cygwin
checking target system type... i686-pc-cygwin
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk

When rummaging through the autoconf macros, I also find (in acspecific.m4)

dnl Check for mawk first since it's generally faster.
AC_DEFUN(AC_PROG_AWK,
[AC_CHECK_PROGS(AWK, mawk gawk nawk awk, )])

To override the location that you use for what program you need, your user might be better to define environment variables, similar to how "CC" is defined while calling "configure".

Also in my experience, you have to be careful on some platforms. An example is the 'id' command. On Linux it works as you might expect. On solaris 2.10, the default "id" doesn't support a lot of functions (/usr/bin/id), but that which is in /usr/xpg4/bin/id is what most people want. So I write a specific function for that executable (i.e. if Solaris then check these locations, even if they're not in the path, and test different options looking for return codes).
AC_PATH_PROG(GAWKPATH, gawk,no, $PATH)
if test $GAWKPATH = no; then
        AC_MSG_ERROR([can not find gawk if you know where it is specify it
at command line using --with-gawk=])
fi

Question 1: is this correct? (i copied from the net somewhere and it works
ok i think)
Question 2: is there a macro which does all this?
e.g. AC_FIND_PROG(gawk ...)
and save us the hassle of typing all the above
I also find, that it's not worth the bother for me to check if autoconf found the program or not. In some cases (in particular with "ar") my configure couldn't find the program, but it would happily compile and somehow found a reference to AR. When I exited in configure (similar to what you're doing) this would have resulted in a complaint that didn't need to be resolved at build time.

What I did do if it couldn't find the program or not, was to assign it to the default name. So if it couldn't find "ar", it would assign the variable AR=ar in anycase.

An example of my macro file to get the current user name:

# AC_PROG_ID_CURRENT_USER
# -----------------------
# Looks for the program 'id' and checks that it works and that it understands
# the option '-un'.
#
# If found,
#  - ac_cv_prog_id=yes
#  - ID=/path/to/id/program
#  - IDFLAGS=-x
# If not found,
#  - ac_cv_prog_id=no
AC_DEFUN([LX_TEST_ID],
 [if test x$ac_cv_prog_id != xyes; then
     uname=`$1 $2 2> /dev/null`
     if test -z $uname; then
        ac_cv_prog_id=no
     else
        ac_cv_prog_id=yes
        ID=`echo $1`
        IDFLAGS=`echo $2`
     fi
  fi
 ])

AC_DEFUN([AC_PROG_ID_CURRENT_USER],
 [AC_MSG_CHECKING([for id])
  # Check if the user provided the variable ID
  if test x$ID != x; then
     LX_TEST_ID([$ID],[$IDFLAGS])
  fi

  case "$host_os" in
     solaris2.*)
        # Check if we're running Solaris
        LX_TEST_ID([/usr/xpg4/bin/id],[-un])
        ;;
     *)
        ;;
  esac

  # Check the default
  LX_TEST_ID([id],[-un])

  # Show the updates
  if test x$ac_cv_prog_id = xyes; then
     AC_MSG_RESULT([$ID $IDFLAGS])
     AC_SUBST(ID)
     AC_SUBST(IDFLAGS)
  else
     AC_MSG_RESULT([Not found])
  fi
 ])

For others on the group, nitpicking definitely welcome :)

The last question is : I have a list of commands to search for (gawk perl
rsh rcp tar gzip gunzip) etc.
is there a macro which takes a list in?
i tried to do (with my limited knowlegde of sh and autoconf, sorry):

for exe in       gawk cp hostname perl rcp mail mv cat mkdir rsh gzip gunzip
tar sleep; do
        exeUpper=`echo $exe | tr a-z A-Z`
     AC_ARG_WITH(${exe}, [  --with-$exe=FULLPATH       set full path to
command $exe (default /usr/bin/$exe)], [${exeUpper}PATH="$withval"])
        AC_PATH_PROG(${exeUpper}PATH, $exe,no, $PATH)
        if test ${exeUpper}PATH = no; then
                AC_MSG_ERROR([can not find $exe if you know where it is
specify it at command line using --with-$exe=])
        fi
done but i get various errors, the most obvious one with using ${exe} as
the first arg of AC_ARG_WITH (it takes it verbatim as ${exe}, and not its
contents, i.e. gawk)
anyway this is the idea, anybody done that or prepare to do it if there is a
real need for it?
(btw is AC_ARG_WITH defined in an m4 file? or is it builtin?)

thank you guys,
andreas

There are some great examples as part of the autoconf package. For example, I looked at /usr/share/autoconf/acgeneral.m4

I found:
dnl AC_PATH_PROGS(VARIABLE, PROGS-TO-CHECK-FOR [, VALUE-IF-NOT-FOUND
dnl               [, PATH]])
AC_DEFUN(AC_PATH_PROGS,
[for ac_prog in $2
do
AC_PATH_PROG($1, [$]ac_prog, , $4)
test -n "[$]$1" && break
done
ifelse([$3], , , [test -n "[$]$1" || $1="$3"
])])

Isn't this similar to what you want to do?

Cheers,
Jason.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]