Collection of DPF-based plugins for packaging
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.

338 lines
14KB

  1. # ===========================================================================
  2. # https://www.gnu.org/software/autoconf-archive/ax_subdirs_configure.html
  3. # ===========================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_SUBDIRS_CONFIGURE( [subdirs], [mandatory arguments], [possibly merged arguments], [replacement arguments], [forbidden arguments])
  8. #
  9. # DESCRIPTION
  10. #
  11. # AX_SUBDIRS_CONFIGURE attempts to be the equivalent of AC_CONFIG_SUBDIRS
  12. # with customizable options for configure scripts.
  13. #
  14. # Run the configure script for each directory from the comma-separated m4
  15. # list 'subdirs'. This macro can be used multiple times. All arguments of
  16. # this macro must be comma-separated lists.
  17. #
  18. # All command line arguments from the parent configure script will be
  19. # given to the subdirectory configure script after the following
  20. # modifications (in that order):
  21. #
  22. # 1. The arguments from the 'mandatory arguments' list shall always be
  23. # appended to the argument list.
  24. #
  25. # 2. The arguments from the 'possibly merged arguments' list shall be
  26. # added if not present in the arguments of the parent configure script or
  27. # merged with the existing argument otherwise.
  28. #
  29. # 3. The arguments from the 'replacement arguments' list shall be added if
  30. # not present in the arguments of the parent configure script or replace
  31. # the existing argument otherwise.
  32. #
  33. # 4. The arguments from the 'forbidden arguments' list shall always be
  34. # removed from the argument list.
  35. #
  36. # The lists 'mandatory arguments' and 'forbidden arguments' can hold any
  37. # kind of argument. The 'possibly merged arguments' and 'replacement
  38. # arguments' expect their arguments to be of the form --option-name=value.
  39. #
  40. # This macro aims to remain as close as possible to the AC_CONFIG_SUBDIRS
  41. # macro. It corrects the paths for '--cache-file' and '--srcdir' and adds
  42. # '--disable-option-checking' and '--silent' if necessary.
  43. #
  44. # This macro also sets the output variable subdirs_extra to the list of
  45. # directories recorded with AX_SUBDIRS_CONFIGURE. This variable can be
  46. # used in Makefile rules or substituted in configured files.
  47. #
  48. # This macro shall do nothing more than managing the arguments of the
  49. # configure script. Just like when using AC_CONFIG_SUBDIRS, it is up to
  50. # the user to check any requirements or define and substitute any required
  51. # variable for the remainder of the project.
  52. #
  53. # Configure scripts recorded with AX_SUBDIRS_CONFIGURE may be executed
  54. # before configure scripts recorded with AC_CONFIG_SUBDIRS.
  55. #
  56. # Without additional arguments, the behaviour of AX_SUBDIRS_CONFIGURE
  57. # should be identical to the behaviour of AC_CONFIG_SUBDIRS, apart from
  58. # the contents of the variables subdirs and subdirs_extra (except that
  59. # AX_SUBDIRS_CONFIGURE expects a comma-separated m4 list):
  60. #
  61. # AC_CONFIG_SUBDIRS([something])
  62. # AX_SUBDIRS_CONFIGURE([something])
  63. #
  64. # This macro may be called multiple times.
  65. #
  66. # Usage example:
  67. #
  68. # Let us assume our project has 4 dependencies, namely A, B, C and D. Here
  69. # are some characteristics of our project and its dependencies:
  70. #
  71. # - A does not require any special option.
  72. #
  73. # - we want to build B with an optional feature which can be enabled with
  74. # its configure script's option '--enable-special-feature'.
  75. #
  76. # - B's configure script is strange and has an option '--with-B=build'.
  77. # After close inspection of its documentation, we don't want B to receive
  78. # this option.
  79. #
  80. # - C and D both need B.
  81. #
  82. # - Just like our project, C and D can build B themselves with the option
  83. # '--with-B=build'.
  84. #
  85. # - We want C and D to use the B we build instead of building it
  86. # themselves.
  87. #
  88. # Our top-level configure script will be called as follows:
  89. #
  90. # $ <path/to/configure> --with-A=build --with-B=build --with-C=build \
  91. # --with-D=build --some-option
  92. #
  93. # Thus we have to make sure that:
  94. #
  95. # - neither B, C or D receive the option '--with-B=build'
  96. #
  97. # - C and D know where to find the headers and libraries of B.
  98. #
  99. # Under those conditions, we can use the AC_CONFIG_SUBDIRS macro for A,
  100. # but need to use AX_SUBDIRS_CONFIGURE for B, C and D:
  101. #
  102. # - B must receive '--enable-special-feature' but cannot receive
  103. # '--with-B=build'
  104. #
  105. # - C and D cannot receive '--with-B=build' (or else it would be built
  106. # thrice) and need to be told where to find B (since we are building it,
  107. # it would probably not be available in standard paths).
  108. #
  109. # Here is a configure.ac snippet that solves our problem:
  110. #
  111. # AC_CONFIG_SUBDIRS([dependencies/A])
  112. # AX_SUBDIRS_CONFIGURE(
  113. # [dependencies/B], [--enable-special-feature], [], [],
  114. # [--with-B=build])
  115. # AX_SUBDIRS_CONFIGURE(
  116. # [[dependencies/C],[dependencies/D]],
  117. # [],
  118. # [[CPPFLAGS=-I${ac_top_srcdir}/dependencies/B -I${ac_top_builddir}/dependencies/B],
  119. # [LDFLAGS=-L${ac_abs_top_builddir}/dependencies/B/.libs]],
  120. # [--with-B=system],
  121. # [])
  122. #
  123. # If using automake, the following can be added to the Makefile.am (we use
  124. # both $(subdirs) and $(subdirs_extra) since our example above used both
  125. # AC_CONFIG_SUBDIRS and AX_SUBDIRS_CONFIGURE):
  126. #
  127. # SUBDIRS = $(subdirs) $(subdirs_extra)
  128. #
  129. # LICENSE
  130. #
  131. # Copyright (c) 2017 Harenome Ranaivoarivony-Razanajato <ranaivoarivony-razanajato@hareno.me>
  132. #
  133. # This program is free software; you can redistribute it and/or modify it
  134. # under the terms of the GNU General Public License as published by the
  135. # Free Software Foundation; either version 3 of the License, or (at your
  136. # option) any later version.
  137. #
  138. # This program is distributed in the hope that it will be useful, but
  139. # WITHOUT ANY WARRANTY; without even the implied warranty of
  140. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  141. # Public License for more details.
  142. #
  143. # Under Section 7 of GPL version 3, you are granted additional permissions
  144. # described in the Autoconf Configure Script Exception, version 3.0, as
  145. # published by the Free Software Foundation.
  146. #
  147. # You should have received a copy of the GNU General Public License along
  148. # with this program. If not, see <https://www.gnu.org/licenses/>.
  149. #serial 4
  150. AC_DEFUN([AX_SUBDIRS_CONFIGURE],
  151. [
  152. dnl Calls to AC_CONFIG_SUBDIRS perform preliminary steps and build a list
  153. dnl '$subdirs' which is used later by _AC_OUTPUT_SUBDIRS (used by AC_OUTPUT)
  154. dnl to actually run the configure scripts.
  155. dnl This macro performs similiar preliminary steps but uses
  156. dnl AC_CONFIG_COMMANDS_PRE to delay the final tasks instead of building an
  157. dnl intermediary list and relying on another macro.
  158. dnl
  159. dnl Since each configure script can get different options, a special variable
  160. dnl named 'ax_sub_configure_args_<subdir>' is constructed for each
  161. dnl subdirectory.
  162. # Various preliminary checks.
  163. AC_REQUIRE([AC_DISABLE_OPTION_CHECKING])
  164. AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT])
  165. AS_LITERAL_IF([$1], [],
  166. [AC_DIAGNOSE([syntax], [$0: you should use literals])])
  167. m4_foreach(subdir_path, [$1],
  168. [
  169. ax_dir="subdir_path"
  170. dnl Build the argument list in a similiar fashion to AC_CONFIG_SUBDIRS.
  171. dnl A few arguments found in the final call to the configure script are not
  172. dnl added here because they rely on variables that may not yet be available
  173. dnl (see below the part that is similiar to _AC_OUTPUT_SUBDIRS).
  174. # Do not complain, so a configure script can configure whichever parts of a
  175. # large source tree are present.
  176. if test -d "$srcdir/$ax_dir"; then
  177. _AC_SRCDIRS(["$ax_dir"])
  178. # Remove --cache-file, --srcdir, and --disable-option-checking arguments
  179. # so they do not pile up.
  180. ax_args=
  181. ax_prev=
  182. eval "set x $ac_configure_args"
  183. shift
  184. for ax_arg; do
  185. if test -n "$ax_prev"; then
  186. ax_prev=
  187. continue
  188. fi
  189. case $ax_arg in
  190. -cache-file | --cache-file | --cache-fil | --cache-fi | --cache-f \
  191. | --cache- | --cache | --cach | --cac | --ca | --c)
  192. ax_prev=cache_file ;;
  193. -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \
  194. | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* \
  195. | --c=*)
  196. ;;
  197. --config-cache | -C)
  198. ;;
  199. -srcdir | --srcdir | --srcdi | --srcd | --src | --sr)
  200. ax_prev=srcdir ;;
  201. -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*)
  202. ;;
  203. -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
  204. ax_prev=prefix ;;
  205. -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* \
  206. | --p=*)
  207. ;;
  208. --disable-option-checking)
  209. ;;
  210. *) case $ax_arg in
  211. *\'*) ax_arg=$(AS_ECHO(["$ax_arg"]) | sed "s/'/'\\\\\\\\''/g");;
  212. esac
  213. AS_VAR_APPEND([ax_args], [" '$ax_arg'"]) ;;
  214. esac
  215. done
  216. # Always prepend --disable-option-checking to silence warnings, since
  217. # different subdirs can have different --enable and --with options.
  218. ax_args="--disable-option-checking $ax_args"
  219. # Options that must be added as they are provided.
  220. m4_ifnblank([$2], [m4_foreach(opt, [$2], [AS_VAR_APPEND(ax_args, " 'opt'")
  221. ])])
  222. # New options that may need to be merged with existing options.
  223. m4_ifnblank([$3], [m4_foreach(opt, [$3],
  224. [ax_candidate="opt"
  225. ax_candidate_flag="${ax_candidate%%=*}"
  226. ax_candidate_content="${ax_candidate#*=}"
  227. if test "x$ax_candidate" != "x" -a "x$ax_candidate_flag" != "x"; then
  228. if echo "$ax_args" | grep -- "${ax_candidate_flag}=" >/dev/null 2>&1; then
  229. [ax_args=$(echo $ax_args | sed "s,\(${ax_candidate_flag}=[^']*\),\1 ${ax_candidate_content},")]
  230. else
  231. AS_VAR_APPEND(ax_args, " 'opt'")
  232. fi
  233. fi
  234. ])])
  235. # New options that must replace existing options.
  236. m4_ifnblank([$4], [m4_foreach(opt, [$4],
  237. [ax_candidate="opt"
  238. ax_candidate_flag="${ax_candidate%%=*}"
  239. ax_candidate_content="${ax_candidate#*=}"
  240. if test "x$ax_candidate" != "x" -a "x$ax_candidate_flag" != "x"; then
  241. if echo "$ax_args" | grep -- "${ax_candidate_flag}=" >/dev/null 2>&1; then
  242. [ax_args=$(echo $ax_args | sed "s,${ax_candidate_flag}=[^']*,${ax_candidate},")]
  243. else
  244. AS_VAR_APPEND(ax_args, " 'opt'")
  245. fi
  246. fi
  247. ])])
  248. # Options that must be removed.
  249. m4_ifnblank([$5], [m4_foreach(opt, [$5], [ax_args=$(echo $ax_args | sed "s,'opt',,")
  250. ])])
  251. AS_VAR_APPEND([ax_args], [" '--srcdir=$ac_srcdir'"])
  252. # Add the subdirectory to the list of target subdirectories.
  253. ax_subconfigures="$ax_subconfigures $ax_dir"
  254. # Save the argument list for this subdirectory.
  255. dnl $1 is a path to some subdirectory: m4_bpatsubsts() is used to convert
  256. dnl $1 into a valid shell variable name.
  257. dnl For instance, "ax_sub_configure_args_path/to/subdir" becomes
  258. dnl "ax_sub_configure_args_path_to_subdir".
  259. ax_var=$(printf "$ax_dir" | tr -c "0-9a-zA-Z_" "_")
  260. eval "ax_sub_configure_args_$ax_var=\"$ax_args\""
  261. eval "ax_sub_configure_$ax_var=\"yes\""
  262. else
  263. AC_MSG_WARN([could not find source tree for $ax_dir])
  264. fi
  265. dnl Add some more arguments to the argument list and then actually run the
  266. dnl configure script. This is mostly what happens in _AC_OUTPUT_SUBDIRS
  267. dnl except it does not iterate over an intermediary list.
  268. AC_CONFIG_COMMANDS_PRE(
  269. dnl This very line cannot be quoted! m4_foreach has some work here.
  270. ax_dir="subdir_path"
  271. [
  272. # Convert the path to the subdirectory into a shell variable name.
  273. ax_var=$(printf "$ax_dir" | tr -c "0-9a-zA-Z_" "_")
  274. ax_configure_ax_var=$(eval "echo \"\$ax_sub_configure_$ax_var\"")
  275. if test "$no_recursion" != "yes" -a "x$ax_configure_ax_var" = "xyes"; then
  276. AC_SUBST([subdirs_extra], ["$subdirs_extra $ax_dir"])
  277. ax_msg="=== configuring in $ax_dir ($(pwd)/$ax_dir)"
  278. _AS_ECHO_LOG([$ax_msg])
  279. _AS_ECHO([$ax_msg])
  280. AS_MKDIR_P(["$ax_dir"])
  281. _AC_SRCDIRS(["$ax_dir"])
  282. ax_popdir=$(pwd)
  283. cd "$ax_dir"
  284. # Check for guested configure; otherwise get Cygnus style configure.
  285. if test -f "$ac_srcdir/configure.gnu"; then
  286. ax_sub_configure=$ac_srcdir/configure.gnu
  287. elif test -f "$ac_srcdir/configure"; then
  288. ax_sub_configure=$ac_srcdir/configure
  289. elif test -f "$ac_srcdir/configure.in"; then
  290. # This should be Cygnus configure.
  291. ax_sub_configure=$ac_aux_dir/configure
  292. else
  293. AC_MSG_WARN([no configuration information is in $ax_dir])
  294. ax_sub_configure=
  295. fi
  296. if test -n "$ax_sub_configure"; then
  297. # Get the configure arguments for the current configure.
  298. eval "ax_sub_configure_args=\"\$ax_sub_configure_args_${ax_var}\""
  299. # Always prepend --prefix to ensure using the same prefix
  300. # in subdir configurations.
  301. ax_arg="--prefix=$prefix"
  302. case $ax_arg in
  303. *\'*) ax_arg=$(AS_ECHO(["$ax_arg"]) | sed "s/'/'\\\\\\\\''/g");;
  304. esac
  305. ax_sub_configure_args="'$ax_arg' $ax_sub_configure_args"
  306. if test "$silent" = yes; then
  307. ax_sub_configure_args="--silent $ax_sub_configure_args"
  308. fi
  309. # Make the cache file name correct relative to the subdirectory.
  310. case $cache_file in
  311. [[\\/]]* | ?:[[\\/]]* )
  312. ax_sub_cache_file=$cache_file ;;
  313. *) # Relative name.
  314. ax_sub_cache_file=$ac_top_build_prefix$cache_file ;;
  315. esac
  316. AC_MSG_NOTICE([running $SHELL $ax_sub_configure $ax_sub_configure_args --cache-file=$ac_sub_cache_file])
  317. eval "\$SHELL \"$ax_sub_configure\" $ax_sub_configure_args --cache-file=\"$ax_sub_cache_file\"" \
  318. || AC_MSG_ERROR([$ax_sub_configure failed for $ax_dir])
  319. fi
  320. cd "$ax_popdir"
  321. fi
  322. ])
  323. ])
  324. ])