source: trunk/third/top/Configure @ 14449

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