--- imap-2006d/src/osdep/unix/Makefile	2006-12-08 02:24:54.000000000 +0100
+++ imap-2006d/src/osdep/unix/Makefile.new	2007-01-25 01:07:14.000000000 +0100
@@ -54,7 +54,7 @@
 
 # Extended flags needed for SSL.  You may need to modify.
 
-SSLDIR=/usr/local/ssl
+SSLDIR=/usr
 SSLCERTS=$(SSLDIR)/certs
 SSLKEYS=$(SSLCERTS)
 SSLINCLUDE=$(SSLDIR)/include
@@ -96,12 +96,12 @@
 LOGINPW=std
 SIGTYPE=bsd
 CRXTYPE=std
-ACTIVEFILE=/usr/lib/news/active
-SPOOLDIR=/usr/spool
+ACTIVEFILE=/var/lib/news/active
+SPOOLDIR=/var/spool
 MAILSPOOL=$(SPOOLDIR)/mail
 NEWSSPOOL=$(SPOOLDIR)/news
-RSHPATH=/usr/ucb/rsh
-LOCKPGM=/etc/mlock
+RSHPATH=/usr/bin/rsh
+#LOCKPGM=/etc/mlock
 MD5PWD="/etc/cram-md5.pwd"
 
 
@@ -148,7 +148,7 @@
 BINARIES=osdep.o mail.o misc.o newsrc.o smanager.o utf8.o utf8aux.o siglocal.o \
  dummy.o pseudo.o netmsg.o flstring.o fdstring.o \
  rfc822.o nntp.o smtp.o imap4r1.o pop3.o \
- unix.o mbx.o mmdf.o tenex.o mtx.o news.o phile.o mh.o mx.o mix.o
+ unix.o mbx.o mmdf.o tenex.o mtx.o news.o phile.o mh.o mx.o mix.o flock.o
 CFLAGS=-g
 
 CAT=cat
@@ -157,6 +157,9 @@
 RM=rm -rf
 SH=sh
 
+# Need this for shared library rule to work correctly
+.SUFFIXES: .o .so
+SOFILES=${BINARIES:.o=.so}
 
 # Primary build command
 
@@ -183,7 +186,7 @@
 	 SIGTYPE=psx CRXTYPE=nfs \
 	 SPOOLDIR=/var/spool \
 	 RSHPATH=/usr/bin/rsh \
-	 BASECFLAGS="-g -Dunix=1 -D_BSD" \
+	 BASECFLAGS="${CFLAGS}" \
 	 BASELDFLAGS="-lbsd"
 
 a41:	# AIX 4.1 for RS/6000
@@ -831,17 +834,23 @@
 
 # Build it!
 
-build:	clean once $(ARCHIVE)
+build:	clean once $(ARCHIVE) $(SHLIBNAME)
 
-all:	$(ARCHIVE)
+all:	$(ARCHIVE) $(SHLIBNAME)
 
 $(ARCHIVE): $(BINARIES)
 	sh -c '$(RM) $(ARCHIVE) || true'
 	@$(CAT) ARCHIVE
 	@$(SH) ARCHIVE
 
+$(SHLIBNAME):  $(SOFILES)
+	gcc -shared -Wl,-soname,$(SHLIBNAME) -o $(SHLIBNAME) $(SOFILES) `cat LDFLAGS`
+	ln -s $(SHLIBNAME) lib$(SHLIBBASE).so
+.c.so: osdep.h
+	$(CC) -fPIC -DPIC -c `$(CAT) CFLAGS` ${@:.so=.c} -o $@
+
 .c.o:
-	`$(CAT) CCTYPE` -c `$(CAT) CFLAGS` $*.c
+	$(CC) -c `$(CAT) CFLAGS` $*.c
 
 
 # Cleanup
@@ -882,7 +891,7 @@
 
 # OS-dependent
 
-osdep.o:mail.h misc.h env.h fs.h ftl.h nl.h tcp.h \
+OSDEPS=                mail.h misc.h env.h fs.h ftl.h nl.h tcp.h \
 	osdep.h env_unix.h tcp_unix.h \
 	osdep.c env_unix.c fs_unix.c ftl_unix.c nl_unix.c tcp_unix.c ip_unix.c\
 	auths.c crexcl.c flockcyg.c flocklnx.c flocksim.c fsync.c \
@@ -896,12 +905,18 @@
 	write.c sslstdio.c \
 	strerror.c strpbrk.c strstr.c strtok.c strtoul.c \
 	OSCFLAGS
+osdep.o:       $(OSDEPS)
+	$(CC) $(CFLAGS) `$(CAT) OSCFLAGS` -c osdep.c
+	@echo ========================================================================
 	@echo Building OS-dependent module
 	@echo If you get No such file error messages for files x509.h, ssl.h,
 	@echo pem.h, buffer.h, bio.h, and crypto.h, that means that OpenSSL
 	@echo is not installed on your system.  Either install OpenSSL first
 	@echo or build with command: make `$(CAT) OSTYPE` SSLTYPE=none
-	`$(CAT) CCTYPE` -c `$(CAT) CFLAGS` `$(CAT) OSCFLAGS` -c osdep.c
+	@echo ========================================================================
+
+osdep.so:      $(OSDEPS)
+	$(CC) -fPIC -DPIC -c $(CFLAGS) `cat OSCFLAGS` osdep.c -o $@
 
 osdep.c: osdepbas.c osdepckp.c osdeplog.c osdepssl.c
 	$(CAT) osdepbas.c osdepckp.c osdeplog.c osdepssl.c > osdep.c
--- imap-2006d/src/osdep/unix/env_unix.c	2006-12-08 02:36:35.000000000 +0100
+++ imap-2006d/src/osdep/unix/env_unix.c.new	2007-01-25 01:16:43.000000000 +0100
@@ -26,6 +26,7 @@
  * Last Edited:	7 December 2006
  */
 
+#include <time.h>
 #include <grp.h>
 #include <signal.h>
 #include <sys/wait.h>
diff -Naur imap-2004e.orig/src/osdep/unix/flock.c imap-2004e/src/osdep/unix/flock.c
--- imap-2004e.orig/src/osdep/unix/flock.c	1970-01-01 01:00:00.000000000 +0100
+++ imap-2004e/src/osdep/unix/flock.c	2000-08-24 00:00:00.000000000 +0200
@@ -0,0 +1,63 @@
+/* One of many ways to emulate flock() on top of real (good) POSIX locks. */
+
+#ident "$RH: flock.c,v 1.2 2000/08/23 17:07:00 nalin Exp $"
+
+#include <sys/types.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+int flock(int fd, int operation)
+{
+	int i, cmd;
+	struct flock l = {0, 0, 0, 0, 0};
+	if(operation & LOCK_NB) {
+		cmd = F_SETLK;
+	} else {
+		cmd = F_SETLKW;
+	}
+	l.l_whence = SEEK_SET;
+	switch(operation & (~LOCK_NB)) {
+		case LOCK_EX:
+			l.l_type = F_WRLCK;
+			i = fcntl(fd, cmd, &l);
+			if(i == -1) {
+				if((errno == EAGAIN) || (errno == EACCES)) {
+					errno = EWOULDBLOCK;
+				}
+			}
+			break;
+		case LOCK_SH:
+			l.l_type = F_RDLCK;
+			i = fcntl(fd, cmd, &l);
+			if(i == -1) {
+				if((errno == EAGAIN) || (errno == EACCES)) {
+					errno = EWOULDBLOCK;
+				}
+			}
+			break;
+		case LOCK_UN:
+			l.l_type = F_UNLCK;
+			i = fcntl(fd, cmd, &l);
+			if(i == -1) {
+				if((errno == EAGAIN) || (errno == EACCES)) {
+					errno = EWOULDBLOCK;
+				}
+			}
+			break;
+		default:
+			i = -1;
+			errno = EINVAL;
+			break;
+	}
+	return i; 
+}
+
+#ifdef FLOCK_EMULATE_IS_MAIN
+int main(int argc, char **argv)
+{
+	int fd = open(argv[1], O_WRONLY);
+	flock(fd, LOCK_EX);
+	return 0;
+}
+#endif
diff -Naur imap-2004e.orig/src/osdep/unix/news.c imap-2004e/src/osdep/unix/news.c
--- imap-2004e.orig/src/osdep/unix/news.c	2005-07-31 23:26:25.000000000 +0200
+++ imap-2004e/src/osdep/unix/news.c	2005-07-31 23:27:10.000000000 +0200
@@ -27,6 +27,7 @@
 #include "osdep.h"
 #include <sys/stat.h>
 #include <sys/time.h>
+#include <time.h>
 #include "misc.h"
 #include "newsrc.h"
 
diff -Naur imap-2004e.orig/src/osdep/unix/phile.c imap-2004e/src/osdep/unix/phile.c
--- imap-2004e.orig/src/osdep/unix/phile.c	2005-07-31 23:26:25.000000000 +0200
+++ imap-2004e/src/osdep/unix/phile.c	2005-07-31 23:27:10.000000000 +0200
@@ -29,6 +29,7 @@
 #include <pwd.h>
 #include <sys/stat.h>
 #include <sys/time.h>
+#include <time.h>
 #include "rfc822.h"
 #include "misc.h"
 #include "dummy.h"
--- imap-2006d/src/osdep/unix/mh.c	2006-11-14 02:40:41.000000000 +0100
+++ imap-2006d/src/osdep/unix/mh.c.new	2007-01-25 01:25:17.000000000 +0100
@@ -36,6 +36,7 @@
 #include <pwd.h>
 #include <sys/stat.h>
 #include <sys/time.h>
+#include <time.h>
 #include "misc.h"
 #include "dummy.h"
 #include "fdstring.h"
--- imap-2006d/src/osdep/unix/mx.c	2006-10-23 00:43:08.000000000 +0200
+++ imap-2006d/src/osdep/unix/mx.c.new	2007-01-25 01:26:51.000000000 +0100
@@ -36,6 +36,7 @@
 #include <pwd.h>
 #include <sys/stat.h>
 #include <sys/time.h>
+#include <time.h>
 #include "misc.h"
 #include "dummy.h"
 #include "fdstring.h"
