Fix compatibility with dash as /bin/sh.

Ubuntu's default /bin/sh is dash, which does not support the `&>`
redirection syntax. This commit moves version.h generation back into the
Makefile, as 8afaedd had it, but restores compatibility with
GNU Make < 4.0, which 8afaedd, broke. This also fixes building on macOS,
as macOS bundles GNU Make 3.81.
This commit is contained in:
Mikaela Szekely 2022-06-11 21:10:52 -06:00 committed by Piotr Esden-Tempski
parent 7180a5b9a2
commit db4b568e52
2 changed files with 15 additions and 20 deletions

View File

@ -1,18 +0,0 @@
#!/bin/sh
if ! command -v git &>/dev/null; then
echo "Git not found, assuming up to date include/version.h"
exit 0
fi
if ! git rev-parse HEAD &>/dev/null; then
echo "No git repository found, not updating include/version.h"
exit 0
fi
version=`git describe --always --dirty --tags`
header="#define FIRMWARE_VERSION \"$version\""
if [ "`cat include/version.h 2>/dev/null`" != "$header" ]; then
echo $header > include/version.h
fi

View File

@ -174,8 +174,21 @@ all_platforms:
command.c: include/version.h
GIT_VERSION := $(shell git describe --always --dirty --tags)
VERSION_HEADER := \#define FIRMWARE_VERSION "$(GIT_VERSION)"
include/version.h: FORCE
@echo " GEN $@"
$(Q)../scripts/gen-version.sh
@# If git isn't found then GIT_VERSION will be an empty string.
ifeq ($(GIT_VERSION),)
@echo Git not found, assuming up to date include/version.h
else
@# Note that when we echo the version to the header file, echo writes a final newline
@# to the file. This is fine and probably makes the file more human-readable, but
@# also means we have to account for that newline in this comparison.
$(Q)if [ ! -f $@ ] || [ "$$(cat $@)" != "$$(echo '$(VERSION_HEADER)\n')" ]; then \
echo " GEN $@"; \
echo '$(VERSION_HEADER)' > $@; \
fi
endif
-include *.d