diff --git a/install/DEFAULTS.inc b/install/DEFAULTS.inc index e0ff8be1d..dfb9024bd 100644 --- a/install/DEFAULTS.inc +++ b/install/DEFAULTS.inc @@ -440,6 +440,10 @@ else $(error "Unsupported C compiler. Must set environment variable CC to a C compiler (e.g. gcc, icc, pgcc)") endif +# Pass the selected toolchain to dependency configure scripts and sub-makes. +export FC CC +export F77 = $(FC) + # List of needed dependencies, will be appended if math or netcdf # libraries are not found NEEDED_DEPS = @@ -560,6 +564,14 @@ else endif endif +# Embed the configured netcdf library directories for runtime lookup. +# These paths must remain available when running the executables. +NETCDF_RPATH = -Wl,-rpath,$(NETCDFDIR) +ifneq ($(NETCDF_C_DIR),$(NETCDFDIR)) + NETCDF_RPATH += -Wl,-rpath,$(NETCDF_C_DIR) +endif +NETCDF_EXTRA_LIBS += $(NETCDF_RPATH) + # Intel specifics #---------------- # include compiler specific libs for intel fast moves diff --git a/install/TARGETS.inc b/install/TARGETS.inc index b596e8c0a..e20d93276 100644 --- a/install/TARGETS.inc +++ b/install/TARGETS.inc @@ -44,7 +44,7 @@ netcdf-c: v hdf5 if [ ! -f ../deps/src/netcdf-c/Makefile ]; then \ cd ../deps/src/netcdf-c; \ CPPFLAGS="-I$(realpath $(DEPSINSTALLDIR))/include" \ - LDFLAGS="-L$(realpath $(DEPSINSTALLDIR))/lib" \ + LDFLAGS="-L$(realpath $(DEPSINSTALLDIR))/lib -Wl,-rpath,$(realpath $(DEPSINSTALLDIR))/lib" \ ./configure --prefix=$(realpath $(DEPSINSTALLDIR)); \ fi cd ../deps/src/netcdf-c; \ @@ -57,7 +57,7 @@ netcdf-fortran: v netcdf-c if [ ! -f ../deps/src/netcdf-fortran/Makefile ]; then \ cd ../deps/src/netcdf-fortran; \ CPPFLAGS="-I$(realpath $(DEPSINSTALLDIR))/include" \ - LDFLAGS="-L$(realpath $(DEPSINSTALLDIR))/lib" \ + LDFLAGS="-L$(realpath $(DEPSINSTALLDIR))/lib -Wl,-rpath,$(realpath $(DEPSINSTALLDIR))/lib" \ ./configure --prefix=$(realpath $(DEPSINSTALLDIR)); \ fi cd ../deps/src/netcdf-fortran; \ @@ -69,6 +69,7 @@ hdf5: v cd ../; git submodule update --init deps/src/hdf5; if [ ! -f ../deps/src/hdf5/Makefile ]; then \ cd ../deps/src/hdf5; \ + LDFLAGS="-Wl,-rpath,$(realpath $(DEPSINSTALLDIR))/lib" \ ./configure --prefix=$(realpath $(DEPSINSTALLDIR)); \ fi cd ../deps/src/hdf5; \ diff --git a/install/makefile b/install/makefile index 056de2ab6..46e02b303 100644 --- a/install/makefile +++ b/install/makefile @@ -103,19 +103,23 @@ clear: cd ../docs/examples/solovev_kinetic_example; rm -f *.out *.bin *.nc cd ../docs/examples/solovev_resistive_example; rm -f *.out *.bin *.nc *.dat -# Revert to clean state +# Remove build products and dependency configuration before switching compilers. +# Dependency sources stay in ../deps/src; custom install prefixes are respected. realclean: clean clear rm -rf ../deps/lib/* ../deps/hdf5 ../deps/include/* ../deps/bin/* ../deps/share ../bin if [ -f ../deps/src/OpenBLAS/Makefile ]; then cd ../deps/src/OpenBLAS && make clean; fi - if [ -f ../deps/src/hdf5/Makefile ]; then cd ../deps/src/hdf5 && make clean; fi - if [ -f ../deps/src/netcdf-c/Makefile ]; then cd ../deps/src/netcdf-c && make clean; fi - if [ -f ../deps/src/netcdf-fortran/Makefile ]; then cd ../deps/src/netcdf-fortran && make clean; fi + if [ -f ../deps/src/hdf5/Makefile ]; then cd ../deps/src/hdf5 && $(MAKE) distclean; fi + if [ -f ../deps/src/netcdf-c/Makefile ]; then cd ../deps/src/netcdf-c && $(MAKE) distclean; fi + if [ -f ../deps/src/netcdf-fortran/Makefile ]; then cd ../deps/src/netcdf-fortran && $(MAKE) distclean; fi + rm -f "$(DEPSINSTALLDIR)"/lib/libnetcdf* "$(DEPSINSTALLDIR)"/lib/libhdf5* \ + "$(DEPSINSTALLDIR)"/include/netcdf*.mod "$(DEPSINSTALLDIR)"/include/typesizes.mod # Dependency graph (DEPENDENCIES.inc) maintenance. # Building GPEC never needs these -- DEPENDENCIES.inc is committed. They are # only for regenerating it when source USE/MODULE relationships change, and # require python3 (used by maintainers and the CI deps job, not end users). PYTHON ?= python3 + .PHONY: deps checkdeps deps: $(PYTHON) gen_deps.py > DEPENDENCIES.inc