Home > Software engineering >  Can GNU Autotools (Autoconf / Automake) handle Apple Mac Frameworks?
Can GNU Autotools (Autoconf / Automake) handle Apple Mac Frameworks?

Time:12-09

The docs for GNU autotools (autoconf and automake) explain how to test for the presence of a needed library. If the library is found, autotools will include it in LIBS to make sure any generated object files are properly linked to it. If the library is not found, autotools can generate an error message.

For libraries, one would use the following macro:

AC_SEARCH_LIBS(function, libraries-list, action-if-found, action-if-not-found, extra-libraries)

e.g.

AC_SEARCH_LIBS([cos], [m], [], [AC_MSG_ERROR([unable to find the cos() function in the math library])])

How you tell GNU autoconf / automake to do that same with a particular Apple Framework?

I probably could use the following to check whether a particular framework exists:

AC_CHECK_FILE(file, [action-if-found], [action-if-not-found])

But how do I tell GNU autotools to make sure my object files are linked to a particular Apple Framework?
(My program (written in C) needs to link to the Apple CoreServices framework).

For manual builds on the command line, one normally would tell the compiler where to find the framework and tell it to link your object files with it.

e.g.

clang -o MyProgram Source.c -F/System/Library/Frameworks -framework CoreServices -L/opt/local/lib -lmpeg2

Can GNU autotools be used when Apple Frameworks are involved? If not, can someone suggest another tool designed to easily generate makefiles for Apple Mac software development?

CodePudding user response:

It looks like one can tell automake to use a specific Apple Mac Framework. It is done by adding the following into Makefile.am:

AM_LDFLAGS = -F/System/Library/Frameworks -framework CoreServices
OR
programname_LDFLAGS = -F/System/Library/Frameworks -framework CoreServices

And if you want to check that the Framework actually exists, one must add that check in configure.ac (presumably via using the AC_CHECK_FILE macro).

It is too bad that autotools does not have a macro for use in configure.ac similar to AC_SEARCH_LIBS that not only checks that the Framework actually exists but also adds it to a variable (e.g. FRAMEWORKS) for use by automake for linking purposes. Perhaps, it could be done by creating your own M4 Macro. M4 macros are very powerful.

P.S. You will not need to include -F/System/Library/Frameworks in AM_LDFLAGS etc. as shown above since that is the standard search path for Frameworks on Macs. But you will need to include the -F flag if the Framework is located in a non-standard location.

CodePudding user response:

How you tell GNU autoconf / automake to do that same with a particular Apple Framework?

This is all about link options, and all the Autotools' usual means for dealing with compile and link options are in play.

If you are talking about using existing autotooling, then, in principle, you can specify the appropriate additional link flags in configure's environment. For example:

LDFLAGS='-framework CoreServices' ./configure

Unless the specific autotooling in question does something to break it, ./configure will use the specified linker flags when performing library checks. You should not then need to repeat that to make or have it explicitly accommodated in Makefile.am.

If you are writing the autotooling then there is all manner of things you can do, from nothing in particular (per above) to autodetecting and / or guessing to providing a --with or --enable option to allow the user to select and activate specific frameworks and framework folders and carry the appropriate link options through to make. You should not need to write AC_SEARCH_LIBS or AC_CHECK_LIB invocations any differently than you otherwise would, but under some circumstances you might want to create one or more additional output variables with which to convey the link options for framework selection.

I know that's a bit vague, but so is the question.

  • Related