Add support for hooks in Justfile and Makefile

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2021-12-31 21:58:26 +01:00
parent 3de0ec13b6
commit aac696fafb
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D

View file

@ -2,14 +2,17 @@
HOOKTYPE=$1
if ! [ -e Makefile ]; then
exit 0
if [ -e Justfile ]; then
just --list --list-heading '' --list-prefix '' |
grep -q "auto-hook-${HOOKTYPE}" && exec just "auto-hook-${HOOKTYPE}" || true
fi
TARGETS=$(make -pRrq : 2>/dev/null |
if [ -e Makefile ]; then
TARGETS=$(make -pRrq : 2>/dev/null |
awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' |
sort | egrep -v -e '^[^[:alnum:]]' | sed 's/:$//' | xargs)
if (echo $TARGETS | grep -q "auto-hook-${HOOKTYPE}"); then
if (echo $TARGETS | grep -q "auto-hook-${HOOKTYPE}"); then
exec make "auto-hook-${HOOKTYPE}"
fi
fi