Re: Autoconf and Automake support for ObjC++

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

 



On Tue, 21 Jul 2009, Eric Blake wrote:

Seconded, especially since autoconf already has ObjC and C++ support, so
you have two similar languages to borrow from.

Hi Eric,

attached is a patch implementing autoconf support for ObjC++.  As expected
this was extremely straightforward and only marginally intrusive.

The only somewhat problematic aspect is the list of potential ObjC++
compilers -- pure guesswork from my side.

There are no tests for ObjC, thus none for ObjC++ either.  I think
eventually some such tests should be added.

I'm under a lot of pressure to get 2.64 out this week before I go on a two
week vacation.  I'm sorry to say it, but that probably means ObjC++
support will have to wait for 2.65.

Maybe the patch is still in time for 2.64.  That would be very helpful for
the Automake part of all that.  Attempting to implement automake support for
ObjC++ without a released autoconf version providing the basics would be
rather awkward.

Regards
Peter
From 8c1de4d15f1550956abace86ad6877e25dc05e9a Mon Sep 17 00:00:00 2001
From: Peter Breitenlohner <peb@xxxxxxxxxxxx>
Date: Tue, 21 Jul 2009 22:55:34 +0200
Subject: [PATCH] Implement and document Objective C++ support.

* lib/autoconf/c.m4 (AC_LANG(Objective C++), AC_LANG_OBJCXX)
(AC_LANG_PREPROC(Objective C++), AC_PROG_OBJCXXCPP)
(AC_LANG_COMPILER(Objective C++), AC_PROG_OBJCXX)
(_AC_PROG_OBJCXX_G): New macros.
(_AC_ARG_VAR_CPPFLAGS, _AC_ARG_VAR_LDFLAGS)
(_AC_ARG_VAR_LIBS): Adjusted.
* doc/autoconf.texi (Objective C++ Compiler): New node.
(Preset Output Variables): Document OBJCXXFLAGS.
(Language Choice): Document `Objective C++' language.
* NEWS: Updated.

* tests/local.at (AT_CHECK_ENV): Ignore AC_SUBSTed Objective C++
related variables.

Signed-off-by: Peter Breitenlohner <peb@xxxxxxxxxxxx>
---
 NEWS              |    3 +
 doc/autoconf.texi |   68 ++++++++++++++++++++--
 lib/autoconf/c.m4 |  167 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 tests/local.at    |    1 +
 4 files changed, 229 insertions(+), 10 deletions(-)

diff --git a/NEWS b/NEWS
index ef67c77..3ad6b07 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,9 @@ GNU Autoconf NEWS - User visible changes.
 * Major changes in Autoconf 2.64 (2009-??-??) [stable]
   Released by Eric Blake, based on git versions 2.63b.*.
 
+** New macros to support Objective C++.
+   AC_PROG_OBJCXX, AC_PROG_OBJCXXCPP.
+
 ** AS_IF and AS_CASE have been taught to avoid syntax errors even when
    given arguments that expand to just whitespace.
 
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 34df30b..f94811f 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -391,6 +391,7 @@ Compilers and Preprocessors
 * C Compiler::                  Checking its characteristics
 * C++ Compiler::                Likewise
 * Objective C Compiler::        Likewise
+* Objective C++ Compiler::      Likewise
 * Erlang Compiler and Interpreter::  Likewise
 * Fortran Compiler::            Likewise
 
@@ -2404,11 +2405,12 @@ needs to be processed by @command{configure} in order to be used.
 @defvar CPPFLAGS
 @evindex CPPFLAGS
 @ovindex CPPFLAGS
-Preprocessor options for the C, C++, and Objective C preprocessors and
-compilers.  If
+Preprocessor options for the C, C++, Objective C, and Objective C++
+preprocessors and compilers.  If
 it is not set in the environment when @command{configure} runs, the default
 value is empty.  @command{configure} uses this variable when preprocessing
-or compiling programs to test for C, C++, and Objective C features.
+or compiling programs to test for C, C++, Objective C, and Objective C++
+features.
 
 This variable's contents should contain options like @option{-I},
 @option{-D}, and @option{-U} that affect only the behavior of the
@@ -2499,7 +2501,7 @@ programs to test for Fortran 77 features.
 Options for the linker.  If it is not set
 in the environment when @command{configure} runs, the default value is empty.
 @command{configure} uses this variable when linking programs to test for
-C, C++, Objective C, and Fortran features.
+C, C++, Objective C, Objective C++, and Fortran features.
 
 This variable's contents should contain options like @option{-s} and
 @option{-L} that affect only the behavior of the linker.  Please see the
@@ -2517,7 +2519,8 @@ Don't use this variable to pass library names
 but some Autoconf macros may prepend extra libraries to this variable if
 those libraries are found and provide necessary functions, see
 @ref{Libraries}.  @command{configure} uses this variable when linking
-programs to test for C, C++, and Fortran features.
+programs to test for C, C++, Objective C, Objective C++, and Fortran
+features.
 @end defvar
 
 @defvar OBJCFLAGS
@@ -2527,6 +2530,13 @@ Debugging and optimization options for the Objective C compiler.  It
 acts like @code{CFLAGS}, but for Objective C instead of C.
 @end defvar
 
+@defvar OBJCXXFLAGS
+@evindex OBJCXXFLAGS
+@ovindex OBJCXXFLAGS
+Debugging and optimization options for the Objective C++ compiler.  It
+acts like @code{CXXFLAGS}, but for Objective C++ instead of C++.
+@end defvar
+
 @defvar builddir
 @ovindex builddir
 Rigorously equal to @samp{.}.  Added for symmetry only.
@@ -6521,6 +6531,7 @@ compiling.
 * C Compiler::                  Checking its characteristics
 * C++ Compiler::                Likewise
 * Objective C Compiler::        Likewise
+* Objective C++ Compiler::      Likewise
 * Erlang Compiler and Interpreter::  Likewise
 * Fortran Compiler::            Likewise
 @end menu
@@ -7224,6 +7235,47 @@ preprocessor.  If @samp{$OBJC -E} doesn't work, @file{/lib/cpp} is used.
 @end defmac
 
 
+@node Objective C++ Compiler
+@subsection Objective C++ Compiler Characteristics
+
+
+@defmac AC_PROG_OBJCXX (@ovar{compiler-search-list})
+@acindex{PROG_OBJCXX}
+@evindex OBJCXX
+@evindex OBJCXXFLAGS
+@ovindex OBJCXX
+@ovindex OBJCXXFLAGS
+Determine an Objective C++ compiler to use.  If @code{OBJCXX} is not already
+set in the environment, check for Objective C++ compilers.  Set output
+variable @code{OBJCXX} to the name of the compiler found.
+
+This macro may, however, be invoked with an optional first argument
+which, if specified, must be a blank-separated list of Objective C++ compilers
+to search for.  This just gives the user an opportunity to specify an
+alternative search list for the Objective C++ compiler.  For example, if you
+didn't like the default order, then you could invoke @code{AC_PROG_OBJCXX}
+like this:
+
+@example
+AC_PROG_OBJCXX([gcc g++ objcc++ objcxx])
+@end example
+
+If using the @acronym{GNU} Objective C++ compiler, set shell variable
+@code{GOBJCXX} to @samp{yes}.  If output variable @code{OBJCXXFLAGS} was not
+already set, set it to @option{-g -O2} for the @acronym{GNU} Objective C++
+compiler (@option{-O2} on systems where @command{gcc} does not accept
+@option{-g}), or @option{-g} for other compilers.
+@end defmac
+
+@defmac AC_PROG_OBJCXXCPP
+@acindex{PROG_OBJCXXCPP}
+@evindex OBJCXXCPP
+@ovindex OBJCXXCPP
+Set output variable @code{OBJCXXCPP} to a command that runs the Objective C++
+preprocessor.  If @samp{$OBJCXX -E} doesn't work, @file{/lib/cpp} is used.
+@end defmac
+
+
 @node Erlang Compiler and Interpreter
 @subsection Erlang Compiler and Interpreter Characteristics
 @cindex Erlang
@@ -8031,6 +8083,12 @@ Do compilation tests using @code{OBJC} and @code{OBJCPP} and use
 extension @file{.m} for test programs.  Use compilation flags:
 @code{CPPFLAGS} with @code{OBJCPP}, and both @code{CPPFLAGS} and
 @code{OBJCFLAGS} with @code{OBJC}.
+
+@item Objective C++
+Do compilation tests using @code{OBJCXX} and @code{OBJCXXCPP} and use
+extension @file{.mm} for test programs.  Use compilation flags:
+@code{CPPFLAGS} with @code{OBJCXXCPP}, and both @code{CPPFLAGS} and
+@code{OBJCXXFLAGS} with @code{OBJCXX}.
 @end table
 @end defmac
 
diff --git a/lib/autoconf/c.m4 b/lib/autoconf/c.m4
index 33d1895..98ab261 100644
--- a/lib/autoconf/c.m4
+++ b/lib/autoconf/c.m4
@@ -58,10 +58,11 @@
 #      1a. C   2a. C
 #      1b. C++
 #      1c. Objective C
+#      1d. Objective C++
 #
 # 3. Looking for a compiler
 #    And possibly the associated preprocessor.
-#      3a. C   3b. C++   3c. Objective C
+#      3a. C   3b. C++   3c. Objective C   3d. Objective C++
 #
 # 4. Compilers' characteristics.
 #      4a. C
@@ -296,6 +297,23 @@ AU_DEFUN([AC_LANG_OBJC], [AC_LANG(Objective C)])
 
 
 
+## -------------------------------- ##
+## 1d. The Objective C++ language.  ##
+## -------------------------------- ##
+
+
+# AC_LANG(Objective C++)
+# ----------------------
+AC_LANG_DEFINE([Objective C++], [objcxx], [OBJCXX], [C++],
+[ac_ext=mm
+ac_cpp='$OBJCXXCPP $CPPFLAGS'
+ac_compile='$OBJCXX -c $OBJCXXFLAGS $CPPFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
+ac_link='$OBJCXX -o conftest$ac_exeext $OBJCXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
+ac_compiler_gnu=$ac_cv_objcxx_compiler_gnu
+])
+
+
+
 ## -------------------------------------------- ##
 ## 3. Looking for Compilers and Preprocessors.  ##
 ## -------------------------------------------- ##
@@ -308,17 +326,17 @@ AU_DEFUN([AC_LANG_OBJC], [AC_LANG(Objective C)])
 # _AC_ARG_VAR_CPPFLAGS
 # --------------------
 # Document and register CPPFLAGS, which is used by
-# AC_PROG_{CC, CPP, CXX, CXXCPP, OBJC, OBJCPP}.
+# AC_PROG_{CC, CPP, CXX, CXXCPP, OBJC, OBJCPP, OBJCXX, OBJCXXCPP}.
 AC_DEFUN([_AC_ARG_VAR_CPPFLAGS],
 [AC_ARG_VAR([CPPFLAGS],
-	    [C/C++/Objective C preprocessor flags, e.g. -I<include dir>
+	    [(Objective) C/C++ preprocessor flags, e.g. -I<include dir>
 	     if you have headers in a nonstandard directory <include dir>])])
 
 
 # _AC_ARG_VAR_LDFLAGS
 # -------------------
 # Document and register LDFLAGS, which is used by
-# AC_PROG_{CC, CXX, F77, FC, OBJC}.
+# AC_PROG_{CC, CXX, F77, FC, OBJC, OBJCXX}.
 AC_DEFUN([_AC_ARG_VAR_LDFLAGS],
 [AC_ARG_VAR([LDFLAGS],
 	    [linker flags, e.g. -L<lib dir> if you have libraries in a
@@ -328,7 +346,7 @@ AC_DEFUN([_AC_ARG_VAR_LDFLAGS],
 # _AC_ARG_VAR_LIBS
 # ----------------
 # Document and register LIBS, which is used by
-# AC_PROG_{CC, CXX, F77, FC, OBJS}.
+# AC_PROG_{CC, CXX, F77, FC, OBJC, OBJCXX}.
 AC_DEFUN([_AC_ARG_VAR_LIBS],
 [AC_ARG_VAR([LIBS],
 	    [libraries to pass to the linker, e.g. -l<library>])])
@@ -947,6 +965,145 @@ fi[]dnl
 
 
 
+# -------------------------------- #
+# 3d. The Objective C++ compiler.  #
+# -------------------------------- #
+
+
+# AC_LANG_PREPROC(Objective C++)
+# ------------------------------
+# Find the Objective C++ preprocessor.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
+AC_DEFUN([AC_LANG_PREPROC(Objective C++)],
+[AC_REQUIRE([AC_PROG_OBJCXXCPP])])
+
+
+# AC_PROG_OBJCXXCPP
+# -----------------
+# Find a working Objective C++ preprocessor.
+AC_DEFUN([AC_PROG_OBJCXXCPP],
+[AC_REQUIRE([AC_PROG_OBJCXX])dnl
+AC_ARG_VAR([OBJCXXCPP],   [Objective C++ preprocessor])dnl
+_AC_ARG_VAR_CPPFLAGS()dnl
+AC_LANG_PUSH(Objective C++)dnl
+AC_MSG_CHECKING([how to run the Objective C++ preprocessor])
+if test -z "$OBJCXXCPP"; then
+  AC_CACHE_VAL(ac_cv_prog_OBJCXXCPP,
+  [dnl
+    # Double quotes because OBJCXXCPP needs to be expanded
+    for OBJCXXCPP in "$OBJCXX -E" "/lib/cpp"
+    do
+      _AC_PROG_PREPROC_WORKS_IFELSE([break])
+    done
+    ac_cv_prog_OBJCXXCPP=$OBJCXXCPP
+  ])dnl
+  OBJCXXCPP=$ac_cv_prog_OBJCXXCPP
+else
+  ac_cv_prog_OBJCXXCPP=$OBJCXXCPP
+fi
+AC_MSG_RESULT([$OBJCXXCPP])
+_AC_PROG_PREPROC_WORKS_IFELSE([],
+	  [AC_MSG_FAILURE([Objective C++ preprocessor "$OBJCXXCPP" fails sanity check])])
+AC_SUBST(OBJCXXCPP)dnl
+AC_LANG_POP(Objective C++)dnl
+])# AC_PROG_OBJCXXCPP
+
+
+# AC_LANG_COMPILER(Objective C++)
+# -------------------------------
+# Find the Objective C++ compiler.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
+AC_DEFUN([AC_LANG_COMPILER(Objective C++)],
+[AC_REQUIRE([AC_PROG_OBJCXX])])
+
+
+
+# AC_PROG_OBJCXX([LIST-OF-COMPILERS])
+# ---------------------------------
+# LIST-OF-COMPILERS is a space separated list of Objective C++ compilers to
+# search for (if not specified, a default list is used).  This just gives
+# the user an opportunity to specify an alternative search list for the
+# Objective C++ compiler.
+# FIXME: this list is pure guesswork
+# objc++ StepStone Objective-C++ compiler (also "standard" name for OBJCXX)
+# objcxx David Stes' POC.  If you installed this, you likely want it.
+# c++    Native C++ compiler (for instance, Apple).
+# CXX    You never know.
+AN_MAKEVAR([OBJCXX],  [AC_PROG_OBJCXX])
+AN_PROGRAM([objcxx],  [AC_PROG_OBJCXX])
+AC_DEFUN([AC_PROG_OBJCXX],
+[AC_LANG_PUSH(Objective C++)dnl
+AC_ARG_VAR([OBJCXX],      [Objective C++ compiler command])dnl
+AC_ARG_VAR([OBJCXXFLAGS], [Objective C++ compiler flags])dnl
+_AC_ARG_VAR_LDFLAGS()dnl
+_AC_ARG_VAR_LIBS()dnl
+_AC_ARG_VAR_CPPFLAGS()dnl
+_AC_ARG_VAR_PRECIOUS([OBJCXX])dnl
+AC_CHECK_TOOLS(OBJCXX,
+	       [m4_default([$1], [g++ objc++ objcxx c++ CXX])],
+	       g++)
+# Provide some information about the compiler.
+_AS_ECHO_LOG([checking for _AC_LANG compiler version])
+set X $ac_compile
+ac_compiler=$[2]
+for ac_option in --version -v -V -qversion; do
+  _AC_DO_LIMIT([$ac_compiler $ac_option >&AS_MESSAGE_LOG_FD])
+done
+
+m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
+m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
+_AC_LANG_COMPILER_GNU
+if test $ac_compiler_gnu = yes; then
+  GOBJCXX=yes
+else
+  GOBJCXX=
+fi
+_AC_PROG_OBJCXX_G
+AC_LANG_POP(Objective C++)dnl
+])# AC_PROG_OBJCXX
+
+
+# _AC_PROG_OBJCXX_G
+# -----------------
+# Check whether -g works, even if OBJCFLAGS is set, in case the package
+# plays around with OBJCFLAGS (such as to build both debugging and
+# normal versions of a library), tasteless as that idea is.
+# Don't consider -g to work if it generates warnings when plain compiles don't.
+m4_define([_AC_PROG_OBJCXX_G],
+[ac_test_OBJCXXFLAGS=${OBJCXXFLAGS+set}
+ac_save_OBJCXXFLAGS=$OBJCXXFLAGS
+AC_CACHE_CHECK(whether $OBJCXX accepts -g, ac_cv_prog_objcxx_g,
+  [ac_save_objcxx_werror_flag=$ac_objcxx_werror_flag
+   ac_objcxx_werror_flag=yes
+   ac_cv_prog_objcxx_g=no
+   OBJCXXFLAGS="-g"
+   _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
+     [ac_cv_prog_objcxx_g=yes],
+     [OBJCXXFLAGS=""
+      _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
+	[],
+	[ac_objcxx_werror_flag=$ac_save_objcxx_werror_flag
+	 OBJCXXFLAGS="-g"
+	 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
+	   [ac_cv_prog_objcxx_g=yes])])])
+   ac_objcxx_werror_flag=$ac_save_objcx_werror_flag])
+if test "$ac_test_OBJCXXFLAGS" = set; then
+  OBJCXXFLAGS=$ac_save_OBJCXXFLAGS
+elif test $ac_cv_prog_objcxx_g = yes; then
+  if test "$GOBJCXX" = yes; then
+    OBJCXXFLAGS="-g -O2"
+  else
+    OBJCXXFLAGS="-g"
+  fi
+else
+  if test "$GOBJCXX" = yes; then
+    OBJCXXFLAGS="-O2"
+  else
+    OBJCXXFLAGS=
+  fi
+fi[]dnl
+])# _AC_PROG_OBJCXX_G
+
+
+
 ## ------------------------------- ##
 ## 4. Compilers' characteristics.  ##
 ## ------------------------------- ##
diff --git a/tests/local.at b/tests/local.at
index 8a81835..19a82c8 100644
--- a/tests/local.at
+++ b/tests/local.at
@@ -297,6 +297,7 @@ if test -f state-env.before && test -f state-env.after; then
       [CC|CFLAGS|CPP|GCC|CXX|CXXFLAGS|CXXCPP|GXX|F77|FFLAGS|FLIBS|G77],
       [ERL|ERLC|ERLCFLAGS|ERLANG_PATH_ERL|ERLANG_ROOT_DIR|ERLANG_LIB_DIR],
       [ERLANG_INSTALL_LIB_DIR|OBJC|OBJCPP|OBJCFLAGS],
+      [OBJCXX|OBJCXXCPP|OBJCXXFLAGS],
       [OPENMP_CFLAGS],
       [LIBS|LIB@&t@OBJS|LTLIBOBJS|LDFLAGS],
       [INSTALL(_(DATA|PROGRAM|SCRIPT))?],
-- 
1.6.3.3

_______________________________________________
Autoconf mailing list
Autoconf@xxxxxxx
http://lists.gnu.org/mailman/listinfo/autoconf

[Index of Archives]     [GCC Help]     [Kernel Discussion]     [RPM Discussion]     [Red Hat Development]     [Yosemite News]     [Linux USB]     [Samba]

  Powered by Linux