From 45056fc022a77c1b7c912ef05c7505d4ab415834 Mon Sep 17 00:00:00 2001 From: Ralph Giles Date: Tue, 19 Oct 2010 12:05:22 -0700 Subject: [PATCH] Update llvm version detection for the 2.8 release. The LLVM project recently released version 2.8, and updated the SVN tree version to 2.9svn, obsoleting the simple check for 'llvm-config --version' returning 2.8svn. With this commit we instead check for the substrings 2.8 and 2.9 in the output of 'llvm-config --version', since we (currently) support both the svn and released varieties of those versions. A stable release also complicates our check for the ocaml bindings. Previously we looked in `llvm-config --libdir`/ocaml which is appropriate for local compiles, but distribution packagers are likely to put the bindings in the default search path, e.g. /usr/lib/ocaml/llvm. We now fall back to trying variations on the standard library path returned by 'ocamlc -config' if we don't find it under 'llvm-config --libdir'. With this change, rust builds against LLVM 2.8 as packaged in Ubuntu 10.10 as well as LLVM 2.9svn compiled locally. (cherry picked from commit b606b65756f087c403180abd5418fe7dce469758) --- src/Makefile | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/Makefile b/src/Makefile index fec01016be6..9984393ab44 100644 --- a/src/Makefile +++ b/src/Makefile @@ -167,16 +167,30 @@ ifneq ($(CFG_LLVM_CONFIG),) endif ifneq ($(CFG_LLVM_CONFIG),) CFG_LLVM_VERSION := $(shell $(CFG_LLVM_CONFIG) --version) - ifeq ($(CFG_LLVM_VERSION),2.8svn) - $(info cfg: using LLVM version 2.8svn) - WHERE := $(shell $(CFG_LLVM_CONFIG) --libdir)/ocaml - ifneq ($(shell test -e $(WHERE)/llvm.cma && echo ok),ok) - CFG_LLVM_CONFIG := $(info cfg: LLVM ocaml bindings not found) - endif + $(info cfg: found llvm-config at $(CFG_LLVM_CONFIG)) + ifneq ($(findstring 2.8,$(CFG_LLVM_VERSION)),) + $(info cfg: using LLVM version $(CFG_LLVM_VERSION)) + else ifneq ($(findstring 2.9,$(CFG_LLVM_VERSION)),) + $(info cfg: using LLVM version $(CFG_LLVM_VERSION)) else CFG_LLVM_CONFIG := $(info cfg: incompatible LLVM version $(CFG_LLVM_VERSION), \ - expected 2.8svn) + expected 2.8) + endif +endif +ifneq ($(CFG_LLVM_CONFIG),) + CFG_OCAML_LIBPATH := $(lastword \ + $(shell ocamlc$(OPT) -config | grep standard_library:)) + CFG_OCAML_LLVM := $(shell \ + for path in $(shell $(CFG_LLVM_CONFIG) --libdir)/ocaml \ + $(CFG_OCAML_LIBPATH)/llvm \ + $(CFG_OCAML_LIBPATH)/llvm-$(CFG_LLVM_VERSION) ; do \ + if test -e $${path}/llvm.cma; then echo $${path}; break; fi \ + done) + ifneq ($(CFG_OCAML_LLVM),) + $(info cfg: found LLVM ocaml bindings in $(CFG_OCAML_LLVM)) + else + CFG_LLVM_CONFIG := $(info cfg: LLVM ocaml bindings not found) endif endif ifdef CFG_LLVM_CONFIG @@ -185,13 +199,12 @@ ifdef CFG_LLVM_CONFIG LLVM_NATIVE_LIBS := llvm.cmxa llvm_bitwriter.cmxa LLVM_CLIBS := $(shell for c in `$(CFG_LLVM_CONFIG) --ldflags --libs` \ -lllvm -lllvm_bitwriter; do echo -cclib && echo $$c; done | xargs echo) - LLVM_INCS := -I boot/llvm -I $(WHERE) + LLVM_INCS := -I boot/llvm -I $(CFG_OCAML_LLVM) LLVM_MLS := $(addprefix boot/llvm/, llabi.ml llasm.ml llfinal.ml \ lltrans.ml llemit.ml) LLC := "$(shell $(CFG_LLVM_CONFIG) --bindir)/llc" CFG_LLC_CFLAGS := -march=x86 LLVM-DIS := "$(shell $(CFG_LLVM_CONFIG) --bindir)/llvm-dis" - $(info cfg: found llvm-config at $(CFG_LLVM_CONFIG)) else VARIANT=x86 LLVM_CLIBS :=