* lib/install.sh: Handle --, and diagnose unknown options.
[platform/upstream/automake.git] / m4 / mkdirp.m4
1 ##                                                          -*- Autoconf -*-
2 # Copyright (C) 2003, 2004, 2005, 2006  Free Software Foundation, Inc.
3 #
4 # This file is free software; the Free Software Foundation
5 # gives unlimited permission to copy and/or distribute it,
6 # with or without modifications, as long as this notice is preserved.
7
8 # AM_PROG_MKDIR_P
9 # ---------------
10 # Check whether `mkdir -p' is supported, fallback to mkinstalldirs otherwise.
11 #
12 # Automake 1.8 used `mkdir -m 0755 -p --' to ensure that directories
13 # created by `make install' are always world readable, even if the
14 # installer happens to have an overly restrictive umask (e.g. 077).
15 # This was a mistake.  There are at least two reasons why we must not
16 # use `-m 0755':
17 #   - it causes special bits like SGID to be ignored,
18 #   - it may be too restrictive (some setups expect 775 directories).
19 #
20 # Do not use -m 0755 and let people choose whatever they expect by
21 # setting umask.
22 #
23 # We cannot accept any implementation of `mkdir' that recognizes `-p'.
24 # Some implementations (such as Solaris 8's) are not thread-safe: if a
25 # parallel make tries to run `mkdir -p a/b' and `mkdir -p a/c'
26 # concurrently, both version can detect that a/ is missing, but only
27 # one can create it and the other will error out.  Consequently we
28 # restrict ourselves to GNU mkdir (using the --version option ensures
29 # this.)
30 AC_DEFUN([AM_PROG_MKDIR_P],
31 [if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then
32   # We used to define $(mkdir_p) as `mkdir -p .', in order to
33   # allow $(mkdir_p) to be used without argument.  As in
34   #   $(mkdir_p) $(somedir)
35   # where $(somedir) is conditionally defined.  However we don't do
36   # that anymore.
37   #  1. before we restricted the check to GNU mkdir, `mkdir -p .' was
38   #     reported to fail in read-only directories.  The system where this
39   #     happened has been forgotten.
40   #  2. in practice we call $(mkdir_p) on directories such as
41   #       $(mkdir_p) "$(DESTDIR)$(somedir)"
42   #     and we don't want to create $(DESTDIR) if $(somedir) is empty.
43   #     To support the latter case, we have to write
44   #       test -z "$(somedir)" || $(mkdir_p) "$(DESTDIR)$(somedir)"
45   #     so $(mkdir_p) always has an argument.
46   #     We will have better chances of detecting a missing test if
47   #     $(mkdir_p) complains about missing arguments.
48   #  3. $(mkdir_p) is named after `mkdir -p' and we don't expect this
49   #     to accept no argument.
50   #  4. having something like `mkdir .' in the output is unsightly.
51   mkdir_p='mkdir -p'
52 else
53   # On NextStep and OpenStep, the `mkdir' command does not
54   # recognize any option.  It will interpret all options as
55   # directories to create.
56   for d in ./-p ./--version;
57   do
58     test -d $d && rmdir $d
59   done
60   # $(mkinstalldirs) is defined by Automake if mkinstalldirs exists.
61   if test -f "$ac_aux_dir/mkinstalldirs"; then
62     mkdir_p='$(mkinstalldirs)'
63   else
64     mkdir_p='$(install_sh) -d'
65   fi
66 fi
67 AC_SUBST([mkdir_p])])