You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

xc-am-iface.m4 7.4KB

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