LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Shell script conditionals: what is this weird syntax? (https://www.linuxquestions.org/questions/linux-newbie-8/shell-script-conditionals-what-is-this-weird-syntax-937416/)

Weapon S 03-31-2012 09:53 AM

Shell script conditionals: what is this weird syntax?
 
Hi everybody,
today I had a problem with a configure script. When I ran ./configure --with-serf, I got "--with-serf requires an argument". This contradicts the manual, that says that without an argument it uses the default location (which is unknown to me).
My first plan was to hack away the check for an argument, but I just can't figure out the syntax by looking at it... I am familiar with C.
Code:

#! /bin/sh
[...]
# Check whether --with-serf was given.
if test "${with_serf+set}" = set; then :
  withval=$with_serf;
    if test "$withval" = "yes" ; then
      as_fn_error $? "--with-serf requires an argument." "$LINENO" 5
    elif test "$withval" != "no" ; then
      { $as_echo "$as_me:${as_lineno-$LINENO}: serf library configuration" >&5
$as_echo "$as_me: serf library configuration" >&6;}
      serf_prefix=$withval
      for serf_major in serf-1 serf-0; do
        if ! test -d $serf_prefix/include/$serf_major; then continue; fi
        save_cppflags="$CPPFLAGS"
        CPPFLAGS="$CPPFLAGS $SVN_APR_INCLUDES $SVN_APRUTIL_INCLUDES -I$serf_prefix/include/$serf_major"
        for ac_header in serf.h
do :
  ac_fn_c_check_header_mongrel "$LINENO" "serf.h" "ac_cv_header_serf_h" "$ac_includes_default"
if test "x$ac_cv_header_serf_h" = xyes; then :
  cat >>confdefs.h <<_ACEOF
#define HAVE_SERF_H 1
_ACEOF

          save_ldflags="$LDFLAGS"
          LDFLAGS="$LDFLAGS -L$serf_prefix/lib"
          as_ac_Lib=`$as_echo "ac_cv_lib_$serf_major''_serf_context_create" | $as_tr_sh`
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for serf_context_create in -l$serf_major" >&5
$as_echo_n "checking for serf_context_create in -l$serf_major... " >&6; }
if eval \${$as_ac_Lib+:} false; then :
  $as_echo_n "(cached) " >&6
else
  ac_check_lib_save_LIBS=$LIBS
LIBS="-l$serf_major $SVN_APRUTIL_LIBS $SVN_APR_LIBS -lz $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

/* Override any GCC internal prototype to avoid an error.
  Use char because int might match the return type of a GCC
  builtin and then its argument prototype would still apply.  */
#ifdef __cplusplus
extern "C"
#endif
char serf_context_create ();
int
main ()
{
return serf_context_create ();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
  eval "$as_ac_Lib=yes"
else
  eval "$as_ac_Lib=no"
fi
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
eval ac_res=\$$as_ac_Lib
              { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
if eval test \"x\$"$as_ac_Lib"\" = x"yes"; then :

            cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

#include <stdlib.h>
#include "serf.h"

int
main ()
{

#if ! SERF_VERSION_AT_LEAST($serf_check_major, $serf_check_minor, $serf_check_patch)
#error Serf version too old: need $serf_check_major.$serf_check_minor.$serf_check_patch
#endif

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
  serf_found=yes
else
  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Serf version too old: need $serf_check_major.$serf_check_minor.$serf_check_patch" >&5
$as_echo "$as_me: WARNING: Serf version too old: need $serf_check_major.$serf_check_minor.$serf_check_patch" >&2;}
          serf_found=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi

          LDFLAGS="$save_ldflags"
fi

done

        CPPFLAGS="$save_cppflags"
        test $serf_found = yes && break
      done
    fi

else

      if test -d "$srcdir/serf"; then
        serf_found=reconfig
      fi

fi
[...]

I was under the impression sh signified a regular 'shell script'. Anybody know a good and easy reference?
Now I did a little research and know fi ends an if-statement. That makes the whole chunk I posted even less readable :eek:

Dark_Helmet 03-31-2012 11:34 AM

Quote:

My first plan was to hack away the check for an argument
I think that would be a bad idea. Ripping out the test for a value will not remove the code's dependence on said value.

Configure scripts are generated using the GNU autotools. Because they are automatically generated, they're not always human-friendly to read. I've spent some time struggling with one or two in the past. So I'll offer some insight (such as it's worth), but I make no guarantees...

First, understand what the configure script is doing. Basically, the configure script doesn't trust you, the user. If you specify an option for a feature, it will run a minimal test to verify the feature-support exists on the system. The vast majority of the code you pasted is precisely that: the configure script using "here" documents to create very small C programs that use a known serf library call, trying to compile that small program, and checking the return/exit code of the compiler.

The line:
Code:

cat confdefs.h - <<_ACEOF >conftest.$ac_ext
signifies the beginning of this process: create code, compile, check compile result.

Almost everything above that line deals with the serf options to the configure script.

Now, if you want to just go rip out the conditional, then modify these lines:
Code:

    if test "$withval" = "yes" ; then
      as_fn_error $? "--with-serf requires an argument." "$LINENO" 5
    elif
test "$withval" != "no" ; then

Delete everything in blue. For example:
Code:

    if test "$withval" != "no" ; then
The code after that conditional creates a loop looking for a header named "serf.h"

It would seem to me that if would be easiest for you to do:
Code:

locate serf.h
or
Code:

find / -type f -name "serf.h"
To find out where the serf library header file(s) are installed. If it's not in /usr/include or /usr/local/include you certainly won't be able to avoid giving the configure script an argument with its location.


All times are GMT -5. The time now is 06:41 AM.