This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[UTIL] Perl system does not default to $_
[metaconfig.git] / dist / U / d_gethname.U
1 ?RCS: $Id$
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 License,
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 License; 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: d_gethname.U,v $
12 ?RCS: Revision 3.0.1.1  1994/10/29  16:13:00  ram
13 ?RCS: patch36: call ./xenix explicitely instead of relying on PATH
14 ?RCS:
15 ?RCS: Revision 3.0  1993/08/18  12:06:11  ram
16 ?RCS: Baseline for dist 3.0 netwide release.
17 ?RCS:
18 ?MAKE:d_gethname d_uname d_phostname aphostname: phostname cat \
19         myhostname package d_portable Loc echo n c +i_whoami +usrinc \
20         Myread Guess Oldconfig Csym
21 ?MAKE:  -pick add $@ %<
22 ?S:d_gethname:
23 ?S:     This variable conditionally defines the HAS_GETHOSTNAME symbol, which
24 ?S:     indicates to the C program that the gethostname() routine may be
25 ?S:     used to derive the host name.
26 ?S:.
27 ?S:d_uname:
28 ?S:     This variable conditionally defines the HAS_UNAME symbol, which
29 ?S:     indicates to the C program that the uname() routine may be
30 ?S:     used to derive the host name.
31 ?S:.
32 ?S:d_phostname:
33 ?S:     This variable conditionally defines the PHOSTNAME symbol, which
34 ?S:     contains the shell command which, when fed to popen(), may be
35 ?S:     used to derive the host name.
36 ?S:.
37 ?S:aphostname:
38 ?S:     Thie variable contains the command which can be used to compute the
39 ?S:     host name. The command is fully qualified by its absolute path, to make
40 ?S:     it safe when used by a process with super-user privileges.
41 ?S:.
42 ?C:HAS_GETHOSTNAME (GETHOSTNAME):
43 ?C:     This symbol, if defined, indicates that the C program may use the
44 ?C:     gethostname() routine to derive the host name.  See also HAS_UNAME
45 ?C:     and PHOSTNAME.
46 ?C:.
47 ?C:HAS_UNAME (UNAME):
48 ?C:     This symbol, if defined, indicates that the C program may use the
49 ?C:     uname() routine to derive the host name.  See also HAS_GETHOSTNAME
50 ?C:     and PHOSTNAME.
51 ?C:.
52 ?C:PHOSTNAME:
53 ?C:     This symbol, if defined, indicates that the C program may use the
54 ?C:     contents of PHOSTNAME as a command to feed to the popen() routine
55 ?C:     to derive the host name.  See also HAS_GETHOSTNAME and HAS_UNAME.
56 ?C:     Note that the command uses a fully qualified path, so that it is safe
57 ?C:     even if used by a process with super-user privileges.
58 ?C:.
59 ?H:#$d_gethname HAS_GETHOSTNAME /**/
60 ?H:#$d_uname HAS_UNAME          /**/
61 ?H:#$d_phostname PHOSTNAME "$aphostname"        /* How to get the host name */
62 ?H:.
63 ?T:file val call
64 ?LINT:change i_whoami
65 : see how we will look up host name
66 echo " "
67 if false; then
68         : dummy stub to allow use of elif
69 @if HAS_GETHOSTNAME
70 elif set gethostname val -f d_gethname; eval $csym; $val; then
71         echo 'gethostname() found.' >&4
72         d_gethname="$define"
73         call=gethostname
74 @end
75 @if HAS_UNAME
76 elif set uname val -f d_uname; eval $csym; $val; then
77         if ./xenix; then
78                 $cat <<'EOM'
79 uname() was found, but you're running xenix, and older versions of xenix
80 have a broken uname(). If you don't really know whether your xenix is old
81 enough to have a broken system call, use the default answer.
82
83 EOM
84                 dflt=y
85                 case "$d_uname" in
86                 "$define") dflt=n;;
87                 esac
88                 rp='Is your uname() broken?'
89                 . ./myread
90                 case "$ans" in
91                 n*) d_uname="$define"; call=uname;;
92                 esac
93         else
94                 echo 'uname() found.' >&4
95                 d_uname="$define"
96                 call=uname
97         fi
98 @end
99 fi
100 case "$d_gethname" in
101 '') d_gethname="$undef";;
102 esac
103 case "$d_uname" in
104 '') d_uname="$undef";;
105 esac
106 @if PHOSTNAME || MYHOSTNAME
107 case "$d_uname$d_gethname" in
108 *define*)
109         dflt=n
110         cat <<EOM
111
112 Every now and then someone has a $call() that lies about the hostname
113 but can't be fixed for political or economic reasons.  If you wish, I can
114 @if MYHOSTNAME && PHOSTNAME
115 pretend $call() isn't there and maybe compile in the hostname or
116 compute it from the '$phostname' command at run-time.
117 @elsif MYHOSTNAME
118 pretend $call() isn't there and maybe compile in the hostname.
119 @elsif PHOSTNAME
120 pretend $call() isn't there and maybe compute hostname at run-time
121 thanks to the '$phostname' command.
122 @elsif WHOAMI
123 get the hostname from whomai.h (provided you have one).
124 @else
125 simply ignore your host name and use someting like "noname" instead.
126 @end
127
128 EOM
129         rp="Shall I ignore $call() from now on?"
130         . ./myread
131         case "$ans" in
132         y*) d_uname="$undef" d_gethname="$undef"; $echo $n "Okay...$c";;
133         esac;;
134 esac
135 @end
136 @if PHOSTNAME || aphostname
137 ?X: Compute the full path name for the command
138 case "$phostname" in
139 '') aphostname='';;
140 *) case "$aphostname" in
141         /*) ;;
142         *) set X $phostname
143                 shift
144                 file=$1
145                 shift
146                 file=`./loc $file $file $pth`
147                 aphostname=`echo $file $*`
148                 ;;
149         esac
150         ;;
151 esac
152 @end
153 @if PHOSTNAME && MYHOSTNAME
154 case "$d_uname$d_gethname" in
155 *define*) ;;
156 *)
157         case "$phostname" in
158         '') ;;
159         *)
160                 $cat <<EOT
161
162 There is no gethostname() or uname() on this system.  You have two
163 possibilities at this point:
164
165 1)  You can have your host name ($myhostname) compiled into $package, which
166     lets $package start up faster, but makes your binaries non-portable, or
167 2)  you can have $package use a
168
169         popen("$aphostname","r")
170
171     which will start slower but be more portable.
172
173 @       if WHOAMI
174 Option 1 will give you the option of using whoami.h if you have one.
175 @       end
176 If you want option 2 but with a different command, you can edit config.sh at
177 the end of this shell script.
178
179 EOT
180                 case "$d_phostname" in
181                 "$define") dflt=n;;
182                 "$undef")  dflt=y;;
183                 '')
184                         case "$d_portable" in
185                         "$define") dflt=n ;;
186                         *) dflt=y ;;
187                         esac;;
188                 esac
189                 rp="Do you want your host name compiled in?"
190                 . ./myread
191                 case "$ans" in
192                 n*) d_phostname="$define" ;;
193                 *) aphostname=''; d_phostname="$undef";;
194                 esac;;
195         esac
196         case "$aphostname" in
197         '')
198 @       if WHOAMI
199                 case "$i_whoami" in
200                 "$define")
201                         dflt=y
202                         $cat <<EOM
203
204 No hostname function--you can either use the whoami.h file, which has this line:
205
206         `grep sysname $usrinc/whoami.h`
207
208 or you can have the name we came up with earlier ($myhostname) hardwired in.
209 EOM
210                         rp="Use whoami.h to get hostname?"
211                         . ./myread
212                         case "$ans" in
213                         n*) i_whoami="$undef";;
214                         esac
215                         ;;
216                 "$undef")
217                         $cat <<EOM
218 No hostname function and no whoami.h -- hardwiring "$myhostname".
219 EOM
220                         ;;
221                 esac;;
222 @       else
223                 echo 'No hostname function -- hardwiring "'$myhostname'".' >&4;;
224 @       end
225         esac;;
226 esac
227 @elsif PHOSTNAME
228 case "$d_uname$d_gethname" in
229 *define*) ;;
230 *)
231         case "$phostname" in
232         '')
233 @       if WHOAMI
234                 case "$i_whoami" in
235                 "$define")
236                         $cat <<EOM
237
238 No hostname function--we'll use the whoami.h file, which has this line:
239
240         `grep sysname $usrinc/whoami.h`
241
242 EOM
243                         ;;
244                 *) echo "There will be no way for $package to get your hostname." >&4;;
245                 esac;;
246 @       else
247                 echo "There will be no way for $package to get your hostname." >&4;;
248 @       end
249         *)
250         echo "I'll use 'popen("'"'$aphostname'", "r")'"' to get your hostname." >&4
251                 ;;
252         esac;;
253 esac
254 @elsif MYHOSTNAME
255 case "$d_uname$d_gethname" in
256 *define*) ;;
257 *)
258 @       if WHOAMI
259         case "$i_whoami" in
260         "$define")
261                 dflt=y
262                 $cat <<EOM
263
264 No hostname function--you can either use the whoami.h file, which has this line:
265
266         `grep sysname $usrinc/whoami.h`
267
268 or you can have the name we came up with earlier ($myhostname) hardwired in.
269 EOM
270                 rp="Use whoami.h to get hostname?"
271                 . ./myread
272                 case "$ans" in
273                 n*) i_whoami="$undef";;
274                 esac
275                 ;;
276         "$undef")
277                 echo 'No whoami.h--hardwiring "'$myhostname'".' >&4;;
278         esac;;
279 @       else
280         echo 'Hardwiring "'$myhostname'".' >&4;;
281 @       end
282 esac
283 @end
284 case "$d_phostname" in
285 '') d_phostname="$undef";;
286 esac
287