xref: /honee/common.mk (revision 0006be33bc3a095c7a40443db044019362bd3e1c)
1*0006be33SJames Wright# Copyright (c) 2017-2024, Lawrence Livermore National Security, LLC and other CEED contributors.
2*0006be33SJames Wright# All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3*0006be33SJames Wright#
4*0006be33SJames Wright# SPDX-License-Identifier: BSD-2-Clause
5*0006be33SJames Wright#
6*0006be33SJames Wright# This file is part of CEED:  http://github.com/ceed
7*0006be33SJames Wright
8*0006be33SJames Wright# Output using the 216-color rules mode
9*0006be33SJames Wrightrule_file = $(notdir $(1))
10*0006be33SJames Wrightrule_path = $(patsubst %/,%,$(dir $(1)))
11*0006be33SJames Wrightlast_path = $(notdir $(patsubst %/,%,$(dir $(1))))
12*0006be33SJames Wrightansicolor = $(shell echo $(call last_path,$(1)) | cksum | cut -b1-2 | xargs -IS expr 2 \* S + 17)
13*0006be33SJames Wrightemacs_out = @printf "  %10s %s/%s\n" $(1) $(call rule_path,$(2)) $(call rule_file,$(2))
14*0006be33SJames Wrightcolor_out = @if [ -t 1 ]; then \
15*0006be33SJames Wright				printf "  %10s \033[38;5;%d;1m%s\033[m/%s\n" \
16*0006be33SJames Wright					$(1) $(call ansicolor,$(2)) \
17*0006be33SJames Wright					$(call rule_path,$(2)) $(call rule_file,$(2)); else \
18*0006be33SJames Wright				printf "  %10s %s\n" $(1) $(2); fi
19*0006be33SJames Wright# if TERM=dumb, use it, otherwise switch to the term one
20*0006be33SJames Wrightoutput = $(if $(TERM:dumb=),$(call color_out,$1,$2),$(call emacs_out,$1,$2))
21*0006be33SJames Wright
22*0006be33SJames Wright# if V is set to non-nil, turn the verbose mode
23*0006be33SJames Wrightquiet = $(if $(V),$($(1)),$(call output,$1,$@);$($(1)))
24*0006be33SJames Wright
25*0006be33SJames Wright# make-4.3 allows string literals like "#include" in variables, but older versions need "\#include". Specifically, the following code:
26*0006be33SJames Wright#
27*0006be33SJames Wright# X := $(shell echo "#foo")
28*0006be33SJames Wright#
29*0006be33SJames Wright# works with make-4.3, but fails with previous versions:
30*0006be33SJames Wright#
31*0006be33SJames Wright# Makefile:1: *** unterminated call to function 'shell': missing ')'.  Stop.
32*0006be33SJames Wright#
33*0006be33SJames Wright# Older versions work if you spell it "\#foo", but 4.3 will include the backslash. We define $(HASH), which works consistently across versions.
34*0006be33SJames WrightHASH := \#
35