xref: /honee/common.mk (revision 8a8cb6e06ce4728cc6d80ca92f8de31da49852e5)
1*ae2b091fSJames Wright# SPDX-FileCopyrightText: Copyright (c) 2017-2024, HONEE contributors.
2*ae2b091fSJames Wright# SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause
30006be33SJames Wright
40006be33SJames Wright# Output using the 216-color rules mode
50006be33SJames Wrightrule_file = $(notdir $(1))
60006be33SJames Wrightrule_path = $(patsubst %/,%,$(dir $(1)))
70006be33SJames Wrightlast_path = $(notdir $(patsubst %/,%,$(dir $(1))))
80006be33SJames Wrightansicolor = $(shell echo $(call last_path,$(1)) | cksum | cut -b1-2 | xargs -IS expr 2 \* S + 17)
90006be33SJames Wrightemacs_out = @printf "  %10s %s/%s\n" $(1) $(call rule_path,$(2)) $(call rule_file,$(2))
100006be33SJames Wrightcolor_out = @if [ -t 1 ]; then \
110006be33SJames Wright				printf "  %10s \033[38;5;%d;1m%s\033[m/%s\n" \
120006be33SJames Wright					$(1) $(call ansicolor,$(2)) \
130006be33SJames Wright					$(call rule_path,$(2)) $(call rule_file,$(2)); else \
140006be33SJames Wright				printf "  %10s %s\n" $(1) $(2); fi
150006be33SJames Wright# if TERM=dumb, use it, otherwise switch to the term one
160006be33SJames Wrightoutput = $(if $(TERM:dumb=),$(call color_out,$1,$2),$(call emacs_out,$1,$2))
170006be33SJames Wright
180006be33SJames Wright# if V is set to non-nil, turn the verbose mode
190006be33SJames Wrightquiet = $(if $(V),$($(1)),$(call output,$1,$@);$($(1)))
200006be33SJames Wright
210006be33SJames Wright# make-4.3 allows string literals like "#include" in variables, but older versions need "\#include". Specifically, the following code:
220006be33SJames Wright#
230006be33SJames Wright# X := $(shell echo "#foo")
240006be33SJames Wright#
250006be33SJames Wright# works with make-4.3, but fails with previous versions:
260006be33SJames Wright#
270006be33SJames Wright# Makefile:1: *** unterminated call to function 'shell': missing ')'.  Stop.
280006be33SJames Wright#
290006be33SJames Wright# Older versions work if you spell it "\#foo", but 4.3 will include the backslash. We define $(HASH), which works consistently across versions.
300006be33SJames WrightHASH := \#
31