bug-gnulib
[Top][All Lists]
Advanced

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

Re: HP C++ and gnulib string.h


From: Bruno Haible
Subject: Re: HP C++ and gnulib string.h
Date: Sun, 9 Sep 2007 00:45:40 +0200
User-agent: KMail/1.5.4

Albert Chin wrote:
> > I'm worried that more differences between the C and C++ compilers are
> > found. It may be not only the location of <string.h>, but also
> > HAVE_DECL_STRRCHR, the presence of an uint32_t type, etc.
> 
> Possibly. lftp-3.5.11, an ftp client which is more a mix of C/C++,
> exposes more differences (cf.
> http://lists.gnu.org/archive/html/bug-gnulib/2005-11/msg00085.html).

Thanks for mentioning this, confirming that this is a maintenance intensive
approach.

> > What's the result of trying three alternative approaches?
> > 
> > a) Instead of "CC=cc CXX=aCC ./configure", use
> >    "CC=aCC CXX=aCC ./configure". This works with g++. Does it also work
> >    with aCC?
> 
> This does not work. The error occurs in the same place. The resulting
> config.status between CC=cc and CC=aCC shows now substantive
> difference.

Ok. Thanks for trying.

> > b) In configure.ac change the gl_INIT invocation into
> > 
> >    AC_LANG_PUSH([C++])
> >    gl_INIT
> >    AC_LANG_POP([C++])
> > 
> >    Does this work?
> 
> No:
>   /opt/fsw/bash30/bin/bash ../libtool --tag=CC --mode=compile cc 
> -DHAVE_CONFIG_H -I. -I. -I.. -I../poppler     -z +O2 +Ofltacc +Olit=all 
> +Oentrysched +Odataprefetch +Onolimit -c -o printf-args.lo printf-args.c
>    cc -DHAVE_CONFIG_H -I. -I. -I.. -I../poppler -z +O2 +Ofltacc +Olit=all 
> +Oentrysched +Odataprefetch +Onolimit -c printf-args.c  +Z -DPIC -o 
> .libs/printf-args.o
> cpp: "///opt/aCC/include/stdio.h", line 4: error 4036: Can't open include 
> file 'cstdio'.
> 
> The problem is that gnulib's generated stdio.h has:
>   #include "///opt/aCC/include/stdio.h"
> rather than the expected:
>   #include "///usr/include/stdio.h"

Ok. Thanks for trying this as well.

> > c) A radically different way of using gnulib: Create a gnulib testdir
> >    with all POSIX functions that you find useful (snprintf-posix etc.).
> >    Configure it once with C and once with C++, like this:
> >      $ GNULIBDIR=`pwd`
> >      $ mkdir build-cc; CC=cc ../configure; make; cd ..
> >      $ mkdir build-c++; CC=aCC ../configure; make; cd ..
> >    Then go back to your package and configure it with
> >      CC="cc -I$GNULIBDIR/build-cc/lib" \
> >      CXX="aCC -I$GNULIBDIR/build-c++/lib" \
> >      LDFLAGS="$GNULIBDIR/build-cc/lib/libgnu.a 
> > $GNULIBDIR/build-c++/lib/libgnu.a" \
> >      ./configure
> > 
> >    Does this work?
> 
> I haven't tried but I'm sure this would work. But, this is really
> ugly. I think "./configure && make && make install" should just work.
> The fundamental problem is mixing a C/C++ project with gnulib when the
> C/C++ compilers exhibit different behavior. I think gnulib should
> accommodate this.

Since you say that the above should work, I am documenting this as the
preferred approach for your case. Can you please check whether it really
works and report any problems with it?

> But, I think it should be supported on a
> case-by-case basis. That is, if someone reports a problem building
> some mixed C/C++ project against gnulib, we fix that part of gnulib
> rather than some major overhaul. This would be the least intrusive and
> require the least amount of work.

I'm not going this way. It may require the least amount of work in the
short term and the most amount of work in the long term.

Bruno


2007-09-08  Bruno Haible  <address@hidden>

        * posix-modules: New file. Portions copied from gnulib-tool.
        * doc/gnulib.texi (POSIX Substitutes Library): New chapter.

*** doc/gnulib.texi     23 Aug 2007 02:00:19 -0000      1.43
--- doc/gnulib.texi     8 Sep 2007 22:37:50 -0000
***************
*** 51,57 ****
  * Introduction::
  * Invoking gnulib-tool::
  * Miscellaneous Notes::
! * Header File Substitutes::
  * Function Substitutes::            Replacing system functions.
  * Particular Modules::              Documentation of individual modules.
  * GNU Free Documentation License::  Copying and sharing this manual.
--- 51,58 ----
  * Introduction::
  * Invoking gnulib-tool::
  * Miscellaneous Notes::
! * POSIX Substitutes Library::       Building as a separate substitutes 
library.
! * Header File Substitutes::         Overriding system headers.
  * Function Substitutes::            Replacing system functions.
  * Particular Modules::              Documentation of individual modules.
  * GNU Free Documentation License::  Copying and sharing this manual.
***************
*** 418,423 ****
--- 419,453 ----
  
  @end enumerate
  
+ @node POSIX Substitutes Library
+ @chapter Building the ISO C and POSIX Substitutes
+ 
+ This section shows a radically different way to use Gnulib.
+ 
+ You can extract the ISO C / POSIX substitutes part of gnulib by running
+ the command
+ @smallexample
+ gnulib-tool --create-testdir --source-base=lib \
+             --dir=/tmp/posixlib `posix-modules`
+ @end smallexample
+ 
+ @noindent
+ The command @samp{posix-modules} is found in the same directory as
+ @code{gnulib-tool}.
+ 
+ The resulting directory can be built on a particular platform,
+ independently of the program being ported.  Then you can configure and
+ build any program, by setting @code{CPPFLAGS} and @code{LDFLAGS} at
+ configure time accordingly: set @code{CPPFLAGS="-I.../posixlib/lib"}, plus
+ any essential type definitions and flags that you find in
+ @code{.../posixlib/config.h}, and set
+ @code{LDFLAGS=".../posixlib/lib/libgnu.a"}.
+ 
+ This way of using Gnulib is useful when you don't want to modify the program's
+ source code, or when the program uses a mix between C and C++ sources
+ (requiring separate builds of the @code{posixlib} for the C compiler and
+ for the C++ compiler).
+ 
  @node Header File Substitutes
  @chapter ISO C and POSIX Header File Substitutes
  
=============================== posix-modules ===========================
#!/bin/sh
#
# Copyright (C) 2002-2007 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#

progname=$0
package=gnulib
cvsdatestamp='$Date: 2007/09/08 22:45:08 $'
last_checkin_date=`echo "$cvsdatestamp" | sed -e 's,^\$[D]ate: ,,'`
version=`echo "$last_checkin_date" | sed -e 's/ .*$//' -e 's,/,-,g'`

# func_usage
# outputs to stdout the --help usage message.
func_usage ()
{
  echo "\
Usage: posix-modules

Report bugs to <address@hidden>."
}

# func_version
# outputs to stdout the --version message.
func_version ()
{
  year=`echo "$last_checkin_date" | sed -e 's,/.*$,,'`
  echo "\
$progname (GNU $package) $version
Copyright (C) $year Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by" "Bruno Haible"
}

case "$0" in
  /*) self_abspathname="$0" ;;
  */*) self_abspathname=`pwd`/"$0" ;;
  *)
    # Look in $PATH.
    # Iterate through the elements of $PATH.
    # We use IFS=: instead of
    #   for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`
    # because the latter does not work when some PATH element contains spaces.
    # We use a canonicalized $pathx instead of $PATH, because empty PATH
    # elements are by definition equivalent to '.', however field splitting
    # according to IFS=: loses empty fields in many shells:
    #   - /bin/sh on OSF/1 and Solaris loses all empty fields (at the
    #     beginning, at the end, and in the middle),
    #   - /bin/sh on IRIX and /bin/ksh on IRIX and OSF/1 lose empty fields
    #     at the beginning and at the end,
    #   - GNU bash, /bin/sh on AIX and HP-UX, and /bin/ksh on AIX, HP-UX,
    #     Solaris lose empty fields at the end.
    # The 'case' statement is an optimization, to avoid evaluating the
    # explicit canonicalization command when $PATH contains no empty fields.
    self_abspathname=
    if test "${PATH_SEPARATOR+set}" != set; then
      func_tmpdir
      { echo "#! /bin/sh"; echo "exit 0"; } > "$tmp"/conf.sh
      chmod +x "$tmp"/conf.sh
      if (PATH="/nonexistent;$tmp"; conf.sh) >/dev/null 2>&1; then
        PATH_SEPARATOR=';'
      else
        PATH_SEPARATOR=:
      fi
      rm -rf "$tmp"
    fi
    if test "$PATH_SEPARATOR" = ";"; then
      # On Windows, programs are searched in "." before $PATH.
      pathx=".;$PATH"
    else
      # On Unix, we have to convert empty PATH elements to ".".
      pathx="$PATH"
      case :$PATH: in
        *::*)
          pathx=`echo ":$PATH:" | sed -e 's/:::*/:.:/g' -e 's/^://' -e 
's/:\$//'`
          ;;
      esac
    fi
    save_IFS="$IFS"
    IFS="$PATH_SEPARATOR"
    for d in $pathx; do
      IFS="$save_IFS"
      test -z "$d" && d=.
      if test -x "$d/$0" && test ! -d "$d/$0"; then
        self_abspathname="$d/$0"
        break
      fi
    done
    IFS="$save_IFS"
    if test -z "$self_abspathname"; then
      func_fatal_error "could not locate the gnulib-tool program - how did you 
invoke it?"
    fi
    ;;
esac
while test -h "$self_abspathname"; do
  # Resolve symbolic link.
  linkval=`func_readlink "$self_abspathname"`
  test -n "$linkval" || break
  case "$linkval" in
    /* ) self_abspathname="$linkval" ;;
    * ) self_abspathname=`echo "$self_abspathname" | sed -e 
's,/[^/]*$,,'`/"$linkval" ;;
  esac
done
gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`

# Command-line option processing.
while test $# -gt 0; do
  case "$1" in
    --help | --hel | --he | --h )
      func_usage
      exit $? ;;
    --version | --versio | --versi | --vers | --ver | --ve | --v )
      func_version
      exit $? ;;
    -* )
      echo "posix-modules: unknown option $1" 1>&2
      echo "Try 'posix-modules --help' for more information." 1>&2
      exit 1 ;;
    * )
      echo "posix-modules: too many arguments" 1>&2
      echo "Try 'posix-modules --help' for more information." 1>&2
      exit 1 ;;
  esac
done

(
  # Get the header modules.
  LC_ALL=C grep -h '^Gnulib module: ' "$gnulib_dir"/doc/headers/* 2>/dev/null \
    | sed -e 's,^Gnulib module: ,,'
  # Get the function modules.
  LC_ALL=C grep -h '^Gnulib module: ' "$gnulib_dir"/doc/functions/* 2>/dev/null 
\
    | sed -e 's,^Gnulib module: ,,'
  # Then filter out the words "---", "and", "or" and remove *-gnu modules.
) | LC_ALL=C sort | LC_ALL=C uniq \
  | { # Then filter out the words "---", "and", "or" and remove *-gnu modules.
      tr ' ' '\012' | sed -e '/^---$/d' -e '/^and$/d' -e '/^or$/d' -e '/-gnu$/d'
    } \
  | LC_ALL=C sort | LC_ALL=C uniq \
  | { # Except ftruncate, which aborts the configuration on mingw. FiXME
      sed -e '/^ftruncate$/d'
    }





reply via email to

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