
diff -ur ggi/lib/libggi/Makerules ggi.OpenBSD/lib/libggi/Makerules
--- ggi/lib/libggi/Makerules	Mon Mar  9 02:33:35 1998
+++ ggi.OpenBSD/lib/libggi/Makerules	Sun Apr 26 00:39:12 1998
@@ -78,6 +78,9 @@
 define _SHLIBLDLIBS
 $(_$(OS)SHLIBLDLIBS) $(SHLIBLDLIBS)
 endef
+define _SHLIBPOSTLDFLAGS
+$(SHLIBPOSTLDFLAGS) $($(OS)SHLIBPOSTLDFLAGS)
+endef
 define _SHLIBLDFLAGS
 $(_SHLIBLDLIBS) $(SHLIBLDFLAGS) $($(OS)SHLIBLDFLAGS)
 endef
@@ -133,7 +136,7 @@
 
 $(SHLIB):: $(SHLIBOBJECTS) $(EXPORTSFILE)
 ifndef HOST_SHLIB_RULE
-	$(SHLIBLINKER) $(_SHLIBLDFLAGS) -o $@ $(SHLIBOBJECTS)
+	$(SHLIBLINKER) $(_SHLIBLDFLAGS) -o $@ $(SHLIBOBJECTS) $(_SHLIBPOSTLDFLAGS)
 else
 	$(HOST_SHLIB_RULE)
 endif
diff -ur ggi/lib/libggi/display/X/Makefile ggi.OpenBSD/lib/libggi/display/X/Makefile
--- ggi/lib/libggi/display/X/Makefile	Mon Mar  9 02:33:55 1998
+++ ggi.OpenBSD/lib/libggi/display/X/Makefile	Sun Apr 26 00:44:38 1998
@@ -23,9 +23,7 @@
 
 INCS=-I$(strip $(word 1,$(wildcard /usr/X11*/include /usr/openwin/include /usr/include/X11)))
 
-ifneq ($(OS),OpenBSD)
-SHLIBLDLIBS=-L/usr/X11R6/lib -lX11 -lXt -lXext
-endif
+SHLIBPOSTLDFLAGS=-L/usr/X11R6/lib -lX11 -lXt -lXext
 
 SUBLIB=$(DIR)
 
diff -ur ggi/lib/libggi/display/Xlib/Makefile ggi.OpenBSD/lib/libggi/display/Xlib/Makefile
--- ggi/lib/libggi/display/Xlib/Makefile	Mon Mar  9 02:33:58 1998
+++ ggi.OpenBSD/lib/libggi/display/Xlib/Makefile	Sun Apr 26 00:45:34 1998
@@ -23,9 +23,7 @@
 
 INCS=-I$(strip $(word 1,$(wildcard /usr/X11*/include /usr/openwin/include /usr/include/X11)))
 
-ifneq ($(OS),OpenBSD)
-SHLIBLDLIBS=-L/usr/X11R6/lib -lX11 -lXt -lXext
-endif
+SHLIBPOSTLDFLAGS=-L/usr/X11R6/lib -lX11 -lXt -lXext
 
 SUBLIB=$(DIR)
 
diff -ur ggi/lib/libggi/display/common/mansync.inc ggi.OpenBSD/lib/libggi/display/common/mansync.inc
--- ggi/lib/libggi/display/common/mansync.inc	Sun Mar 15 02:33:52 1998
+++ ggi.OpenBSD/lib/libggi/display/common/mansync.inc	Thu Apr 23 23:42:07 1998
@@ -55,7 +55,9 @@
 #include <signal.h>
 #include <sys/time.h>
 #include <sys/wait.h>
+#ifdef USE_PTHREADS
 #include <pthread.h>
+#endif
 
 #include "ggi-dl.h"
 
diff -ur ggi/lib/libggi/dl.c ggi.OpenBSD/lib/libggi/dl.c
--- ggi/lib/libggi/dl.c	Sat Feb 14 02:33:39 1998
+++ ggi.OpenBSD/lib/libggi/dl.c	Sun Apr 26 01:35:13 1998
@@ -25,12 +25,47 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <dlfcn.h>
+#include <dlfcn.h>      /* XXX some OS's don't have dlfcn.h */
 #include <sys/ioctl.h>
 
 #include "internal.h"
 #include <ggi/ggi_commands.h>
 
+/*
+ * In some systems, like SunOS 4.1.3, the RTLD_NOW flag isn't defined
+ * and this argument to dlopen must always be 1.  The RTLD_GLOBAL
+ * flag is needed on some systems (e.g. SCO and UnixWare) but doesn't
+ * exist on others;  if it doesn't exist, set it to 0 so it has no effect.
+ */
+   
+#ifndef RTLD_NOW
+#   define RTLD_NOW 1
+#endif
+
+#ifndef RTLD_GLOBAL
+#   define RTLD_GLOBAL 0
+#endif
+
+/* XXX Perl auto configures this and hardcodes the executable.
+ *     Tcl tries opening the symbol w/out '_' then with '_' at runtime
+ *     Here, I am using #defines for now.  In the future for speed I would
+ *         recommend the Perl approach.
+ *     Typically AOUT systems require the underscore
+ */
+#if defined(__OpenBSD__)
+# if !(defined(__mips) || defined(__powerpc))
+#  define DLSYM_AOUT 1
+# else
+#  define DLSYM_AOUT 0 
+# endif
+#endif
+
+#if DLSYM_AOUT == 1
+# define DLSYM_UNDERSCORE "_"
+#else
+# define DLSYM_UNDERSCORE /**/
+#endif
+
 extern int _ggiExtensionSize; 		/* init.c */
 extern ggi_extension *_ggiExtension;
 
@@ -39,25 +74,19 @@
 static ggi_dlhandle *_ggiLoadDL(const char *filename)
 {
 	ggi_dlhandle hand,*hp;
-#if defined(__OpenBSD__)
 	char fn[1024];
 
 	strcpy(fn,filename);
-#endif
 
 	hand.name=NULL;
 	hand.use=0;
-#if defined(__OpenBSD__)
-	hand.handle=dlopen(fn,RTLD_LAZY);
-#else
-	hand.handle=dlopen(filename,RTLD_LAZY);
-#endif
+	hand.handle=dlopen(fn,RTLD_NOW | RTLD_GLOBAL);
 	DPRINT("hand.handle=%p\n",hand.handle);
 	if (hand.handle==NULL) 
 		return NULL;
 
-	hand.init=(int (*)(struct ggi_visual *, const char *))  dlsym(hand.handle,GGI_DLINIT_SYM);
-	hand.cleanup=(int (*)(struct ggi_visual *)) dlsym(hand.handle,GGI_DLCLEANUP_SYM);
+	hand.init=(int (*)(struct ggi_visual *, const char *))  dlsym(hand.handle,DLSYM_UNDERSCORE GGI_DLINIT_SYM);
+	hand.cleanup=(int (*)(struct ggi_visual *)) dlsym(hand.handle,DLSYM_UNDERSCORE GGI_DLCLEANUP_SYM);
 
 	DPRINT("hand.init=%p\n",hand.init);
 	DPRINT("hand.cleanup=%p\n",hand.cleanup);
diff -ur ggi/lib/libggi/rules/OpenBSD ggi.OpenBSD/lib/libggi/rules/OpenBSD
--- ggi/lib/libggi/rules/OpenBSD	Mon Dec 29 02:33:22 1997
+++ ggi.OpenBSD/lib/libggi/rules/OpenBSD	Sun Apr 26 00:35:57 1998
@@ -1,8 +1,8 @@
 OpenBSDmake        =gmake
 OpenBSDINCS        =-I/usr/local/include
 OpenBSDSHLIBLINKER =ld
-_OpenBSDSHLIBLDLIBS=#-lc
-OpenBSDSHLIBLDFLAGS=-x -Bshareable
+_OpenBSDSHLIBLDLIBS=#-L/usr/X11R6/lib -lX11
+OpenBSDSHLIBLDFLAGS=-x -Bshareable -Bforcearchive -soname `echo $@ | sed 's/\.[0-9]*$$//'`
 OpenBSDSHLIBCFLAGS+= -fpic -DPIC #-DLIBC_SCCS #-DBSDSHLIB -DFUNCPROTO=15 -DNARROWPROTO -DCSRG_BASED
 OpenBSDCP          =cp -RP
 OpenBSDLDCONFIG    =/sbin/ldconfig -m /usr/local/lib
@@ -12,5 +12,5 @@
 
 # The below because OpenBSD doesn't give the cpu with uname -m
 ifeq ($(cpu),i386)
-  cpu=i$(shell awk '{print substr($$3,0,3)}' /kern/model || echo 386)
+  cpu=i$(shell awk '{print substr($$3,0,3)}' /kern/model 2> /dev/null || echo 386)
 endif

