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