autoconf
[Top][All Lists]
Advanced

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

Re: checking Mac OS X headers


From: Ralf Wildenhues
Subject: Re: checking Mac OS X headers
Date: Sun, 21 Feb 2010 15:46:47 +0100
User-agent: Mutt/1.5.20 (2009-10-28)

* Vincent Torri wrote on Sat, Feb 20, 2010 at 10:37:00AM CET:
> On Fri, 12 Feb 2010, Vincent Torri wrote:
> 
> >I restart this thread.
> >
> >So, what I would like to do is checking Mac OS X headers in an m4
> >macro. If the objective C compiler is installed, no problem. If it
> >is not, i would like that, in the m4 macro, the test not to be
> >done.
> >
> >I have attached a complete, and I think, minimal example
> >
> >In configure.ac, I call conditionnaly AC_PROG_OBJC.
> >
> >Before using AC_CHECK_HEADER in check.m4, I have to call
> >AC_LANG_PUSH([Objective C]). It is that macro that is the problem:
> >
> >1) Without it and on a system without an obj c compiler, no problem.
> >2) Without it and on a system with an obj c compiler, there is an error.
> >
> >3) With it and on a system without an obj c compiler there is an error
> >4) With it and on a system with an obj c compiler, no problem
> >
> >as there is a failure in point 2), I must use AC_LANG_PUSH([Objective C])
> >
> >What must I do, in check.m4, to disable the check of those
> >headers, so that there is no problem with AC_LANG_PUSH([Objective
> >C]) (point 3) ) ?
> 
> still no idea about the problem ?

I think your problem description is not right, but there is a bug in
Autoconf.  It is definitely not the AC_LANG_PUSH macro, or use of it,
that is buggy.

What is buggy however is that AC_PROG_OBJC does not work right, in the
sense that it does not really check whether the compiler has the
Objective C language frontend enabled (unless, as a side effect of being
the first compiler check expanded, the test for $OBJEXT fails).  What is
also a problem is that AC_PROG_OBJCPP will unconditionally fail
configure if it doesn't find a working preprocessor.

The thing to note is that AC_CHECK_HEADER* will AC_REQUIRE
AC_PROG_OBJCPP (or AC_PROG_CPP, depending on whether you've set the
right language with AC_LANG_PUSH), and the AC_REQUIRE will push the
expansion of AC_PROG_OBJCPP out to before the expansion of the
EVAS_CHECK_ENGINE_DEP_QUARTZ macro (see info Autoconf 'Prerequisite
Macros'), thus outside of your 'if' statement.

Which, BTW, is a hack already, as ${ac_cv_objc_compiler_gnu} isn't meant
to indicate whether the Objective C compiler works or not; it is meant
to say whether that is the GNU Objective C compiler or not.

I've hacked your code to add a macro to check if $OBJC works, and set a
cache variable for this.  I've put the macro at the beginning of
configure.ac but you're free to move this into its own macro file, for
clarity.

I've then added a way to show how to hack the AC_PROG_OBJCPP from within
your macro so that it is expanded inside a shell conditional.  The AS_IF
uses are not relevant but the AC_REQUIRE of the additional
EVAS_MAYBE_GET_OBJCPP macro is.  Alternatively, you could just put
something like this in configure.ac, before calling
EVAS_CHECK_ENGINE_DEP_QUARTZ:

  AS_IF([test "x${rw_cv_prog_objc_works}" = "xyes"],
        [AC_PROG_OBJCPP])


Hope that helps.

Cheers,
Ralf

--- configure.ac ---
# rw_PROG_OBJC_WORKS
# Check whether the Objective C compiler works.
AC_DEFUN([rw_PROG_OBJC_WORKS],
[AC_REQUIRE([AC_PROG_OBJC])dnl
AC_CACHE_CHECK([whether the Objective C compiler works],
               [rw_cv_prog_objc_works],
               [AC_LANG_PUSH([Objective C])
                AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
                               [rw_cv_prog_objc_works=yes],
                               [rw_cv_prog_objc_works=no])
                AC_LANG_POP([Objective C])])
])

AC_INIT([test], [0.0])
AC_PREREQ([2.60])
AC_CONFIG_SRCDIR([configure.ac])
AC_CONFIG_MACRO_DIR([m4])

AM_INIT_AUTOMAKE([1.6 dist-bzip2])

define([AC_LIBTOOL_LANG_F77_CONFIG], [:])dnl
define([AC_LIBTOOL_LANG_CXX_CONFIG], [:])dnl
AC_PROG_LIBTOOL

m4_ifdef([AC_PROG_OBJC],
   [
    AC_PROG_OBJC
    _AM_DEPENDENCIES(OBJC)
   ],
   [
    AC_CHECK_TOOL([OBJC], [gcc])
    AC_SUBST([OBJC])
    AC_SUBST([OBJCFLAGS])
   ])

rw_PROG_OBJC_WORKS
AC_PROG_CC

EVAS_CHECK_ENGINE([quartz], [no], [no], [Quartz])

AC_CONFIG_FILES([Makefile])


AC_OUTPUT

--- m4/check.m4 ---

dnl use: EVAS_CHECK_ENGINE_DEP_QUARTZ(engine, simple, want_static[, 
ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])

AC_DEFUN([EVAS_CHECK_ENGINE_DEP_QUARTZ],
[
AC_REQUIRE([EVAS_MAYBE_GET_OBJCPP])

have_dep="no"
evas_engine_[]$1[]_cflags=""
evas_engine_[]$1[]_libs=""

AS_IF([test "x${rw_cv_prog_objc_works}" = "xyes"],
[
   AC_LANG_PUSH([Objective C]) 
   
AC_CHECK_HEADERS([/System/Library/Frameworks/Cocoa.framework/Headers/Cocoa.h],
      [
       have_dep="yes"
       evas_engine_[]$1[]_libs="-framework Cocoa"
      ],
      [have_dep="no"])
   AC_LANG_POP([Objective C]) 

])

if test "x${have_dep}" = "xyes" ; then
  m4_default([$4], [:])
else
  m4_default([$5], [:])
fi

])

dnl use: EVAS_CHECK_ENGINE(engine, want_engine, simple, description)

AC_DEFUN([EVAS_CHECK_ENGINE],
[

m4_pushdef([UP], m4_translit([$1], [-a-z], [_A-Z]))dnl
m4_pushdef([DOWN], m4_translit([$1], [-A-Z], [_a-z]))dnl

want_engine="$2"
want_static_engine="no"
have_engine="no"
have_evas_engine_[]DOWN="no"

if test "x${want_engine}" = "xyes" ; then
   m4_default([EVAS_CHECK_ENGINE_DEP_]m4_defn([UP]))(DOWN, $3, ${want_engine}, 
[have_engine="yes"], [have_engine="no"])
fi

m4_popdef([UP])
m4_popdef([DOWN])

])

AC_DEFUN([EVAS_MAYBE_GET_OBJCPP],
[AS_IF([test "x${rw_cv_prog_objc_works}" = "xyes"],
       [AC_PROG_OBJCPP])
])




reply via email to

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