diff -ubNr Imakefile Imakefile
--- Imakefile	Mon Dec 16 08:08:41 1996
+++ Imakefile	Sun Oct 13 21:29:12 2002
@@ -7,7 +7,11 @@
 SUBDIRS= $(LIBDIRS) patchy cfortran
 
 #ifdef CERNLIB_UNIX
+#ifdef CERNLIB_MACOSX
+SUBDIRS:= $(SUBDIRS) scripts
+#else
 SUBDIRS:= $(SUBDIRS) scripts mgr
+#endif
 #endif
 
 InstallLibSubdirs($(LIBDIRS))
diff -ubNr config/Imake.cf config/Imake.cf
--- config/Imake.cf	Fri Sep 25 02:23:38 1998
+++ config/Imake.cf	Sun Oct 13 15:33:27 2002
@@ -214,6 +214,13 @@
 #define MacIIArchitecture
 #endif /* macII */
 
+#ifdef __APPLE__
+# define MacroIncludeFile <MacOSX.cf>
+# define MacroFile MacOSX.cf
+# define MacOSXArchitecture
+# define DarwinArchitecture
+#endif
+
 #ifdef _CRAY
 #define MacroIncludeFile <cray.cf>
 #define MacroFile cray.cf
diff -ubNr config/Imake.rules config/Imake.rules
--- config/Imake.rules	Wed Apr 19 08:00:31 2000
+++ config/Imake.rules	Sun Oct 13 18:27:51 2002
@@ -2167,7 +2167,7 @@
 #define CppScriptTarget(dst,src,defs,deplist)				@@\
 dst::  src deplist							@@\
 	RemoveFile($@)							@@\
-	$(CPP) defs <src | CppSedMagic >$@				@@\
+	$(CPP) defs src | CppSedMagic >$@				@@\
 	chmod a+x $@							@@\
 									@@\
 clean::									@@\
@@ -2199,7 +2199,7 @@
 #define CppFileTarget(dst,src,defs,deplist)				@@\
 dst::  src deplist							@@\
 	RemoveFile($@)							@@\
-	$(CPP) defs <src | CppSedMagic >$@				@@\
+	$(CPP) defs src | CppSedMagic >$@				@@\
 									@@\
 clean::									@@\
 	RemoveFiles(dst)
diff -ubNr config/MacOSX.cf config/MacOSX.cf
--- config/MacOSX.cf	Wed Dec 31 16:00:00 1969
+++ config/MacOSX.cf	Sun Oct 13 15:33:27 2002
@@ -0,0 +1,161 @@
+XCOMM platform:  $SFO: MOSXS.cf,v 1.0 95/11/19 23:21:00 sl Exp $
+
+#define OSVendor          Apple Computer, Inc.
+#ifdef MacOSXArchitecture
+#define OSName            MacOSX
+#define OSMajorVersion    DefaultOSMajorVersion
+#define OSMinorVersion    DefaultOSMinorVersion
+#define OSTeenyVersion    0
+#endif
+
+XCOMM #define ProjectRulesFile  <MacOSX.rules>
+XCOMM #define ProjectTmplFile   <MacOSX.tmpl>
+
+#define InstKmemFlags -m 2755 -g kmem
+/* #define ConstructMFLAGS		NO */
+
+#define HasNdbm     YES
+#define SetTtyGroup YES
+#define HasBsearch  YES
+#ifdef MacOSXArchitecture
+#define HasPutenv               YES
+#define MathLibrary             /**/
+#define DBMLibrary              /**/
+#define TermcapLibrary          /**/
+#define HasBSD44Sockets         YES
+#define HAS_SNPRINTF            YES
+#endif
+
+#define NeedConstPrototypes     YES
+#define NeedVarargsPrototypes   YES
+#define NeedFunctionPrototypes  YES
+#define NeedWidePrototypes      NO
+
+#define GzipFontCompression     YES
+#define CompressAllFonts        YES
+
+#ifndef HasShm
+# define HasShm			YES
+#endif
+#ifndef BuildGlxExt
+# define BuildGlxExt 	  	YES
+# define GlxUseNSGL             YES
+#endif
+#define BuildServer             YES
+#define BuildXprint             NO
+#define BuildFonts              YES
+#define BuildDPMS               NO
+
+#define TenonServer             YES
+#define XprtServer              NO
+#define XVendorString "Tenon Intersystems Xtools"
+#define XVendorRelease 1000
+#ifndef UseRgbTxt
+#define UseRgbTxt               YES
+#endif
+
+#define BuildPexExt             NO
+
+#ifndef BuildGLXLibrary
+# define BuildGLXLibrary	YES
+#endif
+
+/* no direct graphics extension */
+#define	BuildXF86DGA	NO
+
+/* no extra tablets and weird input devices */
+#define BuildXInputExt	NO
+
+/* Build Xinerama (aka panoramiX) extension */
+#define BuildXinerama		YES
+
+/* no Display Power Management extension */
+#define	BuildDPMSExt	NO
+
+# define BuildXvExt     NO
+#define OptimizedCDebugFlags -O -fPIC -pipe
+#define ExtraLoadFlags -L/usr/X11R6/lib -L/sw/lib -L/usr/lib -lc
+
+#define BuildExamples YES
+
+#define StandardDefines -DCERNLIB_LINUX -DCERNLIB_PPC -DCERNLIB_MACOSX \
+			-Dunix=unix -D__powerpc__ -D__DARWIN__
+/* -DX_NOT_POSIX -DX_LOCALE */
+
+#define HasVoidSignalReturn YES
+
+#ifndef DependFlags
+#define DependFlags -I/usr/include/ansi -I/usr/include/bsd -I/sw/include
+#endif
+
+#define StandardIncludes -I/sw/include
+
+#define InstallCmd	install	/* unlink old */
+
+/* #define ArCmd libtool -a -o */
+#define ArCmd ar -r
+
+#ifndef RanlibCmd
+#define RanlibCmd	ranlib -c -s
+#endif
+
+/* see below for ServerDefines */
+
+#define PrimaryScreenResolution 95	/* for 17 inch screen */
+
+#define ServerCDebugFlags -O -fPIC -g -pipe
+
+#define HasGcc YES
+
+#undef CcCmd
+#undef CplusplusCmd
+#ifdef MacOSXArchitecture
+#define CcCmd gcc -arch "ppc"
+#define CplusplusCmd          g++
+#endif
+#ifndef CcCmd
+#define CcCmd gcc
+#endif
+
+#define CppCmd        /usr/bin/gcc
+
+#include <MacOSX.rules>
+#include <xf86.rules>
+#undef XFree86Server
+/* #define GLX_DIRECT_RENDERING */
+
+#define f2cFortran              YES
+#define FortranCmd              g77
+#define XargsCmd                xargs
+#define FortranSaveFlags        /* */ /* Everything static !? */
+#define OptimisedFortranFlags	-O -fPIC -funroll-loops -fomit-frame-pointer
+#define DefaultFCOptions        -fno-automatic \
+				-fno-second-underscore \
+				-fno-f90 -fugly-complex -fno-globals \
+				-fugly-init -Wno-globals
+#define CernlibSystem           -DCERNLIB_LINUX -DCERNLIB_UNIX -DCERNLIB_LNX \
+				-DCERNLIB_PPC -DCERNLIB_QMGLIBC \
+				-DCERNLIB_MACOSX
+
+#undef CERNLIB_SHIFT
+
+#define CERNLIB_LINUX
+#define CERNLIB_UNIX
+#define CERNLIB_LNX
+#define CERNLIB_PPC
+#define CERNLIB_QMGLIBC
+#define CERNLIB_MACOSX
+
+#define X11Includes             -I/usr/X11R6/include
+
+/*
+ *  Create a Make Variable to allow building with/out Motif
+ */
+#undef MotifDependantMakeVar
+#define MotifDependantMakeVar(variable,value)                           @@\
+ifneq ($(strip $(HAVE_MOTIF)),)                                         @@\
+    variable=value                                                      @@\
+endif                                                                   @@\
+/* End  CERNLIB changes */
+
+
diff -ubNr config/MacOSX.rules config/MacOSX.rules
--- config/MacOSX.rules	Wed Dec 31 16:00:00 1969
+++ config/MacOSX.rules	Sun Oct 13 15:33:27 2002
@@ -0,0 +1,117 @@
+XCOMM $XConsortium: MOSXS.rules,v 1.1 97/12/12 15:34:45 sl Exp $
+
+/*
+ * MacOSX shared library rules
+ */
+
+#define HasSharedLibraries YES
+
+#define ForceNormalLib NO
+
+#ifndef SharedDataSeparation
+#define SharedDataSeparation YES
+#endif
+#ifndef SharedCodeDef
+#define SharedCodeDef
+#endif
+#ifndef SharedLibraryDef
+#define SharedLibraryDef -fno-common
+#endif
+
+#define ShLibIncludeFile <MacOSX.tmpl>
+
+#ifndef SharedLibraryLoadFlags
+#define SharedLibraryLoadFlags
+#endif
+#ifndef PositionIndependentCFlags
+#define PositionIndependentCFlags
+#endif
+
+
+
+
+/*
+ * InstallSharedLibrary - generate rules to install the shared library.
+ */
+#ifndef InstallSharedLibrary
+#define InstallSharedLibrary(libname,rev,dest)				@@\
+install:: Concat(lib,libname.dylib)					@@\
+	MakeDir($(DESTDIR)dest)						@@\
+	$(INSTALL) $(INSTALLFLAGS) $(INSTBINFLAGS) Concat(lib,libname.dylib) $(DESTDIR)dest
+@@\
+
+#endif /* InstallSharedLibrary */
+
+/*
+ * NormalSharedLibraryTarget - generate rules to create a shared library;
+ * build it into a different name so that the we do not hose people by having
+ * the library gone for long periods.
+ */
+#ifndef SharedLibraryTarget
+#define SharedLibraryTarget(libname,rev,solist,down,up)			@@\
+AllTarget(Concat(lib,libname.dylib))					@@\
+									@@\
+Concat(lib,libname.dylib):  solist $(EXTRALIBRARYDEPS)			@@\
+	$(RM) $@~							@@\
+	(cd down; $(CC) -I/usr/X11R6/lib -dynamiclib -undefined suppress -install_name /usr/X11R6/lib/$@ -o up/$@~ $(SHLIBLDFLAGS) solist $(REQUIREDLIBS)) @@\
+	$(MV) $@~ $@							@@\
+	LinkBuildLibrary($@)						@@\
+									@@\
+clean::									@@\
+	$(RM) Concat(lib,libname.dylib)
+
+#endif /* SharedLibraryTarget */
+
+/*
+ * SharedDepLibraryTarget - generate rules to create a shared library.
+ */
+#ifndef SharedDepLibraryTarget
+#define SharedDepLibraryTarget(libname,rev,deplist,solist,down,up)	@@\
+AllTarget(Concat(lib,libname.dylib))					@@\
+									@@\
+Concat(lib,libname.dylib):  deplist $(EXTRALIBRARYDEPS)		@@\
+	$(RM) $@~							@@\
+	(cd down; $(CC) -I/usr/X11R6/lib -dynamiclib -undefined suppress -install_name /usr/X11R6/lib/$@ -o up/$@~ $(SHLIBLDFLAGS) solist $(REQUIREDLIBS)) @@\
+	$(RM) $@							@@\
+	$(MV) $@~ $@							@@\
+	LinkBuildLibrary($@)						@@\
+									@@\
+clean::									@@\
+	$(RM) Concat(lib,libname.dylib)
+
+#endif /* SharedDepLibraryTarget */
+
+/*
+ * SharedLibraryDataTarget - generate rules to create shlib data file;
+ */
+#ifndef SharedLibraryDataTarget
+#define SharedLibraryDataTarget(libname,rev,salist)
+#endif /* SharedLibraryDataTarget */
+
+#ifndef InstallSharedLibraryData
+#define InstallSharedLibraryData(libname,rev,dest)
+#endif /* InstallSharedLibraryData */
+
+/*
+ * SharedLibReferences - variables for shared libraries
+ */
+#ifndef SharedLibReferences
+#define SharedLibReferences(varname,libname,libsource,revname,rev)	@@\
+revname = rev								@@\
+Concat3(DEP,varname,LIB) = SharedLibDependencies(libname,libsource,revname) @@\
+Concat(varname,LIB) = LoaderLibPrefix Concat(-l,libname)		@@\
+LintLibReferences(varname,libname,libsource)
+#endif
+
+/*
+ * SharedDSLibReferences - variables for shared libraries
+ */
+#ifndef SharedDSLibReferences
+#define SharedDSLibReferences(varname,libname,libsource,revname,rev)	@@\
+revname = rev								@@\
+Concat3(DEP,varname,LIB) = SharedDSLibDependencies(libname,libsource,revname) @@\
+Concat(varname,LIB) = LoaderLibPrefix Concat(-l,libname) Concat3(Shared,libname,Reqs)		@@\
+LintLibReferences(varname,libname,libsource)
+#endif
+
+
diff -ubNr config/MacOSX.tmpl config/MacOSX.tmpl
--- config/MacOSX.tmpl	Wed Dec 31 16:00:00 1969
+++ config/MacOSX.tmpl	Sun Oct 13 15:33:27 2002
@@ -0,0 +1,67 @@
+XCOMM $XConsortium: MOSXS.tmpl,v 1.2 97/12/12 19:07:12 sl Exp $
+
+/*
+ * Xnext shared library template
+ */
+
+
+
+#ifndef SharedXtReqs
+#define SharedXtReqs /**/
+#endif
+#ifndef SharedXawReqs
+#define SharedXawReqs /**/
+#endif
+#ifndef SharedXmuReqs
+#define SharedXmuReqs $(LDPRELIB) $(XTOOLONLYLIB) $(XONLYLIB)
+#endif
+
+#define SharedLibX11 YES
+#define SharedX11Rev F
+SharedLibReferences(XONLY,X11,$(XLIBSRC),SOXLIBREV,SharedX11Rev)
+
+#define SharedLibXau NO		/* don't need shared form */
+#define SharedLibXdmcp NO	/* don't need shared form */
+
+#define SharedLibXmu YES
+#define SharedXmuRev F
+
+#define SharedOldXRev F
+
+#define SharedLibXext YES
+#define SharedXextRev F
+
+#define SharedLibXt YES
+#define SharedXtRev F
+SharedDSLibReferences(XTOOLONLY,Xt,$(TOOLKITSRC),SOXTREV,SharedXtRev)
+
+#define SharedXawRev F
+
+#define SharedXtfRev A
+
+#define SharedLibXi YES
+#define SharedXiRev F
+SharedLibReferences(XI,Xi,$(XILIBSRC),SOXINPUTREV,SharedXiRev)
+
+#define SharedLibXtst YES
+#define SharedXtstRev F
+SharedLibReferences(XTEST,Xtst,$(XTESTLIBSRC),SOXTESTREV,SharedXtstRev)
+
+
+#define SharedPexRev F
+SharedLibReferences(PEX,PEX5,$(PEXLIBSRC),SOPEXREV,SharedPexRev)
+
+#define SharedLibXie YES
+#define SharedXieRev F
+
+#define SharedLibICE YES
+#define SharedICERev F
+SharedLibReferences(ICE,ICE,$(ICESRC),SOICEREV,SharedICERev)
+
+#define SharedLibSM YES
+#define SharedSMRev F
+SharedLibReferences(SM,SM,$(SMSRC),SOSMREV,SharedSMRev)
+
+#define SharedFSRev F
+SharedLibReferences(FS,FS,$(FSLIBSRC),SOFSREV,SharedFSRev)
+
diff -ubNr config/site.def config/site.def
--- config/site.def	Fri Apr 26 08:47:40 2002
+++ config/site.def	Sun Oct 13 15:33:27 2002
@@ -99,9 +99,7 @@
 /*   if it is already defined and false, undef it! */
 /* do not use shift by default
 #if defined(CERNLIB_UNIX) && !defined(CERNLIB_WINNT)
-#if ! defined(CERNLIB_SHIFT)
-#define CERNLIB_SHIFT
-#elif  ! CERNLIB_SHIFT
+#if defined(CERNLIB_SHIFT) && !CERNLIB_SHIFT
 #undef CERNLIB_SHIFT
 #endif
 #endif
diff -ubNr geant321/Imakefile geant321/Imakefile
--- geant321/Imakefile	Thu Mar  5 03:20:07 1998
+++ geant321/Imakefile	Sun Oct 13 23:53:32 2002
@@ -37,7 +37,11 @@
 install.lib:: $(CERN_LIBDIR)/xsneut95.dat
 
 $(CERN_LIBDIR)/xsneut95.dat:
+#if defined(CERNLIB_MACOSX)
+	$(CP) -f data/$(@F) $(@D)
+#else
 	cd $(@D);$(LN) ../share/lib/$(@F) $(@F)
+#endif
 
 #endif
 #if defined(CERNLIB_VAXVMS)
diff -ubNr geant321/gxint/Imakefile geant321/gxint/Imakefile
--- geant321/gxint/Imakefile	Wed Jan 29 08:37:40 1997
+++ geant321/gxint/Imakefile	Sun Oct 13 19:23:57 2002
@@ -30,7 +30,7 @@
 
 gxint321.f:  gxint.F
 	RemoveFile($@)
-	$(CPP) $(FORTRANALLDEFMDEPEND) < $^ | sed -e '/^$$/d' | CppSedMagic >$@
+	FortranCmd -E $(FORTRANALLDEFMDEPEND) $^ | sed -e '/^$$/d' | CppSedMagic >$@
 
 install.lib:: $(CERN_LIBDIR)/gxint.f
 
diff -ubNr mathlib/gen/tests/c327m.F mathlib/gen/tests/c327m.F
--- mathlib/gen/tests/c327m.F	Mon Apr  1 07:01:17 1996
+++ mathlib/gen/tests/c327m.F	Sun Oct 13 15:33:27 2002
@@ -92,7 +92,11 @@
 #endif
       ENDIF
       WRITE(Z,'(2D26.16)') H,T
+#if defined(CERNLIB_MACOSX)
+      READ(Z,'(2(4X,D22.16))') H1,T1
+#else
       READ(Z,'(2(D22.16,4X))') H1,T1
+#endif
        IF(IDS .EQ. 1) THEN
       ERRMAX=MAX(ERRMAX,ABS(H1-T1))
       LTEST= LTEST .AND. ERRMAX .LE.  TSTERR
diff -ubNr mathlib/gen/tests/c342m.F mathlib/gen/tests/c342m.F
--- mathlib/gen/tests/c342m.F	Mon Apr  1 07:01:19 1996
+++ mathlib/gen/tests/c342m.F	Sun Oct 13 15:33:27 2002
@@ -70,7 +70,11 @@
 #endif
       END IF
       WRITE(Z,'(2D26.16)') R,T
+#if defined(CERNLIB_MACOSX)
+      READ(Z,'(2(4X,D22.16))') R1,T1
+#else
       READ(Z,'(2(D22.16,4X))') R1,T1
+#endif
       ERMAX= MAX(ERMAX,ABS(R1-T1))
       IF(IDS .EQ. 3 .OR. IDS .EQ. 4) THEN
        WRITE(LOUT,'(1X,F10.3,2F25.16,1P,D10.1)') SX,R,T,ABS(R1-T1)
diff -ubNr mclibs/cojets/data/Imakefile mclibs/cojets/data/Imakefile
--- mclibs/cojets/data/Imakefile	Wed Mar 27 01:31:06 1996
+++ mclibs/cojets/data/Imakefile	Mon Oct 14 10:51:56 2002
@@ -1,11 +1,11 @@
 
 .SUFFIXES:
 
-CopyFile(cojets.cpp,cojets.cin)
+CopyFile(cojets.cpp,cojets.s)
 CopyFile(decay.cpp,decay.cin)
 CopyFile(table.cpp,table.cin)
 
-CppFileTarget(cojets.dat,cojets.cin,NullParameter,table.cin decay.cin)
+CppFileTarget(cojets.dat,cojets.s,-E -traditional,table.cin decay.cin)
 
 PackageDirFileTarget(cojets.dat)
 
diff -ubNr mclibs/isajet/data/Imakefile mclibs/isajet/data/Imakefile
--- mclibs/isajet/data/Imakefile	Wed Mar 27 01:33:19 1996
+++ mclibs/isajet/data/Imakefile	Mon Oct 14 10:54:55 2002
@@ -1,9 +1,9 @@
 
 .SUFFIXES:
 
-CopyFile(decay.cpp,decay.cin)
+CopyFile(decay.cpp,decay.s)
 
-CppFileTarget(isajet.dat,decay.cin,NullParameter,NullParameter)
+CppFileTarget(isajet.dat,decay.s,-E -traditional ,NullParameter)
 
 PackageDirFileTarget(isajet.dat)
 
diff -ubNr mclibs/jetset/jetset/Imakefile mclibs/jetset/jetset/Imakefile
--- mclibs/jetset/jetset/Imakefile	Fri Sep 25 08:55:08 1998
+++ mclibs/jetset/jetset/Imakefile	Sun Oct 13 15:33:27 2002
@@ -11,7 +11,7 @@
 FORTRANSAVEOPTION = FortranSaveFlags
 
 #if defined(CERNLIB_PPC)
-FDEBUGFLAGS := $(FDEBUGFLAGS) -O0
+FDEBUGFLAGS := -O0 $(FDEBUGFLAGS) -O0
 #endif
 
 SubdirLibraryTarget(NullParameter,NullParameter)
diff -ubNr mclibs/jetset/pythia/Imakefile mclibs/jetset/pythia/Imakefile
--- mclibs/jetset/pythia/Imakefile	Mon Apr 30 06:06:24 2001
+++ mclibs/jetset/pythia/Imakefile	Sun Oct 13 15:33:27 2002
@@ -15,4 +15,8 @@
 FDEBUGFLAGS := $(FDEBUGFLAGS) -Nn15000
 #endif
 
+#if defined(CERNLIB_PPC)
+FDEBUGFLAGS := -O0 $(FDEBUGFLAGS) -O0
+#endif
+
 SubdirLibraryTarget(NullParameter,NullParameter)
diff -ubNr mclibs/pythia/code/Imakefile mclibs/pythia/code/Imakefile
--- mclibs/pythia/code/Imakefile	Mon Apr 30 06:06:39 2001
+++ mclibs/pythia/code/Imakefile	Sun Oct 13 15:33:27 2002
@@ -31,4 +31,9 @@
 FDEBUGFLAGS := $(FDEBUGFLAGS) -Nn15000
 #endif
 
+#if defined(CERNLIB_PPC)
+FDEBUGFLAGS := -O0 $(FDEBUGFLAGS) -O0
+#endif
+
 SubdirLibraryTarget(NullParameter,NullParameter)
+
diff -ubNr packlib/cspack/sysreq/log.c packlib/cspack/sysreq/log.c
--- packlib/cspack/sysreq/log.c	Tue Jul  9 09:07:29 2002
+++ packlib/cspack/sysreq/log.c	Sun Oct 13 15:33:27 2002
@@ -76,7 +76,7 @@
 static int pid;                 /* process identifier                   */
 static int logfd ;              /* logging file descriptor              */
 #if !defined(SOLARIS) && !defined(linux) && !defined(_AIX) \
-  && !defined(IRIX5) && !defined(apollo)
+  && !defined(IRIX5) && !defined(apollo) && !defined(__DARWIN__)
 extern int syslog();
 #endif /* !SOLARIS && !IRIX5 && !apollo && !linux && !AIX */
 extern char *getenv();
diff -ubNr packlib/cspack/tcpaw/tcpaw.c packlib/cspack/tcpaw/tcpaw.c
--- packlib/cspack/tcpaw/tcpaw.c	Wed Sep 15 09:19:46 1999
+++ packlib/cspack/tcpaw/tcpaw.c	Sun Oct 13 15:33:27 2002
@@ -2533,7 +2533,7 @@
 #if !defined(IBM) && !defined(_WIN32)
 /* I provide "getpass" myself as standard version truncates to 8 characters */
 #include <sys/ioctl.h>
-#ifdef CBREAK
+#if defined(CBREAK) || defined(CERNLIB_MACOSX)
 #define BSDTTY         /* First find out if BSD or SYSV terminal handling.. */
 #endif
  
@@ -2541,6 +2541,10 @@
 #include <termio.h>
 #else
 #include <sgtty.h>
+# if defined(CERNLIB_MACOSX)
+# define gtty(x,y) ioctl(x,TIOCGETP,y)
+# define stty(x,y) ioctl(x,TIOCSETP,y)
+# endif
 #endif
  
 #ifndef __convexc__
diff -ubNr packlib/kernlib/kernbit/z268/systems.c packlib/kernlib/kernbit/z268/systems.c
--- packlib/kernlib/kernbit/z268/systems.c	Tue Aug 25 05:45:56 1998
+++ packlib/kernlib/kernbit/z268/systems.c	Sun Oct 13 15:33:27 2002
@@ -200,7 +200,7 @@
 || defined(_IBMR2) \
 || defined(__convexc__) \
 || defined(_OSK) \
-|| defined(__linux) || defined(__FreeBSD__)
+|| defined(__linux) || defined(__FreeBSD__) || defined(__DARWIN__)
 
   void systems_( command, buf, buflen, l, chars, rc, ovflw )
 
diff -ubNr packlib/kernlib/kernnum/d704fort/Imakefile packlib/kernlib/kernnum/d704fort/Imakefile
--- packlib/kernlib/kernnum/d704fort/Imakefile	Wed Jun 12 03:03:53 1996
+++ packlib/kernlib/kernnum/d704fort/Imakefile	Sun Oct 13 15:33:27 2002
@@ -4,6 +4,10 @@
 FDEBUGFLAGS=NoOpFortranDebugFlags
 #endif
 
+#if defined(CERNLIB_MACOSX)
+FDEBUGFLAGS=-O0 -fPIC
+#endif
+
 FORTRANSAVEOPTION=FortranSaveFlags
 
 SubdirLibraryTarget(NullParameter,NullParameter)
diff -ubNr packlib/kernlib/kernnum/f002fort/Imakefile packlib/kernlib/kernnum/f002fort/Imakefile
--- packlib/kernlib/kernnum/f002fort/Imakefile	Wed Jun 12 03:04:09 1996
+++ packlib/kernlib/kernnum/f002fort/Imakefile	Sun Oct 13 15:33:27 2002
@@ -10,6 +10,10 @@
 FDEBUGFLAGS=NoOpFortranDebugFlags
 #endif
 
+#if defined(CERNLIB_MACOSX)
+FDEBUGFLAGS=-O0 -fPIC
+#endif
+
 FORTRANSAVEOPTION=FortranSaveFlags
 
 SubdirLibraryTarget(NullParameter,NullParameter)
diff -ubNr packlib/kernlib/kernnum/f003fort/Imakefile packlib/kernlib/kernnum/f003fort/Imakefile
--- packlib/kernlib/kernnum/f003fort/Imakefile	Wed Jun 12 03:04:12 1996
+++ packlib/kernlib/kernnum/f003fort/Imakefile	Sun Oct 13 15:33:27 2002
@@ -11,6 +11,10 @@
 FDEBUGFLAGS=NoOpFortranDebugFlags
 #endif
 
+#if defined(CERNLIB_MACOSX)
+FDEBUGFLAGS=-O0 -fPIC
+#endif
+
 FORTRANSAVEOPTION=FortranSaveFlags
 
 SubdirLibraryTarget(NullParameter,NullParameter)
diff -ubNr packlib/kernlib/kernnum/f004fort/Imakefile packlib/kernlib/kernnum/f004fort/Imakefile
--- packlib/kernlib/kernnum/f004fort/Imakefile	Wed Jun 12 03:04:16 1996
+++ packlib/kernlib/kernnum/f004fort/Imakefile	Sun Oct 13 15:33:27 2002
@@ -6,6 +6,10 @@
 FDEBUGFLAGS=NoOpFortranDebugFlags
 #endif
 
+#if defined(CERNLIB_MACOSX)
+FDEBUGFLAGS=-O0 -fPIC
+#endif
+
 FORTRANSAVEOPTION=FortranSaveFlags
 
 SubdirLibraryTarget(NullParameter,NullParameter)
diff -ubNr packlib/kernlib/kernnum/f010fort/Imakefile packlib/kernlib/kernnum/f010fort/Imakefile
--- packlib/kernlib/kernnum/f010fort/Imakefile	Wed Jun 12 03:04:19 1996
+++ packlib/kernlib/kernnum/f010fort/Imakefile	Sun Oct 13 15:33:27 2002
@@ -7,6 +7,10 @@
 FDEBUGFLAGS=NoOpFortranDebugFlags
 #endif
 
+#if defined(CERNLIB_MACOSX)
+FDEBUGFLAGS=-O0 -fPIC
+#endif
+
 FORTRANSAVEOPTION=FortranSaveFlags
 	 
 
diff -ubNr packlib/kernlib/kernnum/f011fort/Imakefile packlib/kernlib/kernnum/f011fort/Imakefile
--- packlib/kernlib/kernnum/f011fort/Imakefile	Wed Jun 12 03:04:24 1996
+++ packlib/kernlib/kernnum/f011fort/Imakefile	Sun Oct 13 15:33:27 2002
@@ -7,6 +7,10 @@
 FDEBUGFLAGS=NoOpFortranDebugFlags
 #endif
 
+#if defined(CERNLIB_MACOSX)
+FDEBUGFLAGS=-O0 -fPIC
+#endif
+
 FORTRANSAVEOPTION=FortranSaveFlags
 
 SubdirLibraryTarget(NullParameter,NullParameter)
diff -ubNr packlib/kuip/kuip/ksys.h packlib/kuip/kuip/ksys.h
--- packlib/kuip/kuip/ksys.h	Tue Sep  2 07:50:01 1997
+++ packlib/kuip/kuip/ksys.h	Sun Oct 13 15:33:27 2002
@@ -188,6 +188,17 @@
 #endif
 
 
+#ifdef CERNLIB_MACOSX
+#  define MACOSX
+#  define MACHINE_NAME "MACOSX"
+#  define UNIX
+#  define HAVE_MEMMOVE
+#  define HAVE_STRCASECMP
+#  define HAVE_SELECT
+#  define MATCH_RE_COMP		/* use re_comp/re_exec */
+#endif
+
+
 #ifdef MSDOS
 #  define MACHINE_NAME "IBMPC"
 #  define OS_NAME "MSDOS"
diff -ubNr pawlib/paw/programs/Imakefile pawlib/paw/programs/Imakefile
--- pawlib/paw/programs/Imakefile	Fri Apr 26 08:27:23 2002
+++ pawlib/paw/programs/Imakefile	Sun Oct 13 15:33:27 2002
@@ -9,7 +9,7 @@
 EXTRA_LDOPTIONS=-Wl,-E
 #endif
 
-#if defined(CERNLIB_LINUX)
+#if defined(CERNLIB_LINUX) && !defined(CERNLIB_MACOSX)
 EXTRA_LDOPTIONS=-Wl,-E
 #endif
 
diff -ubNr scripts/cernlib scripts/cernlib
--- scripts/cernlib	Mon Sep 16 00:12:24 2002
+++ scripts/cernlib	Mon Oct 14 14:48:47 2002
@@ -52,8 +52,7 @@
          [ $1 = "genlib"  ] && ln="mathlib.a $dir/libphtools"
          [ $1 = "bvsl"    ] && ln="mathlib"
          [ $1 = "mpalib"  ] && ln="mathlib"
-         [ $1 = "lapack"  ] && ln="lapack3.a $dir/libblas"
-	 [ $1 = "pawlib"  ] && ln="pawlib.a $dir/liblapack3.a $dir/libblas"
+	 [ $1 = "pawlib"  ] && ln="pawlib"
          [ $1 = "pythia"  ] && ln="jetset"
       if [ $1 = "GKS" -o $1 = "gks" ] ; then
          drv="X11" ; glib="$1" ; dir="$CERN/gks/$lver/lib"
@@ -116,6 +115,9 @@
 	       [ -d /usr/X11R6/lib ] && SYSGMOTIF="-L/usr/X11R6/lib -lXm -lXt -lXp -lXext -lX11"
 	       [ `uname -m` = ppc ] && SYSGMOTIF="$SYSGMOTIF -lSM -lICE -lXpm"
 	       ;;
+      Darwin)  [ -d /usr/X11R6/lib ] && SYSGX11="-L/usr/X11R6/lib -lX11"
+	       [ -d /usr/X11R6/lib ] && SYSGMOTIF="-L/usr/X11R6/lib -lXm -lXt -lXp -lXext -lX11 -lSM -lICE -lXpm"
+	       ;;
       NeXT)    SYSGX11="/usr/lib/X11/libX11.r" ;
                SYSGMOTIF="-lXm -lXt /usr/lib/X11/libX11.r" ;;
       OSF1)    SYSGX11="-lX11 -ldnet_stub" ;
@@ -167,7 +169,8 @@
  
   if [ $_u -eq 0 ] ; then
   
-         CERNLIB="$CERNLIB -L/usr/local/lib -lshift"
+#         CERNLIB="$CERNLIB -L/usr/local/lib -lshift"
+         CERNLIB="$CERNLIB -L/usr/local/lib -llapack3 -lblas"
   
 #     SGI needs -lsun, to see yellow pages 
 #   As of 5.x, the yp version is in libc, so -lsun is no longer needed.
@@ -213,6 +216,9 @@
      fi
      if [ "$Msys" = "Linux" ] ; then
         CERNLIB="$CERNLIB -lnsl -lcrypt -ldl"
+     fi
+     if [ "$Msys" = "Darwin" ] ; then
+        CERNLIB="$CERNLIB -latlas -lcompat -ldl"
      fi
   fi
  
