From b44650f9dec49e44c9b8d10e9b4c7f6ccbfd83a4 Mon Sep 17 00:00:00 2001
From: Andreas Beckmann <anbe@debian.org>
Date: Mon, 19 Feb 2024 15:41:46 +0100
Subject: [PATCH] fix Makefiles for installed tests

---
 src/Makefile.inc                             |  5 ++++-
 src/components/Makefile                      |  6 +++++
 src/components/Makefile_comp_tests           | 23 --------------------
 src/components/Makefile_comp_tests.target.in |  8 +++----
 src/components/sde/tests/Makefile            |  2 +-
 src/ctests/Makefile                          | 15 +++----------
 src/ctests/Makefile.target.in                | 19 +++++++++++-----
 src/ftests/Makefile                          |  8 +++----
 src/ftests/Makefile.target.in                | 12 ++++++----
 src/testlib/Makefile                         |  2 +-
 src/validation_tests/Makefile                |  8 +++----
 src/validation_tests/Makefile.target.in      | 12 ++++++----
 12 files changed, 54 insertions(+), 66 deletions(-)
 create mode 100644 src/components/Makefile
 delete mode 100644 src/components/Makefile_comp_tests

diff --git a/src/Makefile.inc b/src/Makefile.inc
index c116239ae..4666f408b 100644
--- a/src/Makefile.inc
+++ b/src/Makefile.inc
@@ -245,7 +245,7 @@ clean: native_clean
 clobber distclean: clean native_clobber 
 	$(MAKE) -C ../doc distclean
 	$(MAKE) -C utils distclean
-	$(MAKE) -C components -f Makefile_comp_tests distclean
+	$(MAKE) -C components distclean
 	rm -f $(LIBRARY) $(SHLIB) $(EXTRALIBS) Makefile config.h libpapi.so sde_lib/libsde.so* sde_lib/libsde.a libsde.so libsde.a papi.pc components_config.h papi_components_config_event_defs.h $(PAPI_EVENTS_TABLE)
 	$(if ${COMPONENTS}, \
 		set -ex; for comp in ${COMPONENTS}; do \
@@ -339,6 +339,9 @@ install-tests:  install-comp_tests
 # Component tests installing
 install-comp_tests:
 ifneq (${COMPONENTS},)
+	mkdir -p $(DESTDIR)$(DATADIR)/components
+	cp components/Makefile_comp_tests.target $(DESTDIR)$(DATADIR)/components
+	sed -i '/^PAPILIBDIR/s/=.*/= $$(LIBDIR)/' $(DESTDIR)$(DATADIR)/components/Makefile_comp_tests.target
 	@set -ex; for comp in ${COMPONENTS} ; do \
 		$(MAKE) -C components/$$comp/tests DATADIR="$(DESTDIR)$(DATADIR)/components" install ; \
 	done
diff --git a/src/components/Makefile b/src/components/Makefile
new file mode 100644
index 000000000..bee5ade00
--- /dev/null
+++ b/src/components/Makefile
@@ -0,0 +1,6 @@
+all:
+
+clean:
+
+distclean clobber: clean
+	rm -f Makefile_comp_tests.target
diff --git a/src/components/Makefile_comp_tests b/src/components/Makefile_comp_tests
deleted file mode 100644
index afbe9a545..000000000
--- a/src/components/Makefile_comp_tests
+++ /dev/null
@@ -1,23 +0,0 @@
-UTILOBJS= ../../../testlib/libtestlib.a
-DOLOOPS= ../../../testlib/do_loops.o
-INCLUDE = -I../../../testlib -I../../.. -I.
-LIBRARY = -L../../../ -lpapi
-PAPILIB = $(LIBRARY)
-
-tests: $(NAME)_tests
-
-install:
-	@echo "$(NAME) tests (DATADIR) being installed in: \"$(DATADIR)\"";
-	mkdir -p $(DATADIR)/$(NAME)/tests
-	chmod go+rx $(DATADIR)
-	chmod go+rx $(DATADIR)/$(NAME)/tests
-	find . -perm -100 -type f -exec cp {} $(DATADIR)/$(NAME)/tests \;
-	chmod go+rx $(DATADIR)/$(NAME)/*
-	find . -name "*.[ch]" -type f -exec cp {} $(DATADIR)/$(NAME)/tests \;
-	cp Makefile $(DATADIR)/$(NAME)/tests
-	cp ../../Makefile_comp_tests.target $(DATADIR)/Makefile_comp_tests
-
-clean:
-
-distclean clobber: clean
-	rm -f Makefile_comp_tests.target
diff --git a/src/components/Makefile_comp_tests.target.in b/src/components/Makefile_comp_tests.target.in
index 253d4059a..1828fb047 100644
--- a/src/components/Makefile_comp_tests.target.in
+++ b/src/components/Makefile_comp_tests.target.in
@@ -9,7 +9,8 @@ INCLUDE = -I. -I$(datadir) -I$(testlibdir) -I$(validationlibdir) -I@includedir@
 LIBDIR  = @libdir@
 LIBRARY = @LIBRARY@
 SHLIB   = @SHLIB@
-PAPILIB = $(datadir)/@LINKLIB@
+PAPILIBDIR = $(datadir)
+PAPILIB = $(PAPILIBDIR)/@LINKLIB@
 TESTLIB = $(testlibdir)/libtestlib.a
 LDFLAGS = @LDFLAGS@ @LDL@
 CC	= @CC@
@@ -38,8 +39,5 @@ install:
 	chmod go+rx $(DATADIR)/$(NAME)/tests
 	find . -perm -100 -type f -exec cp {} $(DATADIR)/$(NAME)/tests \;
 	chmod go+rx $(DATADIR)/$(NAME)/*
-	find . -name "*.[ch]" -type f -exec cp {} $(DATADIR)/$(NAME)/tests \;
-	cp Makefile $(DATADIR)/$(NAME)/tests
-	cp ../../Makefile_comp_tests $(DATADIR)
-
+	find . \( -name "*.[ch]" -o -name "*.[ch]pp" -o -name "*.F" -o -name "*.F90" -o -name Makefile \) -type f -exec install -D -m0644 {} $(DATADIR)/$(NAME)/tests/{} \;
 
diff --git a/src/components/sde/tests/Makefile b/src/components/sde/tests/Makefile
index 3f2a406b8..a39f65d87 100644
--- a/src/components/sde/tests/Makefile
+++ b/src/components/sde/tests/Makefile
@@ -118,7 +118,7 @@ Created_Counter_Test: $(prfx)/Created_Counter_Driver.c libCreated_Counter.so
 Overflow_Test: $(prfx)/Overflow_Driver.c libCreated_Counter.so
 	$(CC) $< -o $@ $(INCLUDE) $(CFLAGS) $(UTILOBJS) -lCreated_Counter $(LDFLAGS) -lm
 Overflow_Static_Test: $(prfx)/Overflow_Driver.c libCreated_Counter_static.a
-	$(CC) $< -o $@ $(INCLUDE) $(CFLAGS) $(LDFLAGS) $(UTILOBJS) lib/libCreated_Counter_static.a $(datadir)/libpapi.a $(datadir)/libsde.a -lpfm -ldl -lrt
+	$(CC) $< -o $@ $(INCLUDE) $(CFLAGS) $(LDFLAGS) $(UTILOBJS) lib/libCreated_Counter_static.a $(PAPILIBDIR)/libpapi.a $(PAPILIBDIR)/libsde.a -lpfm -ldl -lrt
 
 libCreated_Counter++.so: $(prfx)/Lib_With_Created_Counter++.cpp | lib
 	$(CXX) -shared -Wall -fPIC $(CXXFLAGS) $(LDFLAGS) $(INCLUDE) -o lib/$@ $^
diff --git a/src/ctests/Makefile b/src/ctests/Makefile
index e1daa6068..159f763fc 100644
--- a/src/ctests/Makefile
+++ b/src/ctests/Makefile
@@ -2,18 +2,9 @@
 
 include Makefile.target
 
-INCLUDE = -I../testlib -I../validation_tests -I.. -I.
-
-testlibdir= ../testlib
-TESTLIB= $(testlibdir)/libtestlib.a
-DOLOOPS= $(testlibdir)/do_loops.o
-CLOCKCORE= $(testlibdir)/clockcore.o
-
-validationlibdir= ../validation_tests
-TESTFLOPS= $(validationlibdir)/flops_testcode.o
-TESTINS= $(validationlibdir)/instructions_testcode.o
-TESTCYCLES = $(validationlibdir)/busy_work.o
-DISPLAYERROR= $(validationlibdir)/display_error.o
+PAPIINCDIR	 = ..
+PAPILIBDIR	 = ..
+DATADIR = $(DESTDIR)$(datadir)
 
 include Makefile.recipies
 
diff --git a/src/ctests/Makefile.target.in b/src/ctests/Makefile.target.in
index 86b64f534..f16027e49 100644
--- a/src/ctests/Makefile.target.in
+++ b/src/ctests/Makefile.target.in
@@ -3,15 +3,16 @@ prefix = @prefix@
 exec_prefix = @exec_prefix@
 datarootdir = @datarootdir@
 datadir = @datadir@/${PACKAGE_TARNAME}
-testlibdir = $(datadir)/testlib
-validationlibdir = $(datadir)/validation_tests
-DATADIR = $(DESTDIR)$(datadir)
-INCLUDE = -I. -I@includedir@ -I$(testlibdir) -I$(validationlibdir)
+testlibdir = ../testlib
+validationlibdir = ../validation_tests
+PAPIINCDIR = @includedir@
+INCLUDE = -I. -I$(PAPIINCDIR) -I$(testlibdir) -I$(validationlibdir)
 LIBDIR  = @libdir@
 LIBRARY = @LIBRARY@
 SHLIB   = @SHLIB@
 STATIC  = @STATIC@
-PAPILIB = ../@LINKLIB@
+PAPILIBDIR = $(LIBDIR)
+PAPILIB = $(PAPILIBDIR)/@LINKLIB@
 TESTLIB = $(testlibdir)/libtestlib.a
 LDFLAGS = @LDFLAGS@ @LDL@ @STATIC@
 CC	= @CC@
@@ -21,3 +22,11 @@ F77	= @F77@
 CC_R	= @CC_R@
 CFLAGS	= @CFLAGS@ @TOPTFLAGS@
 OMPCFLGS = @OMPCFLGS@
+
+DOLOOPS= $(testlibdir)/do_loops.o
+CLOCKCORE= $(testlibdir)/clockcore.o
+
+TESTFLOPS= $(validationlibdir)/flops_testcode.o
+TESTINS= $(validationlibdir)/instructions_testcode.o
+TESTCYCLES = $(validationlibdir)/busy_work.o
+DISPLAYERROR= $(validationlibdir)/display_error.o
diff --git a/src/ftests/Makefile b/src/ftests/Makefile
index cad77fa17..5fd5a6f87 100644
--- a/src/ftests/Makefile
+++ b/src/ftests/Makefile
@@ -2,11 +2,9 @@
 
 include Makefile.target
 
-INCLUDE = -I../testlib -I. -I..
-FFLAGS	= $(CFLAGS) -ffixed-line-length-132
-testlibdir=../testlib
-TESTLIB= $(testlibdir)/libtestlib.a
-DOLOOPS= $(testlibdir)/do_loops.o
+PAPIINCDIR	 = ..
+PAPILIBDIR	 = ..
+DATADIR = $(DESTDIR)$(datadir)
 
 ifeq ($(ENABLE_FORTRAN_TESTS),yes)
 include Makefile.recipies
diff --git a/src/ftests/Makefile.target.in b/src/ftests/Makefile.target.in
index a2e2fdcba..c9fc02cc9 100644
--- a/src/ftests/Makefile.target.in
+++ b/src/ftests/Makefile.target.in
@@ -3,13 +3,14 @@ prefix = @prefix@
 exec_prefix = @exec_prefix@
 datarootdir = @datarootdir@
 datadir = @datadir@/${PACKAGE_TARNAME}
-testlibdir = $(datadir)/testlib
-DATADIR = $(DESTDIR)$(datadir)
-INCLUDE = -I. -I@includedir@ -I$(testlibdir)
+testlibdir = ../testlib
+PAPIINCDIR = @includedir@
+INCLUDE = -I. -I$(PAPIINCDIR) -I$(testlibdir)
 LIBDIR  = @libdir@
 LIBRARY = @LIBRARY@
 SHLIB   = @SHLIB@
-PAPILIB = ../@LINKLIB@
+PAPILIBDIR = $(LIBDIR)
+PAPILIB = $(PAPILIBDIR)/@LINKLIB@
 TESTLIB = $(testlibdir)/libtestlib.a
 LDFLAGS = @LDFLAGS@ @LDL@
 CC	= @CC@
@@ -21,3 +22,6 @@ FFLAGS	= @FFLAGS@
 TOPTFLAGS= @TOPTFLAGS@
 FTOPTFLAGS= @TOPTFLAGS@
 ENABLE_FORTRAN_TESTS=@ENABLE_FORTRAN_TESTS@
+
+FFLAGS	+= -ffixed-line-length-132
+DOLOOPS = $(testlibdir)/do_loops.o
diff --git a/src/testlib/Makefile b/src/testlib/Makefile
index 5b7fec6e1..4b2a14686 100644
--- a/src/testlib/Makefile
+++ b/src/testlib/Makefile
@@ -42,4 +42,4 @@ install:
 	chmod go+rx $(DATADIR)
 	chmod go+rx $(DATADIR)/testlib
 	find . -name "*.[chaF]" -type f -exec cp {} $(DATADIR)/testlib \;
-	cp Makefile.target $(DATADIR)/testlib/Makefile
+	cp Makefile Makefile.target $(DATADIR)/testlib
diff --git a/src/validation_tests/Makefile b/src/validation_tests/Makefile
index 600de5136..957d80a62 100644
--- a/src/validation_tests/Makefile
+++ b/src/validation_tests/Makefile
@@ -2,11 +2,9 @@
 
 include Makefile.target
 
-INCLUDE = -I../testlib -I.. -I.
-testlibdir= ../testlib
-TESTLIB= $(testlibdir)/libtestlib.a
-DOLOOPS= $(testlibdir)/do_loops.o
-CLOCKCORE= $(testlibdir)/clockcore.o
+PAPIINCDIR	 = ..
+PAPILIBDIR	 = ..
+DATADIR = $(DESTDIR)$(datadir)
 EXTRALIB = -lrt
 
 include Makefile.recipies
diff --git a/src/validation_tests/Makefile.target.in b/src/validation_tests/Makefile.target.in
index bcdbe94e9..6d2348100 100644
--- a/src/validation_tests/Makefile.target.in
+++ b/src/validation_tests/Makefile.target.in
@@ -3,13 +3,14 @@ prefix = @prefix@
 exec_prefix = @exec_prefix@
 datarootdir = @datarootdir@
 datadir = @datadir@/${PACKAGE_TARNAME}
-testlibdir = $(datadir)/testlib
-DATADIR = $(DESTDIR)$(datadir)
-INCLUDE = -I. -I@includedir@ -I$(testlibdir)
+testlibdir = ../testlib
+PAPIINCDIR = @includedir@
+INCLUDE = -I. -I$(PAPIINCDIR) -I$(testlibdir)
 LIBDIR  = @libdir@
 LIBRARY = @LIBRARY@
 SHLIB   = @SHLIB@
-PAPILIB = ../@LINKLIB@
+PAPILIBDIR = $(LIBDIR)
+PAPILIB = $(PAPILIBDIR)/@LINKLIB@
 TESTLIB = $(testlibdir)/libtestlib.a
 LDFLAGS = @LDFLAGS@ @LDL@ @STATIC@
 CC	= @CC@
@@ -18,3 +19,6 @@ F77	= @F77@
 CC_R	= @CC_R@
 CFLAGS	= @CFLAGS@ @OPTFLAGS@
 OMPCFLGS = @OMPCFLGS@
+
+DOLOOPS = $(testlibdir)/do_loops.o
+CLOCKCORE= $(testlibdir)/clockcore.o
-- 
2.20.1

