Skip to content

Ensure PACKAGE_VERSION is set in the Makefile#2038

Merged
jkbonfield merged 1 commit into
samtools:developfrom
daviesrob:working-version-sh-test
Jun 17, 2026
Merged

Ensure PACKAGE_VERSION is set in the Makefile#2038
jkbonfield merged 1 commit into
samtools:developfrom
daviesrob:working-version-sh-test

Conversation

@daviesrob

Copy link
Copy Markdown
Member

This variable is set by expanding $(shell version.sh). As this is not in a normal Makefile rule, failing to run version.sh just results in an empty variable. To check that it really was set, add a check to ensure it's not empty in the rule that builds the version.h file.

See also samtools/samtools#2337. Failing here is unlikely to result in broken files, but we should probably catch it anyway.

This variable is set by expanding $(shell version.sh).  As
this is not in a normal Makefile rule, failing to run version.sh
just results in an empty variable.  To check that it really was
set, add a check to ensure it's not empty in the rule that builds
the version.h file.

Signed-off-by: Rob Davies <rmd+git@sanger.ac.uk>
@jmarshall

Copy link
Copy Markdown
Member

Because PACKAGE_VERSION is constructed using GNU Make-specific functions, there's probably no downside to a GNU Make-specific check. E.g., how about something like

 PACKAGE_VERSION := $(shell $(srcdir)/version.sh)
+ifeq "$(PACKAGE_VERSION)" ""
+$(error PACKAGE_VERSION is not defined.  Check version.sh works)
+endif

Which admittedly differs from your version in not letting you avoid the check by manually making version.h. Which is either a good or a bad thing.

@daviesrob

Copy link
Copy Markdown
Member Author

True, but I preferred a more traditional solution, although it did get a bit more complicated by hiding the if statement from the make output. I did also ponder running version.sh in the make rule so its failure would be detected automatically, but I think the bit that quietly detects if version.h needs a rebuild is useful.

@jkbonfield jkbonfield merged commit 5a8a6bc into samtools:develop Jun 17, 2026
9 checks passed
@daviesrob daviesrob deleted the working-version-sh-test branch June 19, 2026 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants