1 ##===- docs/mk/common.defs.mk ------------------------------*- Makefile -*-===##
3 # The LLVM Compiler Infrastructure
5 # This file is distributed under the University of Illinois Open Source
6 # License. See LICENSE.TXT for details.
8 ##===----------------------------------------------------------------------===##
10 # support for printing errors, warnings and info.
12 # FUNCTION: print error message once and dump makefile list.
13 # $1: error message. do NOT end in punctuation.
14 # $2: optional. one or more words to list. if words > 1 then 1 per line.
16 $(if $(filter 0,$(words $2)) \
17 ,$(error $(call _DUMP.error,$1.)) \
18 ,$(if $(filter 1,$(words $2)) \
19 ,$(error $(call _DUMP.error,$1: $2)) \
20 ,$(error $(call _DUMP.errorm,$1:,$2))))
23 # FUNCTION: print one error message per word and dump makefile list.
24 # $1: error message. do NOT end in punctuation.
25 # $2: one or more words to list. 1 word per line.
27 $(error $(call _DUMP.errorn,$1,$2))
30 ##===----------------------------------------------------------------------===##
33 # support for special makefile printing. Whitespace is very important for all
34 # definitions; modify with caution.
41 $(call _DUMP.makefile_list,***,$1) ERROR
48 ***$(subst *** ,***,$(foreach n,$2, $n$(_TEXT.blank)***))
49 $(call _DUMP.makefile_list,***,$1) ERROR
55 ***$(subst *** ,***,$(foreach n,$2, ERROR: $1: $n$(_TEXT.blank)***))
56 $(call _DUMP.makefile_list,***,$1) ERROR
59 define _DUMP.makefile_list
61 $1 $(abspath $(word 1,$(MAKEFILE_LIST)))
62 $1$(subst $()$1 ,$1,$(foreach n,$(wordlist 2,999,$(MAKEFILE_LIST)), $n$(_TEXT.blank)$1))
72 ##===----------------------------------------------------------------------===##
75 # $1: variable basename (before .__.)
77 # RESULT: variable selection by key
79 SELECT = $(if $($1.__.$2),$($1.__.$2),$($1.__.default))
81 # FUNCTION: safe(r) rm -rf
82 # $1: list of dirs to remove, recursively
84 # Extra safety is put in place by wrapping dirs in $(realpath) which both cleans
85 # up the path and returns blank if the path does not exist.
87 # An error is produced if removal of any generally unsafe dirs is attempted.
89 fn.RMRF = $(if $(call _RMRF.eval,$1) \
90 ,$(call fn.DUMP.errorn,unsafe recursive dir removal in call function fn.RMRF,$(call _RMRF.eval,$1)) \
91 ,$(RM) -rf $(realpath $1))
93 _RMRF.eval = $(sort $(realpath $(filter $(realpath $(_RMRF.never)),$(realpath $1))))
95 _RMRF.never = / /bin /dev /etc /home /net /opt /sbin /tmp /usr /var \
96 /usr/bin /usr/sbin /usr/share \
97 /usr/local/bin /usr/local/sbin /usr/local/share
99 # FUNCTION: pipe and compress.
100 # $1: target filename with filename extension of compression, if any.
101 # RESULT: a suitable pipe for compression or empty.
103 fn.PIPE.COMP = $(fn.PIPE.COMP.$(suffix $1))
104 fn.PIPE.COMP..gz = | $(GZIP)
105 fn.PIPE.COMP..bz2 = | $(BZIP2)
107 # FUNCTION: pipe and decompress.
108 # $1: target filename with filename extension of compression, if any.
109 # RESULT: a suitable pipe for decompression or empty.
111 fn.PIPE.DECOMP = $(fn.PIPE.DECOMP.$(suffix $1))
112 fn.PIPE.DECOMP..gz = | $(GZIP) -d
113 fn.PIPE.DECOMP..bz2 = | $(BZIP2) -d
115 # FUNCTION: fetch working copy 'Last Changed Rev'.
116 # $1: working copy directory.
117 # RESULT: 'Last Changed Rev' value from svn info.
119 fn.SVN.LCREV = $(shell (svn info $1 2>/dev/null || echo "Last Changed Rev: 0") | $(SED) -n 's/^Last Changed Rev: *\([0-9][0-9]*\)/\1/p')