From 2228583a2f164a7945862fb86b00209f1ef62e1c Mon Sep 17 00:00:00 2001 From: Dave Parker Date: Tue, 9 Feb 2021 22:28:18 +0000 Subject: [PATCH] Add support for compiling on Arm-based 64-bit Macs. Resolves #150. --- prism/Makefile | 27 ++++++++++++------- prism/ext/lp_solve_5.5_java/lib/mac/build-osx | 11 +++++--- prism/ext/lpsolve55/Makefile | 4 +++ .../src/lp_solve_5.5/lpsolve55/ccc.osx64 | 17 ++++++++---- 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/prism/Makefile b/prism/Makefile index 2a5739cc..ba3a3e28 100644 --- a/prism/Makefile +++ b/prism/Makefile @@ -78,7 +78,7 @@ endif # Architecture # ################ -# For Linux, we use uname to see if we are on a 64-bit (AMD64 or Itanium) machine +# For Linux/Mac, we use uname to check the architecture ifeq ($(OSTYPE),linux) ifneq (,$(findstring 86_64, $(shell uname -m))) ARCH = amd64 @@ -90,17 +90,16 @@ ifeq ($(OSTYPE),linux) ARCH = aarch64 endif endif -# For Mac/Windows, we decide whether to build in 64-bit mode based on -# whether java is 32/64-bit (since these need to match) ifeq ($(OSTYPE),darwin) - JAVA_VERSION_STRING = $(shell java -version 2>&1) - ifneq (,$(findstring 64-bit, $(JAVA_VERSION_STRING))) - ARCH = x86_64 - endif - ifneq (,$(findstring 64-Bit, $(JAVA_VERSION_STRING))) - ARCH = x86_64 - endif + ifneq (,$(findstring x86_64, $(shell uname -m))) + ARCH = x86_64 + endif + ifneq (,$(findstring arm64, $(shell uname -m))) + ARCH = arm64 + endif endif +# For Windows, we decide whether to build in 64-bit mode based on +# whether java is 32/64-bit (since these need to match) ifeq ($(OSTYPE),cygwin) JAVA_VERSION_STRING = $(shell java -version 2>&1) ifneq (,$(findstring 64-bit, $(JAVA_VERSION_STRING))) @@ -293,6 +292,13 @@ ifeq ($(OSTYPE),darwin) LDFLAGS = $(CFLAGS) -Wl,-search_paths_first BINDISTSUFFIX = osx64 BIN_TARGETS=prism.darwin64 xprism.linux + else + ifeq ($(ARCH),arm64) + CFLAGS = -arch arm64 -fPIC -DPIC -DHAVE_IEEE_754 -DBSD -DSIZEOF_VOID_P=8 -DSIZEOF_LONG=8 -fno-common $(DEBUG) $(OPTIMISE) $(WARNINGS) + CXXFLAGS = --std=c++11 $(CFLAGS) + LDFLAGS = $(CFLAGS) -Wl,-search_paths_first + BINDISTSUFFIX = osx64 + BIN_TARGETS=prism.darwin64 xprism.linux else CFLAGS = -arch i386 -DHAVE_IEEE_754 -DBSD -fno-common $(DEBUG) $(OPTIMISE) $(WARNINGS) CXXFLAGS = --std=c++11 $(CFLAGS) @@ -300,6 +306,7 @@ ifeq ($(OSTYPE),darwin) BINDISTSUFFIX = osx32 BIN_TARGETS=prism.darwin32 xprism.linux endif + endif JFLAGS = -encoding UTF8 SHARED = -dynamiclib EXE = diff --git a/prism/ext/lp_solve_5.5_java/lib/mac/build-osx b/prism/ext/lp_solve_5.5_java/lib/mac/build-osx index acd6e220..5e811ca0 100755 --- a/prism/ext/lp_solve_5.5_java/lib/mac/build-osx +++ b/prism/ext/lp_solve_5.5_java/lib/mac/build-osx @@ -21,12 +21,15 @@ LPSOLVE_LIB_DIR=../../../../lib SRC_DIR=../../src/c INCL="-I$JAVA_JNI_H_DIR -I$JAVA_JNI_MD_H_DIR -I $LPSOLVE_DIR -I $SRC_DIR -idirafter /usr/include/sys" -if [ "$ARCH" = "" ] -then - CFLAGS=-"arch i386 -fno-common" -else +if [ "$ARCH" = "" ]; then + CFLAGS="-arch i386 -fno-common" +fi +if [ "$ARCH" = "x86_64" ]; then CFLAGS="-arch x86_64 -fPIC -DPIC -fno-common" fi +if [ "$ARCH" = "arm64" ]; then + CFLAGS="-arch arm64 -fPIC -DPIC -fno-common" +fi g++ $CFLAGS $INCL -c $SRC_DIR/lpsolve5j.cpp g++ $CFLAGS -dynamiclib lpsolve5j.o -compatibility_version 5.5.0 -current_version 5.5.0 -o liblpsolve55j.jnilib -lc -llpsolve55 -L$LPSOLVE_LIB_DIR diff --git a/prism/ext/lpsolve55/Makefile b/prism/ext/lpsolve55/Makefile index 9aef57c7..6bd0afe0 100644 --- a/prism/ext/lpsolve55/Makefile +++ b/prism/ext/lpsolve55/Makefile @@ -17,9 +17,13 @@ endif ifeq ($(OSTYPE),darwin) ifeq ($(ARCH),x86_64) LPSOLVE55_BUILD=ccc.osx64 + else + ifeq ($(ARCH),arm64) + LPSOLVE55_BUILD=ccc.osx64 else LPSOLVE55_BUILD=ccc.osx endif + endif endif default: all diff --git a/prism/ext/lpsolve55/src/lp_solve_5.5/lpsolve55/ccc.osx64 b/prism/ext/lpsolve55/src/lp_solve_5.5/lpsolve55/ccc.osx64 index c0ecdb2c..f1448fb4 100644 --- a/prism/ext/lpsolve55/src/lp_solve_5.5/lpsolve55/ccc.osx64 +++ b/prism/ext/lpsolve55/src/lp_solve_5.5/lpsolve55/ccc.osx64 @@ -2,12 +2,19 @@ src='../lp_MDO.c ../shared/commonlib.c ../shared/mmio.c ../shared/myblas.c ../ini.c ../fortify.c ../colamd/colamd.c ../lp_rlp.c ../lp_crash.c ../bfp/bfp_LUSOL/lp_LUSOL.c ../bfp/bfp_LUSOL/LUSOL/lusol.c ../lp_Hash.c ../lp_lib.c ../lp_wlp.c ../lp_matrix.c ../lp_mipbb.c ../lp_MPS.c ../lp_params.c ../lp_presolve.c ../lp_price.c ../lp_pricePSE.c ../lp_report.c ../lp_scale.c ../lp_simplex.c ../lp_SOS.c ../lp_utils.c ../yacc_read.c' #c=gcc-4.0 +if [ "$ARCH" = "x86_64" ]; then + CFLAGS="-arch x86_64" +fi +if [ "$ARCH" = "arm64" ]; then + CFLAGS="-arch arm64" +fi + #determine platform (32/64 bit) >/tmp/platform.c echo '#include '>>/tmp/platform.c echo '#include '>>/tmp/platform.c echo 'main(){printf("osx%d", (int) (sizeof(void *)*8));}'>>/tmp/platform.c -$c -arch x86_64 /tmp/platform.c -o /tmp/platform +$c $CFLAGS /tmp/platform.c -o /tmp/platform PLATFORM=`/tmp/platform` rm /tmp/platform /tmp/platform.c >/dev/null 2>&1 @@ -19,7 +26,7 @@ echo '#include '>>/tmp/isnan.c echo '#include '>>/tmp/isnan.c echo '#include '>>/tmp/isnan.c echo 'main(){isnan(0.0);}'>>/tmp/isnan.c -$c -arch x86_64 /tmp/isnan.c -o /tmp/isnan $math >/dev/null 2>&1 +$c $CFLAGS /tmp/isnan.c -o /tmp/isnan $math >/dev/null 2>&1 if [ $? = 0 ] then NOISNAN= else NOISNAN=-DNOISNAN @@ -32,13 +39,13 @@ so=y opts='-idirafter /usr/include/sys -O3 -DINTEGERTIME' -$c -arch x86_64 -s -c -I.. -I../shared -I../bfp -I../bfp/bfp_LUSOL -I../bfp/bfp_LUSOL/LUSOL -I../colamd $opts $def $NOISNAN -DYY_NEVER_INTERACTIVE -DPARSER_LP -DINVERSE_ACTIVE=INVERSE_LUSOL -DRoleIsExternalInvEngine $src +$c $CFLAGS -s -c -I.. -I../shared -I../bfp -I../bfp/bfp_LUSOL -I../bfp/bfp_LUSOL/LUSOL -I../colamd $opts $def $NOISNAN -DYY_NEVER_INTERACTIVE -DPARSER_LP -DINVERSE_ACTIVE=INVERSE_LUSOL -DRoleIsExternalInvEngine $src libtool -static -o bin/$PLATFORM/liblpsolve55.a `echo $src|sed s/[.]c/.o/g|sed 's/[^ ]*\///g'` if [ "$so" != "" ] then - $c -arch x86_64 -fPIC -fno-common -s -c -I.. -I../shared -I../bfp -I../bfp/bfp_LUSOL -I../bfp/bfp_LUSOL/LUSOL -I../colamd -I. $opts $NOISNAN -DYY_NEVER_INTERACTIVE -DPARSER_LP -DINVERSE_ACTIVE=INVERSE_LUSOL -DRoleIsExternalInvEngine $src - $c -arch x86_64 -dynamiclib bin/$PLATFORM/liblpsolve55.a -compatibility_version 5.5.0 -current_version 5.5.0 -o bin/$PLATFORM/liblpsolve55.dylib `echo $src|sed s/[.]c/.o/g|sed 's/[^ ]*\///g'` -lc + $c $CFLAGS -fPIC -fno-common -s -c -I.. -I../shared -I../bfp -I../bfp/bfp_LUSOL -I../bfp/bfp_LUSOL/LUSOL -I../colamd -I. $opts $NOISNAN -DYY_NEVER_INTERACTIVE -DPARSER_LP -DINVERSE_ACTIVE=INVERSE_LUSOL -DRoleIsExternalInvEngine $src + $c $CFLAGS -dynamiclib bin/$PLATFORM/liblpsolve55.a -compatibility_version 5.5.0 -current_version 5.5.0 -o bin/$PLATFORM/liblpsolve55.dylib `echo $src|sed s/[.]c/.o/g|sed 's/[^ ]*\///g'` -lc mv bin/$PLATFORM/liblpsolve55.dylib ../../../lib fi