2
0

xc-am-iface.m4 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. #---------------------------------------------------------------------------
  2. #
  3. # xc-am-iface.m4
  4. #
  5. # Copyright (C) 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. # serial 1
  23. dnl _XC_AUTOMAKE_BODY
  24. dnl -------------------------------------------------
  25. dnl Private macro.
  26. dnl
  27. dnl This macro performs embedding of automake initialization
  28. dnl code into configure script. When automake version 1.14 or
  29. dnl newer is used at configure script generation time, this
  30. dnl results in 'subdir-objects' automake option being used.
  31. dnl When using automake versions older than 1.14 this option
  32. dnl is not used when generating configure script.
  33. dnl
  34. dnl Existence of automake _AM_PROG_CC_C_O m4 private macro
  35. dnl is used to differentiate automake version 1.14 from older
  36. dnl ones which lack this macro.
  37. m4_define([_XC_AUTOMAKE_BODY],
  38. [dnl
  39. ## --------------------------------------- ##
  40. ## Start of automake initialization code ##
  41. ## --------------------------------------- ##
  42. m4_ifdef([_AM_PROG_CC_C_O],
  43. [
  44. AM_INIT_AUTOMAKE([subdir-objects])
  45. ],[
  46. AM_INIT_AUTOMAKE
  47. ])dnl
  48. ## ------------------------------------- ##
  49. ## End of automake initialization code ##
  50. ## ------------------------------------- ##
  51. dnl
  52. m4_define([$0], [])[]dnl
  53. ])
  54. dnl XC_AUTOMAKE
  55. dnl -------------------------------------------------
  56. dnl Public macro.
  57. dnl
  58. dnl This macro embeds automake machinery into configure
  59. dnl script regardless of automake version used in order
  60. dnl to generate configure script.
  61. dnl
  62. dnl When using automake version 1.14 or newer, automake
  63. dnl initialization option 'subdir-objects' is used to
  64. dnl generate the configure script, otherwise this option
  65. dnl is not used.
  66. AC_DEFUN([XC_AUTOMAKE],
  67. [dnl
  68. AC_PREREQ([2.50])dnl
  69. dnl
  70. AC_BEFORE([$0],[AM_INIT_AUTOMAKE])dnl
  71. dnl
  72. _XC_AUTOMAKE_BODY
  73. dnl
  74. m4_ifdef([AM_INIT_AUTOMAKE],
  75. [m4_undefine([AM_INIT_AUTOMAKE])])dnl
  76. dnl
  77. m4_define([$0], [])[]dnl
  78. ])
  79. dnl _XC_AMEND_DISTCLEAN_BODY ([LIST-OF-SUBDIRS])
  80. dnl -------------------------------------------------
  81. dnl Private macro.
  82. dnl
  83. dnl This macro performs shell code embedding into
  84. dnl configure script in order to modify distclean
  85. dnl and maintainer-clean targets of makefiles which
  86. dnl are located in given list of subdirs.
  87. dnl
  88. dnl See XC_AMEND_DISTCLEAN comments for details.
  89. m4_define([_XC_AMEND_DISTCLEAN_BODY],
  90. [dnl
  91. ## ---------------------------------- ##
  92. ## Start of distclean amending code ##
  93. ## ---------------------------------- ##
  94. for xc_subdir in [$1]
  95. do
  96. if test ! -f "$xc_subdir/Makefile"; then
  97. echo "$xc_msg_err $xc_subdir/Makefile file not found. $xc_msg_abrt" >&2
  98. exit 1
  99. fi
  100. # Fetch dependency tracking file list from Makefile include lines.
  101. xc_inc_lines=`grep '^include .*(DEPDIR)' "$xc_subdir/Makefile" 2>/dev/null`
  102. xc_cnt_words=`echo "$xc_inc_lines" | wc -w | tr -d "$xc_space$xc_tab"`
  103. # --disable-dependency-tracking might have been used, consequently
  104. # there is nothing to amend without a dependency tracking file list.
  105. if test $xc_cnt_words -gt 0; then
  106. AC_MSG_NOTICE([amending $xc_subdir/Makefile])
  107. # Build Makefile specific patch hunk.
  108. xc_p="$xc_subdir/xc_patch.tmp"
  109. xc_rm_depfiles=`echo "$xc_inc_lines" \
  110. | $SED 's%include% -rm -f%' 2>/dev/null`
  111. xc_dep_subdirs=`echo "$xc_inc_lines" \
  112. | $SED 's%include[[ ]][[ ]]*%%' 2>/dev/null \
  113. | $SED 's%(DEPDIR)/.*%(DEPDIR)%' 2>/dev/null \
  114. | sort | uniq`
  115. echo "$xc_rm_depfiles" >$xc_p
  116. for xc_dep_dir in $xc_dep_subdirs; do
  117. echo "${xc_tab}@xm_dep_cnt=\`ls $xc_dep_dir | wc -l 2>/dev/null\`; \\" >>$xc_p
  118. echo "${xc_tab}if test \$\$xm_dep_cnt -eq 0 && test -d $xc_dep_dir; then \\" >>$xc_p
  119. echo "${xc_tab} rm -rf $xc_dep_dir; \\" >>$xc_p
  120. echo "${xc_tab}fi" >>$xc_p
  121. done
  122. # Build Makefile patching sed scripts.
  123. xc_s1="$xc_subdir/xc_script_1.tmp"
  124. xc_s2="$xc_subdir/xc_script_2.tmp"
  125. xc_s3="$xc_subdir/xc_script_3.tmp"
  126. cat >$xc_s1 <<\_EOT
  127. /^distclean[[ ]]*:/,/^[[^ ]][[^ ]]*:/{
  128. s/^.*(DEPDIR)/___xc_depdir_line___/
  129. }
  130. /^maintainer-clean[[ ]]*:/,/^[[^ ]][[^ ]]*:/{
  131. s/^.*(DEPDIR)/___xc_depdir_line___/
  132. }
  133. _EOT
  134. cat >$xc_s2 <<\_EOT
  135. /___xc_depdir_line___$/{
  136. N
  137. /___xc_depdir_line___$/D
  138. }
  139. _EOT
  140. cat >$xc_s3 <<_EOT
  141. /^___xc_depdir_line___/{
  142. r $xc_p
  143. d
  144. }
  145. _EOT
  146. # Apply patch to Makefile and cleanup.
  147. $SED -f "$xc_s1" "$xc_subdir/Makefile" >"$xc_subdir/Makefile.tmp1"
  148. $SED -f "$xc_s2" "$xc_subdir/Makefile.tmp1" >"$xc_subdir/Makefile.tmp2"
  149. $SED -f "$xc_s3" "$xc_subdir/Makefile.tmp2" >"$xc_subdir/Makefile.tmp3"
  150. if test -f "$xc_subdir/Makefile.tmp3"; then
  151. mv -f "$xc_subdir/Makefile.tmp3" "$xc_subdir/Makefile"
  152. fi
  153. test -f "$xc_subdir/Makefile.tmp1" && rm -f "$xc_subdir/Makefile.tmp1"
  154. test -f "$xc_subdir/Makefile.tmp2" && rm -f "$xc_subdir/Makefile.tmp2"
  155. test -f "$xc_subdir/Makefile.tmp3" && rm -f "$xc_subdir/Makefile.tmp3"
  156. test -f "$xc_p" && rm -f "$xc_p"
  157. test -f "$xc_s1" && rm -f "$xc_s1"
  158. test -f "$xc_s2" && rm -f "$xc_s2"
  159. test -f "$xc_s3" && rm -f "$xc_s3"
  160. fi
  161. done
  162. ## -------------------------------- ##
  163. ## End of distclean amending code ##
  164. ## -------------------------------- ##
  165. dnl
  166. m4_define([$0], [])[]dnl
  167. ])
  168. dnl XC_AMEND_DISTCLEAN ([LIST-OF-SUBDIRS])
  169. dnl -------------------------------------------------
  170. dnl Public macro.
  171. dnl
  172. dnl This macro embeds shell code into configure script
  173. dnl that amends, at configure runtime, the distclean
  174. dnl and maintainer-clean targets of Makefiles located
  175. dnl in all subdirs given in the mandatory white-space
  176. dnl separated list argument.
  177. dnl
  178. dnl Embedding only takes place when using automake 1.14
  179. dnl or newer, otherwise amending code is not included
  180. dnl in generated configure script.
  181. dnl
  182. dnl distclean and maintainer-clean targets are modified
  183. dnl to avoid unconditional removal of dependency subdirs
  184. dnl which triggers distclean and maintainer-clean errors
  185. dnl when using automake 'subdir-objects' option along
  186. dnl with per-target objects and source files existing in
  187. dnl multiple subdirs used for different build targets.
  188. dnl
  189. dnl New behavior first removes each dependency tracking
  190. dnl file independently, and only removes each dependency
  191. dnl subdir when it finds out that it no longer holds any
  192. dnl dependency tracking file.
  193. dnl
  194. dnl When configure option --disable-dependency-tracking
  195. dnl is used no amending takes place given that there are
  196. dnl no dependency tracking files.
  197. AC_DEFUN([XC_AMEND_DISTCLEAN],
  198. [dnl
  199. AC_PREREQ([2.50])dnl
  200. dnl
  201. m4_ifdef([_AC_OUTPUT_MAIN_LOOP],
  202. [m4_provide_if([_AC_OUTPUT_MAIN_LOOP], [],
  203. [m4_fatal([call to AC_OUTPUT needed before $0])])])dnl
  204. dnl
  205. m4_if([$#], [1], [], [m4_fatal([$0: wrong number of arguments])])dnl
  206. m4_if([$1], [], [m4_fatal([$0: missing argument])])dnl
  207. dnl
  208. AC_REQUIRE([XC_CONFIGURE_PREAMBLE])dnl
  209. dnl
  210. m4_ifdef([_AM_PROG_CC_C_O],
  211. [
  212. _XC_AMEND_DISTCLEAN_BODY([$1])
  213. ])dnl
  214. m4_define([$0], [])[]dnl
  215. ])