1- # Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC.
2- # Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707.
3- # All Rights reserved. See files LICENSE and NOTICE for details.
1+ # Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
2+ # All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
43#
5- # This file is part of CEED, a collection of benchmarks, miniapps, software
6- # libraries and APIs for efficient high-order finite element and spectral
7- # element discretizations for exascale applications. For more information and
8- # source code availability see http://github.com/ceed
4+ # SPDX-License-Identifier: BSD-2-Clause
95#
10- # The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
11- # a collaborative effort of two U.S. Department of Energy organizations (Office
12- # of Science and the National Nuclear Security Administration) responsible for
13- # the planning and preparation of a capable exascale ecosystem, including
14- # software, applications, hardware, advanced system engineering and early
15- # testbed platforms, in support of the nation's exascale computing imperative.
6+ # This file is part of CEED: http://github.com/ceed
167
178CONFIG ?= config.mk
189-include $(CONFIG )
@@ -45,7 +36,13 @@ SED ?= sed
4536# ASAN must be left empty if you don't want to use it
4637ASAN ?=
4738
48- LDFLAGS ?=
39+ # These are the values automatically detected here in the makefile. They are
40+ # augmented with LDFLAGS and LDLIBS from the environment/passed by command line,
41+ # if any. If the user sets CEED_LDFLAGS or CEED_LDLIBS, they are used *instead
42+ # of* what we populate here (thus that's advanced usage and not recommended).
43+ CEED_LDFLAGS ?=
44+ CEED_LDLIBS ?=
45+
4946UNDERSCORE ?= 1
5047
5148# Verbose mode, V or VERBOSE
@@ -145,14 +142,14 @@ FFLAGS ?= $(OPT) $(FFLAGS.$(FC_VENDOR))
145142ifeq ($(COVERAGE ) , 1)
146143 CFLAGS += --coverage
147144 CXXFLAGS += --coverage
148- LDFLAGS += --coverage
145+ CEED_LDFLAGS += --coverage
149146endif
150147
151148CFLAGS += $(if $(ASAN ) ,$(AFLAGS ) )
152149FFLAGS += $(if $(ASAN ) ,$(AFLAGS ) )
153- LDFLAGS += $(if $(ASAN ) ,$(AFLAGS ) )
150+ CEED_LDFLAGS += $(if $(ASAN ) ,$(AFLAGS ) )
154151CPPFLAGS += -I./include
155- LDLIBS = -lm
152+ CEED_LDLIBS = -lm
156153OBJDIR := build
157154LIBDIR := lib
158155
@@ -275,8 +272,8 @@ info:
275272 $(info FFLAGS = $(value FFLAGS) )
276273 $(info NVCCFLAGS = $(value NVCCFLAGS) )
277274 $(info HIPCCFLAGS = $(value HIPCCFLAGS) )
278- $(info LDFLAGS = $(value LDFLAGS ) )
279- $(info LDLIBS = $(LDLIBS ) )
275+ $(info CEED_LDFLAGS = $(value CEED_LDFLAGS ) )
276+ $(info CEED_LDLIBS = $(value CEED_LDLIBS ) )
280277 $(info AR = $(AR ) )
281278 $(info ARFLAGS = $(ARFLAGS ) )
282279 $(info OPT = $(OPT ) )
@@ -309,7 +306,7 @@ info-backends-all:
309306 $(info make: 'lib' with backends: $(filter-out $(TEST_BACKENDS ) ,$(BACKENDS ) ) )
310307 @true
311308
312- $(libceed.so ) : LDFLAGS += $(if $(DARWIN ) , -install_name @rpath/$(notdir $(libceed.so ) ) )
309+ $(libceed.so ) : CEED_LDFLAGS += $(if $(DARWIN ) , -install_name @rpath/$(notdir $(libceed.so ) ) )
313310
314311# Standard Backends
315312libceed.c += $(ref.c )
@@ -339,6 +336,8 @@ endif
339336
340337# Collect list of libraries and paths for use in linking and pkg-config
341338PKG_LIBS =
339+ # Stubs that will not be RPATH'd
340+ PKG_STUBS_LIBS =
342341
343342# libXSMM Backends
344343XSMM_BACKENDS = /cpu/self/xsmm/serial /cpu/self/xsmm/blocked
@@ -386,6 +385,7 @@ CUDA_BACKENDS = /gpu/cuda/ref /gpu/cuda/shared /gpu/cuda/gen
386385ifneq ($(CUDA_LIB_DIR ) ,)
387386 $(libceeds ) : CPPFLAGS += -I$(CUDA_DIR ) /include
388387 PKG_LIBS += -L$(abspath $(CUDA_LIB_DIR ) ) -lcudart -lnvrtc -lcuda -lcublas
388+ PKG_STUBS_LIBS += -L$(CUDA_LIB_DIR_STUBS )
389389 LIBCEED_CONTAINS_CXX = 1
390390 libceed.c += interface/ceed-cuda.c
391391 libceed.c += $(cuda.c ) $(cuda-ref.c ) $(cuda-shared.c ) $(cuda-gen.c )
@@ -458,18 +458,18 @@ export BACKENDS
458458
459459_pkg_ldflags = $(filter -L% ,$(PKG_LIBS ) )
460460_pkg_ldlibs = $(filter-out -L% ,$(PKG_LIBS ) )
461- $(libceeds ) : LDFLAGS += $(_pkg_ldflags ) $(_pkg_ldflags:-L%=-Wl,-rpath,% )
462- $(libceeds ) : LDLIBS += $(_pkg_ldlibs )
461+ $(libceeds ) : CEED_LDFLAGS += $(_pkg_ldflags ) $(_pkg_ldflags:-L%=-Wl,-rpath,% ) $( PKG_STUBS_LIBS )
462+ $(libceeds ) : CEED_LDLIBS += $(_pkg_ldlibs )
463463ifeq ($(STATIC ) ,1)
464- $(examples ) $(tests ) : LDFLAGS += $(_pkg_ldflags ) $(_pkg_ldflags:-L%=-Wl,-rpath,% )
465- $(examples ) $(tests ) : LDLIBS += $(_pkg_ldlibs )
464+ $(examples ) $(tests ) : CEED_LDFLAGS += $(_pkg_ldflags ) $(_pkg_ldflags:-L%=-Wl,-rpath,% ) $( PKG_STUBS_LIBS )
465+ $(examples ) $(tests ) : CEED_LDLIBS += $(_pkg_ldlibs )
466466endif
467467
468468pkgconfig-libs-private = $(PKG_LIBS )
469469ifeq ($(LIBCEED_CONTAINS_CXX ) ,1)
470470 $(libceeds ) : LINK = $(CXX )
471471 ifeq ($(STATIC),1)
472- $(examples ) $(tests ) : LDLIBS += $(LIBCXX )
472+ $(examples ) $(tests ) : CEED_LDLIBS += $(LIBCXX )
473473 pkgconfig-libs-private += $(LIBCXX )
474474 endif
475475endif
@@ -482,7 +482,7 @@ libceed.o = $(libceed.c:%.c=$(OBJDIR)/%.o) $(libceed.cpp:%.cpp=$(OBJDIR)/%.o) $(
482482$(filter % fortran.o,$(libceed.o ) ) : CPPFLAGS += $(if $(filter 1,$(UNDERSCORE ) ) ,-DUNDERSCORE)
483483$(libceed.o ) : | info-backends
484484$(libceed.so ) : $(call weak_last,$(libceed.o ) ) | $$(@D ) /.DIR
485- $(call quiet,LINK) $(LDFLAGS ) -shared -o $@ $^ $(LDLIBS )
485+ $(call quiet,LINK) $(LDFLAGS ) $( CEED_LDFLAGS ) -shared -o $@ $^ $( CEED_LDLIBS ) $(LDLIBS )
486486
487487$(libceed.a ) : $(call weak_last,$(libceed.o ) ) | $$(@D ) /.DIR
488488 $(call quiet,AR) $(ARFLAGS ) $@ $^
@@ -500,16 +500,16 @@ $(OBJDIR)/%.o : $(CURDIR)/%.hip.cpp | $$(@D)/.DIR
500500 $(call quiet,HIPCC) $(HIPCCFLAGS ) -c -o $@ $(abspath $< )
501501
502502$(OBJDIR ) /% : tests/% .c | $$(@D ) /.DIR
503- $(call quiet,LINK.c) $(CEED_LDFLAGS ) -o $@ $(abspath $< ) $(CEED_LIBS ) $(LDLIBS )
503+ $(call quiet,LINK.c) $(CEED_LDFLAGS ) -o $@ $(abspath $< ) $(CEED_LIBS ) $(CEED_LDLIBS ) $( LDLIBS )
504504
505505$(OBJDIR ) /% : tests/% .f90 | $$(@D ) /.DIR
506- $(call quiet,LINK.F) -DSOURCE_DIR=' "$(abspath $(<D))/"' $(CEED_LDFLAGS ) -o $@ $(abspath $< ) $(CEED_LIBS ) $(LDLIBS )
506+ $(call quiet,LINK.F) -DSOURCE_DIR=' "$(abspath $(<D))/"' $(CEED_LDFLAGS ) -o $@ $(abspath $< ) $(CEED_LIBS ) $(CEED_LDLIBS ) $( LDLIBS )
507507
508508$(OBJDIR ) /% : examples/ceed/% .c | $$(@D ) /.DIR
509- $(call quiet,LINK.c) $(CEED_LDFLAGS ) -o $@ $(abspath $< ) $(CEED_LIBS ) $(LDLIBS )
509+ $(call quiet,LINK.c) $(CEED_LDFLAGS ) -o $@ $(abspath $< ) $(CEED_LIBS ) $(CEED_LDLIBS ) $( LDLIBS )
510510
511511$(OBJDIR ) /% : examples/ceed/% .f | $$(@D ) /.DIR
512- $(call quiet,LINK.F) -DSOURCE_DIR=' "$(abspath $(<D))/"' $(CEED_LDFLAGS ) -o $@ $(abspath $< ) $(CEED_LIBS ) $(LDLIBS )
512+ $(call quiet,LINK.F) -DSOURCE_DIR=' "$(abspath $(<D))/"' $(CEED_LDFLAGS ) -o $@ $(abspath $< ) $(CEED_LIBS ) $(CEED_LDLIBS ) $( LDLIBS )
513513
514514$(OBJDIR ) /mfem-% : examples/mfem/% .cpp $(libceed ) | $$(@D ) /.DIR
515515 +$(MAKE ) -C examples/mfem CEED_DIR=` pwd` \
@@ -553,7 +553,7 @@ $(OBJDIR)/solids-% : examples/solids/%.c examples/solids/%.h \
553553
554554$(examples ) : $(libceed )
555555$(tests ) : $(libceed )
556- $(tests ) $(examples ) : LDFLAGS += -Wl,-rpath,$(abspath $(LIBDIR ) ) -L$(LIBDIR )
556+ $(tests ) $(examples ) : override LDFLAGS += -Wl,-rpath,$(abspath $(LIBDIR ) ) -L$(LIBDIR )
557557
558558run-% : $(OBJDIR ) /%
559559 @tests/tap.sh $(<:$(OBJDIR ) /%=% )
0 commit comments