LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-31-2012, 10:53 AM   #1
Weapon S
Member
 
Registered: May 2011
Location: Netherlands
Distribution: Debian, Archlinux
Posts: 259
Blog Entries: 2

Rep: Reputation: 49
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

Last edited by Weapon S; 03-31-2012 at 11:12 AM.
 
Old 03-31-2012, 12:34 PM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 373Reputation: 373Reputation: 373Reputation: 373
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Makefiles and shell conditionals endfx Programming 4 03-16-2011 01:41 PM
[SOLVED] need some clarity about syntax in following shell script tkmsr Programming 4 04-11-2010 12:28 AM
is there a '?:' syntax shell script? logicalfuzz Linux - General 3 01-29-2010 10:26 AM
Shell script syntax question arash8m Programming 4 06-01-2007 09:39 AM
Shell Script Syntax dragon49 Programming 1 03-12-2003 10:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration