| xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 1 | #--------------------------------------------------------------------------- | 
|  | 2 | # | 
|  | 3 | # xc-am-iface.m4 | 
|  | 4 | # | 
|  | 5 | # Copyright (c) 2013 - 2022 Daniel Stenberg <daniel@haxx.se> | 
|  | 6 | # | 
|  | 7 | # Permission to use, copy, modify, and distribute this software for any | 
|  | 8 | # purpose with or without fee is hereby granted, provided that the above | 
|  | 9 | # copyright notice and this permission notice appear in all copies. | 
|  | 10 | # | 
|  | 11 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | 
|  | 12 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | 
|  | 13 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | 
|  | 14 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | 
|  | 15 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | 
|  | 16 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | 
|  | 17 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 
|  | 18 | # | 
|  | 19 | # SPDX-License-Identifier: ISC | 
|  | 20 | # | 
|  | 21 | #--------------------------------------------------------------------------- | 
|  | 22 |  | 
|  | 23 | # serial 1 | 
|  | 24 |  | 
|  | 25 |  | 
|  | 26 | dnl _XC_AUTOMAKE_BODY | 
|  | 27 | dnl ------------------------------------------------- | 
|  | 28 | dnl Private macro. | 
|  | 29 | dnl | 
|  | 30 | dnl This macro performs embedding of automake initialization | 
|  | 31 | dnl code into configure script. When automake version 1.14 or | 
|  | 32 | dnl newer is used at configure script generation time, this | 
|  | 33 | dnl results in 'subdir-objects' automake option being used. | 
|  | 34 | dnl When using automake versions older than 1.14 this option | 
|  | 35 | dnl is not used when generating configure script. | 
|  | 36 | dnl | 
|  | 37 | dnl Existence of automake _AM_PROG_CC_C_O m4 private macro | 
|  | 38 | dnl is used to differentiate automake version 1.14 from older | 
|  | 39 | dnl ones which lack this macro. | 
|  | 40 |  | 
|  | 41 | m4_define([_XC_AUTOMAKE_BODY], | 
|  | 42 | [dnl | 
|  | 43 | ## --------------------------------------- ## | 
|  | 44 | ##  Start of automake initialization code  ## | 
|  | 45 | ## --------------------------------------- ## | 
|  | 46 | m4_ifdef([_AM_PROG_CC_C_O], | 
|  | 47 | [ | 
|  | 48 | AM_INIT_AUTOMAKE([subdir-objects]) | 
|  | 49 | ],[ | 
|  | 50 | AM_INIT_AUTOMAKE | 
|  | 51 | ])dnl | 
|  | 52 | ## ------------------------------------- ## | 
|  | 53 | ##  End of automake initialization code  ## | 
|  | 54 | ## ------------------------------------- ## | 
|  | 55 | dnl | 
|  | 56 | m4_define([$0], [])[]dnl | 
|  | 57 | ]) | 
|  | 58 |  | 
|  | 59 |  | 
|  | 60 | dnl XC_AUTOMAKE | 
|  | 61 | dnl ------------------------------------------------- | 
|  | 62 | dnl Public macro. | 
|  | 63 | dnl | 
|  | 64 | dnl This macro embeds automake machinery into configure | 
|  | 65 | dnl script regardless of automake version used in order | 
|  | 66 | dnl to generate configure script. | 
|  | 67 | dnl | 
|  | 68 | dnl When using automake version 1.14 or newer, automake | 
|  | 69 | dnl initialization option 'subdir-objects' is used to | 
|  | 70 | dnl generate the configure script, otherwise this option | 
|  | 71 | dnl is not used. | 
|  | 72 |  | 
|  | 73 | AC_DEFUN([XC_AUTOMAKE], | 
|  | 74 | [dnl | 
|  | 75 | AC_PREREQ([2.50])dnl | 
|  | 76 | dnl | 
|  | 77 | AC_BEFORE([$0],[AM_INIT_AUTOMAKE])dnl | 
|  | 78 | dnl | 
|  | 79 | _XC_AUTOMAKE_BODY | 
|  | 80 | dnl | 
|  | 81 | m4_ifdef([AM_INIT_AUTOMAKE], | 
|  | 82 | [m4_undefine([AM_INIT_AUTOMAKE])])dnl | 
|  | 83 | dnl | 
|  | 84 | m4_define([$0], [])[]dnl | 
|  | 85 | ]) | 
|  | 86 |  | 
|  | 87 |  | 
|  | 88 | dnl _XC_AMEND_DISTCLEAN_BODY ([LIST-OF-SUBDIRS]) | 
|  | 89 | dnl ------------------------------------------------- | 
|  | 90 | dnl Private macro. | 
|  | 91 | dnl | 
|  | 92 | dnl This macro performs shell code embedding into | 
|  | 93 | dnl configure script in order to modify distclean | 
|  | 94 | dnl and maintainer-clean targets of makefiles which | 
|  | 95 | dnl are located in given list of subdirs. | 
|  | 96 | dnl | 
|  | 97 | dnl See XC_AMEND_DISTCLEAN comments for details. | 
|  | 98 |  | 
|  | 99 | m4_define([_XC_AMEND_DISTCLEAN_BODY], | 
|  | 100 | [dnl | 
|  | 101 | ## ---------------------------------- ## | 
|  | 102 | ##  Start of distclean amending code  ## | 
|  | 103 | ## ---------------------------------- ## | 
|  | 104 |  | 
|  | 105 | for xc_subdir in [$1] | 
|  | 106 | do | 
|  | 107 |  | 
|  | 108 | if test ! -f "$xc_subdir/Makefile"; then | 
|  | 109 | echo "$xc_msg_err $xc_subdir/Makefile file not found. $xc_msg_abrt" >&2 | 
|  | 110 | exit 1 | 
|  | 111 | fi | 
|  | 112 |  | 
|  | 113 | # Fetch dependency tracking file list from Makefile include lines. | 
|  | 114 |  | 
|  | 115 | xc_inc_lines=`grep '^include .*(DEPDIR)' "$xc_subdir/Makefile" 2>/dev/null` | 
|  | 116 | xc_cnt_words=`echo "$xc_inc_lines" | wc -w | tr -d "$xc_space$xc_tab"` | 
|  | 117 |  | 
|  | 118 | # --disable-dependency-tracking might have been used, consequently | 
|  | 119 | # there is nothing to amend without a dependency tracking file list. | 
|  | 120 |  | 
|  | 121 | if test $xc_cnt_words -gt 0; then | 
|  | 122 |  | 
|  | 123 | AC_MSG_NOTICE([amending $xc_subdir/Makefile]) | 
|  | 124 |  | 
|  | 125 | # Build Makefile specific patch hunk. | 
|  | 126 |  | 
|  | 127 | xc_p="$xc_subdir/xc_patch.tmp" | 
|  | 128 |  | 
|  | 129 | xc_rm_depfiles=`echo "$xc_inc_lines" \ | 
|  | 130 | | $SED 's%include%	-rm -f%' 2>/dev/null` | 
|  | 131 |  | 
|  | 132 | xc_dep_subdirs=`echo "$xc_inc_lines" \ | 
|  | 133 | | $SED 's%include[[ ]][[ ]]*%%' 2>/dev/null \ | 
|  | 134 | | $SED 's%(DEPDIR)/.*%(DEPDIR)%' 2>/dev/null \ | 
|  | 135 | | sort | uniq` | 
|  | 136 |  | 
|  | 137 | echo "$xc_rm_depfiles" >$xc_p | 
|  | 138 |  | 
|  | 139 | for xc_dep_dir in $xc_dep_subdirs; do | 
|  | 140 | echo "${xc_tab}@xm_dep_cnt=\`ls $xc_dep_dir | wc -l 2>/dev/null\`; \\"            >>$xc_p | 
|  | 141 | echo "${xc_tab}if test \$\$xm_dep_cnt -eq 0 && test -d $xc_dep_dir; then \\"      >>$xc_p | 
|  | 142 | echo "${xc_tab}  rm -rf $xc_dep_dir; \\"                                          >>$xc_p | 
|  | 143 | echo "${xc_tab}fi"                                                                >>$xc_p | 
|  | 144 | done | 
|  | 145 |  | 
|  | 146 | # Build Makefile patching sed scripts. | 
|  | 147 |  | 
|  | 148 | xc_s1="$xc_subdir/xc_script_1.tmp" | 
|  | 149 | xc_s2="$xc_subdir/xc_script_2.tmp" | 
|  | 150 | xc_s3="$xc_subdir/xc_script_3.tmp" | 
|  | 151 |  | 
|  | 152 | cat >$xc_s1 <<\_EOT | 
|  | 153 | /^distclean[[ ]]*:/,/^[[^	]][[^	]]*:/{ | 
|  | 154 | s/^.*(DEPDIR)/___xc_depdir_line___/ | 
|  | 155 | } | 
|  | 156 | /^maintainer-clean[[ ]]*:/,/^[[^	]][[^	]]*:/{ | 
|  | 157 | s/^.*(DEPDIR)/___xc_depdir_line___/ | 
|  | 158 | } | 
|  | 159 | _EOT | 
|  | 160 |  | 
|  | 161 | cat >$xc_s2 <<\_EOT | 
|  | 162 | /___xc_depdir_line___$/{ | 
|  | 163 | N | 
|  | 164 | /___xc_depdir_line___$/D | 
|  | 165 | } | 
|  | 166 | _EOT | 
|  | 167 |  | 
|  | 168 | cat >$xc_s3 <<_EOT | 
|  | 169 | /^___xc_depdir_line___/{ | 
|  | 170 | r $xc_p | 
|  | 171 | d | 
|  | 172 | } | 
|  | 173 | _EOT | 
|  | 174 |  | 
|  | 175 | # Apply patch to Makefile and cleanup. | 
|  | 176 |  | 
|  | 177 | $SED -f "$xc_s1" "$xc_subdir/Makefile"      >"$xc_subdir/Makefile.tmp1" | 
|  | 178 | $SED -f "$xc_s2" "$xc_subdir/Makefile.tmp1" >"$xc_subdir/Makefile.tmp2" | 
|  | 179 | $SED -f "$xc_s3" "$xc_subdir/Makefile.tmp2" >"$xc_subdir/Makefile.tmp3" | 
|  | 180 |  | 
|  | 181 | if test -f "$xc_subdir/Makefile.tmp3"; then | 
|  | 182 | mv -f "$xc_subdir/Makefile.tmp3" "$xc_subdir/Makefile" | 
|  | 183 | fi | 
|  | 184 |  | 
|  | 185 | test -f "$xc_subdir/Makefile.tmp1" && rm -f "$xc_subdir/Makefile.tmp1" | 
|  | 186 | test -f "$xc_subdir/Makefile.tmp2" && rm -f "$xc_subdir/Makefile.tmp2" | 
|  | 187 | test -f "$xc_subdir/Makefile.tmp3" && rm -f "$xc_subdir/Makefile.tmp3" | 
|  | 188 |  | 
|  | 189 | test -f "$xc_p"  && rm -f "$xc_p" | 
|  | 190 | test -f "$xc_s1" && rm -f "$xc_s1" | 
|  | 191 | test -f "$xc_s2" && rm -f "$xc_s2" | 
|  | 192 | test -f "$xc_s3" && rm -f "$xc_s3" | 
|  | 193 |  | 
|  | 194 | fi | 
|  | 195 |  | 
|  | 196 | done | 
|  | 197 |  | 
|  | 198 | ## -------------------------------- ## | 
|  | 199 | ##  End of distclean amending code  ## | 
|  | 200 | ## -------------------------------- ## | 
|  | 201 | dnl | 
|  | 202 | m4_define([$0], [])[]dnl | 
|  | 203 | ]) | 
|  | 204 |  | 
|  | 205 |  | 
|  | 206 | dnl XC_AMEND_DISTCLEAN ([LIST-OF-SUBDIRS]) | 
|  | 207 | dnl ------------------------------------------------- | 
|  | 208 | dnl Public macro. | 
|  | 209 | dnl | 
|  | 210 | dnl This macro embeds shell code into configure script | 
|  | 211 | dnl that amends, at configure runtime, the distclean | 
|  | 212 | dnl and maintainer-clean targets of Makefiles located | 
|  | 213 | dnl in all subdirs given in the mandatory white-space | 
|  | 214 | dnl separated list argument. | 
|  | 215 | dnl | 
|  | 216 | dnl Embedding only takes place when using automake 1.14 | 
|  | 217 | dnl or newer, otherwise amending code is not included | 
|  | 218 | dnl in generated configure script. | 
|  | 219 | dnl | 
|  | 220 | dnl distclean and maintainer-clean targets are modified | 
|  | 221 | dnl to avoid unconditional removal of dependency subdirs | 
|  | 222 | dnl which triggers distclean and maintainer-clean errors | 
|  | 223 | dnl when using automake 'subdir-objects' option along | 
|  | 224 | dnl with per-target objects and source files existing in | 
|  | 225 | dnl multiple subdirs used for different build targets. | 
|  | 226 | dnl | 
|  | 227 | dnl New behavior first removes each dependency tracking | 
|  | 228 | dnl file independently, and only removes each dependency | 
|  | 229 | dnl subdir when it finds out that it no longer holds any | 
|  | 230 | dnl dependency tracking file. | 
|  | 231 | dnl | 
|  | 232 | dnl When configure option --disable-dependency-tracking | 
|  | 233 | dnl is used no amending takes place given that there are | 
|  | 234 | dnl no dependency tracking files. | 
|  | 235 |  | 
|  | 236 | AC_DEFUN([XC_AMEND_DISTCLEAN], | 
|  | 237 | [dnl | 
|  | 238 | AC_PREREQ([2.50])dnl | 
|  | 239 | dnl | 
|  | 240 | m4_ifdef([_AC_OUTPUT_MAIN_LOOP], | 
|  | 241 | [m4_provide_if([_AC_OUTPUT_MAIN_LOOP], [], | 
|  | 242 | [m4_fatal([call to AC_OUTPUT needed before $0])])])dnl | 
|  | 243 | dnl | 
|  | 244 | m4_if([$#], [1], [], [m4_fatal([$0: wrong number of arguments])])dnl | 
|  | 245 | m4_if([$1], [], [m4_fatal([$0: missing argument])])dnl | 
|  | 246 | dnl | 
|  | 247 | AC_REQUIRE([XC_CONFIGURE_PREAMBLE])dnl | 
|  | 248 | dnl | 
|  | 249 | m4_ifdef([_AM_PROG_CC_C_O], | 
|  | 250 | [ | 
|  | 251 | _XC_AMEND_DISTCLEAN_BODY([$1]) | 
|  | 252 | ])dnl | 
|  | 253 | m4_define([$0], [])[]dnl | 
|  | 254 | ]) |