Skip to content

Commit

Permalink
Consolidate preload logic. Implement logic into preload.sh to cater to
Browse files Browse the repository at this point in the history
Darwin issues with empty incoming DYLD_INSERT_LIBRARIES variable.
  • Loading branch information
theurich committed Oct 23, 2023
1 parent 48daf2c commit 717d979
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions build/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -1148,14 +1148,10 @@ ifeq ($(ESMF_OS),MinGW)
ESMF_LIB_SUFFIX = lib
endif

# - Shared library and preload environment variable
# - Shared library
ESMF_SL_SUFFIX = so
ESMF_PRELOAD = LD_PRELOAD
ESMF_PRELOAD_DELIMIT = ' '
ifeq ($(ESMF_OS),Darwin)
ESMF_SL_SUFFIX = dylib
ESMF_PRELOAD = DYLD_INSERT_LIBRARIES
ESMF_PRELOAD_DELIMIT = ':'
endif
ifeq ($(ESMF_OS),Cygwin)
ESMF_SL_SUFFIX = dll.a
Expand Down Expand Up @@ -2027,9 +2023,11 @@ ESMF_TRACE_LDPRELOAD := $(ESMF_LIBDIR)/libesmftrace_preload.$(ESMF_SL_SUFFIX)
ESMF_PRELOADSCRIPT = $(ESMF_LIBDIR)/preload.sh

ifneq ($(ESMF_OS),Darwin)
ESMF_ENV_PRELOAD = LD_PRELOAD
ESMF_ENV_PRELOAD = LD_PRELOAD
ESMF_ENV_PRELOAD_DELIMIT = ' '
else
ESMF_ENV_PRELOAD = DYLD_INSERT_LIBRARIES
ESMF_ENV_PRELOAD = DYLD_INSERT_LIBRARIES
ESMF_ENV_PRELOAD_DELIMIT = ':'
endif

# MPI implementations do not pick up LD_PRELOAD
Expand All @@ -2052,7 +2050,11 @@ endif
build_preload_script:
-@echo "#!/bin/sh" > $(ESMF_PRELOADDIR)/preload.sh
-@echo "# Script to preload ESMF dynamic trace library" >> $(ESMF_PRELOADDIR)/preload.sh
-@echo 'env $(ESMF_PRELOAD)="$$$(ESMF_PRELOAD)$(ESMF_PRELOAD_DELIMIT)$(ESMF_PRELOADDIR)/libesmftrace_preload.$(ESMF_SL_SUFFIX)" $$*' >> $(ESMF_PRELOADDIR)/preload.sh
-@echo 'if [ "$(ESMF_ENV_PRELOAD)" != "" ]; then' >> $(ESMF_PRELOADDIR)/preload.sh
-@echo 'env $(ESMF_ENV_PRELOAD)="$$$(ESMF_ENV_PRELOAD)$(ESMF_ENV_PRELOAD_DELIMIT)$(ESMF_PRELOADDIR)/libesmftrace_preload.$(ESMF_SL_SUFFIX)" $$*' >> $(ESMF_PRELOADDIR)/preload.sh
-@echo 'else' >> $(ESMF_PRELOADDIR)/preload.sh
-@echo 'env $(ESMF_ENV_PRELOAD)="$(ESMF_PRELOADDIR)/libesmftrace_preload.$(ESMF_SL_SUFFIX)" $$*' >> $(ESMF_PRELOADDIR)/preload.sh
-@echo 'fi' >> $(ESMF_PRELOADDIR)/preload.sh
chmod 755 $(ESMF_PRELOADDIR)/preload.sh

ESMF_TRACE_STATICLINKLIBS := -lesmftrace_static
Expand Down

0 comments on commit 717d979

Please sign in to comment.