Skip to content

Commit

Permalink
Improve stand-alone build tie-in to netCDF
Browse files Browse the repository at this point in the history
I needed to use homebrew to install netCDF on my laptop for a different project
and the way homebrew distributed the library and include files didn't play nice
with the old system... so now the first thing CVMix does is look for nc-config
to determine both the include directory and the linking flags. If that
information isn't available, it reverts back to the old build.
  • Loading branch information
mnlevy1981 committed Mar 24, 2015
1 parent afac94a commit b1f892c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 29 deletions.
29 changes: 21 additions & 8 deletions bld/cvmix_setup
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,35 @@ if have_compiler + have_netcdf != 2:
# For now, just need fortran compiler and netCDF location / flags
if have_compiler == 0:
compiler = raw_input('Fortran compiler (mpi not necessary): ')

netcdf_bin = ""
netcdf_inc = ""
netcdf_lib = ""
if have_netcdf == 0:
netcdf_dir = raw_input('Directory containing netcdf (enter "need_both" to enter netcdf include directory and netcdf lib directory separately): ')
if netcdf_dir == "need_both":
netcdf_inc = raw_input('netCDF/include location: ')
netcdf_lib = raw_input('netCDF/lib location: ')
netcdf_dir = raw_input('Directory containing netcdf configuration tool nc-config (or enter "no-nc-config" to enter location of netcdf include and netcdf lib directories): ')
if netcdf_dir == "no-nc-config":
netcdf_dir = raw_input('Directory containing netcdf (enter "need_both" to enter netcdf include directory and netcdf lib directory separately): ')
if netcdf_dir == "need_both":
netcdf_inc = raw_input('netCDF/include location: ')
netcdf_lib = raw_input('netCDF/lib location: ')
else:
netcdf_inc = netcdf_dir+"/include"
netcdf_lib = netcdf_dir+"/lib"
else:
netcdf_inc = netcdf_dir+"/include"
netcdf_lib = netcdf_dir+"/lib"
netcdf_bin = netcdf_dir
else:
netcdf_inc = netcdf_dir+"/include"
netcdf_lib = netcdf_dir+"/lib"
netcdf_bin = netcdf_dir+"/bin"

if have_compiler + have_netcdf != 2:
print "Writing environment settings to " + filename

fid = open(filename, 'w')
fid.write("FC = " + compiler+"\n")
fid.write("NETCDF_INC = " + netcdf_inc+"\n")
fid.write("NETCDF_LIB = " + netcdf_lib+"\n")
if netcdf_bin != "":
fid.write("NETCDF_BIN = " + netcdf_bin+"\n")
if netcdf_inc != "":
fid.write("NETCDF_INC = " + netcdf_inc+"\n")
if netcdf_lib != "":
fid.write("NETCDF_LIB = " + netcdf_lib+"\n")
51 changes: 30 additions & 21 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,31 +68,40 @@ ifeq ($(USE_NETCDF),TRUE)
else
FCFLAGS += -D_NETCDF
endif
ifeq ($(wildcard $(NETCDF_BIN)/nc-config),)
# If $(NETCDF_BIN)/nc-config exists, we will use it to determine both the
# compile flags and linking flags needed, otherwise we depend on the
# directories $(NETCDF_INC) and $(NETCDF_LIB)
FCFLAGS += -I$(NETCDF_INC)
# Check for netcdf4 library
ifeq ($(wildcard $(NETCDF_LIB)/libnetcdff.a),)
LINKING_FLAGS += -L$(NETCDF_LIB) -lnetcdf
else
# with netcdf4, need to know whether to include hdf5 or not
# That comes from $(NETCDF_LIB)/pkgconfig/netcdf.pc
# (Note: some distributions now have netcdf-fortran.pc in addition to
# netcdf.pc... so check for netcdf-fortran.pc first)
NETCDF_PC = $(NETCDF_LIB)/pkgconfig/netcdf-fortran.pc
ifeq ($(wildcard $(NETCDF_PC)),)
NETCDF_PC = $(NETCDF_LIB)/pkgconfig/netcdf.pc
endif
ifeq ($(wildcard $(NETCDF_PC)),)
LINKING_FLAGS += -L$(NETCDF_LIB) -lnetcdff -lnetcdf
# Check for netcdf4 library
ifeq ($(wildcard $(NETCDF_LIB)/libnetcdff.a),)
LINKING_FLAGS += -L$(NETCDF_LIB) -lnetcdf
else
# get flibs from netcdf.pc
FLIBS = $(subst flibs=,,$(shell grep flibs $(NETCDF_PC)))
# Workaround for yellowstone, I need to figure out where this
# @NC_FLIBS@ comes from
ifeq ($(FLIBS),@NC_FLIBS@)
FLIBS = -lnetcdf
# with netcdf4, need to know whether to include hdf5 or not
# That comes from either $(NETCDF_BIN)/nc-config or from
# $(NETCDF_LIB)/pkgconfig/netcdf.pc
# (Note: some distributions now have netcdf-fortran.pc in addition to
# netcdf.pc... so check for netcdf-fortran.pc first)
NETCDF_PC = $(NETCDF_LIB)/pkgconfig/netcdf-fortran.pc
ifeq ($(wildcard $(NETCDF_PC)),)
NETCDF_PC = $(NETCDF_LIB)/pkgconfig/netcdf.pc
endif
ifeq ($(wildcard $(NETCDF_PC)),)
LINKING_FLAGS += -L$(NETCDF_LIB) -lnetcdff -lnetcdf
else
# get flibs from netcdf.pc
FLIBS = $(subst flibs=,,$(shell grep flibs $(NETCDF_PC)))
# Workaround for yellowstone, I need to figure out where this
# @NC_FLIBS@ comes from
ifeq ($(FLIBS),@NC_FLIBS@)
FLIBS = -lnetcdf
endif
LINKING_FLAGS += -L$(NETCDF_LIB) $(FLIBS)
endif
LINKING_FLAGS += -L$(NETCDF_LIB) $(FLIBS)
endif
else
LINKING_FLAGS += $(shell $(NETCDF_BIN)/nc-config --flibs)
FCFLAGS += -I$(shell $(NETCDF_BIN)/nc-config --includedir)
endif
NEW_NETCDF = YES
else
Expand Down

0 comments on commit b1f892c

Please sign in to comment.