--- configure.orig	2019-05-13 00:44:17.000000000 +0800
+++ configure	2022-10-20 01:57:19.000000000 +0800
@@ -69,7 +69,7 @@
 echo
 
 if   [ ${os_type} = MAC_OSX ] ; then
-	cp makefile_darwinLP64_utf8_ffi makefile_build
+	cp %MAKEFILE_DARWIN% makefile_build
 elif [ ${os_type} = LINUX ] ; then
 	if [ -f /etc/redhat-release ] ; then
 		libffi_version=$(ls -d /usr/lib*/libffi*/include)

--- Makefile.orig	2019-05-13 00:44:17.000000000 +0800
+++ Makefile	2022-10-20 02:36:33.000000000 +0800
@@ -103,9 +103,9 @@
 # make macOS newlisp 64bit executable and dynamic link library
 macosall:
 	make clean
-	make -f makefile_darwinLP64_utf8_ffi
+	make -f %MAKEFILE_DARWIN%
 	rm *.o
-	make -f makefile_darwinLP64_utf8_lib
+	make -f %MAKEFILE_DYLIB%
 	rm *.o
 	./newlisp qa-dot
 	tar czvf newlisp-macos-utf8.tgz newlisp newlisp.dylib

--- makefile_darwinLP64_utf8_lib.orig	2019-05-13 00:44:17.000000000 +0800
+++ makefile_darwinLP64_utf8_lib	2022-10-20 02:52:27.000000000 +0800
@@ -6,12 +6,12 @@
 OBJS = newlisp.o nl-symbol.o nl-math.o nl-list.o nl-liststr.o nl-string.o nl-filesys.o \
 	nl-sock.o nl-import.o nl-xml-json.o nl-web.o nl-matrix.o nl-debug.o pcre.o nl-utf8.o unix-lib.o
 
-CFLAGS = -m64 -Wall -O1 -c -DREADLINE -DMAC_OSX -DSUPPORT_UTF8 -DLIBRARY -DNEWLISP64
+CFLAGS = %CFLAGS% -c -O1 -DREADLINE -DMAC_OSX -DSUPPORT_UTF8 -DLIBRARY -DNEWLISP64
 
-CC = cc
+CC = %COMPILER%
 
 default: $(OBJS)
-	$(CC) $(OBJS) -m64 -lm -lreadline -bundle -o newlisp.dylib
+	$(CC) %CFLAGS% $(OBJS) -lm -lreadline -bundle -o newlisp.dylib
 
 .c.o:
 	$(CC) $(CFLAGS) $<

--- makefile_darwin_utf8_lib.orig	2019-05-13 00:44:17.000000000 +0800
+++ makefile_darwin_utf8_lib	2022-10-20 02:52:09.000000000 +0800
@@ -6,12 +6,12 @@
 OBJS = newlisp.o nl-symbol.o nl-math.o nl-list.o nl-liststr.o nl-string.o nl-filesys.o \
 	nl-sock.o nl-import.o nl-xml-json.o nl-web.o nl-matrix.o nl-debug.o pcre.o nl-utf8.o unix-lib.o
 
-CFLAGS = -m32 -Wall -O1 -c -DREADLINE -DMAC_OSX -DSUPPORT_UTF8 -DLIBRARY
+CFLAGS = %CFLAGS% -c -O1 -DREADLINE -DMAC_OSX -DSUPPORT_UTF8 -DLIBRARY
 
-CC = cc
+CC = %COMPILER%
 
 default: $(OBJS)
-	$(CC) $(OBJS) -m32 -lm -lreadline -bundle -o newlisp.dylib
+	$(CC) %CFLAGS% $(OBJS) -lm -lreadline -bundle -o newlisp.dylib
 
 .c.o:
 	$(CC) $(CFLAGS) $<

--- makefile_darwinLP64_utf8_ffi.orig	2019-05-13 00:44:17.000000000 +0800
+++ makefile_darwinLP64_utf8_ffi	2022-10-20 03:53:32.000000000 +0800
@@ -6,13 +6,12 @@
 OBJS = newlisp.o nl-symbol.o nl-math.o nl-list.o nl-liststr.o nl-string.o nl-filesys.o \
 	nl-sock.o nl-import.o nl-xml-json.o nl-web.o nl-matrix.o nl-debug.o pcre.o nl-utf8.o
 
-CFLAGS = -m64 -Wall -O1 -c -DREADLINE -DNEWLISP64 -DMAC_OSX -DSUPPORT_UTF8 -DFFI
+CFLAGS = %CFLAGS% -c -O1 -DREADLINE -DNEWLISP64 -DMAC_OSX -DSUPPORT_UTF8 -DFFI
 
-CC = cc
-#CC = gcc 
+CC = %COMPILER%
 
 default: $(OBJS)
-	$(CC) $(OBJS) -m64 -lm -lreadline -lffi -o newlisp
+	$(CC) %CFLAGS% $(OBJS) -lm -lreadline -lffi -o newlisp
 	strip newlisp
 
 .c.o:

--- makefile_darwin_utf8_leopardPPC_ffi.orig	2019-05-13 00:44:17.000000000 +0800
+++ makefile_darwin_utf8_leopardPPC_ffi	2022-10-20 03:50:24.000000000 +0800
@@ -14,18 +14,18 @@
 
 # to run on 10.4 we must use gcc-4.0
 #CC = /usr/bin/gcc-4.0
-CC = /usr/bin/gcc-4.2
+CC = %COMPILER%
 
 # SDKROOT = /Developer/SDKs/MacOSX10.4u.sdk
-SDKROOT = /Developer/SDKs/MacOSX10.5.sdk
+SDKROOT = %DEVDIR%/SDKs/MacOSX%SDK%.sdk
 
-CFLAGS = -m32 -Wall -arch ppc -Os -c -g -DREADLINE -DMAC_OSX -DSUPPORT_UTF8 -DFFI -isysroot $(SDKROOT) 
+CFLAGS = %CFLAGS% -Os -c -g -DREADLINE -DMAC_OSX -DSUPPORT_UTF8 -DFFI -isysroot $(SDKROOT) 
 
 OBJS = newlisp.o nl-symbol.o nl-math.o nl-list.o nl-liststr.o nl-string.o nl-filesys.o \
 	nl-sock.o nl-import.o nl-xml-json.o nl-web.o nl-matrix.o nl-debug.o nl-utf8.o pcre.o
 
 default: $(OBJS)
-	$(CC) $(OBJS) -m32 -mmacosx-version-min=10.5 -arch ppc -g -lm -lreadline -lffi -o newlisp
+	$(CC) %CFLAGS% $(OBJS) -mmacosx-version-min=%VER% -g -lm -lreadline -lffi -o newlisp
 	strip newlisp
 
 .c.o:

--- makefile_darwin_utf8_leopardIntel_ffi.orig	2019-05-13 00:44:17.000000000 +0800
+++ makefile_darwin_utf8_leopardIntel_ffi	2022-10-20 03:48:20.000000000 +0800
@@ -11,16 +11,16 @@
 #CC = /usr/bin/gcc-4.0
 #SDKROOT = /Developer/SDKs/MacOSX10.4u.sdk
 
-CC = /usr/bin/gcc-4.2
-SDKROOT = /Developer/SDKs/MacOSX10.5.sdk
+CC = %COMPILER%
+SDKROOT = %DEVDIR%/SDKs/MacOSX%SDK%.sdk
 
-CFLAGS = -Wall -arch i386 -Os -c -g -DREADLINE -DMAC_OSX -DSUPPORT_UTF8 -DFFI -isysroot $(SDKROOT) 
+CFLAGS = %CFLAGS% -Os -c -g -DREADLINE -DMAC_OSX -DSUPPORT_UTF8 -DFFI -isysroot $(SDKROOT) 
 
 OBJS = newlisp.o nl-symbol.o nl-math.o nl-list.o nl-liststr.o nl-string.o nl-filesys.o \
 	nl-sock.o nl-import.o nl-xml-json.o nl-web.o nl-matrix.o nl-debug.o nl-utf8.o pcre.o
 
 default: $(OBJS)
-	$(CC) $(OBJS) -mmacosx-version-min=10.5 -arch i386 -g -lm -lreadline -lffi -o newlisp
+	$(CC) %CFLAGS% $(OBJS) -mmacosx-version-min=%VER% -g -lm -lreadline -lffi -o newlisp
 	strip newlisp
 
 .c.o:

--- nl-filesys.c.orig	2019-05-13 00:44:17.000000000 +0800
+++ nl-filesys.c	2022-10-20 03:10:53.000000000 +0800
@@ -65,7 +65,12 @@
 #endif /* LINUX || KFREEBSD */
 
 #ifndef TRU64
-extern char ** environ;
+#ifdef __APPLE__
+#include <crt_externs.h>
+#define environ (*_NSGetEnviron())
+#else
+ extern char **environ;
+#endif
 #endif
 
 #ifdef WINDOWS

--- newlisp.h.orig	2019-05-13 00:44:17.000000000 +0800
+++ newlisp.h	2022-10-20 03:18:41.000000000 +0800
@@ -37,7 +37,7 @@
 #ifdef NEWCONFIG
 #include "config.h"
 #else
-#define NEWLISPDIR "/usr/local/share/newlisp"
+#define NEWLISPDIR "%PREFIX%/share/newlisp"
 #endif
 
 /* force ISO_C90 restrictions */

--- makefile_original_install.orig	2019-05-13 00:44:17.000000000 +0800
+++ makefile_original_install	2022-10-20 03:26:13.000000000 +0800
@@ -6,7 +6,7 @@
 # run in an environment, where NEWLISPDIR is predefined,
 # else NEWLISPDIR will be defined during newlisp startup
 # as /usr/share/newlisp which is hardcoded in newlisp.c
-prefix=/usr/local
+prefix=%PREFIX%
 datadir=$(prefix)/share
 bindir=$(prefix)/bin
 mandir=$(prefix)/share/man
