Skip to content

Commit

Permalink
Fix LDFLAGS definition and usage
Browse files Browse the repository at this point in the history
`ld` flags are currently specified incorrectly. For example:
1. `-lnetcdf` is not required since it is a dependency of the netCDF
Fortran library - only `-lnetcdff` is needed.
2. `ld` flags are being split across two variables: `LDFLAGS` and `LD`
when there should only be one (`LD` typically refers to the path  to the
`ld` executable). Having the flags split across two variables allows for
the flags to be passed to the compiler in an inconsistent way.
See #198 for more details.

This change removes the `LD` variable and any hard-coded linker flags or
include flags in the Makefile or build script. Linker flags and include
flags are replaced with a query to `pkg-config` so that the build system
is insulated from changes to library versions and dependencies.

Fixes #198
  • Loading branch information
SeanBryan51 committed Jan 23, 2024
1 parent d141d9c commit a13c268
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
7 changes: 2 additions & 5 deletions src/offline/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,6 @@ PROG_MPI = cable-mpi
# from the compiled object files
OBJS := ${LSRC:.F90=.o}

#compiler switches and flags
CINC = -I$(NCMOD)

#suffixes we use
.SUFFIXES:
.SUFFIXES: .F90 .o
Expand All @@ -162,11 +159,11 @@ SUPPRESS_FLAGS := -warn nostderrors -diag-disable 10145
# the first target is the default target
.PHONY: serial
serial: cable_driver.F90 $(OBJS)
$(FC) $(SUPPRESS_FLAGS) $(CFLAGS) $(LDFLAGS) $(LD) -o $(PROG_SERIAL) $^ $(CINC)
$(FC) $(SUPPRESS_FLAGS) $(CFLAGS) -o $(PROG_SERIAL) $^ $(CINC) $(LDFLAGS)

.PHONY: mpi
mpi: cable_mpidrv.F90 cable_mpicommon.o cable_mpimaster.o cable_mpiworker.o pop_mpi.o $(OBJS)
$(FC) $(SUPPRESS_FLAGS) $(CFLAGS) $(LDFLAGS) -o $(PROG_MPI) $^ $(CINC) $(LD)
$(FC) $(SUPPRESS_FLAGS) $(CFLAGS) -o $(PROG_MPI) $^ $(CINC) $(LDFLAGS)

cable_mpicommon.o: cable_mpicommon.F90 $(OBJS)
pop_mpi.o: pop_mpi.F90 cable_mpicommon.o $(OBJS)
Expand Down
19 changes: 12 additions & 7 deletions src/offline/build3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,20 @@ host_gadi()
module purge
module add intel-compiler/2019.5.281
module add netcdf/4.6.3
# This is required so that the netcdf-fortran library is discoverable by
# pkg-config:
module prepend-path PKG_CONFIG_PATH "${NETCDF_BASE}/lib/Intel/pkgconfig/"

if ! pkg-config --exists netcdf-fortran; then
echo ''
echo 'Unable to find netcdf-fortran via pkg-config. Exiting...'
echo ''
exit 1
fi

export NCDIR=$NETCDF_ROOT'/lib/Intel'
export NCMOD=$NETCDF_ROOT'/include/Intel'
export CFLAGS='-O2 -fp-model precise '
export LDFLAGS='-L'$NCDIR
export LD='-lnetcdf -lnetcdff'
export LDFLAGS=`pkg-config --libs netcdf-fortran`
export CINC=`pkg-config --cflags netcdf-fortran`

if [[ $1 = 'mpi' ]]; then
module add intel-mpi/2019.5.281
Expand Down Expand Up @@ -144,9 +152,6 @@ build_status()
echo ''
echo 'Oooops. Something went wrong'
echo ''
echo 'Other than compiler messages, known build issues:'
echo 'Some systems require additional library. '
echo 'e.g. Edit Makefile; add -lnetcdff to LD = ...'
fi
exit
}
Expand Down

0 comments on commit a13c268

Please sign in to comment.