From 3096d8026ab912c95a5aa7c9ca978e5681387cb1 Mon Sep 17 00:00:00 2001 From: "Viral B. Shah" Date: Sat, 6 Jun 2026 16:06:16 +0000 Subject: [PATCH] Deduplicate build files Two pieces of pure duplication in the build system: - `src/Makefile` defined `TARGET_LIBRARIES` twice, identically. Remove the second (dead) copy. - The eight `test/_test/Makefile` files were byte-for-byte identical except for the test name. Replace them with a shared `test/test.mk` that derives the test name from its directory (`$(notdir $(CURDIR))`); each per-test Makefile is now just `include ../test.mk`. The test build contract is unchanged: `test/common.jl` still invokes `make -sC test/ prefix=... CFLAGS=... LDFLAGS=...` and gets `$(prefix)/$(EXE)` built and `run`-able. Note: the deeper packaging gap from the review (no pkg-config/CMake config export) is intentionally left for a separate follow-up, since shipping per-interface/per-target headers makes a correct `.pc` non-trivial. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/Makefile | 8 -------- test/cdotc_test/Makefile | 16 +--------------- test/dgemm_test/Makefile | 16 +--------------- test/dgemmt_test/Makefile | 16 +--------------- test/dpstrf_test/Makefile | 16 +--------------- test/inconsolable_test/Makefile | 16 +--------------- test/isamax_test/Makefile | 16 +--------------- test/sdot_test/Makefile | 16 +--------------- test/sgesv_test/Makefile | 16 +--------------- test/test.mk | 22 ++++++++++++++++++++++ 10 files changed, 30 insertions(+), 128 deletions(-) create mode 100644 test/test.mk diff --git a/src/Makefile b/src/Makefile index cb50444..886f8bc 100644 --- a/src/Makefile +++ b/src/Makefile @@ -32,14 +32,6 @@ MAIN_OBJS += complex_return_style_adapters.o # Place the `.o` files into `$(builddir)` MAIN_OBJS := $(addprefix $(builddir)/,$(MAIN_OBJS)) -ifeq ($(OS),WINNT) -# On Windows only build the library with the major soversion, all other copies -# are useless and error prone. -TARGET_LIBRARIES = $(builddir)/$(LIB_MAJOR_VERSION) -else -TARGET_LIBRARIES = $(builddir)/$(LIB_MAJOR_VERSION) $(builddir)/$(LIB_FULL_VERSION) $(builddir)/libblastrampoline.$(SHLIB_EXT) -endif - $(builddir) $(builddir)/trampolines: @mkdir -p $@ diff --git a/test/cdotc_test/Makefile b/test/cdotc_test/Makefile index 881af3c..32e9003 100644 --- a/test/cdotc_test/Makefile +++ b/test/cdotc_test/Makefile @@ -1,15 +1 @@ -include ../../src/Make.inc - -all: $(prefix)/cdotc_test$(EXE) - -$(prefix): - @mkdir -p $@ - -$(prefix)/cdotc_test$(EXE): cdotc_test.c | $(prefix) - @$(CC) -o $@ $(CFLAGS) $^ $(LDFLAGS) - -clean: - @rm -f $(prefix)/cdotc_test$(EXE) - -run: $(prefix)/cdotc_test$(EXE) - @$(prefix)/cdotc_test$(EXE) +include ../test.mk diff --git a/test/dgemm_test/Makefile b/test/dgemm_test/Makefile index bb18810..32e9003 100644 --- a/test/dgemm_test/Makefile +++ b/test/dgemm_test/Makefile @@ -1,15 +1 @@ -include ../../src/Make.inc - -all: $(prefix)/dgemm_test$(EXE) - -$(prefix): - @mkdir -p $@ - -$(prefix)/dgemm_test$(EXE): dgemm_test.c | $(prefix) - @$(CC) -o $@ $(CFLAGS) $^ $(LDFLAGS) - -clean: - @rm -f $(prefix)/dgemm_test$(EXE) - -run: $(prefix)/dgemm_test$(EXE) - @$(prefix)/dgemm_test$(EXE) +include ../test.mk diff --git a/test/dgemmt_test/Makefile b/test/dgemmt_test/Makefile index a4e4103..32e9003 100644 --- a/test/dgemmt_test/Makefile +++ b/test/dgemmt_test/Makefile @@ -1,15 +1 @@ -include ../../src/Make.inc - -all: $(prefix)/dgemmt_test$(EXE) - -$(prefix): - @mkdir -p $@ - -$(prefix)/dgemmt_test$(EXE): dgemmt_test.c | $(prefix) - @$(CC) -o $@ $(CFLAGS) $^ $(LDFLAGS) - -clean: - @rm -f $(prefix)/dgemmt_test$(EXE) - -run: $(prefix)/dgemmt_test$(EXE) - @$(prefix)/dgemmt_test$(EXE) +include ../test.mk diff --git a/test/dpstrf_test/Makefile b/test/dpstrf_test/Makefile index 783e277..32e9003 100644 --- a/test/dpstrf_test/Makefile +++ b/test/dpstrf_test/Makefile @@ -1,15 +1 @@ -include ../../src/Make.inc - -all: $(prefix)/dpstrf_test$(EXE) - -$(prefix): - @mkdir -p $@ - -$(prefix)/dpstrf_test$(EXE): dpstrf_test.c | $(prefix) - @$(CC) -o $@ $(CFLAGS) $^ $(LDFLAGS) - -clean: - @rm -f $(prefix)/dpstrf_test$(EXE) - -run: $(prefix)/dpstrf_test$(EXE) - @$(prefix)/dpstrf_test$(EXE) +include ../test.mk diff --git a/test/inconsolable_test/Makefile b/test/inconsolable_test/Makefile index 0f41651..32e9003 100644 --- a/test/inconsolable_test/Makefile +++ b/test/inconsolable_test/Makefile @@ -1,15 +1 @@ -include ../../src/Make.inc - -all: $(prefix)/inconsolable_test$(EXE) - -$(prefix): - @mkdir -p $@ - -$(prefix)/inconsolable_test$(EXE): inconsolable_test.c | $(prefix) - @$(CC) -o $@ $(CFLAGS) $^ $(LDFLAGS) - -clean: - @rm -f $(prefix)/inconsolable_test$(EXE) - -run: $(prefix)/inconsolable_test$(EXE) - @$(prefix)/inconsolable_test$(EXE) +include ../test.mk diff --git a/test/isamax_test/Makefile b/test/isamax_test/Makefile index ac46fb7..32e9003 100644 --- a/test/isamax_test/Makefile +++ b/test/isamax_test/Makefile @@ -1,15 +1 @@ -include ../../src/Make.inc - -all: $(prefix)/isamax_test$(EXE) - -$(prefix): - @mkdir -p $@ - -$(prefix)/isamax_test$(EXE): isamax_test.c | $(prefix) - @$(CC) -o $@ $(CFLAGS) $^ $(LDFLAGS) - -clean: - @rm -f $(prefix)/isamax_test$(EXE) - -run: $(prefix)/isamax_test$(EXE) - @$(prefix)/isamax_test$(EXE) +include ../test.mk diff --git a/test/sdot_test/Makefile b/test/sdot_test/Makefile index 118e9ab..32e9003 100644 --- a/test/sdot_test/Makefile +++ b/test/sdot_test/Makefile @@ -1,15 +1 @@ -include ../../src/Make.inc - -all: $(prefix)/sdot_test$(EXE) - -$(prefix): - @mkdir -p $@ - -$(prefix)/sdot_test$(EXE): sdot_test.c | $(prefix) - @$(CC) -o $@ $(CFLAGS) $^ $(LDFLAGS) - -clean: - @rm -f $(prefix)/sdot_test$(EXE) - -run: $(prefix)/sdot_test$(EXE) - @$(prefix)/sdot_test$(EXE) +include ../test.mk diff --git a/test/sgesv_test/Makefile b/test/sgesv_test/Makefile index 06ea1d8..32e9003 100644 --- a/test/sgesv_test/Makefile +++ b/test/sgesv_test/Makefile @@ -1,15 +1 @@ -include ../../src/Make.inc - -all: $(prefix)/sgesv_test$(EXE) - -$(prefix): - @mkdir -p $@ - -$(prefix)/sgesv_test$(EXE): sgesv_test.c | $(prefix) - @$(CC) -o $@ $(CFLAGS) $^ $(LDFLAGS) - -clean: - @rm -f $(prefix)/sgesv_test$(EXE) - -run: $(prefix)/sgesv_test$(EXE) - @$(prefix)/sgesv_test$(EXE) +include ../test.mk diff --git a/test/test.mk b/test/test.mk new file mode 100644 index 0000000..ca8c119 --- /dev/null +++ b/test/test.mk @@ -0,0 +1,22 @@ +# Shared build rules for the standalone C test programs under `test/_test/`. +# Each test directory's Makefile simply does `include ../test.mk`; the test name is +# derived from the containing directory, so there is no per-test boilerplate to keep +# in sync. Invoked by `test/common.jl` as `make -sC test/ prefix=... CFLAGS=...`. +include ../../src/Make.inc + +# e.g. `dgemm_test` for `test/dgemm_test/` +TEST_NAME := $(notdir $(CURDIR)) + +all: $(prefix)/$(TEST_NAME)$(EXE) + +$(prefix): + @mkdir -p $@ + +$(prefix)/$(TEST_NAME)$(EXE): $(TEST_NAME).c | $(prefix) + @$(CC) -o $@ $(CFLAGS) $^ $(LDFLAGS) + +clean: + @rm -f $(prefix)/$(TEST_NAME)$(EXE) + +run: $(prefix)/$(TEST_NAME)$(EXE) + @$(prefix)/$(TEST_NAME)$(EXE)