From 7730cca8d38fd159e500893a2edf2e11bf898980 Mon Sep 17 00:00:00 2001
From: Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
Date: Tue, 21 Nov 2017 13:28:17 +0100
Subject: Drop bin wrappers for nxagent and nxproxy, directly install nxproxy
 and nxagent to BINDIR.

 Fixes ArcticaProject/nx-libs#546.
---
 Makefile                  | 43 +++++++++++++------------------------------
 bin/nxagent.in            | 24 ------------------------
 bin/nxproxy.in            | 24 ------------------------
 debian/nxagent.install    |  3 ++-
 debian/nxproxy.install    |  1 -
 nx-X11/config/cf/X11.tmpl |  2 +-
 nx-libs.spec              |  7 +------
 nxproxy/src/Makefile.am   |  2 +-
 8 files changed, 18 insertions(+), 88 deletions(-)
 delete mode 100644 bin/nxagent.in
 delete mode 100644 bin/nxproxy.in

diff --git a/Makefile b/Makefile
index 27a6f966c..95ebd26e3 100644
--- a/Makefile
+++ b/Makefile
@@ -23,7 +23,7 @@ SHLIBDIR        ?= $(LIBDIR)
 NXLIBDIR        ?= $(SHLIBDIR)/nx
 USRLIBDIR       ?= $(NXLIBDIR)/X11
 INCLUDEDIR      ?= $(PREFIX)/include
-CONFIGURE       ?= ./configure --prefix=$(DESTDIR)$(PREFIX) --libexecdir=$(NXLIBDIR)/bin
+CONFIGURE       ?= ./configure --prefix=$(DESTDIR)$(PREFIX)
 
 # use Xfont2 if available in the build env
 FONT_DEFINES	?= $(shell pkg-config --modversion xfont2 1>/dev/null 2>/dev/null && echo "-DHAS_XFONT2")
@@ -75,8 +75,6 @@ NX_XTRANS_HEADERS =		\
 	    rm -Rf nx-X11/extras/Mesa/.pc/; \
 	    rm -f nx-X11/config/cf/nxversion.def; \
 	    rm -f nx-X11/config/cf/date.def; \
-	    rm -f bin/nxagent; \
-	    rm -f bin/nxproxy; \
 	    ${MAKE} clean-env; \
 	fi
 
@@ -168,30 +166,24 @@ install-lite:
 	# install nxcomp library
 	$(MAKE) -C nxcomp install
 
-	# install nxproxy wrapper script
-	$(INSTALL_DIR) $(DESTDIR)$(BINDIR)
-	sed -e 's|@@NXLIBDIR@@|$(NXLIBDIR)|g' bin/nxproxy.in > bin/nxproxy
-	$(INSTALL_PROGRAM) bin/nxproxy $(DESTDIR)$(BINDIR)
-
 	# install the nxproxy executable and its man page
 	$(MAKE) -C nxproxy install
 
 install-full:
-	# install nxagent wrapper script
-	$(INSTALL_DIR) $(DESTDIR)$(BINDIR)
-	sed -e 's|@@NXLIBDIR@@|$(NXLIBDIR)|g' bin/nxagent.in > bin/nxagent
-	$(INSTALL_PROGRAM) bin/nxagent $(DESTDIR)$(BINDIR)
-
 	$(MAKE) -C nxcompshad install
 
+	$(INSTALL_DIR) $(DESTDIR)$(BINDIR)/bin
+	$(INSTALL_PROGRAM) nx-X11/programs/Xserver/nxagent $(DESTDIR)$(BINDIR)
+
 	$(INSTALL_DIR) $(DESTDIR)$(PREFIX)/share/pixmaps
 	$(INSTALL_FILE) nx-X11/programs/Xserver/hw/nxagent/nxagent.xpm $(DESTDIR)$(PREFIX)/share/pixmaps
 
 	$(INSTALL_DIR) $(DESTDIR)$(PREFIX)/share/nx
 	$(INSTALL_FILE) nx-X11/programs/Xserver/Xext/SecurityPolicy $(DESTDIR)$(PREFIX)/share/nx
 
+	# FIXME: Drop this symlink for 3.6.0. Requires that third party frameworks like X2Go have become aware of this...
 	$(INSTALL_DIR) $(DESTDIR)$(NXLIBDIR)/bin
-	$(INSTALL_PROGRAM) nx-X11/programs/Xserver/nxagent $(DESTDIR)$(NXLIBDIR)/bin
+	$(INSTALL_SYMLINK) $(BINDIR)/nxagent $(DESTDIR)$(NXLIBDIR)/bin/nxagent
 
 	$(INSTALL_DIR) $(DESTDIR)$(PREFIX)/share/man/man1/
 	$(INSTALL_FILE) nx-X11/programs/Xserver/hw/nxagent/man/nxagent.1 $(DESTDIR)$(PREFIX)/share/man/man1/
@@ -243,28 +235,19 @@ uninstall:
 
 uninstall-lite:
 	if test -f nxcomp/Makefile; then ${MAKE} -C nxcomp $@; fi
+	if test -f nxproxy/Makefile; then ${MAKE} -C nxproxy $@; fi
 
-	# uninstall nproxy wrapper script
-	$(RM_FILE) $(DESTDIR)$(BINDIR)/nxproxy
-	# FIXME: don't use uninstall rule in nxproxy/Makefile.in, let's do
-        # it on our own for now...
-	$(RM_FILE) $(DESTDIR)$(NXLIBDIR)/bin/nxproxy
-	$(RM_DIR) $(DESTDIR)$(NXLIBDIR)/bin/
-	$(RM_FILE) $(DESTDIR)$(PREFIX)/share/man/man1/*.1
 	$(RM_FILE) $(DESTDIR)$(PREFIX)/share/nx/VERSION.nxproxy
 	$(RM_DIR) $(DESTDIR)$(PREFIX)/share/nx/
 
 uninstall-full:
-	for f in nxagent; do \
-	    $(RM_FILE) $(DESTDIR)$(BINDIR)/$$f; done
+	if test -f nxcompshad/Makefile; then ${MAKE} -C nxcompshad $@; fi
+	if test -f nx-X11/lib/Makefile; then ${MAKE} -C nx-X11/lib $@; fi
+
+	$(RM_FILE) $(DESTDIR)$(BINDIR)/nxagent
 
 	$(RM_FILE) $(DESTDIR)$(PREFIX)/share/nx/VERSION.nxagent
 	$(RM_DIR) $(DESTDIR)$(PREFIX)/share/nx/
 
-	if test -d nx-X11; then \
-	    if test -f nxcompshad/Makefile; then ${MAKE} -C nxcompshad $@; fi; \
-	    if test -f nx-X11/Makefile; then \
-	        if test -d $(NXLIBDIR); then rm -rf $(NXLIBDIR); fi; \
-	        if test -d $(INCLUDEDIR)/nx; then rm -rf $(INCLUDEDIR)/nx; fi; \
-	    fi; \
-	fi
+	if test -d $(NXLIBDIR); then rm -rf $(NXLIBDIR); fi
+	if test -d $(INCLUDEDIR)/nx; then rm -rf $(INCLUDEDIR)/nx; fi
diff --git a/bin/nxagent.in b/bin/nxagent.in
deleted file mode 100644
index 3a9dfc649..000000000
--- a/bin/nxagent.in
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/bin/bash
-
-# Copyright (C) 2012 Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see http://www.gnu.org/licenses/.
-
-NX_LIBDIR=@@NXLIBDIR@@
-
-# make sure nxagent starts properly with pam_tmpdir.so being in use
-NX_TEMP=${NX_TEMP:-/tmp}
-export NX_TEMP
-
-exec $NX_LIBDIR/bin/${NXAPP:-"nxagent"} "$@"
diff --git a/bin/nxproxy.in b/bin/nxproxy.in
deleted file mode 100644
index 0866d25ac..000000000
--- a/bin/nxproxy.in
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/bin/bash
-
-# Copyright (C) 2012 Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see http://www.gnu.org/licenses/.
-
-NX_LIBDIR=@@NXLIBDIR@@
-
-# make sure nxagent starts properly with pam_tmpdir.so being in use
-NX_TEMP=${NX_TEMP:-/tmp}
-export NX_TEMP
-
-exec $NX_LIBDIR/bin/${NXAPP:="nxproxy"} "$@"
diff --git a/debian/nxagent.install b/debian/nxagent.install
index 34f5c3a76..87ba3583f 100644
--- a/debian/nxagent.install
+++ b/debian/nxagent.install
@@ -1,8 +1,9 @@
 etc/nxagent/keystrokes.cfg
 usr/share/nx/VERSION.nxagent
 usr/share/man/man1/nxagent.1*
-usr/lib/*/nx/bin/nxagent
 usr/lib/*/nx/X11/
 usr/bin/nxagent
 usr/share/pixmaps/nxagent.xpm
 etc/nxagent/nxagent.keyboard
+# FIXME: compatibility symlink, drop for 3.6.0 release
+usr/lib/*/nx/bin/nxagent
diff --git a/debian/nxproxy.install b/debian/nxproxy.install
index 8ade77d6d..988f2842f 100644
--- a/debian/nxproxy.install
+++ b/debian/nxproxy.install
@@ -1,4 +1,3 @@
-usr/lib/*/nx/bin/nxproxy
 usr/bin/nxproxy
 usr/share/man/man1/nxproxy.1*
 usr/share/nx/VERSION.nxproxy
diff --git a/nx-X11/config/cf/X11.tmpl b/nx-X11/config/cf/X11.tmpl
index ddd6e0bad..9b3e0e8b3 100644
--- a/nx-X11/config/cf/X11.tmpl
+++ b/nx-X11/config/cf/X11.tmpl
@@ -769,7 +769,7 @@ FCHOWN_DEFINES = -DHAS_FCHOWN
 
 #ifndef BinDir
 #ifdef ProjectRoot
-#define BinDir Concat(ProjectRoot,/lib/nx/bin)
+#define BinDir Concat(ProjectRoot,/bin)
 #else
 #define BinDir /usr/bin/X11
 #endif
diff --git a/nx-libs.spec b/nx-libs.spec
index 4a64b8aed..68bec6397 100644
--- a/nx-libs.spec
+++ b/nx-libs.spec
@@ -367,10 +367,6 @@ This package provides the NX proxy (client) binary.
 rm -Rf nx*/configure nx*/autom4te.cache*
 # Install into /usr
 sed -i -e 's,/usr/local,/usr,' nx-X11/config/cf/site.def
-# Use multilib dirs
-# We're installing binaries into %%{_libdir}/nx/bin rather than %%{_libexedir}/nx
-# because upstream expects libraries and binaries in the same directory
-sed -i -e 's,/lib/nx,/%{_lib}/nx,' nx-X11/config/cf/X11.tmpl
 # Fix FSF address
 find -name LICENSE | xargs sed -i \
   -e 's/59 Temple Place/51 Franklin Street/' -e 's/Suite 330/Fifth Floor/' \
@@ -575,6 +571,7 @@ rm -r %{buildroot}%{_includedir}/nx-X11/Xtrans
 %config(noreplace) %{_sysconfdir}/nxagent/nxagent.keyboard
 %doc doc/nxagent/README.keystrokes
 %{_bindir}/nxagent
+# FIXME: compatibility symlink to BINDIR/nxagent, remove for 3.6.0
 %dir %{_libdir}/nx/bin
 %{_libdir}/nx/bin/nxagent
 %dir %{_libdir}/nx/X11
@@ -590,8 +587,6 @@ rm -r %{buildroot}%{_includedir}/nx-X11/Xtrans
 %doc doc/nxproxy/README-VALGRIND
 %{_bindir}/nxproxy
 %{_datadir}/man/man1/nxproxy.1*
-%dir %{_libdir}/nx/bin
-%{_libdir}/nx/bin/nxproxy
 %dir %{_datadir}/nx
 %{_datadir}/nx/VERSION.nxproxy
 
diff --git a/nxproxy/src/Makefile.am b/nxproxy/src/Makefile.am
index 7e55900d3..4fd2eefd6 100644
--- a/nxproxy/src/Makefile.am
+++ b/nxproxy/src/Makefile.am
@@ -1,6 +1,6 @@
 NULL =
 
-nxexecdir = $(libexecdir)
+nxexecdir = $(bindir)
 
 nxexec_PROGRAMS = nxproxy
 
-- 
cgit v1.2.3