mysqlautoconfm4ldflagscflags

Determining the target architecture in an Autoconf M4 script


I'm currently working with a system that requires building both i686 and x86_64 libraries, building and installing them on the same system - it is a legacy project that has a mix of newer ABI-agnostic code that is generally run in 64 bit because it can use the extra memory, and some older code that breaks when built for 64.

For 99% of linked libraries, this works without issue; between autoconf, rpm-build, and pkg_config, it finds the correct libraries without issue. There is, unfortunately, a major exception - MySQL. Rather than shipping pkg_config scripts, they have their own custom mysql_config script, and it doesn't respect target ABIs - it just reports the values for the last one installed.

So, while we get the last of the code ported to run properly on 64 bit, I'm trying to work around this problem by editing the Autoconf MySQL configuration script (the official GNU one, ax_lib_mysql.m4) to postprocess the reported CFLAGS and LDFLAGS depending on the target platform. And therein lies the crux of the question - is there a good way in Autoconf M4 to detect if you're building for a 32 or 64 bit target? The exact ABI does not matter - it's primarily knowing whether I need to link against /usr/lib or /usr/lib64.

Sorry about writing a novel for a one-sentence question, but I found a number of places online where people asked how to do this, and never got an answer because everyone was too busy telling them that they shouldn't do it since it would make the build process more brittle, so I was trying to set the stage a bit. I know this is a horrible hack (and am very welcome to alternative approaches!), but I need some way to work around this to keep the system building during the transition.


Solution

  • I think what you want is to use either $host_cpu or $build_cpu which is set will be set if you add AC_CANONICAL_HOST in your configure script.

    See the Getting the Canonical System Type in the autoconf info documentation.