From e1d4e4cbf52f675a693d6654df4395ddb881cb98 Mon Sep 17 00:00:00 2001
From: "Mulas, Giacomo" <gmulas@oa-cagliari.inaf.it>
Date: Tue, 13 Feb 2024 10:26:41 +0100
Subject: [PATCH] pass library to make -c ../libnptm in all other Makefiles,
 add comments

---
 src/Makefile          | 4 ++--
 src/cluster/Makefile  | 3 ++-
 src/libnptm/Makefile  | 2 +-
 src/sphere/Makefile   | 3 ++-
 src/testing/Makefile  | 4 +++-
 src/trapping/Makefile | 3 ++-
 6 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/src/Makefile b/src/Makefile
index dd65769a..61a13c6f 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -9,8 +9,8 @@ override BUILDDIR_NPTM=$(BUILDDIR)/libnptm
 endif
 ifndef LIBNPTM
 # choose one of the two following lines, depending on whether a static or dynamic libnptm is wanted
-#override LIBNPTM=$(BUILDDIR_NPTM)/libnptm.a
-override LIBNPTM=$(BUILDDIR_NPTM)/libnptm.so
+override LIBNPTM=$(BUILDDIR_NPTM)/libnptm.a
+#override LIBNPTM=$(BUILDDIR_NPTM)/libnptm.so
 endif
 DOCSDIR=$(SRCDIR)/../doc
 
diff --git a/src/cluster/Makefile b/src/cluster/Makefile
index 7aa295bd..e3896764 100644
--- a/src/cluster/Makefile
+++ b/src/cluster/Makefile
@@ -31,7 +31,7 @@ $(OBJDIR):
 	mkdir -p $(OBJDIR)
 
 $(LIBNPTM):
-	$(MAKE) -C ../libnptm $@
+	BUILDDIR=$(BUILDDIR) BUILDDIR_NPTM=$(BUILDDIR_NPTM) LIBNPTM=$(LIBNPTM) $(MAKE) -C ../libnptm $@
 
 $(BUILDDIR_CLU):
 	mkdir -p $(BUILDDIR_CLU)
@@ -42,6 +42,7 @@ $(BUILDDIR_CLU)/clu: $(OBJDIR) $(OBJDIR)/clu.o $(BUILDDIR_CLU)
 $(BUILDDIR_CLU)/edfb_clu: $(OBJDIR) $(OBJDIR)/edfb_clu.o $(BUILDDIR_CLU)
 	$(FC) $(FCFLAGS) -o $(BUILDDIR_CLU)/edfb_clu $(OBJDIR)/edfb_clu.o $(LDFLAGS)
 
+# We put $(LIBNPTM) as an object to link in directly, so that it will be found at runtime even if it is a shared object library. May change in the future when we have an install: target
 $(BUILDDIR_CLU)/np_cluster: $(OBJDIR) $(CXX_CLU_OBJS) $(BUILDDIR_CLU) $(LIBNPTM)
 	$(CXX) $(CXXFLAGS) -o $(BUILDDIR_CLU)/np_cluster $(CXX_CLU_OBJS) $(LIBNPTM) $(CXXLDFLAGS) 
 
diff --git a/src/libnptm/Makefile b/src/libnptm/Makefile
index e7e4cdf1..33dfa35e 100644
--- a/src/libnptm/Makefile
+++ b/src/libnptm/Makefile
@@ -47,5 +47,5 @@ clean:
 wipe:
 	#echo "BUILDDIR_NPTM in libnptm is $(BUILDDIR_NPTM)"
 	#echo "LIBNPTM in libnptm is $(LIBNPTM)"
-	rm -f $(BUILDDIR_NPTM)/libnptm.a $(BUILDDIR_NPTM)/libnptm.so $(CXX_NPTM_OBJS) $(CXX_NPTM_DYNOBJS) 
+	rm -f $(BUILDDIR_NPTM)/libnptm.a $(BUILDDIR_NPTM)/libnptm.so $(CXX_NPTM_OBJS) $(CXX_NPTM_DYNOBJS)
 
diff --git a/src/sphere/Makefile b/src/sphere/Makefile
index a2b56691..d5f9e499 100644
--- a/src/sphere/Makefile
+++ b/src/sphere/Makefile
@@ -30,7 +30,7 @@ $(OBJDIR):
 	mkdir -p $(OBJDIR)
 
 $(LIBNPTM):
-	$(MAKE) -C ../libnptm $@
+	BUILDDIR=$(BUILDDIR) BUILDDIR_NPTM=$(BUILDDIR_NPTM) LIBNPTM=$(LIBNPTM) $(MAKE) -C ../libnptm $@
 
 $(BUILDDIR_SPH):
 	mkdir -p $(BUILDDIR_SPH)
@@ -41,6 +41,7 @@ $(BUILDDIR_SPH)/edfb_sph: $(OBJDIR) $(OBJDIR)/edfb_sph.o $(BUILDDIR_SPH)
 $(BUILDDIR_SPH)/sph: $(OBJDIR) $(OBJDIR)/sph.o $(BUILDDIR_SPH)
 	$(FC) $(FCFLAGS) -o $(BUILDDIR_SPH)/sph $(OBJDIR)/sph.o $(LDFLAGS)
 
+# We put $(LIBNPTM) as an object to link in directly, so that it will be found at runtime even if it is a shared object library. May change in the future when we have an install: target
 $(BUILDDIR_SPH)/np_sphere: $(OBJDIR) $(CXX_SPH_OBJS) $(BUILDDIR_SPH) $(LIBNPTM)
 	$(CXX) $(CXXFLAGS) -o $(BUILDDIR_SPH)/np_sphere $(CXX_SPH_OBJS) $(LIBNPTM) $(CXXLDFLAGS) 
 
diff --git a/src/testing/Makefile b/src/testing/Makefile
index 4e3f4abe..88d265d8 100644
--- a/src/testing/Makefile
+++ b/src/testing/Makefile
@@ -29,14 +29,16 @@ $(OBJDIR):
 	mkdir -p $(OBJDIR)
 
 $(LIBNPTM):
-	$(MAKE) -C ../libnptm $@
+	BUILDDIR=$(BUILDDIR) BUILDDIR_NPTM=$(BUILDDIR_NPTM) LIBNPTM=$(LIBNPTM) $(MAKE) -C ../libnptm $@
 
 $(BUILDDIR_TEST):
 	mkdir -p $(BUILDDIR_TEST)
 
+# We put $(LIBNPTM) as an object to link in directly, so that it will be found at runtime even if it is a shared object library. May change in the future when we have an install: target
 $(BUILDDIR_TEST)/test_TEDF: $(OBJDIR) $(CXX_TEDF_OBJS) $(BUILDDIR_TEST) $(LIBNPTM)
 	$(CXX) $(CXXFLAGS) -o $(BUILDDIR_TEST)/test_TEDF $(CXX_TEDF_OBJS) $(LIBNPTM) $(CXXLDFLAGS) 
 
+# We put $(LIBNPTM) as an object to link in directly, so that it will be found at runtime even if it is a shared object library. May change in the future when we have an install: target
 $(BUILDDIR_TEST)/test_TTMS: $(OBJDIR) $(CXX_TTMS_OBJS) $(BUILDDIR_TEST) $(LIBNPTM)
 	$(CXX) $(CXXFLAGS) -o $(BUILDDIR_TEST)/test_TTMS $(CXX_TTMS_OBJS) $(LIBNPTM) $(CXXLDFLAGS) 
 
diff --git a/src/trapping/Makefile b/src/trapping/Makefile
index 624a0607..ec6059e8 100644
--- a/src/trapping/Makefile
+++ b/src/trapping/Makefile
@@ -29,7 +29,7 @@ $(OBJDIR):
 	mkdir -p $(OBJDIR)
 
 $(LIBNPTM):
-	$(MAKE) -C ../libnptm $@
+	BUILDDIR=$(BUILDDIR) BUILDDIR_NPTM=$(BUILDDIR_NPTM) LIBNPTM=$(LIBNPTM) $(MAKE) -C ../libnptm $@
 
 $(BUILDDIR_TRA):
 	mkdir -p $(BUILDDIR_TRA)
@@ -40,6 +40,7 @@ $(BUILDDIR_TRA)/frfme: $(OBJDIR) $(OBJDIR)/frfme.o $(BUILDDIR_TRA)
 $(BUILDDIR_TRA)/lffft: $(OBJDIR) $(OBJDIR)/lffft.o $(BUILDDIR_TRA)
 	$(FC) $(FCFLAGS) -o $(BUILDDIR_TRA)/lffft $(OBJDIR)/lffft.o $(LDFLAGS)
 
+# We put $(LIBNPTM) as an object to link in directly, so that it will be found at runtime even if it is a shared object library. May change in the future when we have an install: target
 $(BUILDDIR_TRA)/np_trapping: $(OBJDIR) $(CXX_TRAP_OBJS) $(BUILDDIR_TRA) $(LIBNPTM)
 	$(CXX) $(CXXFLAGS) -o $(BUILDDIR_TRA)/np_trapping $(CXX_TRAP_OBJS) $(LIBNPTM) $(CXXLDFLAGS) 
 
-- 
GitLab