[LLVMdev] [PATCH] llvm-config: add svn revision to --version

Xerxes RĂ„nby xerxes at zafena.se
Mon May 18 08:03:20 PDT 2009

Frits van Bommel skrev:
> Benjamin Kramer wrote:
>> At the moment llvm-config outputs "2.6svn" if llvm is build from trunk
>> $ llvm-config --version
>> 2.6svn
>> Some external projects (built out-of-tree) need to know which revision 
>> of llvm is installed. LDC currently asks llvm-config --src-root for the 
>> source directory and then parses svn info's output to get the revision 
>> number. This requires the user to keep the llvm source tree around even 
>> if it is not needed to build ldc.
> Not technically true; it's not *required*. However, if this isn't done you need 
> to set it manually in the cmake configuration...
>> The attached patch modifies the llvm build system (both autotools and 
>> cmake) to write the revision into PACKAGE_VERSION:
>> $ llvm-config --version
>> 2.6-71981
> I don't think that's enough for LDC; we want to be able to compare the version 
> with #if, so we need it to produce something like '#define LLVM_REV 71981' (i.e. 
> a raw integer, not a string).
When we build Icedtea shark JIT we use the llvm-config version to make 
the icedtea code compatible with api changes in llvm.
I belive you are trying to do something similarwith LDC. This can be 
done without changing the llvm codebase.

I suggest the following:
add to the LDC configure.

LLVM_CFLAGS="$LLVM_CFLAGS -DLLVM_VERSION=`$LLVM_CONFIG --version | sed 's/\.//;s/svn.*//'`"

this will take the llvm-config --version output and truncates the versionnumber from

2.6svn to 26

now the LLVM_VERSION can be used in your source code like this:

#if LLVM_VERSION >= 26
/*llvm 2.6 and above compatible code*/

#if LLVM_VERSION >= 25
// etc...


More information about the llvm-dev mailing list