From: Eric Blake Date: Thu, 18 Mar 2010 16:23:10 +0000 (-0600) Subject: pty: improve replacement header X-Git-Tag: v0.1~4483 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=953fd38889e35a0ddbf8e9ada17f4fd001662003;p=gnulib.git pty: improve replacement header Build pty.h in the same way as all other replacement headers. * lib/pty.in.h: New file. * modules/pty (Files): Ship it. (Makefile.am): Always build replacement. * m4/pty.m4: Rename... * m4/pty_h.m4: ...to this. (gl_PTY): Modernize setting of witness macros; update check of forkpty to take proper advantage of cache. (gl_PTY_MODULE_INDICATOR, gl_PTY_H_DEFAULTS): New macros. Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index 678870787..bbb04445f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2010-03-19 Eric Blake + pty: improve replacement header + * lib/pty.in.h: New file. + * modules/pty (Files): Ship it. + (Makefile.am): Always build replacement. + * m4/pty.m4: Rename... + * m4/pty_h.m4: ...to this. + (gl_PTY): Modernize setting of witness macros; update check of + forkpty to take proper advantage of cache. + (gl_PTY_MODULE_INDICATOR, gl_PTY_H_DEFAULTS): New macros. + getopt: avoid compiler warning * lib/getopt.c (attribute_hidden): Remove unused macro. diff --git a/lib/pty.in.h b/lib/pty.in.h new file mode 100644 index 000000000..8d80f8aac --- /dev/null +++ b/lib/pty.in.h @@ -0,0 +1,67 @@ +/* Substitute for and wrapper around . + Copyright (C) 2010 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. */ + +#ifndef _GL_PTY_H + +#if __GNUC__ >= 3 +@PRAGMA_SYSTEM_HEADER@ +#endif + +/* The include_next requires a split double-inclusion guard. */ +#if @HAVE_PTY_H@ +# @INCLUDE_NEXT@ @NEXT_PTY_H@ +#endif + +#ifndef _GL_PTY_H +#define _GL_PTY_H + +/* Some platforms declare this in a different header than glibc. */ +#if @HAVE_UTIL_H@ +# include +#endif +#if @HAVE_LIBUTIL_H@ +# include +#endif + +/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ + +/* The definition of _GL_WARN_ON_USE is copied here. */ + + +/* Declare overridden functions. */ + +#if 1 /* FIXME - split forkpty into separate module */ +#elif defined GNULIB_POSIXCHECK +# undef forkpty +# if HAVE_RAW_DECL_FORKPTY +_GL_WARN_ON_USE (forkpty, "forkpty is not declared consistently - " + "use gnulib module pty for portability"); +# endif +#endif + +#if 1 /* FIXME - split openpty into separate module */ +#elif defined GNULIB_POSIXCHECK +# undef openpty +# if HAVE_RAW_DECL_OPENPTY +_GL_WARN_ON_USE (openpty, "openpty is not declared consistently - " + "use gnulib module pty for portability"); +# endif +#endif + + +#endif /* _GL_PTY_H */ +#endif /* _GL_PTY_H */ diff --git a/m4/pty.m4 b/m4/pty.m4 deleted file mode 100644 index 35ff929d7..000000000 --- a/m4/pty.m4 +++ /dev/null @@ -1,43 +0,0 @@ -# pty.m4 serial 1 -dnl Copyright (C) 2009, 2010 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -# gl_PTY -# ------ -# Make sure that pty.h provides forkpty, or sets up a replacement header. -# Also define automake variable PTY_LIB to the library needed (if any). -AC_DEFUN([gl_PTY], -[ - PTY_H='' - PTY_LIB='' - # First make sure that pty.h provides forkpty, or setup the replacement. - AC_CHECK_HEADERS_ONCE([pty.h]) - if test $ac_cv_header_pty_h != yes; then - AC_CHECK_DECL([forkpty],,, [[#include ]]) - if test $ac_cv_have_decl_forkpty = no; then - unset ac_cv_have_decl_forkpty - AC_CHECK_DECL([forkpty],,, [[#include ]]) - if test $ac_cv_have_decl_forkpty = no; then - AC_MSG_WARN([[Cannot find forkpty, build will likely fail]]) - else - PTY_H='pty.h' - PTY_HEADER='libutil.h' - fi - else - PTY_H='pty.h' - PTY_HEADER='util.h' - fi - fi - # Second check for the library required for forkpty. - save_LIBS="$LIBS" - AC_SEARCH_LIBS([forkpty], [util], - [if test "$ac_cv_search_forkpty" != "none required"; then - PTY_LIB="$ac_cv_search_forkpty" - fi]) - LIBS="$save_LIBS" - AC_SUBST([PTY_H]) - AC_SUBST([PTY_LIB]) - AC_SUBST([PTY_HEADER]) -]) diff --git a/m4/pty_h.m4 b/m4/pty_h.m4 new file mode 100644 index 000000000..3b6d91018 --- /dev/null +++ b/m4/pty_h.m4 @@ -0,0 +1,81 @@ +# pty_h.m4 serial 2 +dnl Copyright (C) 2009, 2010 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +# gl_PTY +# ------ +# Make sure that pty.h provides forkpty, or sets up a replacement header. +# Also define automake variable PTY_LIB to the library needed (if any). +AC_DEFUN_ONCE([gl_PTY], +[ + AC_REQUIRE([gl_PTY_H_DEFAULTS]) + + PTY_LIB='' + # First make sure that pty.h provides forkpty, or setup the replacement. + AC_CHECK_HEADERS_ONCE([pty.h]) + if test $ac_cv_header_pty_h != yes; then + HAVE_PTY_H=0 + AC_CHECK_HEADERS([util.h libutil.h]) + if test $ac_cv_header_util_h = yes; then + HAVE_UTIL_H=1 + fi + if test $ac_cv_header_libutil_h = yes; then + HAVE_LIBUTIL_H=1 + fi + AC_CHECK_DECLS([forkpty],,, [[ +#if HAVE_UTIL_H +# include +#endif +#if HAVE_LIBUTIL_H +# include +#endif +]]) + if test $ac_cv_have_decl_forkpty = no; then + AC_MSG_WARN([[Cannot find forkpty, build will likely fail]]) + fi + else # Have , assume forkpty is declared there. + HAVE_PTY_H=1 + fi + AC_SUBST([HAVE_PTY_H]) + dnl is always overridden, because of GNULIB_POSIXCHECK. + gl_CHECK_NEXT_HEADERS([pty.h]) + + # Second check for the library required for forkpty. + save_LIBS="$LIBS" + AC_SEARCH_LIBS([forkpty], [util], + [if test "$ac_cv_search_forkpty" != "none required"; then + PTY_LIB="$ac_cv_search_forkpty" + fi]) + LIBS="$save_LIBS" + AC_SUBST([PTY_LIB]) + + dnl Check for declarations of anything we want to poison if the + dnl corresponding gnulib module is not in use. + gl_WARN_ON_USE_PREPARE([[ +#if HAVE_PTY_H +# include +#endif +#if HAVE_UTIL_H +# include +#endif +#if HAVE_LIBUTIL_H +# include +#endif + ]], [forkpty openpty]) +]) + +AC_DEFUN([gl_PTY_MODULE_INDICATOR], +[ + dnl Use AC_REQUIRE here, so that the default settings are expanded once only. + AC_REQUIRE([gl_PTY_H_DEFAULTS]) + GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1 +]) + +AC_DEFUN([gl_PTY_H_DEFAULTS], +[ + dnl Assume proper GNU behavior unless another module says otherwise. + HAVE_UTIL_H=0; AC_SUBST([HAVE_UTIL_H]) + HAVE_LIBUTIL_H=0; AC_SUBST([HAVE_LIBUTIL_H]) +]) diff --git a/modules/pty b/modules/pty index 66cecefb2..ef064be8e 100644 --- a/modules/pty +++ b/modules/pty @@ -2,22 +2,36 @@ Description: A for systems that lacks it. Files: -m4/pty.m4 +lib/pty.in.h +m4/pty_h.m4 + +Depends-on: +c++defs +include_next +warn-on-use configure.ac: gl_PTY Makefile.am: -BUILT_SOURCES += $(PTY_H) +BUILT_SOURCES += pty.h # We need the following in order to create when the system # doesn't have one that works with the given compiler. -pty.h: +pty.h: pty.in.h $(CXXDEFS_H) $(WARN_ON_USE_H) $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ - echo '#include <'$(PTY_HEADER)'>'; \ + sed -e 's|@''HAVE_PTY_H''@|$(HAVE_PTY_H)|g' \ + -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ + -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ + -e 's|@''NEXT_PTY_H''@|$(NEXT_PTY_H)|g' \ + -e 's|@''HAVE_UTIL_H''@|$(HAVE_UTIL_H)|g' \ + -e 's|@''HAVE_LIBUTIL_H''@|$(HAVE_LIBUTIL_H)|g' \ + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ + < $(srcdir)/pty.in.h; \ } > $@-t && \ - mv -f $@-t $@ + mv $@-t $@ MOSTLYCLEANFILES += pty.h pty.h-t Include: