Hi Sébastien,

I've not heard of that tool, but it sounds useful.

Unfortunately we now use cmake internally, but a while ago I wrote
some GNU makefile code to perform some checks like this for our rather
complex GNU make-based build system of the time. See the attached
file; it should still work and the undefined variables test is
hopefully relatively straight-forward and self-explanatory. You will
obviously need to adjust the targets in the check_undefined_vars
recipe as may be appropriate for your project. Note also the self-test
code, which should verify that the check actually works.

It also does several other checks which are probably not relevant to
you, but which I can explain if you are interested. Otherwise just
delete all the code unrelated to check_undefined_vars.

Cheers,
Duane.

On Fri, May 3, 2019 at 12:18 AM Sébastien Hinderer
<sebastien.hinde...@inria.fr> wrote:
>
> Dear all,
>
> We recently noticed a few undefined variables in our makefiles.
> We would like to use --warn-undefined-variables to track them, e.g. on
> our CI infrastructure, but we find it problematic that the warning can
> not be turned into an error.
>
> Am I correct that there is currently no way to achieve this and, if so,
> am I correct that it is a deliberate choice not to provide this featur?
> In that case I'd be curious about why this has been decided.
>
> Is there any other known approach to deal with this?
>
> In particular, has somebody ever tried
> https://github.com/mrtazz/checkmake
> ?
>
> Many thanks in advance for any help,
>
> Sébastien.
>
> _______________________________________________
> Help-make mailing list
> Help-make@gnu.org
> https://lists.gnu.org/mailman/listinfo/help-make



-- 
"I never could learn to drink that blood and call it wine" - Bob Dylan
.PHONY: check check_undefined_vars check_target_clash check_source_clash check_messaging
.PHONY: warn_source_clash
.PHONY: self_test_check_undefined_vars self_test_check_target_clash

LIB_TARGET_NAMES = $(AR_TARGETS) $(DLL_TARGETS)
ALL_TARGET_NAMES = $(foreach component,$(patsubst %,%_TARGETS,$(COMPONENT_TYPES)),$(value $(component)))

check:: first \
	self_test_check_undefined_vars check_undefined_vars \
	self_test_check_target_clash check_target_clash \
	check_dependencies \
	check_messaging \
	warn_source_clash

define CheckNonUnique
TMPFILE := $$(shell mktemp -u)
check_$(1)_clash:
	@echo $(strip $(3)) | sed -e 's/ /\n/g' | sort | uniq -d > $$(TMPFILE)
	@test \! -s $$(TMPFILE) || (echo "$(2)" && sed -e 's/^/\t/' $$(TMPFILE) && rm -f $$(TMPFILE) && /bin/false)
	@rm -f $$(TMPFILE)
endef

TMPFILE := $(shell mktemp -u)
check_undefined_vars:
	@$(MAKE) --warn-undefined-variables --silent --dry-run clean veryclean all install 2>&1 > /dev/null | tee $(TMPFILE)
	@test \! -s $(TMPFILE) || (rm -f $(TMPFILE) && /bin/false)
	@rm -f $(TMPFILE)

ifdef TEST_TARGET_CLASH
AR_TARGETS += clash
DLL_TARGETS += clash
endif

ifdef TEST_UNDEFINED_VARS
$(nothing at all)
endif

self_test_check_undefined_vars:
	@!($(MAKE) TEST_UNDEFINED_VARS=1 check_undefined_vars > /dev/null 2>&1 && echo "undefined variables self-test failed")

self_test_check_target_clash:
	@!($(MAKE) TEST_TARGET_CLASH=1 check_target_clash > /dev/null 2>&1 && echo "target clash self-test failed")

$(eval $(call CheckNonUnique,target,Clashing library names:,$(LIB_TARGET_NAMES)))

ALL_TARGET_SOURCES := $(strip $(foreach srcs,$(patsubst %,%_SRCS,$(DEFINED_COMPONENTS)),$(value $(srcs))))
$(eval $(call CheckNonUnique,source,Source files that are prereqs of multiple targets:,$(ALL_TARGET_SOURCES)))

warn_source_clash:
	@echo Source files that are prereqs of multiple targets: $$(($(shell $(MAKE) check_source_clash 2> /dev/null | wc -l) - 2))
	@echo Make target check_source_clash to list them

check_messaging:
	@$(MSG_UTILS_DIR)/msg_gen_header.py -V $(wildcard $(MSG_DATA_DIR)/*/*.mrs)
_______________________________________________
Help-make mailing list
Help-make@gnu.org
https://lists.gnu.org/mailman/listinfo/help-make

Reply via email to