From 8c1de4d15f1550956abace86ad6877e25dc05e9a Mon Sep 17 00:00:00 2001 From: Peter Breitenlohner 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 --- 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 address@hidden OBJCXXFLAGS address@hidden OBJCXXFLAGS address@hidden OBJCXXFLAGS +Debugging and optimization options for the Objective C++ compiler. It +acts like @code{CXXFLAGS}, but for Objective C++ instead of C++. address@hidden 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 address@hidden Objective C++ Compiler address@hidden Objective C++ Compiler Characteristics + + address@hidden AC_PROG_OBJCXX (@ovar{compiler-search-list}) address@hidden address@hidden OBJCXX address@hidden OBJCXXFLAGS address@hidden OBJCXX address@hidden 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: + address@hidden +AC_PROG_OBJCXX([gcc g++ objcc++ objcxx]) address@hidden example + +If using the @acronym{GNU} Objective C++ compiler, set shell variable address@hidden 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 address@hidden), or @option{-g} for other compilers. address@hidden defmac + address@hidden AC_PROG_OBJCXXCPP address@hidden address@hidden OBJCXXCPP address@hidden 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. address@hidden 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}. + address@hidden Objective C++ +Do compilation tests using @code{OBJCXX} and @code{OBJCXXCPP} and use +extension @file{.mm} for test programs. Use compilation flags: address@hidden with @code{OBJCXXCPP}, and both @code{CPPFLAGS} and address@hidden 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 + [(Objective) C/C++ preprocessor flags, e.g. -I if you have headers in a nonstandard directory ])]) # _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 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])]) @@ -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@&address@hidden|LTLIBOBJS|LDFLAGS], [INSTALL(_(DATA|PROGRAM|SCRIPT))?], -- 1.6.3.3