🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
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.

173 lines
7.0 KiB

  1. # ==============================================================================
  2. # https://www.gnu.org/software/autoconf-archive/ax_compute_relative_paths.html
  3. # ==============================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_COMPUTE_RELATIVE_PATHS(PATH_LIST)
  8. #
  9. # DESCRIPTION
  10. #
  11. # PATH_LIST is a space-separated list of colon-separated triplets of the
  12. # form 'FROM:TO:RESULT'. This function iterates over these triplets and
  13. # set $RESULT to the relative path from $FROM to $TO. Note that $FROM and
  14. # $TO needs to be absolute filenames for this macro to success.
  15. #
  16. # For instance,
  17. #
  18. # first=/usr/local/bin
  19. # second=/usr/local/share
  20. # AX_COMPUTE_RELATIVE_PATHS([first:second:fs second:first:sf])
  21. # # $fs is set to ../share
  22. # # $sf is set to ../bin
  23. #
  24. # $FROM and $TO are both eval'ed recursively and normalized, this means
  25. # that you can call this macro with autoconf's dirnames like `prefix' or
  26. # `datadir'. For example:
  27. #
  28. # AX_COMPUTE_RELATIVE_PATHS([bindir:datadir:bin_to_data])
  29. #
  30. # AX_COMPUTE_RELATIVE_PATHS should also works with DOS filenames.
  31. #
  32. # You may want to use this macro in order to make your package
  33. # relocatable. Instead of hardcoding $datadir into your programs just
  34. # encode $bin_to_data and try to determine $bindir at run-time.
  35. #
  36. # This macro requires AX_NORMALIZE_PATH and AX_RECURSIVE_EVAL.
  37. #
  38. # LICENSE
  39. #
  40. # Copyright (c) 2008 Alexandre Duret-Lutz <adl@gnu.org>
  41. #
  42. # This program is free software; you can redistribute it and/or modify it
  43. # under the terms of the GNU General Public License as published by the
  44. # Free Software Foundation; either version 2 of the License, or (at your
  45. # option) any later version.
  46. #
  47. # This program is distributed in the hope that it will be useful, but
  48. # WITHOUT ANY WARRANTY; without even the implied warranty of
  49. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  50. # Public License for more details.
  51. #
  52. # You should have received a copy of the GNU General Public License along
  53. # with this program. If not, see <https://www.gnu.org/licenses/>.
  54. #
  55. # As a special exception, the respective Autoconf Macro's copyright owner
  56. # gives unlimited permission to copy, distribute and modify the configure
  57. # scripts that are the output of Autoconf when processing the Macro. You
  58. # need not follow the terms of the GNU General Public License when using
  59. # or distributing such scripts, even though portions of the text of the
  60. # Macro appear in them. The GNU General Public License (GPL) does govern
  61. # all other use of the material that constitutes the Autoconf Macro.
  62. #
  63. # This special exception to the GPL applies to versions of the Autoconf
  64. # Macro released by the Autoconf Archive. When you make and distribute a
  65. # modified version of the Autoconf Macro, you may extend this special
  66. # exception to the GPL to apply to your modified version as well.
  67. #serial 12
  68. AU_ALIAS([ADL_COMPUTE_RELATIVE_PATHS], [AX_COMPUTE_RELATIVE_PATHS])
  69. AC_DEFUN([AX_COMPUTE_RELATIVE_PATHS],
  70. [for _lcl_i in $1; do
  71. _lcl_from=\[$]`echo "[$]_lcl_i" | sed 's,:.*$,,'`
  72. _lcl_to=\[$]`echo "[$]_lcl_i" | sed 's,^[[^:]]*:,,' | sed 's,:[[^:]]*$,,'`
  73. _lcl_result_var=`echo "[$]_lcl_i" | sed 's,^.*:,,'`
  74. AX_RECURSIVE_EVAL([[$]_lcl_from], [_lcl_from])
  75. AX_RECURSIVE_EVAL([[$]_lcl_to], [_lcl_to])
  76. _lcl_notation="$_lcl_from$_lcl_to"
  77. AX_NORMALIZE_PATH([_lcl_from],['/'])
  78. AX_NORMALIZE_PATH([_lcl_to],['/'])
  79. AX_COMPUTE_RELATIVE_PATH([_lcl_from], [_lcl_to], [_lcl_result_tmp])
  80. AX_NORMALIZE_PATH([_lcl_result_tmp],["[$]_lcl_notation"])
  81. eval $_lcl_result_var='[$]_lcl_result_tmp'
  82. done])
  83. ## Note:
  84. ## *****
  85. ## The following helper macros are too fragile to be used out
  86. ## of AX_COMPUTE_RELATIVE_PATHS (mainly because they assume that
  87. ## paths are normalized), that's why I'm keeping them in the same file.
  88. ## Still, some of them maybe worth to reuse.
  89. dnl AX_COMPUTE_RELATIVE_PATH(FROM, TO, RESULT)
  90. dnl ===========================================
  91. dnl Compute the relative path to go from $FROM to $TO and set the value
  92. dnl of $RESULT to that value. This function work on raw filenames
  93. dnl (for instead it will considerate /usr//local and /usr/local as
  94. dnl two distinct paths), you should really use AX_COMPUTE_RELATIVE_PATHS
  95. dnl instead to have the paths sanitized automatically.
  96. dnl
  97. dnl For instance:
  98. dnl first_dir=/somewhere/on/my/disk/bin
  99. dnl second_dir=/somewhere/on/another/disk/share
  100. dnl AX_COMPUTE_RELATIVE_PATH(first_dir, second_dir, first_to_second)
  101. dnl will set $first_to_second to '../../../another/disk/share'.
  102. AC_DEFUN([AX_COMPUTE_RELATIVE_PATH],
  103. [AX_COMPUTE_COMMON_PATH([$1], [$2], [_lcl_common_prefix])
  104. AX_COMPUTE_BACK_PATH([$1], [_lcl_common_prefix], [_lcl_first_rel])
  105. AX_COMPUTE_SUFFIX_PATH([$2], [_lcl_common_prefix], [_lcl_second_suffix])
  106. $3="[$]_lcl_first_rel[$]_lcl_second_suffix"])
  107. dnl AX_COMPUTE_COMMON_PATH(LEFT, RIGHT, RESULT)
  108. dnl ============================================
  109. dnl Compute the common path to $LEFT and $RIGHT and set the result to $RESULT.
  110. dnl
  111. dnl For instance:
  112. dnl first_path=/somewhere/on/my/disk/bin
  113. dnl second_path=/somewhere/on/another/disk/share
  114. dnl AX_COMPUTE_COMMON_PATH(first_path, second_path, common_path)
  115. dnl will set $common_path to '/somewhere/on'.
  116. AC_DEFUN([AX_COMPUTE_COMMON_PATH],
  117. [$3=''
  118. _lcl_second_prefix_match=''
  119. while test "[$]_lcl_second_prefix_match" != 0; do
  120. _lcl_first_prefix=`expr "x[$]$1" : "x\([$]$3/*[[^/]]*\)"`
  121. _lcl_second_prefix_match=`expr "x[$]$2" : "x[$]_lcl_first_prefix"`
  122. if test "[$]_lcl_second_prefix_match" != 0; then
  123. if test "[$]_lcl_first_prefix" != "[$]$3"; then
  124. $3="[$]_lcl_first_prefix"
  125. else
  126. _lcl_second_prefix_match=0
  127. fi
  128. fi
  129. done])
  130. dnl AX_COMPUTE_SUFFIX_PATH(PATH, SUBPATH, RESULT)
  131. dnl ==============================================
  132. dnl Subtract $SUBPATH from $PATH, and set the resulting suffix
  133. dnl (or the empty string if $SUBPATH is not a subpath of $PATH)
  134. dnl to $RESULT.
  135. dnl
  136. dnl For instance:
  137. dnl first_path=/somewhere/on/my/disk/bin
  138. dnl second_path=/somewhere/on
  139. dnl AX_COMPUTE_SUFFIX_PATH(first_path, second_path, common_path)
  140. dnl will set $common_path to '/my/disk/bin'.
  141. AC_DEFUN([AX_COMPUTE_SUFFIX_PATH],
  142. [$3=`expr "x[$]$1" : "x[$]$2/*\(.*\)"`])
  143. dnl AX_COMPUTE_BACK_PATH(PATH, SUBPATH, RESULT)
  144. dnl ============================================
  145. dnl Compute the relative path to go from $PATH to $SUBPATH, knowing that
  146. dnl $SUBPATH is a subpath of $PATH (any other words, only repeated '../'
  147. dnl should be needed to move from $PATH to $SUBPATH) and set the value
  148. dnl of $RESULT to that value. If $SUBPATH is not a subpath of PATH,
  149. dnl set $RESULT to the empty string.
  150. dnl
  151. dnl For instance:
  152. dnl first_path=/somewhere/on/my/disk/bin
  153. dnl second_path=/somewhere/on
  154. dnl AX_COMPUTE_BACK_PATH(first_path, second_path, back_path)
  155. dnl will set $back_path to '../../../'.
  156. AC_DEFUN([AX_COMPUTE_BACK_PATH],
  157. [AX_COMPUTE_SUFFIX_PATH([$1], [$2], [_lcl_first_suffix])
  158. $3=''
  159. _lcl_tmp='xxx'
  160. while test "[$]_lcl_tmp" != ''; do
  161. _lcl_tmp=`expr "x[$]_lcl_first_suffix" : "x[[^/]]*/*\(.*\)"`
  162. if test "[$]_lcl_first_suffix" != ''; then
  163. _lcl_first_suffix="[$]_lcl_tmp"
  164. $3="../[$]$3"
  165. fi
  166. done])