From: Prarit Bhargava Subject: Makefile: Make `git` check portable (POSIX compatible) commit 0755b55afbf76fcacc31e98bb8c163c8e055ccb2 Author: Paul Menzel Date: Mon Jan 30 15:56:41 2017 +0100 Makefile: Make `git` check portable (POSIX compatible) On systems using not the *GNU Bourne-Again SHell* (bash) as shell, the git check might fail. This happens on Debian systems where the *Debian Almquist Shell* (dash) is used by default for `/bin/sh`. As a result, after running `make` the file `version.c` always contains `unknown` instead of the correct version. The problem is, that `type -p git` is not portable. Use `command -v` instead [1][2]. > Where bash is your shell/hashbang, consistently use hash (for > commands) or type (to consider built-ins & keywords). > > When writing a POSIX script, use command -v. Fixes: #42 [1] https://stackoverflow.com/questions/592620/check-if-a-program-exists-from-a-bash-script "Check if a program exists from a Bash script" [2] https://unix.stackexchange.com/questions/85249/why-not-use-which-what-to-use-then "Why not use “which”? What to use then?" diff --git a/Makefile b/Makefile index 9dbbdbf8eb97e21a6d2efee7f308c1e7e742845b..e4341fceb882597ceebb56883625338c89923ee0 100644 --- a/Makefile +++ b/Makefile @@ -82,7 +82,7 @@ depend: .depend version.tmp: FORCE ( echo -n "char version[] = \"" ; \ - if type -p git >/dev/null; then \ + if command -v git >/dev/null; then \ if [ -d .git ] ; then \ git describe --tags HEAD | tr -d '\n'; \ else \