Disable man->postscript and man->pdf doc generation unless explicitly
[oota-llvm.git] / docs / mk / common.defs.mk
1 ##===- docs/mk/common.defs.mk ------------------------------*- Makefile -*-===##
2
3 #                     The LLVM Compiler Infrastructure
4 #
5 # This file is distributed under the University of Illinois Open Source
6 # License. See LICENSE.TXT for details.
7
8 ##===----------------------------------------------------------------------===##
9
10 # support for printing errors, warnings and info.
11
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.
15 define fn.DUMP.error
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))))
21 endef
22
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.
26 define fn.DUMP.errorn
27 $(error $(call _DUMP.errorn,$1,$2))
28 endef
29
30 ##===----------------------------------------------------------------------===##
31
32 # MAKEFILE PRIVATE.
33 # support for special makefile printing. Whitespace is very important for all
34 # definitions; modify with caution.
35
36 define _DUMP.error
37 ERROR.
38 ***
39 *** $1
40 ***
41 $(call _DUMP.makefile_list,***,$1) ERROR
42 endef
43
44 define _DUMP.errorm
45 ERROR.
46 ***
47 *** $1
48 ***$(subst *** ,***,$(foreach n,$2,    $n$(_TEXT.blank)***))
49 $(call _DUMP.makefile_list,***,$1) ERROR
50 endef
51
52 define _DUMP.errorn
53 ERROR.
54 ***
55 ***$(subst *** ,***,$(foreach n,$2, ERROR: $1: $n$(_TEXT.blank)***))
56 $(call _DUMP.makefile_list,***,$1) ERROR
57 endef
58
59 define _DUMP.makefile_list
60 $1 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))
63 $1
64 endef
65
66 # force linefeed.
67 define _TEXT.blank
68
69
70 endef
71
72 ##===----------------------------------------------------------------------===##
73
74 # FUNCTION: select
75 # $1: variable basename (before .__.)
76 # $2: selection key
77 # RESULT: variable selection by key
78 #
79 SELECT = $(if $($1.__.$2),$($1.__.$2),$($1.__.default))
80
81 # FUNCTION: safe(r) rm -rf
82 # $1: list of dirs to remove, recursively
83 #
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.
86 #
87 # An error is produced if removal of any generally unsafe dirs is attempted.
88
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))
92
93 _RMRF.eval = $(sort $(realpath $(filter $(realpath $(_RMRF.never)),$(realpath $1))))
94
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
98
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.
102 #
103 fn.PIPE.COMP = $(fn.PIPE.COMP.$(suffix $1))
104 fn.PIPE.COMP..gz  = | $(GZIP)
105 fn.PIPE.COMP..bz2 = | $(BZIP2)
106
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.
110 #
111 fn.PIPE.DECOMP = $(fn.PIPE.DECOMP.$(suffix $1))
112 fn.PIPE.DECOMP..gz  = | $(GZIP) -d
113 fn.PIPE.DECOMP..bz2 = | $(BZIP2) -d
114
115 # FUNCTION: fetch working copy 'Last Changed Rev'.
116 # $1: working copy directory.
117 # RESULT: 'Last Changed Rev' value from svn info.
118 #
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')