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