#! /bin/sh /usr/share/dpatch/dpatch-run
## 85_nx-X11_debian-ld.dpatch by  <marceloshima@gmail.com>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Change the library filename to not conflict with Xorg ones.

@DPATCH@
Index: nx-x11-ubuntu/config/cf/X11.tmpl
===================================================================
--- nx-x11-ubuntu.orig/config/cf/X11.tmpl	2010-03-18 17:43:37.113684797 -0300
+++ nx-x11-ubuntu/config/cf/X11.tmpl	2010-03-18 17:46:07.532435434 -0300
@@ -2665,9 +2665,9 @@
 #ifndef SharedXrenderRev
 #define SharedXrenderRev 1.2.2
 #endif
-SharedLibReferences(XRENDER,Xrender,$(XRENDERLIBSRC),SOXRENDERREV,SharedXrenderRev)
+SharedLibReferences(XRENDER,Xrender-nx,$(XRENDERLIBSRC),SOXRENDERREV,SharedXrenderRev)
 #else
-ProjectUnsharedLibReferences(XRENDER,Xrender,$(XRENDERLIBSRC),XBuildLibDir)
+ProjectUnsharedLibReferences(XRENDER,Xrender-nx,$(XRENDERLIBSRC),XBuildLibDir)
 #endif
 
     XRANDRLIBSRC = $(LIBSRC)/Xrandr
Index: nx-x11-ubuntu/lib/X11/Imakefile
===================================================================
--- nx-x11-ubuntu.orig/lib/X11/Imakefile	2010-03-18 17:46:05.702437552 -0300
+++ nx-x11-ubuntu/lib/X11/Imakefile	2010-03-18 17:46:07.532435434 -0300
@@ -83,7 +83,7 @@
 #define DoExtraLib SharedLibX11
 #define DoDebugLib DebugLibX11
 #define DoProfileLib ProfileLibX11
-#define LibName X11
+#define LibName X11-nx
 #define SoRev SOXLIBREV
 #define HugeLibrary YES
 #define IncSubdir X11
Index: nx-x11-ubuntu/lib/Xext/Imakefile
===================================================================
--- nx-x11-ubuntu.orig/lib/Xext/Imakefile	2010-03-18 17:43:37.033687480 -0300
+++ nx-x11-ubuntu/lib/Xext/Imakefile	2010-03-18 17:46:07.532435434 -0300
@@ -10,14 +10,15 @@
 #define DoExtraLib SharedLibXext
 #define DoDebugLib DebugLibXext
 #define DoProfileLib ProfileLibXext
-#define LibName Xext
+#define LibName Xext-nx
 #define SoRev SOXEXTREV
 #define LibHeaders NO
 
 #include <Threads.tmpl>
 
 #ifdef SharedXextReqs
-REQUIREDLIBS = SharedXextReqs
+/* REQUIREDLIBS = SharedXextReqs $(NX_REQUIREDLIBS) */
+REQUIREDLIBS = -L../../exports/lib/ -lX11-nx $(NX_REQUIREDLIBS)
 #endif
 
 #if HasShm
Index: nx-x11-ubuntu/lib/Xft/Imakefile
===================================================================
--- nx-x11-ubuntu.orig/lib/Xft/Imakefile	2010-03-18 17:43:37.053695190 -0300
+++ nx-x11-ubuntu/lib/Xft/Imakefile	2010-03-18 17:46:07.532435434 -0300
@@ -94,8 +94,7 @@
 	  FONTCONFIG_CFLAGS="$(FONTCONFIG_CFLAGS)" \
 	  FONTCONFIG_LIBS="$(FONTCONFIG_LIBS)"
 
-REQUIREDLIBS=$(LDPRELIBS) $(XRENDERLIB) $(XLIB) $(FONTCONFIGLIB) $(EXPATLIB) $(FREETYPE2LIB)
-
+REQUIREDLIBS=$(LDPRELIBS) -L../../exports/lib/ -lXrender-nx -lX11-nx $(FONTCONFIGLIB) $(EXPATLIB) $(FREETYPE2LIB)
 HEADERS = Xft.h XftCompat.h
 
    SRCS = xftcolor.c xftdbg.c xftdpy.c \
Index: nx-x11-ubuntu/lib/Xft1/Imakefile
===================================================================
--- nx-x11-ubuntu.orig/lib/Xft1/Imakefile	2010-03-18 17:43:37.073687814 -0300
+++ nx-x11-ubuntu/lib/Xft1/Imakefile	2010-03-18 17:46:07.532435434 -0300
@@ -92,7 +92,7 @@
 FREETYPE2REQLIB = $(FREETYPE2LIB)
 #endif
 
-REQUIREDLIBS=$(LDPRELIBS) $(XRENDERLIB) $(XLIB) $(FONTCONFIGLIB) $(EXPATLIB) $(FREETYPE2REQLIB)
+REQUIREDLIBS=$(LDPRELIBS) -L../../exports/lib/ -lXrender-nx -lX11-nx $(FONTCONFIGLIB) $(EXPATLIB) $(FREETYPE2REQLIB)
 
 #if UseFreetype2
 FT_OLD = xftcache.c
Index: nx-x11-ubuntu/lib/Xrender/Imakefile
===================================================================
--- nx-x11-ubuntu.orig/lib/Xrender/Imakefile	2010-03-18 17:43:37.093686165 -0300
+++ nx-x11-ubuntu/lib/Xrender/Imakefile	2010-03-18 17:46:07.532435434 -0300
@@ -74,7 +74,7 @@
 #define DoSharedLib SharedLibXrender
 #define DoDebugLib DebugLibXrender
 #define DoProfileLib ProfileLibXrender
-#define LibName Xrender
+#define LibName Xrender-nx
 #define SoRev SOXRENDERREV
 
 #ifdef XBuildIncDir
@@ -89,7 +89,8 @@
 #include <Threads.tmpl>
 
 #ifdef SharedXrenderReqs
-REQUIREDLIBS = SharedXrenderReqs
+/* REQUIREDLIBS = SharedXrenderReqs */
+REQUIREDLIBS = $(LDPRELIB) -L../../exports/lib/ -lXext-nx -lX11-nx
 #endif
 
 #if Malloc0ReturnsNull
Index: nx-x11-ubuntu/programs/Xserver/Imakefile
===================================================================
--- nx-x11-ubuntu.orig/programs/Xserver/Imakefile	2010-03-18 17:46:06.573684670 -0300
+++ nx-x11-ubuntu/programs/Xserver/Imakefile	2010-03-18 17:46:07.542462477 -0300
@@ -997,7 +997,7 @@
 XPMLIB =  -lXpm
 NXAGENT = hw/nxagent/LibraryTargetName(nxagent)
 NXAGENTLIBS = PreFbLibs $(NXAGENT) FbPostFbLibs $(NXAGENT) $(MI)
-NXAGENTSYSLIBS = $(FONTLIBS) $(LDPRELIBS) $(XLIB) $(SYSLIBS) $(XPMLIB)
+NXAGENTSYSLIBS = $(FONTLIBS) $(LDPRELIBS) -lX11-nx -lXext-nx -lXrender-nx $(SYSLIBS) $(XPMLIB)
 #if HasParallelMake
 MakeMutex($(NXAGENTDIRS) $(NXAGENTOBJS) $(NXAGENTLIBS) $(NXAGENTSYSLIBS))
 #endif
@@ -1016,11 +1016,11 @@
                 -L../../../nx-X11/exports/lib -lXtst -lXdamage -lXrandr -lXcomposite
 #elif defined(cygwinArchitecture)
 NXAGENTNXLIBS = -L ../../../nxcomp -L ../../../nxcompext \
-                -lXcomp -lXcompext -lXrender -lX11 -lXext -lXcomposite -lXfixes \
+                -lXcomp -lXcompext -lX11-nx -lXext-nx -lXrender-nx -lXcomposite -lXfixes \
                 -L ../../../nxcompshad -lXcompshad -L../../../nx-X11/exports/lib -lXtst
 #else
 NXAGENTNXLIBS = -L ../../../nxcomp -L ../../../nxcompext -L ../../../nxcompshad \
-                -lXcomp -lXcompext -lXcompshad -lXrender -lX11 -lXext -lXfixes \
+                -lXcomp -lXcompext -lXcompshad -lX11-nx -lXext-nx -lXrender-nx -lXfixes \
                 -L../../../nx-X11/exports/lib -lXtst -lXdamage -lXrandr -lXcomposite
 #endif
 
@@ -1073,7 +1073,7 @@
 	else exit 0; fi
 	$(CCLINK) -o nxagent_static_nolibs -Wl,-Bstatic $(LDOPTIONS) $(NXAGENTOBJS) \
 	$(NXAGENTLIBS) $(LOADABLEEXTS) $(LIBCWRAPPER) $(LDLIBS) $(FONTLIBS) \
-	$(LDPRELIBS) $(SYSLIBS) -Wl,-Bdynamic -lXext -lX11 $(EXTRA_LOAD_FLAGS)
+	$(LDPRELIBS) $(SYSLIBS) -Wl,-Bdynamic -lX11-nx -lXext-nx $(EXTRA_LOAD_FLAGS)
 #endif /* NXAgentServer */
 
 #if defined(XnonServer) && XnonServer