From d4dd866d444112a4520d2492ab8b913bcd131452 Mon Sep 17 00:00:00 2001
From: deuce <>
Date: Tue, 25 Jan 2005 06:37:56 +0000
Subject: [PATCH] Support a static link of utilities on *nix(sbbs itself most
 likely can't be linked statically, and even if it could, you probobly
 wouldn't want it to be) Use gmake STATIC=1 to enable.

---
 src/build/Common.gmake |  6 ++++++
 src/conio/Common.gmake | 14 +++++++++-----
 src/conio/console.c    | 31 +++++++++++++++++++++++++++++++
 3 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/src/build/Common.gmake b/src/build/Common.gmake
index 87f2bb62a9..f568e776e3 100644
--- a/src/build/Common.gmake
+++ b/src/build/Common.gmake
@@ -50,6 +50,7 @@
 #  DONT_CLOBBER_CC	- Do not change the default setting of CC				#
 #  OBJPATH_SUFFIX	- Suffix appended to OBJPATH usefull for compiling 		#
 #					  different options of the same source file				#
+#  STATIC			- Create a statically linked build if possible			#
 #																			#
 # Common Build Macros Defined:												#
 #  DELETE			- Delete files (Preferrably verbose)					#
@@ -204,6 +205,11 @@ UL_SUF		:=
 OUTPUT		:=	-o
 LOUTPUT		:=	-o
 
+ifdef STATIC
+ LDFLAGS	+=	-static
+ CFLAGS		+=	-DSTATIC_LINK
+endif
+
 ifeq ($(os),openbsd)
  SOFILE	:=	$(SOFILE).$(VERSION)
 else
diff --git a/src/conio/Common.gmake b/src/conio/Common.gmake
index 49827d0a7a..a451f9b1d4 100644
--- a/src/conio/Common.gmake
+++ b/src/conio/Common.gmake
@@ -1,9 +1,13 @@
 CIOLIB-MT_LIBS		+=	$(UL_PRE)ncurses$(UL_SUF)
 ifndef NO_X
- ifeq ($(os),linux)
-  CIOLIB-MT_LIBS		+=  $(UL_PRE)dl$(UL_SUF)
- endif
- ifeq ($(os),sunos)
-  CIOLIB-MT_LIBS		+=  $(UL_PRE)dl$(UL_SUF)
+ ifdef STATIC
+  CIOLIB-MT_LIBS		+=	-lXlib
+ else
+  ifeq ($(os),linux)
+   CIOLIB-MT_LIBS		+=  $(UL_PRE)dl$(UL_SUF)
+  endif
+  ifeq ($(os),sunos)
+   CIOLIB-MT_LIBS		+=  $(UL_PRE)dl$(UL_SUF)
+  endif
  endif
 endif
diff --git a/src/conio/console.c b/src/conio/console.c
index 99e53f6e72..bbfa4a9e34 100644
--- a/src/conio/console.c
+++ b/src/conio/console.c
@@ -93,7 +93,9 @@
 #include <sys/time.h>
 #include <sys/types.h>
 
+#ifndef STATIC_LINK
 #include <dlfcn.h>
+#endif
 #include <fcntl.h>
 #include <limits.h>
 #include <paths.h>
@@ -1286,6 +1288,34 @@ console_init()
 	if(dpy!=NULL)
 		return(0);
 
+#ifdef STATIC_LINK
+	x11.XChangeGC=XChangeGC;
+	x11.XCopyPlane=XCopyPlane;
+	x11.XFillRectangle=XFillRectangle;
+	x11.XFlush=XFlush;
+	x11.XBell=XBell;
+	x11.XLookupString=XLookupString;
+	x11.XNextEvent=XNextEvent;
+	x11.XAllocSizeHints=XAllocSizeHints;
+	x11.XSetWMNormalHints=XSetWMNormalHints;
+	x11.XResizeWindow=XResizeWindow;
+	x11.XMapWindow=XMapWindow;
+	x11.XFree=XFree;
+	x11.XFreePixmap=XFreePixmap;
+	x11.XCreateBitmapFromData=XCreateBitmapFromData;
+	x11.XAllocColor=XAllocColor;
+	x11.XOpenDisplay=XOpenDisplay;
+	x11.XCreateSimpleWindow=XCreateSimpleWindow;
+	x11.XCreateGC=dlsym(dl,"XCreateGC");
+	x11.XSelectInput=XSelectInput;
+	x11.XStoreName=XStoreName;
+	x11.XGetSelectionOwner=XGetSelectionOwner;
+	x11.XConvertSelection=XConvertSelection;
+	x11.XGetWindowProperty=XGetWindowProperty;
+	x11.XChangeProperty=XChangeProperty;
+	x11.XSendEvent=XSendEvent;
+	x11.XSetSelectionOwner=XSetSelectionOwner;
+#else
 	if((dl=dlopen("libX11.so",RTLD_LAZY))==NULL)
 		return(-1);
 	if((x11.XChangeGC=dlsym(dl,"XChangeGC"))==NULL) {
@@ -1392,6 +1422,7 @@ console_init()
 		dlclose(dl);
 		return(-1);
 	}
+#endif
 
 	sem_init(&console_mode_changed,0,0);
 	sem_init(&copybuf_set,0,0);
-- 
GitLab