Discussion:
Using LLVM with Autotools
Russell Wallace
2016-03-24 15:05:02 UTC
Permalink
I'm writing a C++ program that needs to compile and link with LLVM, and
trying to figure out how to build it with autotools.

The good news is, llvm-config will supply the relevant compiler and linker
flags.

The bad news is, the llvm-config in the current path is not likely to be
the right one (e.g. Ubuntu 14.04 thinks LLVM 3.4 is the latest version
whereas it's actually up to 3.8, and the differences between versions do
matter) so the user or packager needs to supply a path to the correct
llvm-config. What's the best way to do this?

I was given a link to a macro that tries to do this...
https://github.com/google/autofdo/blob/master/m4/ax_llvm.m4
https://github.com/google/autofdo/pull/30/commits/0029f4be825f851b9d99bcd19dcb34fd59f1775e
... But it doesn't work, and I don't know enough M4 to figure out why.
Jeffrey Walton
2016-03-24 16:00:38 UTC
Permalink
Post by Russell Wallace
The bad news is, the llvm-config in the current path is not likely to be
the right one (e.g. Ubuntu 14.04 thinks LLVM 3.4 is the latest version
whereas it's actually up to 3.8, and the differences between versions do
matter) so the user or packager needs to supply a path to the correct
llvm-config. What's the best way to do this?
I've run into this a few times due to unrecognized triplets on mobile platforms.

I've found reaching out to the package maintainer is the best course
of action. When you contact them, clearly state:

(1) the problem you are encountering
(2) how to solve the problem

In the case of the missing triplets and updated Autoconf files, I
usually provide a prescriptive recipe:

wget https://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.xz
tar xf autoconf-latest.tar.xz
autoconf-2.69
cp build-aux/config.sub <where needed>

Jeff
Russell Wallace
2016-03-24 16:13:11 UTC
Permalink
I don't think I'm understanding you - in this case, I'm the one writing the
program, and thinking about the configure.ac and Makefile.am I'll be
supplying to users and prospective package maintainers?

I think the default autoconf on typical Linux distributions is normally
sufficient these days?

What is build-aux/config.sub?
Post by Jeffrey Walton
Post by Russell Wallace
The bad news is, the llvm-config in the current path is not likely to be
the right one (e.g. Ubuntu 14.04 thinks LLVM 3.4 is the latest version
whereas it's actually up to 3.8, and the differences between versions do
matter) so the user or packager needs to supply a path to the correct
llvm-config. What's the best way to do this?
I've run into this a few times due to unrecognized triplets on mobile platforms.
I've found reaching out to the package maintainer is the best course
(1) the problem you are encountering
(2) how to solve the problem
In the case of the missing triplets and updated Autoconf files, I
wget https://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.xz
tar xf autoconf-latest.tar.xz
autoconf-2.69
cp build-aux/config.sub <where needed>
Jeff
Jeffrey Walton
2016-03-24 16:16:34 UTC
Permalink
On Thu, Mar 24, 2016 at 12:13 PM, Russell Wallace
Post by Russell Wallace
I don't think I'm understanding you - in this case, I'm the one writing the
program, and thinking about the configure.ac and Makefile.am I'll be
supplying to users and prospective package maintainers?
I think the default autoconf on typical Linux distributions is normally
sufficient these days?
What is build-aux/config.sub?
My bad; I miss understood you.

I thought you were a user of a library that needed some updated
autoconf files, and you needed to contact the package maintainer to
get the files picked up so "things just worked" for you.

build-aux/config.sub is the code that guesses the platform based on
the triplets.

Jeff
Gavin Smith
2016-03-24 16:33:36 UTC
Permalink
Post by Russell Wallace
I'm writing a C++ program that needs to compile and link with LLVM, and
trying to figure out how to build it with autotools.
The good news is, llvm-config will supply the relevant compiler and linker
flags.
Is llvm-config hardcoded into configure.ac or Makefile.am, or is
configure being invoked like "./configure CC=llvm "CFLAGS=`llvm-config
--cflags`" or whatever it is? If it's the latter it should be easy to
give the path to the correct llvm-config.
Russell Wallace
2016-03-24 16:39:48 UTC
Permalink
In this case I'm the one who has to write configure.ac and Makefile.am so I
need to find out what the answers need to be. But I see what you're saying,
that it's at least theoretically possible to do the whole job on the
./configure command line. That would make said command line a bit long and
unwieldy, having to invoke the full path to llvm-config twice (once to get
compiler flags, once to get linker flags). Is there a way to abbreviate
this, by putting something into configure.ac or Makefile.am or otherwise?
Post by Russell Wallace
Post by Russell Wallace
I'm writing a C++ program that needs to compile and link with LLVM, and
trying to figure out how to build it with autotools.
The good news is, llvm-config will supply the relevant compiler and
linker
Post by Russell Wallace
flags.
Is llvm-config hardcoded into configure.ac or Makefile.am, or is
configure being invoked like "./configure CC=llvm "CFLAGS=`llvm-config
--cflags`" or whatever it is? If it's the latter it should be easy to
give the path to the correct llvm-config.
Mike Miller
2016-03-25 16:20:19 UTC
Permalink
Post by Russell Wallace
In this case I'm the one who has to write configure.ac and Makefile.am so I
need to find out what the answers need to be. But I see what you're saying,
that it's at least theoretically possible to do the whole job on the
./configure command line. That would make said command line a bit long and
unwieldy, having to invoke the full path to llvm-config twice (once to get
compiler flags, once to get linker flags). Is there a way to abbreviate
this, by putting something into configure.ac or Makefile.am or otherwise?
In Octave, we do something like the following (simplified for clarity):

AC_ARG_VAR([LLVM_CONFIG], [path to llvm-config utility])
LLVM_CPPFLAGS="-I`$LLVM_CONFIG --includedir`"
LLVM_LDFLAGS="-L`$LLVM_CONFIG --libdir`"
LLVM_LIBS=`$LLVM_CONFIG --libs`

(and AC_SUBST for each of these of course).

Full example starts at line 829 here:

http://hg.savannah.gnu.org/hgweb/octave/file/@/configure.ac#l829

This allows the user to select the version of LLVM with

./configure LLVM_CONFIG=/usr/bin/llvm-config-3.7

and the rest of the flags fall from that. I suppose you could simplify
further with something like an AC_ARG_WITH option to allow the user to

./configure --with-llvm=3.7

and use that answer to choose which version of LLVM you look for.
--
mike
Loading...