On 6/14/23 14:16, Anders Roxell wrote:
(It's too bad that we have all this duplication between the Makefile
and lib.mk.)
I agree, also the duplication of get_sys_includes in bpf, hid and net Makefile's
Do you have any idea how we can remove the duplication?
Well, since you asked... :)
Yes. Given that the goal is to support two similar, related activities:
a) make -C tools/testing/selftests
b) make -C tools/testing/selftests/<subtest>
, we could move common functionality into common_vars.mk and
common_targets.mk, and include those from both the top level
tools/testing/selftests/Makefile, and the subtest Makefiles.
This allows deduplication in a fairly safe sort of way, because it also
simultaneously moves everything to a non-recursive Make design. That's
especially nice, because then dependencies work reliably, and you also
don't have to worry about propagating Make variables (via Make's export
directive).
I haven't done this, because a few years ago I somehow got the vague
impression that it would not be well-received. But maybe that's
pessimistic and/or obsolete--times change, after all!
***************************************************************
Contents of tools/testing/selftests/Makefile:
include common_vars.mk
include alsa/alsa.mk
include amd-pstate/amd-pstate.mk
include arm64/arm64.mk
...etc, there are 100+ subdirs
include common_targets.mk
(This is instead of doing "TARGETS += xxx" in the Makefile. Including
the subtest *.mk fragments allows each subtest to add features and
quirks as necessary, while also enabling full dependency checking via a
true non-recursive Make.)
***************************************************************
Contents of tools/testing/selftests/common_targets.mk:
all: kernel_headers
...
Other rules/targets here.
***************************************************************
Contents of tools/testing/selftests/common_vars.mk:
Common variables, some of which may be overridden by a Makefile.
***************************************************************
Using alsa as an example of a subtest:
***************************************************************
Contents of tools/testing/selftests/alsa/alsa.mk:
TARGETS += alsa
TEST* items
Plus: alsa-specific items, such as:
CFLAGS += $(shell pkg-config --cflags alsa)
***************************************************************
Contents of tools/testing/selftests/alsa/Makefile:
include ../common_vars.mk
include alsa.mk
...maybe very little else needs to go here.
include ../common_targets.mk
thanks,
--
John Hubbard
NVIDIA