From 9dad3de8f0337ff6a71e575dcd92a9dce16f368e Mon Sep 17 00:00:00 2001
From: Dave Airlie <airlied@redhat.com>
Date: Sun, 28 Mar 2010 18:45:32 +1000
Subject: [PATCH] llvmpipe: add initial autoconf support.

allows the swrastg_dri.so to be built with llvmpipe, not sure
its all correct yet though.

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 configs/autoconf.in                     |   12 ++++++++++++
 configure.ac                            |   30 ++++++++++++++++++++++++++++++
 src/gallium/Makefile.template           |    2 +-
 src/gallium/drivers/llvmpipe/Makefile   |    5 +++--
 src/gallium/targets/Makefile.dri        |    6 +++++-
 src/gallium/targets/dri-swrast/Makefile |    9 +++++++++
 6 files changed, 60 insertions(+), 4 deletions(-)

diff --git a/configs/autoconf.in b/configs/autoconf.in
index b6cc9b3..3ef385a 100644
--- a/configs/autoconf.in
+++ b/configs/autoconf.in
@@ -26,6 +26,10 @@ INTEL_LIBS = @INTEL_LIBS@
 INTEL_CFLAGS = @INTEL_CFLAGS@
 X11_LIBS = @X11_LIBS@
 X11_CFLAGS = @X11_CFLAGS@
+LLVM_CFLAGS = @LLVM_CFLAGS@
+LLVM_LDFLAGS = @LLVM_LDFLAGS@
+LLVM_LIBS = @LLVM_LIBS@
+
 
 # Assembler
 MESA_ASM_SOURCES = @MESA_ASM_SOURCES@
@@ -157,3 +161,11 @@ OSMESA_PC_LIB_PRIV = @OSMESA_PC_LIB_PRIV@
 
 EGL_DRI2_CFLAGS = @EGL_DRI2_CFLAGS@
 EGL_DRI2_LIBS = @EGL_DRI2_LIBS@
+
+MESA_LLVM = @MESA_LLVM@
+
+LLVM_VERSION = @LLVM_VERSION@
+ifneq ($(LLVM_VERSION),)
+  HAVE_LLVM := 0x0$(subst .,0,$(LLVM_VERSION:svn=))
+  DEFINES += -DHAVE_LLVM=$(HAVE_LLVM)
+endif
diff --git a/configure.ac b/configure.ac
index f2e87f4..f2476a8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -465,6 +465,17 @@ GALLIUM_WINSYS_DIRS="sw"
 GALLIUM_DRIVERS_DIRS="softpipe failover trace identity"
 GALLIUM_STATE_TRACKERS_DIRS=""
 
+if test "x$LLVM_CONFIG" != xno; then
+	GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS llvmpipe"
+        DEFINES="$DEFINES -DMESA_LLVM"
+	if test "x$HAS_UDIS86" != xno; then
+        	DEFINES="$DEFINES -DHAVE_UDIS86"
+	fi
+	MESA_LLVM=1
+else
+	MESA_LLVM=0
+fi
+
 case "$mesa_driver" in
 xlib)
     DRIVER_DIRS="x11"
@@ -488,6 +499,7 @@ AC_SUBST([GALLIUM_TARGET_DIRS])
 AC_SUBST([GALLIUM_WINSYS_DIRS])
 AC_SUBST([GALLIUM_DRIVERS_DIRS])
 AC_SUBST([GALLIUM_STATE_TRACKERS_DIRS])
+AC_SUBST([MESA_LLVM])
 
 dnl
 dnl User supplied program configuration
@@ -1181,8 +1193,26 @@ AC_ARG_ENABLE([gallium],
     [enable_gallium=yes])
 if test "x$enable_gallium" = xyes; then
     SRC_DIRS="$SRC_DIRS gallium gallium/winsys gallium/targets"
+    AC_CHECK_HEADER([udis86.h], [HAS_UDIS86="yes"],
+                [HAS_UDIS86="no"])
+    AC_PATH_PROG([LLVM_CONFIG], [llvm-config], [no])
+    if test "x$LLVM_CONFIG" != xno; then
+	LLVM_VERSION=`$LLVM_CONFIG --version`
+	LLVM_CFLAGS=`$LLVM_CONFIG --cflags`
+	LLVM_LIBS="`$LLVM_CONFIG --libs jit interpreter nativecodegen bitwriter` -lstdc++"
+
+	if test "x$HAS_UDIS86" != xno; then
+		LLVM_LIBS="$LLVM_LIBS -ludis86"
+	fi
+	LLVM_LDFLAGS=`$LLVM_CONFIG --ldflags`
+    fi
 fi
 
+AC_SUBST([LLVM_CFLAGS])
+AC_SUBST([LLVM_LIBS])
+AC_SUBST([LLVM_LDFLAGS])
+AC_SUBST([LLVM_VERSION])
+
 dnl
 dnl Gallium state trackers configuration
 dnl
diff --git a/src/gallium/Makefile.template b/src/gallium/Makefile.template
index b5a9938..1ba0724 100644
--- a/src/gallium/Makefile.template
+++ b/src/gallium/Makefile.template
@@ -37,7 +37,7 @@ depend: $(C_SOURCES) $(CPP_SOURCES) $(ASM_SOURCES) $(SYMLINKS) $(GENERATED_SOURC
 	$(MKDEP) $(MKDEP_OPTIONS) $(INCLUDES) $(C_SOURCES) $(CPP_SOURCES) $(ASM_SOURCES) $(GENERATED_SOURCES) 2> /dev/null
 
 $(PROGS): % : %.o
-	$(LD) $(filter %.o,$^) -o $@ -Wl,--start-group  $(LIBS) -Wl,--end-group
+	$(LD) $(LDFLAGS) $(filter %.o,$^) -o $@ -Wl,--start-group  $(LIBS) -Wl,--end-group
 
 # Emacs tags
 tags:
diff --git a/src/gallium/drivers/llvmpipe/Makefile b/src/gallium/drivers/llvmpipe/Makefile
index 74d728d..24b976a 100644
--- a/src/gallium/drivers/llvmpipe/Makefile
+++ b/src/gallium/drivers/llvmpipe/Makefile
@@ -52,8 +52,9 @@ include ../../Makefile.template
 lp_tile_soa.c: lp_tile_soa.py ../../auxiliary/util/u_format_parse.py ../../auxiliary/util/u_format_access.py ../../auxiliary/util/u_format.csv
 	python lp_tile_soa.py ../../auxiliary/util/u_format.csv > $@
 
-
-LIBS += $(GL_LIB_DEPS) -L../../auxiliary/ -lgallium
+LDFLAGS += $(LLVM_LDFLAGS)
+LIBS += $(GL_LIB_DEPS) -L../../auxiliary/ -lgallium $(LLVM_LIBS)
+LD=g++
 
 $(PROGS): lp_test_main.o
 
diff --git a/src/gallium/targets/Makefile.dri b/src/gallium/targets/Makefile.dri
index 6d9b81a..6e04b03 100644
--- a/src/gallium/targets/Makefile.dri
+++ b/src/gallium/targets/Makefile.dri
@@ -69,7 +69,11 @@ $(LIBNAME): $(OBJECTS) $(MESA_MODULES) $(PIPE_DRIVERS) Makefile \
 		$(OBJECTS) $(PIPE_DRIVERS) \
                 -Wl,--start-group $(MESA_MODULES) -Wl,--end-group \
                  $(DRI_LIB_DEPS) $(DRIVER_EXTRAS)
-	$(CC) -o $@.test $(TOP)/src/mesa/drivers/dri/common/dri_test.o $@.tmp $(DRI_LIB_DEPS)
+	if [ "x${USE_CXX}" == "x" ]; then \
+		$(CC) -o $@.test $(TOP)/src/mesa/drivers/dri/common/dri_test.o $@.tmp $(DRI_LIB_DEPS); \
+	else \
+		$(CXX) -o $@.test $(TOP)/src/mesa/drivers/dri/common/dri_test.o $@.tmp $(DRI_LIB_DEPS); \
+	fi
 	@rm -f $@.test
 	mv -f $@.tmp $@
 
diff --git a/src/gallium/targets/dri-swrast/Makefile b/src/gallium/targets/dri-swrast/Makefile
index fcfd690..6af1ee7 100644
--- a/src/gallium/targets/dri-swrast/Makefile
+++ b/src/gallium/targets/dri-swrast/Makefile
@@ -22,6 +22,15 @@ C_SOURCES = \
 
 ASM_SOURCES =
 
+ifeq ($(MESA_LLVM),1)
+DRIVER_DEFINES += -DGALLIUM_LLVMPIPE
+PIPE_DRIVERS += $(TOP)/src/gallium/drivers/llvmpipe/libllvmpipe.a
+LDFLAGS += $(LLVM_LDFLAGS)
+LD = g++
+DRIVER_EXTRAS = $(LLVM_LIBS)
+USE_CXX=1
+endif
+
 include ../Makefile.dri
 
 INCLUDES += \
-- 
1.6.6.1

