backward compatible processing for "+/pattern"
[unix-history] / usr / src / usr.bin / more / linstall
CommitLineData
bfe13c81
KB
1#! /bin/sh
2# Installation script for less.
3# This script prompts the operator for various information
4# and constructs a makefile.
5
6echo "This script will build a makefile for less."
7echo "If you already have a file called \"makefile\" it will be overwritten."
8echo "Press RETURN to continue."
9read ans
10
11echo "I will ask you some questions about your system."
12echo "If you do not know the answer to any question,"
13echo "just press RETURN and I will choose a default for you."
14echo "Press RETURN now."
15read ans
16
17ECHO=./vecho
18if [ ! -x $ECHO ]
19then
20 echo "One moment..."
21 cc -o $ECHO vecho.c
22 echo ""
23fi
24
25$ECHO "Most Unix systems are derived from either System V"
26$ECHO "or Berkeley BSD 4.1, 4.2, 4.3, etc."
27$ECHO ""
28$ECHO "Is your system closest to:"
29$ECHO " 1. System V"
30$ECHO " 2. BSD 4.1"
31$ECHO " 3. BSD 4.2 or later"
32$ECHO " 4. Xenix"
33$ECHO "Enter a number, or just RETURN if you don't know: \c"
34read ans
35xenix=0
36case "X$ans" in
37X1) sys=sys5; sysname="System V" ;;
38X2) sys=bsd; bsd41=1; sysname="BSD 4.1" ;;
39X3) sys=bsd; bsd41=0; sysname="BSD 4.2" ;;
40X4) sys=sys5; xenix=1; sysname="Xenix" ;;
41*) sys=unknown ;;
42esac
43$ECHO ""
44
45DATE=`date`
46cat >makefile <<EOF
47# Makefile for "less"
48# Generated $DATE by $0.
49EOF
50
51cat >>makefile <<"EOF"
52#
53# Invoked as:
54# make all
55# or make install
56# Plain "make" is equivalent to "make all".
57#
58# If you add or delete functions, remake funcs.h by doing:
59# make newfuncs
60# This depends on the coding convention of function headers looking like:
61# " \t public <function-type> \n <function-name> ( ... ) "
62#
63# Also provided:
64# make lint # Runs "lint" on all the sources.
65# make clean # Removes "less" and the .o files.
66# make clobber # Pretty much the same as make "clean".
67
68SHELL = /bin/sh
69
70EOF
71
72cat >defines.h <<EOF
73/* Definition file for less */
74/* Generated $DATE by $0. */
75
76EOF
77
78cat >>defines.h <<EOF
79/*
80 * Define XENIX if running under XENIX 3.0.
81 */
82#define XENIX $xenix
83
84EOF
85$ECHO ""
86
87
88
89if [ "X$sys" = "Xunknown" ]
90then
91 alldefault=0
92else
93 def=yes
94 alldefault=1
95 $ECHO "Do you want to use ALL the defaults for $sysname?"
96 $ECHO " Enter \"yes\" if you have a STANDARD $sysname."
97 $ECHO " Enter \"no\" if you want to change any of the defaults. [$def] \c"
98 read ans
99 case "X$ans" in
100 X[yY]*) alldefault=1 ;;
101 X[nN]*) alldefault=0 ;;
102 esac
103 $ECHO ""
104fi
105
106if [ $alldefault = 0 ]
107then
108 alloptional=0
109else
110 def=yes
111 alloptional=1
112 $ECHO "Do you want to use all the optional features of less?"
113 $ECHO " Less has several features which you may or may not"
114 $ECHO " wish to include, such as shell escapes."
115 $ECHO " Enter \"yes\" if you want to include ALL the optional features."
116 $ECHO " Enter \"no\" if you want to select individual features. [$def] \c"
117 read ans
118 case "X$ans" in
119 X[yY]*) alloptional=1 ;;
120 X[nN]*) alloptional=0 ;;
121 esac
122 $ECHO ""
123fi
124
125
126
127def=yes
128x=1
129if [ $alldefault = 0 ]
130then
131 $ECHO "Does your C compiler support the \"void\" type? [$def] \c"
132 read ans
133 case "X$ans" in
134 X[yY]*) x=1 ;;
135 X[nN]*) x=0 ;;
136 esac
137 $ECHO ""
138fi
139cat >>defines.h <<EOF
140/*
141 * VOID is 1 if your C compiler supports the "void" type,
142 * 0 if it does not.
143 */
144#define VOID $x
145
146EOF
147
148
149
150def=long
151if [ $alldefault = 0 ]
152then
153 $ECHO "What type is the \"offset\" argument to lseek? [$def] \c"
154 read ans
155 if [ "X$ans" != "X" ]
156 then
157 def=$ans
158 fi
159 $ECHO ""
160fi
161cat >>defines.h <<EOF
162/*
163 * offset_t is the type which lseek() returns.
164 * It is also the type of lseek()'s second argument.
165 */
166#define offset_t $def
167
168EOF
169
170
171
172
173def=yes; x=1
174if [ $alldefault = 0 ]
175then
176 $ECHO "Most Unix systems provide the stat() function."
177 $ECHO "Does your system have stat()? [$def] \c"
178 read ans
179 case "X$ans" in
180 X[yY]*) x=1 ;;
181 X[nN]*) x=0 ;;
182 esac
183 $ECHO ""
184fi
185cat >>defines.h <<EOF
186/*
187 * STAT is 1 if your system has the stat() call.
188 */
189#define STAT $x
190
191EOF
192
193
194
195
196def=yes; x=1
197if [ $alldefault = 0 ]
198then
199 $ECHO "Most Unix systems provide the perror() function."
200 $ECHO "Does your system have perror()? [$def] \c"
201 read ans
202 case "X$ans" in
203 X[yY]*) x=1 ;;
204 X[nN]*) x=0 ;;
205 esac
206 $ECHO ""
207fi
208cat >>defines.h <<EOF
209/*
210 * PERROR is 1 if your system has the perror() call.
211 * (Actually, if it has sys_errlist, sys_nerr and errno.)
212 */
213#define PERROR $x
214
215EOF
216
217
218
219
220def=yes; x=1
221if [ $alldefault = 0 ]
222then
223 $ECHO "Most Unix systems provide the time() function."
224 $ECHO "Does your system have time()? [$def] \c"
225 read ans
226 case "X$ans" in
227 X[yY]*) x=1 ;;
228 X[nN]*) x=0 ;;
229 esac
230 $ECHO ""
231fi
232cat >>defines.h <<EOF
233/*
234 * GET_TIME is 1 if your system has the time() call.
235 */
236#define GET_TIME $x
237
238EOF
239
240if [ $x = 0 ]
241then
242 $ECHO "What is the APPROXIMATE performance of your"
243 $ECHO "machine, as a percentage of a Vax 11/750?"
244 $ECHO "(Enter 100 if your machine is as fast as a Vax,"
245 $ECHO " 50 if it is half as fast, 200 if it is twice as fast, etc.)"
246 $ECHO "The accuracy of this information is not critical."
247 while :
248 do
249 $ECHO "Percent of Vax 11/750 [100]: \c"
250 read ans
251 if [ "X$ans" = "X" ]
252 then
253 ans=100
254 fi
255 longloop=`expr "$ans" "*" 3`
256 if [ $? = 0 ]
257 then
258 break
259 fi
260 $ECHO "Enter a number please!"
261 done
262 $ECHO ""
263
264 cat >>defines.h <<EOF
265/*
266 * LONGLOOP is the number of lines we should process in the line number
267 * scan before displaying a warning that it will take a while.
268 */
269#define LONGLOOP ($longloop)
270EOF
271fi
272
273
274
275
276if [ "$sys" = "bsd" ]
277then
278 def=no; x=0
279else
280 def=yes; x=1
281fi
282if [ $alldefault = 0 ]
283then
284 $ECHO "Most System V systems have termio.h, while most"
285 $ECHO "Berkeley-derived systems have sgtty.h."
286 $ECHO "Does your system have termio.h? [$def] \c"
287 read ans
288 case "X$ans" in
289 X[yY]*) x=1 ;;
290 X[nN]*) x=0 ;;
291 esac
292 $ECHO ""
293fi
294cat >>defines.h <<EOF
295/*
296 * TERMIO is 1 if your system has /usr/include/termio.h.
297 * This is normally the case for System 5.
298 * If TERMIO is 0 your system must have /usr/include/sgtty.h.
299 * This is normally the case for BSD.
300 */
301#define TERMIO $x
302
303EOF
304
305
306
307
308if [ "$sys" = "bsd" -a "$bsd41" = "0" ]
309then
310 def=yes; x=1
311else
312 def=no; x=0
313fi
314if [ $alldefault = 0 ]
315then
316 $ECHO "Most BSD 4.2 and 4.3 systems have the sigsetmask() call."
317 $ECHO "Most System V and BSD 4.1 systems do not."
318 $ECHO "Does your system have sigsetmask()? [$def] \c"
319 read ans
320 case "X$ans" in
321 X[yY]*) x=1 ;;
322 X[nN]*) x=0 ;;
323 esac
324 $ECHO ""
325fi
326cat >>defines.h <<EOF
327/*
328 * SIGSETMASK is 1 if your system has the sigsetmask() call.
329 * This is normally the case only for BSD 4.2,
330 * not for BSD 4.1 or System 5.
331 */
332#define SIGSETMASK $x
333
334EOF
335
336
337
338if [ "$sys" = "bsd" ]
339then
340 def=2; REGCMP=0;RECOMP=1
341else
342 def=1; REGCMP=1;RECOMP=0
343fi
344if [ $alldefault = 0 ]
345then
346 $ECHO "Most System V systems have the regcmp() function."
347 $ECHO "Most Berkeley-derived systems have the re_comp() function."
348 $ECHO "Does your system have:"
349 $ECHO " 1. regcmp"
350 $ECHO " 2. re_comp"
351 $ECHO " 3. neither [$def] \c"
352 read ans
353 case "X$ans" in
354 X1) REGCMP=1;RECOMP=0 ;;
355 X2) REGCMP=0;RECOMP=1 ;;
356 X3) REGCMP=0;RECOMP=0 ;;
357 esac
358 $ECHO ""
359fi
360cat >>defines.h <<EOF
361/*
362 * REGCMP is 1 if your system has the regcmp() function.
363 * This is normally the case for System 5.
364 * RECOMP is 1 if your system has the re_comp() function.
365 * This is normally the case for BSD.
366 * If neither is 1, pattern matching is supported, but without metacharacters.
367 */
368#define REGCMP $REGCMP
369#define RECOMP $RECOMP
370
371EOF
372
373
374
375
376def=yes
377x=1
378if [ $alloptional = 0 ]
379then
380 $ECHO "Do you wish to allow shell escapes? [$def] \c"
381 read ans
382 case "X$ans" in
383 X[yY]*) x=1 ;;
384 X[nN]*) x=0 ;;
385 esac
386 $ECHO ""
387fi
388cat >>defines.h <<EOF
389/*
390 * SHELL_ESCAPE is 1 if you wish to allow shell escapes.
391 * (This is possible only if your system supplies the system() function.)
392 */
393#define SHELL_ESCAPE $x
394
395EOF
396
397
398
399def=yes
400x=1
401edname="vi"
402if [ $alloptional = 0 ]
403then
404 $ECHO "Do you wish to allow editor escapes? [$def] \c"
405 read ans
406 case "X$ans" in
407 X[nN]*) x=0; edname="" ;;
408 X[yY]*) x=1
409 $ECHO "What is the pathname of the default editor? [$edname] \c"
410 read ans
411 if [ "x$ans" != "x" ]
412 then
413 edname=$ans
414 fi
415 ;;
416 esac
417 $ECHO ""
418fi
419cat >>defines.h <<EOF
420/*
421 * EDITOR is 1 if you wish to allow editor invocation (the "v" command).
422 * (This is possible only if your system supplies the system() function.)
423 * EDIT_PGM is the name of the (default) editor to be invoked.
424 */
425#define EDITOR $x
426#define EDIT_PGM "$edname"
427
428EOF
429
430
431
432
433def=yes
434x=1
435if [ $alloptional = 0 ]
436then
437 $ECHO "Do you wish to support \"tag\" files? [$def] \c"
438 read ans
439 case "X$ans" in
440 X[yY]*) x=1 ;;
441 X[nN]*) x=0 ;;
442 esac
443 $ECHO ""
444fi
445cat >>defines.h <<EOF
446/*
447 * TAGS is 1 if you wish to support tag files.
448 */
449#define TAGS $x
450
451EOF
452
453
454
455def=yes
456x=1
457if [ $alloptional = 0 ]
458then
459 $ECHO "Do you wish to allow user-defined key definitions? [$def] \c"
460 read ans
461 case "X$ans" in
462 X[yY]*) x=1 ;;
463 X[nN]*) x=0 ;;
464 esac
465 $ECHO ""
466fi
467USERFILE=$x
468cat >>defines.h <<EOF
469/*
470 * USERFILE is 1 if you wish to allow a .less file to specify
471 * user-defined key bindings.
472 */
473#define USERFILE $x
474
475EOF
476
477
478
479def=yes
480x=1
481if [ $alldefault = 0 ]
482then
483 $ECHO "If your system provides the popen() function and"
484 $ECHO "the \"$ECHO\" shell command, you may allow shell metacharacters"
485 $ECHO "to be expanded in filenames."
486 $ECHO "Do you wish to allow shell metacharacters in filenames? [$def] \c"
487 read ans
488 case "X$ans" in
489 X[yY]*) x=1 ;;
490 X[nN]*) x=0 ;;
491 esac
492 $ECHO ""
493fi
494cat >>defines.h <<EOF
495/*
496 * GLOB is 1 if you wish to have shell metacharacters expanded in filenames.
497 * This will generally work if your system provides the "popen" function
498 * and the "$ECHO" shell command.
499 */
500#define GLOB $x
501
502EOF
503
504
505
506def=yes
507x=1
508if [ $alloptional = 0 ]
509then
510 $ECHO "Do you wish to allow log files (-l option)? [$def] \c"
511 read ans
512 case "X$ans" in
513 X[yY]*) x=1 ;;
514 X[nN]*) x=0 ;;
515 esac
516 $ECHO ""
517fi
518cat >>defines.h <<EOF
519/*
520 * LOGFILE is 1 if you wish to allow the -l option (to create log files).
521 */
522#define LOGFILE $x
523
524EOF
525
526cat >>defines.h <<EOF
527/*
528 * ONLY_RETURN is 1 if you want RETURN to be the only input which
529 * will continue past an error message.
530 * Otherwise, any key will continue past an error message.
531 */
532#define ONLY_RETURN 0
533
534EOF
535
536cat >>makefile <<EOF
537
538##########################################################################
539# Compilation environment.
540##########################################################################
541
542EOF
543
544
545
546if [ "$xenix" = "1" ]
547then
548 LIBS="-ltermlib"
549elif [ "$sys" = "bsd" ]
550then
551 LIBS="-ltermcap"
552else
553 LIBS="-lcurses -ltermcap -lPW"
554fi
555if [ $alldefault = 0 ]
556then
557 $ECHO "To build \"less\", you must link with libraries supplied by your system."
558 $ECHO "(If this needs to be changed later, edit the makefile"
559 $ECHO "and change the definition of LIBS.)"
560 $ECHO "What libraries should be used [$LIBS] \c"
561 read ans
562 if [ "X$ans" != "X" ]
563 then
564 LIBS="$ans"
565 fi
566 $ECHO ""
567fi
568cat >>makefile <<EOF
569# LIBS is the list of libraries needed.
570LIBS = $LIBS
571
572EOF
573
574
575
576INSTALL_LESS="/usr/local/bin/less"
577INSTALL_KEY="/usr/local/bin/lesskey"
578INSTALL_HELP="/usr/local/bin/less.help"
579INSTALL_LESSMAN="/usr/man/man1/less.1"
580INSTALL_KEYMAN="/usr/man/man1/lesskey.1"
581LESS_MANUAL="less.nro"
582KEY_MANUAL="lesskey.nro"
583if [ $alldefault = 0 ]
584then
585 $ECHO "What is the name of the \"public\" (installed) version of less?"
586 $ECHO " [$INSTALL_LESS] \c"
587 read ans
588 if [ "X$ans" != "X" ]
589 then
590 INSTALL_LESS="$ans"
591 fi
592 $ECHO "What is the name of the \"public\" (installed) version of lesskey?"
593 $ECHO " [$INSTALL_KEY] \c"
594 read ans
595 if [ "X$ans" != "X" ]
596 then
597 INSTALL_KEY="$ans"
598 fi
599 $ECHO "What is the name of the \"public\" (installed) version of the help file?"
600 $ECHO " [$INSTALL_HELP] \c"
601 read ans
602 if [ "X$ans" != "X" ]
603 then
604 INSTALL_HELP="$ans"
605 fi
606 $ECHO "What is the name of the \"public\" (installed) version of the less manual page?"
607 $ECHO " [$INSTALL_LESSMAN] \c"
608 read ans
609 if [ "X$ans" != "X" ]
610 then
611 INSTALL_LESSMAN="$ans"
612 fi
613 $ECHO "What is the name of the \"public\" (installed) version of the lesskey manual page?"
614 $ECHO " [$INSTALL_KEYMAN] \c"
615 read ans
616 if [ "X$ans" != "X" ]
617 then
618 INSTALL_KEYMAN="$ans"
619 fi
620 $ECHO ""
621fi
622cat >>makefile <<EOF
623# INSTALL_LESS is a list of the public versions of less.
624# INSTALL_KEY is a list of the public versions of lesskey.
625# INSTALL_HELP is a list of the public version of the help file.
626# INSTALL_LESSMAN is a list of the public versions of the less manual page.
627# INSTALL_KEYMAN is a list of the public versions of the lesskey manual page.
628INSTALL_LESS = \$(ROOT)$INSTALL_LESS
629INSTALL_KEY = \$(ROOT)$INSTALL_KEY
630INSTALL_HELP = \$(ROOT)$INSTALL_HELP
631INSTALL_LESSMAN = \$(ROOT)$INSTALL_LESSMAN
632INSTALL_KEYMAN = \$(ROOT)$INSTALL_KEYMAN
633LESS_MANUAL = $LESS_MANUAL
634KEY_MANUAL = $KEY_MANUAL
635HELPFILE = $INSTALL_HELP
636
637
638EOF
639
640
641
642cat >>makefile <<"EOF"
643# OPTIM is passed to the compiler and the loader.
644# It is normally "-O" but may be, for example, "-g".
645OPTIM = -O
646
647CFLAGS = $(OPTIM)
648
649
650
651##########################################################################
652# Files
653##########################################################################
654
655SRC1 = main.c option.c prim.c ch.c position.c input.c linenum.c
656SRC2 = screen.c prompt.c line.c signal.c os.c help.c ttyin.c command.c
657SRC3 = output.c decode.c tags.c version.c
658SRC = $(SRC1) $(SRC2) $(SRC3)
659OBJ = main.o option.o prim.o ch.o position.o input.o output.o \
660 screen.o prompt.o line.o signal.o os.o help.o ttyin.o \
661 decode.o command.o linenum.o tags.o version.o
662
663
664##########################################################################
665# Rules for building stuff
666##########################################################################
667
668EOF
669
670if [ "$USERFILE" = "1" ]
671then
672 cat >>makefile <<"EOF"
673all: less lesskey
674install: install_less install_help install_key install_lman install_kman
675EOF
676else
677 cat >>makefile <<"EOF"
678all: less
679install: install_less install_help install_lman
680EOF
681fi
682
683cat >>makefile <<"EOF"
684
685less: $(OBJ)
686 $(CC) $(LDFLAGS) $(OPTIM) -o less $(OBJ) $(LIBS) $(LDLIBS)
687
688lesskey: lesskey.o
689 $(CC) $(LDFLAGS) $(OPTIM) -o lesskey lesskey.o $(LDLIBS)
690
691# help.o depends on makefile for the definition of HELPFILE
692help.o: makefile
693 $(CC) $(CFLAGS) -c -DHELPFILE=\"$(HELPFILE)\" help.c
694
695install_less: less
696 for f in $(INSTALL_LESS); do rm -f $$f; cp less $$f; done
697 touch install_less
698
699install_key: lesskey
700 for f in $(INSTALL_KEY); do rm -f $$f; cp lesskey $$f; done
701 touch install_key
702
703install_help: less.help
704 for f in $(INSTALL_HELP); do rm -f $$f; cp less.help $$f; done
705 touch install_help
706
707install_lman: $(LESS_MANUAL)
708 for f in $(INSTALL_LESSMAN); do rm -f $$f; cp $(LESS_MANUAL) $$f; done
709 touch install_lman
710
711install_kman: $(KEY_MANUAL)
712 for f in $(INSTALL_KEYMAN); do rm -f $$f; cp $(KEY_MANUAL) $$f; done
713 touch install_kman
714
715##########################################################################
716# Maintenance
717##########################################################################
718
719lint:
720 lint -hp $(SRC)
721
722newfuncs:
723 mv funcs.h funcs.h.OLD
724 awk -f mkfuncs.awk $(SRC) >funcs.h
725
726clean:
727 rm -f $(OBJ) lesskey.o less lesskey vecho
728
729clobber:
730 rm -f *.o less lesskey vecho install_less install_key \
731 install_help install_lman install_kman
732
733shar:
734 shar -v linstall less.h position.h funcs.h cmd.h \
735 vecho.c lesskey.c less.nro lesskey.nro lesskey.man > less.shar.a
736 shar -v $(SRC1) > less.shar.b
737 shar -v $(SRC2) > less.shar.c
738 shar -v $(SRC3) less.man README less.help *.awk >less.shar.d
739
740
741##########################################################################
742# Dependencies
743##########################################################################
744
745$(OBJ): less.h funcs.h defines.h position.h
746command.o decode.o: cmd.h
747lesskey.o: less.h funcs.h defines.h cmd.h
748
749EOF
750$ECHO ""
751
752$ECHO "The makefile has been built."
753$ECHO "You should check it to make sure everything is as you want it to be."
754$ECHO "When you are satisfied with the makefile, just type \"make\""
755$ECHO "and \"less\" will be built."