Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Apple arm64 #191

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
13 changes: 13 additions & 0 deletions README.apple_m1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
I have netcdf installed separately and other ncarg dependencies were installed with homebrew. GCC version 12 was installed with homebrew, as well. That version (gcc-12) is wired into the Darwin_Arm configure file and probably should be made generic.

For Configure, my library and include settings are:

/opt/X11/lib /Users/Shared/opt/local/netcdf480ser/lib /Users/Shared/homebrew/lib

/opt/X11/include /opt/X11/include/freetype2 /Users/Shared/opt/local/netcdf480ser/include /Users/Shared/homebrew/include

Make sure to install proj at version 7 in homebrew:
brew install proj@7
And if proj v. 9 is install, then unlink that with 'brew unlink proj' and then link the v7 with 'brew link proj@7'

Also need to set g++ at as g\+\+-12 so that ncl linking finds the gfortran library.
9 changes: 9 additions & 0 deletions common/src/libncarg_c/yMakefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,19 @@ EXCSRCS = bcopyswap.c logic32.c
EXFSRCS = gbytes.f sbytes.f
EXOBJS = sbytes.o gbytes.o bcopyswap.o logic32.o

#elif defined(Darwin) && defined(arm64) && defined(__LP64__)
EXCSRCS = bcopyswap.c logic32.c
EXFSRCS = gbytes.f sbytes.f
EXOBJS = sbytes.o gbytes.o bcopyswap.o logic32.o

#elif defined(Darwin) && defined(i386) && !defined(__LP64__)
EXCSRCS = bcopyswap.c logic32.c gsbytes.c
EXOBJS = bcopyswap.o logic32.o gsbytes.o

#elif defined(Darwin) && defined(arm64) && !defined(__LP64__)
EXCSRCS = bcopyswap.c logic32.c gsbytes.c
EXOBJS = bcopyswap.o logic32.o gsbytes.o

#elif defined(Darwin) && !defined(i386)
EXCSRCS = gsbytes.c logic32.c
EXOBJS = gsbytes.o logic32.o
Expand Down
68 changes: 68 additions & 0 deletions config/Darwin_Arm
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Description: This file contains the configuration for a
* gfortran/gcc build on a *64 bit* ARM (Apple Silicon) Mac system.
*
* You may need to modify it to change or include
* options. This version was tested with GCC-12.2
* built with Homebrew and XCode 13.4.1 on OS 12.6 (Monterey)
*
* Note: if the build has trouble finding the
* "gfortran" library, then you may need to modify
* the "CtoFLibraries" line below and include a "-L"
* path to help it. For example:
*
* #define CtoFLibraries -L/usr/local/lib -lgfortran -lquadmath
* or
* #define CtoFLibraries /usr/local/lib/libgfortran.a /usr/local/lib/libquadmath.a
*
* You'll need to change "/usr/local/lib" to
* whatever directory contains "libgfortran.so".
*
* The references to the "User" macros below is for building the
* ncargcc, ncargf90, nhlcc, etc, scripts. We don't want the
* development stuff (like the CtoFLibraries) jammed into those
* scripts, like "/usr/local/lib/libcairo.a"; instead, we want
* clean paths like "-lcairo".
* #define CtoFLibraries -L/Users/Shared/homebrew/Cellar/gcc/12.2.0/lib/gcc/current -lgfortran -lquadmath
* #define CtoFLibrariesUser -L/Users/Shared/homebrew/Cellar/gcc/12.2.0/lib/gcc/current -lgfortran -lquadmath
*/
#define DEBUG 1
#define HdfDefines -DDARWIN
#define StdDefines -DSYSV -D_POSIX_SOURCE -D_XOPEN_SOURCE -DByteSwapped -D__UNIXOS2__ -D_DARWIN_C_SOURCE
#define ByteSwapped
#define Cstatic
#define Cdynamic
#define CppCommand '/usr/bin/cpp -traditional'
#define CCompiler gcc-12
#define CxxCompiler g\+\+-12
#define FCompiler gfortran-12
#define CcOptions -ansi -fPIC -Wall -std=c99 -Wno-error=implicit-function-declaration -O

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't disable the implicit function declaration error. This condition was made an error for a reason. It is important to fix it properly by declaring all functions before you use them.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it used to be OK to have implicit declarations, but more recent compilers have started treating these as errors. I'm not the one to fix all those, and if I recall there are a lot of them.

#define FcOptions -fPIC -fno-range-check -Wall -fallow-argument-mismatch -fallow-invalid-boz -O
#define CtoFLibraries -lgfortran -lquadmath
#define CtoFLibrariesUser -lgfortran -lquadmath
#define XToolLibrary -lXt -lSM -lICE
#define BuildShared NO
#define XLibrary -lXpm -lX11 -lXext

#define LibSearchUser -L/opt/X11/lib
#define IncSearchUser -I/opt/X11/include -I/opt/X11/include/freetype2
#define ExtraIncSearch -I/opt/X11/include/freetype2

#define ArchRecLibSearch -L/opt/X11/lib
#define ArchRecIncSearch -I/opt/X11/include -I/opt/X11/include/freetype2

#define LexLibrary -ll

FC = $(F77)

/*************** Redefine Macros from Rules ********************************/

/*
* Macro: MakeDir
*
* Description: This rule creates a directory - if a parent dir doesn't exist
* it attempts to create it.
*/
#ifndef MakeDir
#define MakeDir(dir) @if (test ! -d dir); then ($(MKDIRHIER) dir); fi
#endif
6 changes: 6 additions & 0 deletions config/ymake
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,12 @@ case Darwin:
set sysincs = Darwin_Intel
set vendor = Apple
breaksw
case arm64:
set model = $mach
set arch = $mach
set sysincs = Darwin_Arm
set vendor = Apple
breaksw
default:
echo "$0 : Unknown machine type" > /dev/tty
exit 1
Expand Down
4 changes: 2 additions & 2 deletions ncarg2d/src/libncarg/conpack/CodeIftran
Original file line number Diff line number Diff line change
Expand Up @@ -9666,7 +9666,7 @@ C
C Find the length of the character buffer and initialize it to blanks.
C
LBUF=LEN(CBUF)
CBUF=' '
CBUF(1:lbuf)=' '
C
C Use the local I/O routines to generate an E-format representation of
C the number.
Expand Down Expand Up @@ -9788,7 +9788,7 @@ C which requires special action).
C
IF (NDGS.EQ.0.OR.IEXF.EQ.0)
IF (IEXP.GT.0.OR.LMSD.EQ.-10000)
CBUF='0'
CBUF(1:LBUF)='0'
NBUF=1
NDGS=1
IEVA=0
Expand Down
16 changes: 10 additions & 6 deletions ncarg2d/src/libncarg_gks/bwi/argb2ci.f
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ integer function argb2ci(index)
integer index, nearest
integer i
integer ARGBMASK, RMASK, GMASK, BMASK
parameter (ARGBMASK = Z'40000000')
parameter (RMASK = Z'00FF0000')
parameter (GMASK = Z'0000FF00')
parameter (BMASK = Z'000000FF')
parameter (ARGBMASK = int(Z'40000000'))
parameter (RMASK = int(Z'00FF0000'))
parameter (GMASK = int(Z'0000FF00'))
parameter (BMASK = int(Z'000000FF'))
! parameter (ARGBMASK = Z'40000000')
! parameter (RMASK = Z'00FF0000')
! parameter (GMASK = Z'0000FF00')
! parameter (BMASK = Z'000000FF')
real r, g, b, dist, mindist

if (iand(index, ARGBMASK).eq.0) then
Expand All @@ -31,8 +35,8 @@ integer function argb2ci(index)
mindist = 2e31
nearest = 0
do i=1,mol
r = (iand(index, RMASK) / Z'0000FFFF') / 255.
g = (iand(index, GMASK) / Z'000000FF') / 255.
r = (iand(index, RMASK) / int(Z'0000FFFF')) / 255.
g = (iand(index, GMASK) / int(Z'000000FF')) / 255.
b = (iand(index, BMASK)) / 255.

C we don't need absolute distance, so forego the sqrt operation...
Expand Down
4 changes: 2 additions & 2 deletions ni/src/lib/hlu/Format.c
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ NhlString _NhlFormatFloat
NGCALLF(cpinrc,CPINRC)();

{
int len1,len2,len3,len4;
long len1,len2,len3,len4;
NGstring cex1_f;
NGstring cex2_f;
NGstring cex3_f;
Expand Down Expand Up @@ -1283,7 +1283,7 @@ NhlErrorTypes _NhlGetScaleInfo
NGCALLF(cpinrc,CPINRC)();

{
int len1,len2,len3,len4;
long len1,len2,len3,len4;
NGstring cex1_f;
NGstring cex2_f;
NGstring cex3_f;
Expand Down
2 changes: 1 addition & 1 deletion ni/src/lib/nfpfort/yMakefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ FOBJS = aam.o areaAve.o areaAve2.o areaRmse.o areaRmse2.o areaSum2.o \
det_code42.o kmeans_kmns_as136.o spi3.o wrf_vinterp.o wrf_fctt.o \
wrf_write_wps.o pres_hybrid_jra55_dp.o relhum_ice.o relhum_water.o \
wetbulb_profs.o wrf_cloud_fracf.o mlegev_memory.o kernel_density.o \
meemd.o dpsort_large.o wrf_pw.o wrf_wind.o wrf_constants.o wrf_constants.mod
meemd.o dpsort_large.o wrf_pw.o wrf_wind.o wrf_constants.o

COBJS =

Expand Down