From 3296eee22058060f19e0e0a09cae4fa5eea511fa Mon Sep 17 00:00:00 2001
From: Jeff Smith <whydoubt@yahoo.com>
Date: Fri, 12 Mar 2010 18:55:09 -0600
Subject: [PATCH] Use X11_LIBS from pkg-config, instead of libdir, for locating libX11

Signed-off-by: Jeff Smith <whydoubt@yahoo.com>
---
 configs/autoconf.in   |    2 ++
 configure.ac          |   10 +++++++++-
 progs/egl/Makefile    |    6 +++---
 progs/xdemos/Makefile |    4 ++--
 4 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/configs/autoconf.in b/configs/autoconf.in
index bf34f3b..66c1ee4 100644
--- a/configs/autoconf.in
+++ b/configs/autoconf.in
@@ -24,6 +24,8 @@ RADEON_CFLAGS = @RADEON_CFLAGS@
 RADEON_LDFLAGS = @RADEON_LDFLAGS@
 INTEL_LIBS = @INTEL_LIBS@
 INTEL_CFLAGS = @INTEL_CFLAGS@
+X11_LIBS = @X11_LIBS@
+X11_CFLAGS = @X11_CFLAGS@
 
 # Assembler
 MESA_ASM_SOURCES = @MESA_ASM_SOURCES@
diff --git a/configure.ac b/configure.ac
index c5ff8dc..ccc3107 100644
--- a/configure.ac
+++ b/configure.ac
@@ -547,8 +547,16 @@ else
     x11_pkgconfig=no
 fi
 dnl Use the autoconf macro if no pkg-config files
-if test "$x11_pkgconfig" = no; then
+if test "$x11_pkgconfig" = yes; then
+    PKG_CHECK_MODULES([X11], [x11])
+else
     AC_PATH_XTRA
+    if test -z "$X11_CFLAGS"; then
+        X11_CFLAGS="$X_CFLAGS"
+    fi
+    if test -z "$X11_LIBS"; then
+        X11_LIBS="$X_LIBS -lX11"
+    fi
 fi
 
 dnl Try to tell the user that the --x-* options are only used when
diff --git a/progs/egl/Makefile b/progs/egl/Makefile
index 25de6e1..8dfcb4e 100644
--- a/progs/egl/Makefile
+++ b/progs/egl/Makefile
@@ -57,13 +57,13 @@ peglgears: peglgears.o $(HEADERS) $(LIB_DEP)
 	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) -lm
 
 xeglgears: xeglgears.o $(HEADERS) $(LIB_DEP)
-	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm -L$(libdir) -lX11
+	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm $(X11_LIBS)
 
 xeglthreads: xeglthreads.o $(HEADERS) $(LIB_DEP)
-	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm -L$(libdir) -lX11
+	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm $(X11_LIBS)
 
 xegl_tri: xegl_tri.o $(HEADERS) $(LIB_DEP)
-	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm -L$(libdir) -lX11
+	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm $(X11_LIBS)
 
 clean:
 	-rm -f *.o *~
diff --git a/progs/xdemos/Makefile b/progs/xdemos/Makefile
index 60bacbf..65870f2 100644
--- a/progs/xdemos/Makefile
+++ b/progs/xdemos/Makefile
@@ -9,9 +9,9 @@ INCDIR = $(TOP)/include
 LIB_DEP = $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME)
 
 # Add X11 and pthread libs to satisfy GNU gold.
-APP_LIB_DEPS += -lX11 -lpthread
+APP_LIB_DEPS += $(X11_LIBS) -lpthread
 
-LIBS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -L$(libdir) $(APP_LIB_DEPS)
+LIBS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) $(APP_LIB_DEPS)
 
 PROGS = \
 	corender \
-- 
1.6.0.6

