[97a3b2] | 1 | # =========================================================================== |
---|
| 2 | # http://www.gnu.org/software/autoconf-archive/ax_normalize_path.html |
---|
| 3 | # =========================================================================== |
---|
| 4 | # |
---|
| 5 | # SYNOPSIS |
---|
| 6 | # |
---|
| 7 | # AX_NORMALIZE_PATH(VARNAME, [REFERENCE_STRING]) |
---|
| 8 | # |
---|
| 9 | # DESCRIPTION |
---|
| 10 | # |
---|
| 11 | # Perform some cleanups on the value of $VARNAME (interpreted as a path): |
---|
| 12 | # |
---|
| 13 | # - empty paths are changed to '.' |
---|
| 14 | # - trailing slashes are removed |
---|
| 15 | # - repeated slashes are squeezed except a leading doubled slash '//' |
---|
| 16 | # (which might indicate a networked disk on some OS). |
---|
| 17 | # |
---|
| 18 | # REFERENCE_STRING is used to turn '/' into '\' and vice-versa: if |
---|
| 19 | # REFERENCE_STRING contains some backslashes, all slashes and backslashes |
---|
| 20 | # are turned into backslashes, otherwise they are all turned into slashes. |
---|
| 21 | # |
---|
| 22 | # This makes processing of DOS filenames quite easier, because you can |
---|
| 23 | # turn a filename to the Unix notation, make your processing, and turn it |
---|
| 24 | # back to original notation. |
---|
| 25 | # |
---|
| 26 | # filename='A:\FOO\\BAR\' |
---|
| 27 | # old_filename="$filename" |
---|
| 28 | # # Switch to the unix notation |
---|
| 29 | # AX_NORMALIZE_PATH([filename], ["/"]) |
---|
| 30 | # # now we have $filename = 'A:/FOO/BAR' and we can process it as if |
---|
| 31 | # # it was a Unix path. For instance let's say that you want |
---|
| 32 | # # to append '/subpath': |
---|
| 33 | # filename="$filename/subpath" |
---|
| 34 | # # finally switch back to the original notation |
---|
| 35 | # AX_NORMALIZE_PATH([filename], ["$old_filename"]) |
---|
| 36 | # # now $filename equals to 'A:\FOO\BAR\subpath' |
---|
| 37 | # |
---|
| 38 | # One good reason to make all path processing with the unix convention is |
---|
| 39 | # that backslashes have a special meaning in many cases. For instance |
---|
| 40 | # |
---|
| 41 | # expr 'A:\FOO' : 'A:\Foo' |
---|
| 42 | # |
---|
| 43 | # will return 0 because the second argument is a regex in which |
---|
| 44 | # backslashes have to be backslashed. In other words, to have the two |
---|
| 45 | # strings to match you should write this instead: |
---|
| 46 | # |
---|
| 47 | # expr 'A:\Foo' : 'A:\\Foo' |
---|
| 48 | # |
---|
| 49 | # Such behavior makes DOS filenames extremely unpleasant to work with. So |
---|
| 50 | # temporary turn your paths to the Unix notation, and revert them to the |
---|
| 51 | # original notation after the processing. See the macro |
---|
| 52 | # AX_COMPUTE_RELATIVE_PATHS for a concrete example of this. |
---|
| 53 | # |
---|
| 54 | # REFERENCE_STRING defaults to $VARIABLE, this means that slashes will be |
---|
| 55 | # converted to backslashes if $VARIABLE already contains some backslashes |
---|
| 56 | # (see $thirddir below). |
---|
| 57 | # |
---|
| 58 | # firstdir='/usr/local//share' |
---|
| 59 | # seconddir='C:\Program Files\\' |
---|
| 60 | # thirddir='C:\home/usr/' |
---|
| 61 | # AX_NORMALIZE_PATH([firstdir]) |
---|
| 62 | # AX_NORMALIZE_PATH([seconddir]) |
---|
| 63 | # AX_NORMALIZE_PATH([thirddir]) |
---|
| 64 | # # $firstdir = '/usr/local/share' |
---|
| 65 | # # $seconddir = 'C:\Program Files' |
---|
| 66 | # # $thirddir = 'C:\home\usr' |
---|
| 67 | # |
---|
| 68 | # LICENSE |
---|
| 69 | # |
---|
| 70 | # Copyright (c) 2008 Alexandre Duret-Lutz <adl@gnu.org> |
---|
| 71 | # |
---|
| 72 | # This program is free software; you can redistribute it and/or modify it |
---|
| 73 | # under the terms of the GNU General Public License as published by the |
---|
| 74 | # Free Software Foundation; either version 2 of the License, or (at your |
---|
| 75 | # option) any later version. |
---|
| 76 | # |
---|
| 77 | # This program is distributed in the hope that it will be useful, but |
---|
| 78 | # WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 79 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
---|
| 80 | # Public License for more details. |
---|
| 81 | # |
---|
| 82 | # You should have received a copy of the GNU General Public License along |
---|
| 83 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
| 84 | # |
---|
| 85 | # As a special exception, the respective Autoconf Macro's copyright owner |
---|
| 86 | # gives unlimited permission to copy, distribute and modify the configure |
---|
| 87 | # scripts that are the output of Autoconf when processing the Macro. You |
---|
| 88 | # need not follow the terms of the GNU General Public License when using |
---|
| 89 | # or distributing such scripts, even though portions of the text of the |
---|
| 90 | # Macro appear in them. The GNU General Public License (GPL) does govern |
---|
| 91 | # all other use of the material that constitutes the Autoconf Macro. |
---|
| 92 | # |
---|
| 93 | # This special exception to the GPL applies to versions of the Autoconf |
---|
| 94 | # Macro released by the Autoconf Archive. When you make and distribute a |
---|
| 95 | # modified version of the Autoconf Macro, you may extend this special |
---|
| 96 | # exception to the GPL to apply to your modified version as well. |
---|
| 97 | |
---|
| 98 | #serial 5 |
---|
| 99 | |
---|
| 100 | AU_ALIAS([ADL_NORMALIZE_PATH], [AX_NORMALIZE_PATH]) |
---|
| 101 | AC_DEFUN([AX_NORMALIZE_PATH], |
---|
| 102 | [case ":[$]$1:" in |
---|
| 103 | # change empty paths to '.' |
---|
| 104 | ::) $1='.' ;; |
---|
| 105 | # strip trailing slashes |
---|
| 106 | :*[[\\/]]:) $1=`echo "[$]$1" | sed 's,[[\\/]]*[$],,'` ;; |
---|
| 107 | :*:) ;; |
---|
| 108 | esac |
---|
| 109 | # squeze repeated slashes |
---|
| 110 | case ifelse($2,,"[$]$1",$2) in |
---|
| 111 | # if the path contains any backslashes, turn slashes into backslashes |
---|
| 112 | *\\*) $1=`echo "[$]$1" | sed 's,\(.\)[[\\/]][[\\/]]*,\1\\\\,g'` ;; |
---|
| 113 | # if the path contains slashes, also turn backslashes into slashes |
---|
| 114 | *) $1=`echo "[$]$1" | sed 's,\(.\)[[\\/]][[\\/]]*,\1/,g'` ;; |
---|
| 115 | esac]) |
---|