| @@ -1,30 +1,36 @@ | | | @@ -1,30 +1,36 @@ |
1 | # $NetBSD: subst.mk,v 1.66 2020/03/21 12:22:31 rillig Exp $ | | 1 | # $NetBSD: subst.mk,v 1.67 2020/03/21 13:30:35 rillig Exp $ |
2 | # | | 2 | # |
3 | # The subst framework replaces text in one or more files in the WRKSRC | | 3 | # The subst framework replaces text in one or more files in the WRKSRC |
4 | # directory. Packages can define several ``classes'' of replacements. | | 4 | # directory. Packages can define several ``classes'' of replacements. |
5 | # Each such class defines: | | 5 | # Each such class defines: |
6 | # | | 6 | # |
7 | # - in which stage of the build process the replacement happens | | 7 | # - in which stage of the build process the replacement happens |
8 | # - which files are affected by the replacement | | 8 | # - which files are affected by the replacement |
9 | # - which text or pattern is replaced by which replacement text | | 9 | # - which text or pattern is replaced by which replacement text |
10 | # | | 10 | # |
11 | # A typical example is: | | 11 | # A typical example is: |
12 | # | | 12 | # |
13 | # SUBST_CLASSES+= prefix | | 13 | # SUBST_CLASSES+= prefix |
14 | # SUBST_STAGE.prefix= pre-configure | | 14 | # SUBST_STAGE.prefix= pre-configure |
15 | # SUBST_FILES.prefix= ./configure doc/*.html | | 15 | # SUBST_FILES.prefix= ./configure doc/*.html |
16 | # SUBST_SED.prefix= -e 's,/usr/local,${PREFIX},g' | | 16 | # SUBST_SED.prefix= -e 's,/usr/local,${PREFIX},g' |
17 | # | | 17 | # |
| | | 18 | # User-settable variables: |
| | | 19 | # |
| | | 20 | # SUBST_SHOW_DIFF |
| | | 21 | # Whether to log each changed file as a unified diff, for all |
| | | 22 | # SUBST classes. Defaults to "no". |
| | | 23 | # |
18 | # Package-settable variables: | | 24 | # Package-settable variables: |
19 | # | | 25 | # |
20 | # SUBST_CLASSES | | 26 | # SUBST_CLASSES |
21 | # A list of class names. When adding new classes to this list, be | | 27 | # A list of class names. When adding new classes to this list, be |
22 | # sure to append them (+=) instead of overriding them (=). | | 28 | # sure to append them (+=) instead of overriding them (=). |
23 | # | | 29 | # |
24 | # SUBST_STAGE.<class> | | 30 | # SUBST_STAGE.<class> |
25 | # "stage" at which we do the text replacement. Should be one of | | 31 | # "stage" at which we do the text replacement. Should be one of |
26 | # {pre,do,post}-{extract,patch,configure,build,install}. | | 32 | # {pre,do,post}-{extract,patch,configure,build,install}. |
27 | # | | 33 | # |
28 | # SUBST_MESSAGE.<class> | | 34 | # SUBST_MESSAGE.<class> |
29 | # The message to display before doing the substitution. | | 35 | # The message to display before doing the substitution. |
30 | # | | 36 | # |
| @@ -72,26 +78,27 @@ | | | @@ -72,26 +78,27 @@ |
72 | # In most cases, "yes" is appropriate, to catch typos and outdated | | 78 | # In most cases, "yes" is appropriate, to catch typos and outdated |
73 | # definitions. | | 79 | # definitions. |
74 | # | | 80 | # |
75 | # Default: no (up to 2019Q4), yes (starting with 2020Q1) | | 81 | # Default: no (up to 2019Q4), yes (starting with 2020Q1) |
76 | # | | 82 | # |
77 | # See also: | | 83 | # See also: |
78 | # PLIST_SUBST | | 84 | # PLIST_SUBST |
79 | # | | 85 | # |
80 | # Keywords: subst | | 86 | # Keywords: subst |
81 | # | | 87 | # |
82 | | | 88 | |
83 | _VARGROUPS+= subst | | 89 | _VARGROUPS+= subst |
84 | _PKG_VARS.subst= SUBST_CLASSES | | 90 | _PKG_VARS.subst= SUBST_CLASSES |
| | | 91 | SUBST_SHOW_DIFF?= no |
85 | .for c in ${SUBST_CLASSES} | | 92 | .for c in ${SUBST_CLASSES} |
86 | . for pv in SUBST_STAGE SUBST_MESSAGE SUBST_FILES SUBST_SED SUBST_VARS \ | | 93 | . for pv in SUBST_STAGE SUBST_MESSAGE SUBST_FILES SUBST_SED SUBST_VARS \ |
87 | SUBST_FILTER_CMD SUBST_SKIP_TEXT_CHECK SUBST_NOOP_OK | | 94 | SUBST_FILTER_CMD SUBST_SKIP_TEXT_CHECK SUBST_NOOP_OK |
88 | _PKG_VARS.subst+= ${pv}.${c} | | 95 | _PKG_VARS.subst+= ${pv}.${c} |
89 | . endfor | | 96 | . endfor |
90 | .endfor | | 97 | .endfor |
91 | _DEF_VARS.subst= ECHO_SUBST_MSG | | 98 | _DEF_VARS.subst= ECHO_SUBST_MSG |
92 | _USE_VARS.subst= WRKDIR WRKSRC | | 99 | _USE_VARS.subst= WRKDIR WRKSRC |
93 | _IGN_VARS.subst= _SUBST_IS_TEXT_FILE_CMD | | 100 | _IGN_VARS.subst= _SUBST_IS_TEXT_FILE_CMD |
94 | _SORTED_VARS.subst= SUBST_CLASSES SUBST_FILES.* SUBST_VARS.* | | 101 | _SORTED_VARS.subst= SUBST_CLASSES SUBST_FILES.* SUBST_VARS.* |
95 | _LISTED_VARS.subst= SUBST_SED.* SUBST_FILTER_CMD.* | | 102 | _LISTED_VARS.subst= SUBST_SED.* SUBST_FILTER_CMD.* |
96 | | | 103 | |
97 | ECHO_SUBST_MSG?= ${STEP_MSG} | | 104 | ECHO_SUBST_MSG?= ${STEP_MSG} |
| @@ -103,27 +110,27 @@ _SUBST_IS_TEXT_FILE_CMD?= \ | | | @@ -103,27 +110,27 @@ _SUBST_IS_TEXT_FILE_CMD?= \ |
103 | .if ${SUBST_CLASSES:U:O} != ${SUBST_CLASSES:U:O:u} | | 110 | .if ${SUBST_CLASSES:U:O} != ${SUBST_CLASSES:U:O:u} |
104 | PKG_FAIL_REASON+= "[subst.mk] duplicate SUBST class in: ${SUBST_CLASSES:O}" | | 111 | PKG_FAIL_REASON+= "[subst.mk] duplicate SUBST class in: ${SUBST_CLASSES:O}" |
105 | .endif | | 112 | .endif |
106 | | | 113 | |
107 | .for _class_ in ${SUBST_CLASSES:O:u} | | 114 | .for _class_ in ${SUBST_CLASSES:O:u} |
108 | _SUBST_COOKIE.${_class_}= ${WRKDIR}/.subst_${_class_}_done | | 115 | _SUBST_COOKIE.${_class_}= ${WRKDIR}/.subst_${_class_}_done |
109 | | | 116 | |
110 | SUBST_FILTER_CMD.${_class_}?= LC_ALL=C ${SED} ${SUBST_SED.${_class_}} | | 117 | SUBST_FILTER_CMD.${_class_}?= LC_ALL=C ${SED} ${SUBST_SED.${_class_}} |
111 | SUBST_VARS.${_class_}?= # none | | 118 | SUBST_VARS.${_class_}?= # none |
112 | SUBST_MESSAGE.${_class_}?= Substituting "${_class_}" in ${SUBST_FILES.${_class_}} | | 119 | SUBST_MESSAGE.${_class_}?= Substituting "${_class_}" in ${SUBST_FILES.${_class_}} |
113 | . for v in ${SUBST_VARS.${_class_}} | | 120 | . for v in ${SUBST_VARS.${_class_}} |
114 | SUBST_FILTER_CMD.${_class_}+= -e s,@${v:C|[^A-Za-z0-9_]|\\\\&|gW:Q}@,${${v}:S|\\|\\\\|gW:S|,|\\,|gW:S|&|\\\&|gW:S|${.newline}|\\${.newline}|gW:Q},g | | 121 | SUBST_FILTER_CMD.${_class_}+= -e s,@${v:C|[^A-Za-z0-9_]|\\\\&|gW:Q}@,${${v}:S|\\|\\\\|gW:S|,|\\,|gW:S|&|\\\&|gW:S|${.newline}|\\${.newline}|gW:Q},g |
115 | . endfor | | 122 | . endfor |
116 | . if !empty(SUBST_SHOW_DIFF.${_class_}:Uno:M[Yy][Ee][Ss]) | | 123 | . if ${SUBST_SHOW_DIFF.${_class_}:U${SUBST_SHOW_DIFF}:tl} == yes |
117 | _SUBST_KEEP.${_class_}?= ${DIFF} -u "$$file" "$$tmpfile" || true | | 124 | _SUBST_KEEP.${_class_}?= ${DIFF} -u "$$file" "$$tmpfile" || true |
118 | . endif | | 125 | . endif |
119 | _SUBST_KEEP.${_class_}?= ${DO_NADA} | | 126 | _SUBST_KEEP.${_class_}?= ${DO_NADA} |
120 | SUBST_SKIP_TEXT_CHECK.${_class_}?= no | | 127 | SUBST_SKIP_TEXT_CHECK.${_class_}?= no |
121 | SUBST_NOOP_OK.${_class_}?= yes # TODO: change to no after 2020Q1 | | 128 | SUBST_NOOP_OK.${_class_}?= yes # TODO: change to no after 2020Q1 |
122 | | | 129 | |
123 | .if !empty(SUBST_SKIP_TEXT_CHECK.${_class_}:M[Yy][Ee][Ss]) | | 130 | .if !empty(SUBST_SKIP_TEXT_CHECK.${_class_}:M[Yy][Ee][Ss]) |
124 | _SUBST_IS_TEXT_FILE_CMD.${_class_}= ${TRUE} | | 131 | _SUBST_IS_TEXT_FILE_CMD.${_class_}= ${TRUE} |
125 | .else | | 132 | .else |
126 | _SUBST_IS_TEXT_FILE_CMD.${_class_}= ${_SUBST_IS_TEXT_FILE_CMD} | | 133 | _SUBST_IS_TEXT_FILE_CMD.${_class_}= ${_SUBST_IS_TEXT_FILE_CMD} |
127 | .endif | | 134 | .endif |
128 | | | 135 | |
129 | . if defined(SUBST_STAGE.${_class_}) | | 136 | . if defined(SUBST_STAGE.${_class_}) |