From db4b568e52fe9ec1f216a5143f0c1dafadd184a6 Mon Sep 17 00:00:00 2001 From: Mikaela Szekely Date: Sat, 11 Jun 2022 21:10:52 -0600 Subject: [PATCH] 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. --- scripts/gen-version.sh | 18 ------------------ src/Makefile | 17 +++++++++++++++-- 2 files changed, 15 insertions(+), 20 deletions(-) delete mode 100755 scripts/gen-version.sh diff --git a/scripts/gen-version.sh b/scripts/gen-version.sh deleted file mode 100755 index d0a09e0..0000000 --- a/scripts/gen-version.sh +++ /dev/null @@ -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 diff --git a/src/Makefile b/src/Makefile index ae67eae..b618bfc 100644 --- a/src/Makefile +++ b/src/Makefile @@ -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