source: trunk/third/top/Configure @ 16189

Revision 16189, 14.6 KB checked in by ghudson, 24 years ago (diff)
Merge with top 3.5beta12.
  • Property svn:executable set to *
Line 
1#!/bin/csh -f
2#
3# Configuration script for top.
4#
5# Use with version 3.0 and higher.
6#
7set PRIME = "/usr/games/primes"
8set vars = (module LoadMax topn NominalTopn delay owner group mode random \
9        TableSize bindir mandir manext mansty \
10        Cmdshell Cmdcc Cmdawk Cmdinstall cdefs)
11set fastrack = 0
12set yesno = (no yes)
13
14onintr byebye
15
16# make sure that getans is there and ready
17if (! -x getans) then
18   echo 'This package is not complete.  The shell file "getans" is missing.'
19   exit 10
20endif
21
22if ($#argv > 0) then
23# fast track configuration
24   set fastrack = 1
25else
26cat <<'EOF'
27Configuration for top, version 3.5
28
29One moment....
30'EOF'
31endif
32
33# collect file names and module names
34ls machine/m_*.c >$$.f
35ls machine/m_*.man >$$.m
36sed -e 's@^machine/m_@@' -e 's/.c$//' $$.f >$$.n
37
38# build Make.desc
39sed -e 's@\.c@.desc\\@' $$.f | sed -e '$s/\\//' >$$.a
40sed -e "/^DESCS/r $$.a" Make.desc.X >Make.desc
41
42# build desc files and SYNOPSIS as needed
43make -f Make.desc >/dev/null
44if ($status != 0) then
45   echo "Unable to build the synopsis."
46   echo 'Make sure the command "make" is on your path and try'
47   echo 'running Configure again.'
48   exit 1
49endif
50
51if (-e .defaults) then
52   echo ""
53   echo "Reading configuration from last time..."
54   source .defaults
55   set nodefaults = 0
56   if ($fastrack == 1) then
57      set module = $1
58   endif
59else
60   if ($fastrack == 1) then
61      echo "No previous configuration was found."
62      set fastrack = 0
63      set module = $1
64   else
65      set module = ""
66   endif
67   set LoadMax     = 5.0
68   set topn        = 15
69   set NominalTopn = 18
70   set delay       = 5
71   set TableSize   = 0
72   set bindir      = /usr/local/bin
73   set mandir      = /usr/man/manl
74   set manext      = l
75   set mansty      = man
76   set nodefaults  = 1
77   set Cmdshell    = /bin/sh
78   set Cmdawk      = awk
79   set Cmdinstall  = ./install
80   set Cmdcc       = cc
81   set cdefs       = -O
82endif
83echo ""
84
85if ($fastrack == 1) then
86   grep -s $module $$.n >/dev/null
87   if ($status != 0) then
88      echo "$module is not recognized.  To see a list of available modules"
89      echo 'run "Configure" with no arguments.'
90      rm -f $$.[fmna]
91      exit 1
92   endif
93   set random1 = `expr $random + 1`
94   cat <<EOF
95Using these settings:
96        Bourne Shell   $Cmdshell
97          C compiler   $Cmdcc
98    Compiler options   $cdefs
99         Awk command   $Cmdawk
100     Install command   $Cmdinstall
101
102              Module   $module
103             LoadMax   $LoadMax
104        Default TOPN   $topn
105        Nominal TOPN   $NominalTopn
106       Default Delay   $delay
107Random passwd access   $yesno[$random1]
108          Table Size   $TableSize
109               Owner   $owner
110         Group Owner   $group
111                Mode   $mode
112       bin directory   $bindir
113       man directory   $mandir
114       man extension   $manext
115       man style       $mansty
116
117EOF
118   goto fast
119endif
120
121cat <<'EOF'
122You will be asked a series of questions.  Each question will have a
123default answer enclosed in brackets, such as "[5.0]".  In most cases,
124the default answer will work well.  To use that value, merely press
125return.
126
127'EOF'
128
129# display synopses
130
131getmod:
132cat <<'EOF'
133
134The following machine-dependent modules are available:
135'EOF'
136awk -F: ' { printf "%-10s %s\n", $1, $2 }' SYNOPSIS
137echo ''
138./getans "What module is appropriate for this machine? " string "$module" .$$
139set module = `cat .$$`
140
141if ("$module" == "") then
142    echo "Please specify a valid module name."
143    goto getmod
144endif
145
146# is it a valid one?
147grep -s "$module" $$.n >/dev/null
148if ($status != 0) then
149    echo "That is not a recognized module name."
150    goto getmod
151endif
152
153# display a full description
154sed -e '1,/DESCRIPTION:/d' -e '/^$/,$d' machine/m_${module}.desc
155
156# verify it
157echo ""
158./getans "Is this what you want to use?" yesno 1 .$$
159if (`cat .$$` == 0) then
160   goto getmod
161endif
162endif
163
164cat <<'EOF'
165
166First we need to find out a little bit about the executables needed to
167compile top.
168
169'EOF'
170./getans "What is the full path name for the Bourne shell" file "$Cmdshell" .$$
171set Cmdshell = `cat .$$`
172
173cat <<'EOF'
174
175Please supply the name of the appropriate command.  It need not be a
176full path name, but the named command does need to exist somewhere on
177the current path.
178
179'EOF'
180./getans "AWK Interpreter" path "$Cmdawk" .$$
181set Cmdawk = `cat .$$`
182./getans "C Compiler" path "$Cmdcc" .$$
183set Cmdcc = `cat .$$`
184
185cat <<'EOF'
186
187The installer command needs to understand Berkeley-esque arguments:
188"-o" for owner, "-g" for group, and "-m" for mode.  A shell script
189called "install" is distributed with top and is suitable for use by
190top.  You can specify a different program here if you like, or use
191the shell script (the default).
192
193'EOF'
194./getans "Installer" path "$Cmdinstall" .$$
195set Cmdinstall = `cat .$$`
196
197cat <<EOF
198
199What other options should be used with the $Cmdcc command (use "none" to
200specify no options)?
201EOF
202./getans "Compiler options" string "$cdefs" .$$
203set cdefs = `cat .$$`
204if ("$cdefs" == "none") then
205    set cdefs = ""
206endif
207
208cat <<'EOF'
209
210Now you need to answer some questions concerning the configuration of
211top itself.
212
213The space command forces an immediate update.  Sometimes, on loaded
214systems, this update will take a significant period of time (because all
215the output is buffered).  So, if the short-term load average is above
216"LoadMax", then top will put the cursor home immediately after the space
217is pressed before the next update is attempted.  This serves as a visual
218acknowledgement of the command.  "LoadMax" should always be specified as a
219floating point number.
220
221'EOF'
222./getans "LoadMax" number "$LoadMax" .$$
223set LoadMax = `cat .$$`
224
225cat <<'EOF'
226
227"Default TOPN" is the default number of processes to show.  This is the
228number that will be used when the user does not specify the number of
229processes to show.  If you want "all" (or infinity) as the default, use
230the value "-1".
231
232'EOF'
233
234./getans "Default TOPN" neginteger "$topn" .$$
235set topn = `cat .$$`
236
237cat <<'EOF'
238
239"Nominal_TOPN" is used as the default TOPN when Default_TOPN is Infinity
240and the output is a dumb terminal.  If we didn't do this, then
241installations who use a default TOPN of Infinity will get every process in
242the system when running top on a dumb terminal (or redirected to a file).
243Note that Nominal_TOPN is a default: it can still be overridden on the
244command line, even with the value "infinity".
245
246'EOF'
247
248./getans "Nominal TOPN" integer "$NominalTopn" .$$
249set NominalTopn = `cat .$$`
250
251cat <<'EOF'
252
253Default Delay is the default number of seconds to wait between screen
254updates.
255
256'EOF'
257
258./getans "Default Delay" integer "$delay" .$$
259set delay = `cat .$$`
260
261echo ""
262
263set rand = 0
264if (-e /etc/nsswitch.conf) then
265   set rand = `grep '^passwd:.*nis' /etc/nsswitch.conf | wc -l`
266   if ($rand > 1) then
267      set rand = 1
268   endif
269else
270   ypwhich >&/dev/null
271   if ($status == 0 || -e /etc/passwd.dir || -e /etc/pwd.db) then
272      set rand = 1
273   endif
274endif
275
276if ($rand == 1) then
277   echo "It looks like you have a passwd file that can be accessed at random."
278   set pr = 'Do you want top to take advantage of this'
279else
280   echo "It looks like you have conventional passwd file access.  Top can take"
281   echo "advantage of a random access passwd mechanism if such exists.  Do"
282   echo "you want top to assume that accesses to the file /etc/passwd are done"
283   set pr = 'with random access rather than sequential'
284endif
285
286if ($nodefaults == 1) then
287   set random = $rand
288endif
289
290./getans "${pr}?" yesno $random .$$
291set random = `cat .$$`
292
293echo ""
294echo "Compiling prime.c"
295$Cmdcc $cdefs -o prime prime.c -lm
296if ($status != 0) then
297    echo "Oh well."
298    rm -f prime
299endif
300
301echo ""
302
303ypcat passwd.byname >&/tmp/$$.a
304if ($status == 0) then
305   set cnt = `wc -l </tmp/$$.a`
306   set mapfile = "NIS map"
307else
308   rm /tmp/$$.a
309   niscat passwd.org_dir >&/tmp/$$.a
310   if ($status == 0) then
311      set cnt = `wc -l </tmp/$$.a`
312      set mapfile = "NISPLUS map"
313   else
314      set cnt = `wc -l </etc/passwd`
315      set mapfile = "file"
316   endif
317endif
318rm /tmp/$$.a
319set double = `expr $cnt \* 2`
320echo "I found $cnt entries in your passwd $mapfile.  Top hashes the username to"
321echo "uid mappings as it goes along and it needs a good guess on the size of"
322echo "that hash table.  This number should be the next highest prime number"
323echo "after $double."
324echo ""
325if (-e prime) then
326   set pr = `./prime $double`
327   echo "I have calculated that to be $pr."
328else if (-e $PRIME) then
329   set pr = `$PRIME $double | head -1`
330   echo "I have calculated that to be $pr."
331else
332   set pr = $double
333   echo "I cannot calculate that prime number, so you will need to provide it for me."
334endif
335
336if ($TableSize == 0) then
337   set TableSize = $pr
338endif
339
340./getans "Enter the hash table size" integer "$TableSize" .$$
341set TableSize = `cat .$$`
342
343echo ""
344
345# !!! I need to fix this:  /dev/kmem might not exist on some machines !!!
346
347# determine the right way to invoke ls to get full output
348set ls = "ls -l"
349if (`$ls getans | wc -w` < 9) then
350   set ls = "ls -lg"
351endif
352
353set t_owner = root
354set t_group = `$ls -d /usr/bin | awk ' { print $4 }'`
355if (-e /proc) then
356   cat <<EOF
357I see /proc out there.  Many Unix variants provide the /proc file
358system as a mechanism to get to a process's address space.  This
359directory is typically only accessible by root.  However, there are a
360few systems (such as DG/UX) on which this directory exists, but isn't
361used.
362
363EOF
364   if (-r /proc/0/psinfo) then
365       set t_mode = 2711
366       set mode = 2711
367       set t_group = sys
368       set group = sys
369       cat <<EOF
370It looks like this system is running Solaris 2.6 or greater.  If this
371is the case, then top can function just fine installed set group id to
372sys.  It does not need to be installed set-uid to root.
373
374EOF
375   else
376       set t_mode = 4711
377       set mode = 4711
378       cat <<EOF
379I'm going to assume that top needs to run setuid to root, but you
380should double check and use mode 2755 (set group id) if top doesn't
381really need root access.  If you are running SunOS 5.0 through SunOS
3825.5.1 (that's Solaris 2.0 through Solaris 2.5.1) then you will need to
383install top setuid root (owner root and mode 4711).  In SunOS 5.6
384and higher top only requires set group id sys permissions.
385
386EOF
387    endif
388else if (-e /dev/kmem) then
389   $ls /dev/kmem >/tmp/$$.b
390   grep '^....r..r..' /tmp/$$.b >&/dev/null
391   if ($status == 1) then
392      grep '^....r..-..' /tmp/$$.b >&/dev/null
393      if ($status == 0) then
394         set t_group = `awk ' { print $4 }' /tmp/$$.b`
395         set t_mode = 2755
396         echo "It looks like only group $t_group can read the memory devices."
397      else
398         set t_mode = 4755
399         echo "It looks like only root can read the memory devices."
400      endif
401   else
402      set t_mode = 755
403      echo "It looks like anybody can read the memory devices."
404   endif
405else
406   echo "It looks like there are no memory device special files."
407   set t_mode = 755
408endif
409if ($nodefaults) then
410   set owner = $t_owner
411   set group = $t_group
412   set mode =  $t_mode
413endif
414echo "Tell me how to set the following when top is installed:"
415./getans "Owner" user "$owner" .$$
416set owner = `cat .$$`
417./getans "Group owner" group "$group" .$$
418set group = `cat .$$`
419./getans "Mode" integer "$mode" .$$
420set mode = `cat .$$`
421rm -f /tmp/$$.b
422
423echo ""
424./getans "Install the executable in this directory" file "$bindir" .$$
425set bindir = `cat .$$`
426
427echo ""
428./getans "Install the manual page in this directory" file "$mandir" .$$
429set mandir = `cat .$$`
430
431echo ""
432./getans "Install the manual page with this extension" string "$manext" .$$
433set manext = `cat .$$`
434
435echo ""
436./getans "Install the manual page as 'man' or 'catman'" string "$mansty" .$$
437set mansty = `cat .$$`
438
439echo ""
440echo "We are done with the questions."
441
442# Some Unix environments are so poor that their csh doesn't even support
443# the "eval" builtin.  Check for this before relying on its use to save
444# the current configuration.
445/bin/csh -fc "eval echo foo" >&/dev/null
446if ($status == 1) then
447   echo "Can't save configuration (nonfatal)"
448else
449   echo "Saving configuration..."
450# save settings to use as defaults the next time
451   rm -f .defaults
452   touch .defaults
453   foreach v ($vars)
454      set tmp = `eval echo \$$v`
455      echo set $v = "'$tmp'" >>.defaults
456   end
457endif
458
459fast:
460
461# clean up
462rm -f $$.[fmna]
463
464# set the link for machine.c
465rm -f machine.c machine.o
466ln -s machine/m_${module}.c machine.c
467
468# get definitions out of the module file
469set libs = `grep LIBS: machine/m_${module}.desc | sed -e 's/^.[^:]*: *//'`
470set cflgs = `grep CFLAGS: machine/m_${module}.desc | sed -e 's/^.[^:]*: *//'`
471set tcap = `grep TERMCAP: machine/m_${module}.desc | sed -e 's/^.[^:]*: *//'`
472set math = `grep MATH: machine/m_${module}.desc | sed -e 's/^.[^:]*: *//'`
473
474# get osrev defition, if we can
475set uname=""
476if (-e /usr/bin/uname) then
477    set uname=/usr/bin/uname
478else if (-e /bin/uname) then
479    set uname=/bin/uname
480endif
481
482if ("$uname" != "") then
483# different versions of tr can't agree on the way to specify ranges, so
484# we will have to give the range explicitly.....sigh.
485    set osrev="-DOSREV=`$uname -r | tr -cd ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`"
486else
487    set osrev=""
488endif
489
490# default for tcap (termcap)
491if ("$tcap" == "") then
492    set tcap="-ltermcap"
493else if ("$tcap" == "none") then
494    set tcap=""
495endif
496
497# allow for the module to override or remove -lm
498if ("$math" == "") then
499    set math="-lm"
500else if ("$math" == "none") then
501    set math=""
502endif
503
504if ( { grep -s SIGKILL /usr/include/signal.h } ) then
505    set signal="/usr/include/signal.h"
506else
507    set signal="/usr/include/sys/signal.h"
508endif
509
510
511echo "Building Makefile..."
512sed -e "s|%topn%|$topn|" \
513    -e "s|%delay%|$delay|" \
514    -e "s|%owner%|$owner|" \
515    -e "s|%group%|$group|" \
516    -e "s|%mode%|$mode|" \
517    -e "s|%bindir%|$bindir|" \
518    -e "s|%mandir%|$mandir|" \
519    -e "s|%manext%|$manext|" \
520    -e "s|%mansty%|$mansty|" \
521    -e "s|%tablesize%|$TableSize|" \
522    -e "s|%libs%|$libs|" \
523    -e "s|%cflgs%|$cflgs|" \
524    -e "s|%termcap%|$tcap|" \
525    -e "s|%math%|$math|" \
526    -e "s|%cdefs%|$cdefs|" \
527    -e "s|%signal%|$signal|" \
528    -e "s|%cc%|$Cmdcc|" \
529    -e "s|%awk%|$Cmdawk|" \
530    -e "s|%install%|$Cmdinstall|" \
531    -e "s|%shell%|$Cmdshell|" \
532    -e "s|%osrev%|$osrev|" \
533        Makefile.X >Makefile
534
535echo "Building top.local.h..."
536sed -e "s|%LoadMax%|$LoadMax|" \
537    -e "s|%TableSize%|$TableSize|" \
538    -e "s|%NominalTopn%|$NominalTopn|" \
539    -e "s|%topn%|$topn|" \
540    -e "s|%delay%|$delay|" \
541    -e "s|%random%|$random|" \
542        top.local.H >top.local.h
543
544echo "Building top.1..."
545sed -e "s|%topn%|$topn|" \
546    -e "s|%delay%|$delay|" \
547        top.X >top.1
548if (-e machine/m_${module}.man ) then
549    cat machine/m_${module}.man >>top.1
550endif
551
552# clean up
553rm -f .$$
554
555echo 'Doing a "make clean".'
556make clean
557
558echo 'To create the executable, type "make".'
559echo 'To install the executable, type "make install".'
560exit 0
561
562byebye:
563rm -f .$$ $$.[fmna] /tmp/$$.[ab]
564exit 1
Note: See TracBrowser for help on using the repository browser.