Modify the build system to add support for macOS and honor environment variables set by the user, including CXX, CXXFLAGS, CPPFLAGS and LDFLAGS. --- apps/Make1.orig 2018-08-31 00:09:40.000000000 -0500 +++ apps/Make1 2019-10-03 18:25:14.000000000 -0500 @@ -121,11 +121,16 @@ #------------------------------------------------------------------------ LIBPATH = `pwd | sed 's/apps/lib/g'` MODELGEN = `pwd | sed 's/apps/modelgen/g'`/gnucap-modelgen +ifeq ($(shell uname -s),Darwin) + LD_LIBRARY_PATH_VARIABLE=DYLD_LIBRARY_PATH +else + LD_LIBRARY_PATH_VARIABLE=LD_LIBRARY_PATH +endif #------------------------------------------------------------------------ %.h : %.model - (export LD_LIBRARY_PATH=$(LIBPATH); $(MODELGEN) -h $<) + (export $(LD_LIBRARY_PATH_VARIABLE)=$(LIBPATH); $(MODELGEN) -h $<) #------------------------------------------------------------------------ %.cc : %.model - (export LD_LIBRARY_PATH=$(LIBPATH); $(MODELGEN) -cc $<) + (export $(LD_LIBRARY_PATH_VARIABLE)=$(LIBPATH); $(MODELGEN) -cc $<) #----------------------------------------------------------------------------- #----------------------------------------------------------------------------- --- apps/configure.orig 2018-08-31 00:09:40.000000000 -0500 +++ apps/configure 2019-10-03 18:35:27.000000000 -0500 @@ -25,7 +25,7 @@ #---------------------------------------------------------------- echo "CCFLAGS = -fPIC \\" >Make.ccflags -echo "-DUNIX -O2 -DNDEBUG -I. -I../include -I../../include -W" >>Make.ccflags +echo "-DUNIX -DNDEBUG -I. -I../include -I../../include -W ${CXXFLAGS--O2} ${CPPFLAGS-}" >>Make.ccflags echo "LIBS = \\" >Make.libs echo "" >>Make.libs @@ -35,10 +35,14 @@ cat <Make.sys #------------------------------------------------------------------------ VPATH = .:.. -CCC = c++ +CCC = ${CXX-c++} TARGET_EXT = .so -LDFLAGS = -shared +ifeq (\$(shell uname -s),Darwin) + LDFLAGS = -bundle -undefined dynamic_lookup ${LDFLAGS-} +else + LDFLAGS = -shared ${LDFLAGS-} +endif .SUFFIXES: .SUFFIXES: .o .cc --- include/configure.orig 2018-08-31 00:09:40.000000000 -0500 +++ include/configure 2019-10-03 18:39:16.000000000 -0500 @@ -22,7 +22,7 @@ #---------------------------------------------------------------- echo \# created by $PWD/$0. do not edit >Make2 echo \#------------------------------------------------------------------------ >>Make2 -echo "CCC = c++" >>Make2 +echo "CCC = ${CXX-c++}" >>Make2 echo "PREFIX = " $prefix >>Make2 echo "" >>Make2 --- lib/configure.orig 2018-08-31 00:09:40.000000000 -0500 +++ lib/configure 2019-10-03 18:35:19.000000000 -0500 @@ -28,7 +28,7 @@ echo "LIBS = -ldl \\" >Make.libs rm -f a.out -c++ test_readline.cc -lreadline -ltermcap +${CXX-c++} ${CXXFLAGS-} ${CPPFLAGS-} ${LDFLAGS-} test_readline.cc -lreadline -ltermcap if [ -f a.out ] ; then echo "using readline" echo "-DHAVE_LIBREADLINE \\" >>Make.ccflags @@ -38,7 +38,7 @@ fi rm -f a.out -echo "-DUNIX -O2 -DNDEBUG -I. -I../include -I../../include -W" >>Make.ccflags +echo "-DUNIX -DNDEBUG -I. -I../include -I../../include -W ${CXXFLAGS--O2} ${CPPFLAGS-}" >>Make.ccflags echo "" >>Make.libs echo "PREFIX = " $prefix >>Make.libs echo "" >>Make.libs @@ -46,10 +46,15 @@ cat <Make.sys #------------------------------------------------------------------------ VPATH = .:.. -CCC = c++ -TARGET_EXT = .so +CCC = ${CXX-c++} -LDFLAGS = -shared +ifeq (\$(shell uname -s),Darwin) + TARGET_EXT = .dylib + LDFLAGS = -dynamiclib -install_name \$(INSTALL_DIR)/\$@ ${LDFLAGS-} +else + TARGET_EXT = .so + LDFLAGS = -shared ${LDFLAGS-} +endif .SUFFIXES: .SUFFIXES: .o .cc --- main/configure.orig 2018-08-31 00:09:40.000000000 -0500 +++ main/configure 2019-10-03 18:35:12.000000000 -0500 @@ -49,7 +49,7 @@ chmod +x gnucap-conf #---------------------------------------------------------------- echo "CCFLAGS = \\" >Make.ccflags -echo "-DUNIX -O2 -DNDEBUG -I. -I../include -I../../include -W" >>Make.ccflags +echo "-DUNIX -DNDEBUG -I. -I../include -I../../include -W ${CXXFLAGS--O2} ${CPPFLAGS-}" >>Make.ccflags echo "LIBS = \\" >Make.libs echo "-lgnucap \\" >>Make.libs @@ -60,11 +60,11 @@ cat <Make.sys #------------------------------------------------------------------------ VPATH = .:.. -CCC = c++ +CCC = ${CXX-c++} TARGET_EXT = LDFLAGS = -rdynamic \ --L../../lib/O +-L../../lib/O ${LDFLAGS-} .SUFFIXES : .o .cc .cc.o:; \$(CCC) \$(CXXFLAGS) \$(CPPFLAGS) \$(CCFLAGS) -c \$< --- modelgen/configure.orig 2018-08-31 00:09:40.000000000 -0500 +++ modelgen/configure 2019-10-03 18:35:22.000000000 -0500 @@ -25,7 +25,7 @@ #---------------------------------------------------------------- echo "CCFLAGS = \\" >Make.ccflags -echo "-DUNIX -O2 -DNDEBUG -I. -I../include -I../../include -W" >>Make.ccflags +echo "-DUNIX -DNDEBUG -I. -I../include -I../../include -W ${CXXFLAGS--O2} ${CPPFLAGS-}" >>Make.ccflags echo "LIBS = \\" >Make.libs echo "-lgnucap \\" >>Make.libs @@ -36,11 +36,11 @@ cat <Make.sys #------------------------------------------------------------------------ VPATH = .:.. -CCC = c++ +CCC = ${CXX-c++} TARGET_EXT = LDFLAGS = -rdynamic \ --L../../lib/O +-L../../lib/O ${LDFLAGS-} .SUFFIXES : .o .cc .cc.o:; \$(CCC) \$(CXXFLAGS) \$(CPPFLAGS) \$(CCFLAGS) -c \$<