This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add the files from dist/meta to perl's repo
[metaconfig.git] / dist / U / install.U
1 ?RCS: $Id: install.U 1 2006-08-24 12:32:52Z rmanfredi $
2 ?RCS:
3 ?RCS: Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi
4 ?RCS: 
5 ?RCS: You may redistribute only under the terms of the Artistic Licence,
6 ?RCS: as specified in the README file that comes with the distribution.
7 ?RCS: You may reuse parts of this distribution only within the terms of
8 ?RCS: that same Artistic Licence; a copy of which may be found at the root
9 ?RCS: of the source tree for dist 4.0.
10 ?RCS:
11 ?RCS: $Log: install.U,v $
12 ?RCS: Revision 3.0.1.2  1995/09/25  09:16:37  ram
13 ?RCS: patch59: all possible install programs are now looked for
14 ?RCS:
15 ?RCS: Revision 3.0.1.1  1995/01/11  15:30:41  ram
16 ?RCS: patch45: created
17 ?RCS:
18 ?MAKE:install installdir: Loc Oldconfig Getfile cat test startsh rm +cc \
19         eunicefix package contains mkdir echo n c
20 ?MAKE:  -pick add $@ %<
21 ?S:install:
22 ?S:     This variable contains the name of an install program that can accept
23 ?S:     BSD-style arguments. It must correctly support -c, -s, and -m at least.
24 ?S:     It is a fully qualified pathname when found. If you have a local
25 ?S:     install.SH file at the root directory of your package, it is assumed to
26 ?S:     be the default script emulating a BSD install and the variable will be
27 ?S:     set to ./install. Otherwise, it is set to plain 'install', relying on
28 ?S:     the user's PATH to perform miracles.
29 ?S:.
30 ?S:installdir:
31 ?S:     This variable contains the name of a program that can install nested
32 ?S:     directories. Often set to 'mkdir -p', it can also be 'install -d' if
33 ?S:     you have such a beast and lack the former. If you have an install.SH
34 ?S:     file at the root directory of your package, it will be used in last
35 ?S:     resort, setting the variable to './install -d'. Otherwise, it is set to
36 ?S:     plain 'mkdir', and cross your fingers!
37 ?S:.
38 ?T:dir file tryit prog creatdir either
39 ?F:!tryinst
40 : locate a BSD compatible install program
41 echo " "
42 echo "Looking for a BSD-compatible install program..." >&4
43 @if installdir
44 creatdir=''
45 @end
46 case "$install" in
47 '')
48         tryit=''
49         for dir in $pth; do
50                 for file in ginstall installbsd scoinst install; do
51                         if $test -f $dir/$file; then
52                                 tryit="$tryit $dir/$file"
53                         fi
54                 done
55         done
56         $cat >try.c <<EOC
57 int main()
58 {
59         printf("OK\n");
60         exit(0);
61 }
62 EOC
63         if $cc -o try try.c >/dev/null 2>&1; then
64                 cp try try.ns
65                 strip try >/dev/null 2>&1
66         else
67                 echo "(I can't seem to compile a trivial C program -- bypassing.)"
68                 echo "try" >try
69                 cp try try.ns
70         fi
71         $cat >tryinst <<EOS
72 $startsh
73 $rm -rf foo d
74 @if installdir
75 \$1 -d foo/bar
76 @end
77 $mkdir d
78 \$1 -c -m 764 try.ns d
79 \$1 -c -s -m 642 try.ns d/try
80 EOS
81         chmod +x tryinst
82         $eunicefix tryinst
83         dflt=''
84         either=''
85         for prog in $tryit; do
86                 $echo $n "Checking $prog... $c"
87                 ./tryinst $prog >/dev/null 2>&1
88 @if installdir
89                 if $test -d foo/bar; then
90                         creatdir="$prog -d"
91                 fi
92 @end
93                 (ls -l d/try >try.ls; ls -l d/try.ns >tryno.ls) 2>/dev/null
94                 if (cmp -s d/try try && cmp -s d/try.ns try.ns && \
95                         $contains 'rwxrw-r--' tryno.ls && \
96                         $contains 'rw-r---w-' try.ls) >/dev/null 2>&1
97                 then
98                         dflt="$prog"
99                         echo "ok, that will do."
100                         break
101                 fi
102                 echo "not good$either."
103                 either=' either'
104                 $rm -f try*.ls
105         done
106         $rm -rf foo d tryinst try try*.ls try.*
107         case "$dflt" in
108         '')
109 @if {test -f ../install.SH}
110                 echo "Hopefully, $package comes with its own install script!"
111                 dflt='./install'
112 @else
113                 dflt='install'
114 @end
115                 ;;
116         esac
117         ;;
118 *) dflt="$install";;
119 esac
120 $cat <<EOM
121
122 I will be requiring a BSD-compatible install program (one that allows
123 options like -s to strip executables or -m to specify a file mode) to
124 install $package.
125
126 If the question below contains a fully qualified default path, then it
127 is probably ok. If it is an unqualified name such as 'install', then it
128 means I was unable to find out a good install program I could use. If
129 @if {test -f ../install.SH}
130 you know of one, please tell me about it. If the default is './install',
131 then I shall be using the install script supplied with $package.
132 @else
133 you know of one, please tell me about it.
134 @end
135
136 EOM
137 @if {test -f ../install.SH}
138 fn='/fe~(install,./install)'
139 @else
140 fn='/fe~(install)'
141 @end
142 rp='Which install program shall I use?'
143 . ./getfile
144 install="$ans"
145
146 @if installdir
147 : how can we create nested directories?
148 echo " "
149 echo "Ok, let's see how we can create nested directories..." >&4
150 case "$installdir" in
151 '')
152 ?X: First time, maybe we already found out a working one in $creatdir above...
153 ?X: Prefer "mkdir -p" because of bugs in GNU install when not running as root
154         $mkdir -p foo/bar >/dev/null 2>&1
155         if $test -d foo/bar; then
156                 echo "Great, we can build them using 'mkdir -p'."
157                 creatdir='mkdir -p'
158         else
159                 case "$creatdir" in
160                 '')
161                         if eval "$install -d foo/bar"; $test -d foo/bar; then
162                                 creatdir="install -d"
163                                 echo "It looks like '$creatdir' will do it for us."
164                         fi
165                         ;;
166                 *)
167                         eval "$creatdir foo/bar" >/dev/null 2>&1
168                         if $test -d foo/bar; then
169                                 echo "Ah! We can use '$creatdir' to do just that."
170                         else
171                                 creatdir=''
172                         fi
173                         ;;
174                 esac
175         fi
176         $rm -rf foo
177         case "$creatdir" in
178         '')
179                 echo "Heck! Another ancient system lacking the comfort of modern ones!"
180 @if {test -f ../install.SH}
181                 echo "You can thank $package for bringing you its own install script!"
182                 installdir='./install -d'
183 @else
184                 echo "We have no choice but to use plain old 'mkdir' -- wish me luck!"
185                 installdir=mkdir
186 @end
187                 ;;
188         *) installdir="$creatdir";;
189         esac
190         ;;
191 *) echo "As you already told me, '$installdir' should work.";;
192 esac
193
194 @end