276276 <condition property =" os.prefix" value =" win32-${ jre.arch } " >
277277 <equals arg1=" ${ build.os.family } " arg2=" windows" />
278278 </condition >
279- <!-- Darwin builds are universal, no arch required -->
280- <condition property =" os.prefix" value =" darwin" >
279+ <condition property =" os.prefix" value =" darwin-${ jre.arch } " >
281280 <equals arg1=" ${ build.os.family } " arg2=" mac" />
282281 </condition >
283282 <condition property =" os.prefix" value =" sunos-${ jre.arch } " >
295294 <condition property =" os.prefix" value =" kfreebsd-${ jre.arch } " >
296295 <equals arg1=" ${ build.os.name } " arg2=" GNU/kFreeBSD" />
297296 </condition >
297+ <!-- Darwin's resource prefix lacks arch info, use "darwin" instead -->
298+ <condition property =" resource.prefix" value =" darwin" >
299+ <matches string =" ${ os.prefix } " pattern =" ^darwin-" />
300+ </condition >
301+ <property name =" resource.prefix" value =" ${ os.prefix } " description =" fallback" />
298302 <fail unless =" os.prefix" message =" OS/arch not supported (${ os.name } /${ jre.arch } ), edit build.xml and native/Makefile to add it." />
299303 <!-- Keep all natives separate -->
300304 <property name =" native.subdir" value =" native-${ os.prefix } " />
316320 <condition property =" ld.preload.name" value =" LD_PRELOAD" else =" IGNORE" >
317321 <not ><equals arg1=" ${ libjsig } " arg2=" " /></not >
318322 </condition >
323+ <condition property =" native.jar" value =" darwin.jar" >
324+ <matches string =" ${ os.prefix } " pattern =" ^darwin-" />
325+ </condition >
319326 <property name =" native.jar" value =" ${ os.prefix } .jar" />
320327 <property name =" build.native" location =" ${ build } /${ native.subdir } " />
321328 <property name =" build.headers" location =" ${ build } /headers" />
@@ -521,7 +528,7 @@ com/sun/jna/openbsd-x86-64/libjnidispatch.so;
521528processor=x86-64;osname=openbsd,
522529
523530com/sun/jna/darwin/libjnidispatch.jnilib;
524- osname=macosx;processor=x86;processor=x86-64;processor=ppc
531+ osname=macosx;processor=x86;processor=x86-64;processor=aarch64;processor= ppc
525532" />
526533 </manifest >
527534 <manifest file =" @{ target } " mode =" update" if : true =" @{ module-info } " >
@@ -873,6 +880,21 @@ osname=macosx;processor=x86;processor=x86-64;processor=ppc
873880 </condition >
874881 <property name =" make.OS" value =" IGNORE=" />
875882 <!-- Ensure Makefile ARCH property properly set -->
883+ <condition property =" ARCH" value =" aarch64" >
884+ <matches string =" ${ os.prefix } " pattern =" -aarch64$" />
885+ </condition >
886+ <condition property =" ARCH" value =" x86-64" >
887+ <matches string =" ${ os.prefix } " pattern =" -x86-64$" />
888+ </condition >
889+ <condition property =" ARCH" value =" ppc" >
890+ <matches string =" ${ os.prefix } " pattern =" -ppc$" />
891+ </condition >
892+ <condition property =" ARCH" value =" ppc64" >
893+ <matches string =" ${ os.prefix } " pattern =" -ppc64$" />
894+ </condition >
895+ <condition property =" ARCH" value =" x86" >
896+ <matches string =" ${ os.prefix } " pattern =" -x86$" />
897+ </condition >
876898 <condition property =" ARCH" value =" arm" >
877899 <equals arg1=" ${ os.prefix } " arg2=" w32ce-arm" />
878900 </condition >
@@ -882,27 +904,12 @@ osname=macosx;processor=x86;processor=x86-64;processor=ppc
882904 <condition property =" ARCH" value =" armv7" >
883905 <equals arg1=" ${ os.prefix } " arg2=" android-armv7" />
884906 </condition >
885- <condition property =" ARCH" value =" aarch64" >
886- <matches string =" ${ os.prefix } " pattern =" -aarch64$" />
887- </condition >
888- <condition property =" ARCH" value =" x86" >
889- <equals arg1=" ${ os.prefix } " arg2=" android-x86" />
890- </condition >
891- <condition property =" ARCH" value =" x86-64" >
892- <equals arg1=" ${ os.prefix } " arg2=" android-x86-64" />
893- </condition >
894907 <condition property =" ARCH" value =" mips" >
895908 <equals arg1=" ${ os.prefix } " arg2=" android-mips" />
896909 </condition >
897910 <condition property =" ARCH" value =" mips64" >
898911 <equals arg1=" ${ os.prefix } " arg2=" android-mips64" />
899912 </condition >
900- <condition property =" ARCH" value =" ppc" >
901- <equals arg1=" ${ os.prefix } " arg2=" aix-ppc" />
902- </condition >
903- <condition property =" ARCH" value =" ppc64" >
904- <equals arg1=" ${ os.prefix } " arg2=" aix-ppc64" />
905- </condition >
906913 <!-- ensure ARCH is set properly for 64-bit capable platforms -->
907914 <!-- use ANT_OPTS=-d64/-d32 to build 64-bit/32-bit if not the platform default -->
908915 <property name =" ARCH" value =" ${ build.os.arch } " />
@@ -918,49 +925,41 @@ osname=macosx;processor=x86;processor=x86-64;processor=ppc
918925 <condition property =" make.SDKROOT" value =" SDKROOT=${ SDKROOT } " >
919926 <isset property =" SDKROOT" />
920927 </condition >
921- <property name =" xcode" value =" /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform" />
922- <condition property =" make.SDKROOT"
923- value =" SDKROOT=${ xcode } /Developer/SDKs/MacOSX10.11.sdk" >
924- <and >
925- <equals arg1=" ${ os.prefix } " arg2=" darwin" trim =" true" />
926- <available file =" ${ xcode } /Developer/SDKs/MacOSX10.11.sdk" />
927- </and >
928- </condition >
929- <condition property =" make.SDKROOT"
930- value =" SDKROOT=${ xcode } /Developer/SDKs/MacOSX10.9.sdk" >
931- <and >
932- <equals arg1=" ${ os.prefix } " arg2=" darwin" trim =" true" />
933- <available file =" ${ xcode } /Developer/SDKs/MacOSX10.9.sdk" />
934- </and >
935- </condition >
936- <condition property =" make.SDKROOT"
937- value =" SDKROOT=${ xcode } /Developer/SDKs/MacOSX10.8.sdk" >
938- <and >
939- <equals arg1=" ${ os.prefix } " arg2=" darwin" trim =" true" />
940- <available file =" ${ xcode } /Developer/SDKs/MacOSX10.8.sdk" />
941- </and >
942- </condition >
943- <condition property =" make.SDKROOT"
944- value =" SDKROOT=/Developer/SDKs/MacOSX10.6.sdk" >
928+ <!-- If not manually provided, detect the SDKROOT in various locations:
929+ - Modern build environments ("MacOSX.sdk", no version):
930+ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
931+
932+ - macOS 10.8 and older:
933+ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX(version).sdk
934+
935+ - Prior versions:
936+ /Developer/SDKs/MacOSX(version).sdk
937+ -->
938+ <condition property =" make.SDKROOT" value =" SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk" >
945939 <and >
946- <equals arg1 =" ${ os.prefix } " arg2= " darwin" trim = " true " />
947- <available file =" /Developer/SDKs/MacOSX10.6 .sdk" />
940+ <matches string =" ${ os.prefix } " pattern = " ^ darwin- " />
941+ <available file =" /Applications/Xcode.app/Contents/ Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX .sdk" />
948942 </and >
949943 </condition >
950- <condition property =" make.SDKROOT"
951- value =" SDKROOT=/Developer/SDKs/MacOSX10.5.sdk" >
944+ <condition property =" sdk-parent" value =" /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs" >
952945 <and >
953- <equals arg1 =" ${ os.prefix } " arg2= " darwin" trim = " true " />
954- <available file =" /Developer/SDKs/MacOSX10.5.sdk " />
946+ <matches string =" ${ os.prefix } " pattern = " ^ darwin- " />
947+ <available file =" /Applications/Xcode.app/Contents/ Developer/Platforms/MacOSX.platform/Developer/SDKs " />
955948 </and >
956949 </condition >
957- <condition property =" make.SDKROOT"
958- value =" SDKROOT=/Developer/SDKs/MacOSX10.4u.sdk" else =" IGNORE=" >
950+ <condition property =" sdk-parent" value =" /Developer/SDKs" >
959951 <and >
960- <equals arg1 =" ${ os.prefix } " arg2= " darwin" trim = " true " />
961- <available file =" /Developer/SDKs/MacOSX10.4u.sdk " />
952+ <matches string =" ${ os.prefix } " pattern = " ^ darwin- " />
953+ <available file =" /Developer/SDKs" />
962954 </and >
963955 </condition >
956+ <!-- Multiple SDKs is common; find the most recent (sort -V requires 10.12+) -->
957+ <exec executable =" sh" dir =" ${ sdk-parent } " outputproperty =" sdk-latest" unless : set =" make.SDKROOT" >
958+ <arg value =" -c" />
959+ <arg line =" "ls -d MacOSX10.*.sdk | sort -t "." -k2 -n | tail -1"" />
960+ </exec >
961+ <property name =" make.SDKROOT" value =" SDKROOT=${ sdk-parent } /${ sdk-latest } " />
962+
964963 <!-- Windows' drive letters and spaces in absolute paths wreak havoc on
965964 make -->
966965 <condition property =" make.BUILD" value =" BUILD=../${ build } /${ native.subdir } " else =" BUILD=${ build.native } " >
@@ -989,7 +988,7 @@ osname=macosx;processor=x86;processor=x86-64;processor=ppc
989988 <isset property =" EXTRA_MAKE_OPTS" />
990989 </condition >
991990 <!-- Native resource path within jna.jar -->
992- <property name =" native.path" value =" com/sun/jna/${ os .prefix} " />
991+ <property name =" native.path" value =" com/sun/jna/${ resource .prefix} " />
993992
994993 <!-- Default make program -->
995994 <property name =" make" value =" make" />
@@ -1055,6 +1054,68 @@ cd ..
10551054 </zip >
10561055 </target >
10571056
1057+ <!--
1058+ Darwin prefers fat libraries. native/Makefile outputs a binary file for
1059+ one architecture. The binary is joined into a preexisting library pulled
1060+ from dist/darwin.jar using lipo.
1061+
1062+ If the preexisting library does not exist, or the library is thin and
1063+ only supports the target arch, the output binary will be renamed and
1064+ used in lieu of joining a fat lib.
1065+ -->
1066+ <macrodef name =" darwin-lipo" >
1067+ <sequential >
1068+ <available file =" ${ dist } /${ native.jar } " property =" dist-available" />
1069+ <unzip src =" ${ dist } /${ native.jar } " dest =" ${ build.native } " if : true =" ${ dist-available } " >
1070+ <patternset >
1071+ <include name =" libjnidispatch.jnilib" />
1072+ </patternset >
1073+ </unzip >
1074+ <!--
1075+ Detect the arch that was just built.
1076+ Note, lipo -info will not exactly match that provided by ${ARCH}, this is OK
1077+ -->
1078+ <exec executable =" lipo" dir =" ${ build.native } " failonerror =" true" outputproperty =" lipo-info" if : true =" ${ dist-available } " >
1079+ <arg value =" -info" />
1080+ <arg value =" libjnidispatch-${ ARCH } .jnilib" />
1081+ </exec >
1082+ <regexp id =" lipo-regex" pattern =" \b(\w+)$" />
1083+ <loadresource property =" lipo-arch" if : true =" ${ dist-available } " >
1084+ <propertyresource name =" lipo-info" />
1085+ <filterchain >
1086+ <tokenfilter >
1087+ <filetokenizer />
1088+ <replaceregex pattern =" .*\s" replace =" " />
1089+ </tokenfilter >
1090+ </filterchain >
1091+ </loadresource >
1092+ <!-- Use the detected arch to remove the old binary, and add the new binary to the fat library -->
1093+ <exec executable =" lipo" dir =" ${ build.native } " failonerror =" false" if : true =" ${ dist-available } " >
1094+ <arg value =" -remove" />
1095+ <arg value =" ${ lipo-arch } " />
1096+ <arg value =" libjnidispatch.jnilib" />
1097+ <arg value =" -output" />
1098+ <arg value =" libjnidispatch.jnilib" />
1099+ </exec >
1100+ <exec executable =" lipo" dir =" ${ build.native } " failonerror =" false" if : true =" ${ dist-available } " resultproperty =" lipo-result" >
1101+ <arg value =" -create" />
1102+ <arg value =" libjnidispatch.jnilib" />
1103+ <arg value =" libjnidispatch-${ ARCH } .jnilib" />
1104+ <arg value =" -output" />
1105+ <arg value =" libjnidispatch.jnilib" />
1106+ </exec >
1107+ <condition property =" replace-lib" value =" true" >
1108+ <or >
1109+ <not >
1110+ <equals arg1=" 0" arg2=" ${ lipo-result } " />
1111+ </not >
1112+ <isfalse value =" ${ dist-available } " />
1113+ </or >
1114+ </condition >
1115+ <move file =" ${ build.native } /libjnidispatch-${ ARCH } .jnilib" tofile =" ${ build.native } /libjnidispatch.jnilib" if : true =" ${ replace-lib } " overwrite =" true" />
1116+ </sequential >
1117+ </macrodef >
1118+
10581119 <target name =" native" depends =" -enable-native,javah,-native-api-check,-prepare-native" unless =" -native"
10591120 description =" Build native libraries. Use 'ant -DCC=xxx' to build using a compiler other than gcc" >
10601121 <exec executable =" ${ make } " dir =" ${ native } " failonerror =" true" >
@@ -1074,6 +1135,7 @@ cd ..
10741135 <arg value =" JNA_JNI_VERSION=${ jni.version } " />
10751136 <arg value =" CHECKSUM=${ jni.md5 } " />
10761137 </exec >
1138+ <darwin-lipo if : set =" make.SDKROOT" />
10771139 <mkdir dir =" ${ classes } /${ native.path } " />
10781140 <copy todir =" ${ classes } /${ native.path } " >
10791141 <fileset dir =" ${ build.native } "
@@ -1132,13 +1194,13 @@ cd ..
11321194 <exclude name =" ${ tests.exclude } " />
11331195 </javac >
11341196 <!-- Embed testlib-jar at root and at default resource path -->
1135- <mkdir dir =" ${ test.classes } /${ os .prefix} " />
1197+ <mkdir dir =" ${ test.classes } /${ resource .prefix} " />
11361198 <copy todir =" ${ test.classes } " >
11371199 <fileset dir =" ${ build.native } " >
11381200 <include name =" *testlib-jar*" />
11391201 </fileset >
11401202 </copy >
1141- <copy todir =" ${ test.classes } /${ os .prefix} " >
1203+ <copy todir =" ${ test.classes } /${ resource .prefix} " >
11421204 <fileset dir =" ${ build.native } " >
11431205 <include name =" *testlib-jar*" />
11441206 </fileset >
0 commit comments