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

Frits van Bommel fvbommel at wxs.nl
Mon May 18 10:06:46 PDT 2009

Xerxes RĂ„nby wrote:
> Frits van Bommel skrev:
>> Benjamin Kramer wrote:
>>> 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*/
> #endif
> #if LLVM_VERSION >= 25
> // etc...
> #endif

That's not precise enough. API changes are introduced in svn all the time, and 
bugs are fixed (obsoleting workarounds). We currently test for 5 different trunk 
revisions after 2.5.

Though I suppose a similar technique could be used with the original version of 
the patch, sed'ing out the revision nr. It'd certainly be less error-prone than 
the current approach.

More information about the llvm-dev mailing list