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 / Loc.U
1 ?RCS: $Id: Loc.U 14 2006-08-28 16:51:14Z 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: Loc.U,v $
12 ?RCS: Revision 3.0.1.10  1997/02/28  15:04:16  ram
13 ?RCS: patch61: allow users to specify paths on the command line
14 ?RCS: patch61: will now substitute cp for ln if not supported
15 ?RCS:
16 ?RCS: Revision 3.0.1.9  1995/09/25  09:11:24  ram
17 ?RCS: patch59: commented the purpose of the #un-def directive
18 ?RCS: patch59: abort Configure run when mandatory command is missing
19 ?RCS:
20 ?RCS: Revision 3.0.1.8  1995/07/25  13:40:40  ram
21 ?RCS: patch56: now knows about OS/2 platforms
22 ?RCS:
23 ?RCS: Revision 3.0.1.7  1995/01/11  15:13:37  ram
24 ?RCS: patch45: protected "sh -c" within backquotes for Linux and SGI
25 ?RCS: patch45: added path lookup for the 'comm' program
26 ?RCS:
27 ?RCS: Revision 3.0.1.6  1994/10/29  15:56:14  ram
28 ?RCS: patch36: added ?F: line for metalint file checking
29 ?RCS: patch36: be careful and guard against wildcard searching (ADO)
30 ?RCS:
31 ?RCS: Revision 3.0.1.5  1994/06/20  06:54:55  ram
32 ?RCS: patch30: now locates find
33 ?RCS:
34 ?RCS: Revision 3.0.1.4  1994/05/13  15:18:15  ram
35 ?RCS: patch27: added byacc to the trylist (ADO)
36 ?RCS: patch27: lint lines reformatted (ADO)
37 ?RCS:
38 ?RCS: Revision 3.0.1.3  1994/01/24  14:01:44  ram
39 ?RCS: patch16: added metalint hint on changed PATH variable
40 ?RCS:
41 ?RCS: Revision 3.0.1.2  1993/12/15  08:16:52  ram
42 ?RCS: patch15: now set _test variable when test is built-in
43 ?RCS: patch15: fixed rare cases where echo is not needed
44 ?RCS:
45 ?RCS: Revision 3.0.1.1  1993/09/13  15:47:13  ram
46 ?RCS: patch10: test program not always in /bin/test (WAD)
47 ?RCS:
48 ?RCS: Revision 3.0  1993/08/18  12:05:05  ram
49 ?RCS: Baseline for dist 3.0 netwide release.
50 ?RCS:
51 ?X:
52 ?X: This unit produces a shell script "loc" which can be used to find out
53 ?X: where in a list of directories something is.  It then uses loc to
54 ?X: determine the location of commonly used programs.  It leaves loc sitting
55 ?X: around for other Configure units to use, but arranges for its demise
56 ?X: at the end of Configure.
57 ?X:
58 ?X: To add a new program to find, add it both to the ?MAKE: line and to either
59 ?X: the loclist or trylist variable.
60 ?X:
61 ?X: I put startsh at the end of the dependency list, in order to avoid the
62 ?X: loading of the spitshell unit before the instructions.
63 ?X:
64 ?MAKE:Loc awk ar bash bison byacc cat chgrp chmod chown \
65         comm compress cp cpio cpp csh date echo egrep emacs expr find flex \
66         gmake gzip grep inews ksh less line lint ln lp lpr ls mail mailx \
67         make mkdir more mv nm nroff perl pg pmake pr rm rmail sed sendmail \
68         shar sleep smail sort submit tail tar tbl tee test touch tr troff \
69         uname uniq uuname vi zcat zip:  eunicefix n c startsh Instruct Warn
70 ?MAKE:  -pick weed $@ %<
71 ?LINT:describe awk ar bash bison byacc cat chgrp chmod chown \
72         comm compress cp cpio cpp csh date echo egrep emacs expr find flex \
73         gmake gzip grep inews ksh less line lint ln lp lpr ls mail mailx \
74         make mkdir more mv nm nroff perl pg pmake pr rm rmail sed sendmail \
75         shar sleep smail sort submit tail tar tbl tee test touch tr troff \
76         uname uniq uuname vi zcat zip
77 ?V::pth loclist trylist
78 ?F:./loc
79 ?T:thisthing thing xxx dir file say DJGPP
80 ?T:_test _grep _cp _gmake _egrep _ln _make dflt
81 ?LINT: change PATH
82 : find out where common programs are
83 echo " "
84 echo "Locating common programs..." >&4
85 cat <<EOSC >loc
86 $startsh
87 case \$# in
88 0) exit 1;;
89 esac
90 thing=\$1
91 shift
92 dflt=\$1
93 shift
94 for dir in \$*; do
95         case "\$thing" in
96         .)
97         if test -d \$dir/\$thing; then
98                 echo \$dir
99                 exit 0
100         fi
101         ;;
102         *)
103 ?X:     Be careful in case thing includes wildcards that might expand to multiple
104 ?X:     files.  Choose the last one.  This happens when searching for shared
105 ?X:     libraries with version numbers.  How to choose which one we want is
106 ?X:     probably an insoluble problem, in general.
107 ?X:     Some folks leave things like libc.so.orig around w/o read
108 ?X:     permission.  A -r test would handle that, but since ./loc is
109 ?X:     also used to find executables (which are installed w/o read
110 ?X:     permission on SCO ODT 3.0, we can't include the -r test.
111         for thisthing in \$dir/\$thing; do
112                 : just loop through to pick last item
113         done
114         if test -f \$thisthing; then
115                 echo \$thisthing
116                 exit 0
117         elif test -f \$thisthing$_exe; then
118                 echo \$thisthing
119                 exit 0
120         elif test -f \$dir/\$thing.exe; then
121                 if test -n "$DJGPP"; then
122                         echo \$dir/\$thing.exe
123                 else
124                         : on Eunice apparently
125                         echo \$dir/\$thing
126                 fi
127                 exit 0
128         fi
129         ;;
130         esac
131 done
132 echo \$dflt
133 exit 1
134 EOSC
135 chmod +x loc
136 $eunicefix loc
137 loclist="
138 ?awk:awk
139 ?cat:cat
140 ?chgrp:chgrp
141 ?chmod:chmod
142 ?chown:chown
143 ?comm:comm
144 ?cp:cp
145 ?echo:echo
146 ?expr:expr
147 ?find:find
148 ?grep:grep
149 ?ls:ls
150 ?mkdir:mkdir
151 ?mv:mv
152 ?rm:rm
153 ?sed:sed
154 ?sleep:sleep
155 ?sort:sort
156 ?tail:tail
157 ?touch:touch
158 ?tr:tr
159 ?uniq:uniq
160 "
161 trylist="
162 ?Mcc:Mcc
163 ?ar:ar
164 ?bash:bash
165 ?bison:bison
166 ?byacc:byacc
167 ?compress:compress
168 ?cpio:cpio
169 ?cpp:cpp
170 ?csh:csh
171 ?date:date
172 ?egrep:egrep
173 ?emacs:emacs
174 ?flex:flex
175 ?gmake:gmake
176 ?gzip:gzip
177 ?inews:inews
178 ?ksh:ksh
179 ?less:less
180 ?line:line
181 ?lint:lint
182 ?ln:ln
183 ?lp:lp
184 ?lpr:lpr
185 ?mail:mail
186 ?mailx:mailx
187 ?make:make
188 ?more:more
189 ?nm:nm
190 ?nroff:nroff
191 ?perl:perl
192 ?pg:pg
193 ?pmake:pmake
194 ?pr:pr
195 ?rmail:rmail
196 ?sendmail:sendmail
197 ?shar:shar
198 ?smail:smail
199 ?submit:submit
200 ?tar:tar
201 ?tbl:tbl
202 ?tee:tee
203 ?test:test
204 ?troff:troff
205 ?uname:uname
206 ?uuname:uuname
207 ?vi:vi
208 ?zcat:zcat
209 ?zip:zip
210 "
211 ?LINT:set awk ar bash bison byacc cat chgrp chmod chown \
212         comm compress cp cpio cpp csh date echo emacs expr find flex \
213         gmake gzip grep inews ksh less line lint lp lpr ls mail mailx \
214         mkdir more mv nm nroff perl pg pmake pr rm rmail sed sendmail \
215         shar sleep smail sort submit tail tar tbl tee touch tr troff \
216         uname uniq uuname vi zcat zip
217 pth=`echo $PATH | sed -e "s/$p_/ /g"`
218 pth="$pth /lib /usr/lib"
219 for file in $loclist; do
220 ?X:
221 ?X: Allow them to -Dmake=pmake on the command line for instance...
222 ?X: If the file is not fully qualified, as in -Dmake=pmake, then we
223 ?X: look the for the specified command (pmake here). If they say
224 ?X: -Dmake=/sbin/make for instance, then we make sure the file
225 ?X: exists, or we die...
226 ?X:
227         eval xxx=\$$file
228         case "$xxx" in
229         /*|?:[\\/]*)
230                 if test -f "$xxx"; then
231                         : ok
232                 else
233                         ./warn "no $xxx -- ignoring your setting for $file."
234                         xxx=`./loc $file $file $pth`
235                 fi
236                 ;;
237         '') xxx=`./loc $file $file $pth`;;
238         *) xxx=`./loc $xxx $xxx $pth`;;
239         esac
240         eval $file=$xxx$_exe
241         eval _$file=$xxx
242         case "$xxx" in
243         /*)
244                 echo $file is in $xxx.
245                 ;;
246 ?X: Under OS/2, we have PC-like paths
247         ?:[\\/]*)
248                 echo $file is in $xxx.
249                 ;;
250         *)
251                 echo "I don't know where '$file' is, and my life depends on it." >&4
252                 echo "Go find a public domain implementation or fix your PATH setting!" >&4
253                 exit 1
254                 ;;
255         esac
256 done
257 echo " "
258 echo "Don't worry if any of the following aren't found..."
259 say=offhand
260 for file in $trylist; do
261 ?X: Allow them to -Dmake=pmake on the command line for instance (see above)
262         eval xxx=\$$file
263         case "$xxx" in
264         /*|?:[\\/]*)
265                 if test -f "$xxx"; then
266                         : ok
267                 else
268                         ./warn "no $xxx -- ignoring your setting for $file."
269                         xxx=`./loc $file $file $pth`
270                 fi
271                 ;;
272         '') xxx=`./loc $file $file $pth`;;
273         *) xxx=`./loc $xxx $xxx $pth`;;
274         esac
275         eval $file=$xxx$_exe
276         eval _$file=$xxx
277         case "$xxx" in
278         /*)
279                 echo $file is in $xxx.
280                 ;;
281 ?X: Under OS/2, we have PC-like paths
282         ?:[\\/]*)
283                 echo $file is in $xxx.
284                 ;;
285         *)
286                 echo "I don't see $file out there, $say."
287                 say=either
288                 ;;
289         esac
290 done
291 case "$egrep" in
292 egrep)
293         echo "Substituting grep for egrep."
294         egrep=$grep
295         _egrep=$_grep
296         ;;
297 esac
298 @if ln
299 case "$ln" in
300 ln)
301         echo "Substituting cp for ln."
302         ln=$cp
303         _ln=$_cp
304         ;;
305 esac
306 @end
307 @if make || gmake
308 case "$make" in
309 make)
310         case "$gmake" in
311         gmake)
312         echo "I can't find make or gmake, and my life depends on it." >&4
313         echo "Go find a public domain implementation or fix your PATH setting!" >&4
314         exit 1
315         ;;
316         esac
317         ;;
318 esac
319 case "$gmake" in
320 gmake)  ;;
321 *)      # We can't have osname yet.
322         if test -f "/system/gnu_library/bin/ar.pm"; then # Stratus VOS
323                 # Assume that gmake, if found, is definitely GNU make
324                 # and prefer it over the system make.
325                 echo "Substituting gmake for make."
326                 make=$gmake
327                 _make=$_gmake
328         fi
329         ;;
330 esac
331 @end
332 case "$test" in
333 test)
334         echo "Hopefully test is built into your sh."
335         ;;
336 *)
337         if `sh -c "PATH= test true" >/dev/null 2>&1`; then
338                 echo "Using the test built into your sh."
339 ?X:
340 ?X: We need to set both test and _test, since Oldconfig.U will use the _test
341 ?X: value to systematically restore computed paths, which may be wrong if
342 ?X: we choose to load an old config.sh generated on another platform.
343 ?X:
344                 test=test
345                 _test=test
346         fi
347         ;;
348 esac
349 ?LINT:change n c
350 case "$echo" in
351 echo)
352         echo "Hopefully echo is built into your sh."
353         ;;
354 ?X: For those rare cases where we don't need $echo...
355 '') ;;
356 *)
357         echo " "
358 echo "Checking compatibility between $echo and builtin echo (if any)..." >&4
359         $echo $n "hi there$c" >foo1
360         echo $n "hi there$c" >foo2
361         if cmp foo1 foo2 >/dev/null 2>&1; then
362                 echo "They are compatible.  In fact, they may be identical."
363         else
364                 case "$n" in
365                 '-n') n='' c='\c';;
366                 *) n='-n' c='';;
367                 esac
368                 cat <<FOO
369 They are not compatible!  You are probably running ksh on a non-USG system.
370 I'll have to use $echo instead of the builtin, since Bourne shell doesn't
371 have echo built in and we may have to run some Bourne shell scripts.  That
372 means I'll have to use '$n$c' to suppress newlines now.  Life is ridiculous.
373
374 FOO
375                 $echo $n "The star should be here-->$c"
376                 $echo "*"
377         fi
378         $rm -f foo1 foo2
379         ;;
380 esac
381