2
0

xc-am-iface.m4 7.4 KB

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