1# Makefile $Revision: 7.16 $
2#
3# 1) Select the proper EXDIR (path), MANDIR, MANEXT, LIBDIR, SIGVOID,
4#	REGEX, DFLT_PAGER, and FMOD. Most of the other things aren't
5#	normally changed (see the comments with each)
6# 2) Select the proper machine/compiler/OS section of code
7#	for MS-DOS look for the pattern 'MS-DOS'
8# 3) make install
9# 4) If you have the command 'file' that uses /etc/magic add the line:
10#	38	string		Spreadsheet	sc file
11
12
13# Specify the name of the program.
14# All documentation and installation keys on this value.
15#
16name=sc
17NAME=SC
18
19# The base directory where everything should be installed.  If you're
20# packaging this with an O/S, for example, you'll probably want to change
21# this to /usr.  Otherwise, /usr/local is probably more appropriate, unless
22# you're replacing the vendor-supplied version.
23prefix=${PREFIX}
24
25# This is where the install step puts it.
26EXDIR=${DESTDIR}/usr/local/bin
27
28# This is where the man page goes.
29MANDIR=${DESTDIR}${prefix}/man/man1
30MANEXT=1
31MANMODE=644
32
33# This is where the library file (tutorial) goes.
34#LIBDIR=/usr/local/share/$(name) # reno
35LIBDIR=${DESTDIR}/usr/local/share/sc
36LIBRARY=-DLIBDIR=\"${LIBDIR}\"
37
38# Set SIMPLE for lex.c if you don't want arrow keys or lex.c blows up
39#SIMPLE=-DSIMPLE
40SIMPLE=
41
42# Set BROKENCURSES if your curses has the nl/nonl bug
43# if it does and you don't set BROKENCURSES, the display will
44# be staggered across the screen. Also try IDLOKBAD below.
45#BROKENCURSES=-DBROKENCURSES
46BROKENCURSES=
47
48# Set USELOCALE to enable country-dependent display of decimal points,
49# local character recognition in words, and local @date() format.
50#USELOCALE=
51USELOCALE=-DUSELOCALE
52
53# Set DOBACKUPS if you would like a backup copy of a source file on a save
54#DOBACKUPS=
55DOBACKUPS=-DDOBACKUPS
56
57# Set SIGVOID if signal routines are type void.
58# use: SIGVOID=-DSIGVOID for:
59#	System 5.3, SunOS 4.X, VMS, BSD4.4 (reno), and ANSI C Compliant systems
60# use: SIGVOID=		for:
61#  BSD systems (excluding reno, BSD4.4), and the UNIXPC 'cc'
62#SIGVOID=
63SIGVOID=-DSIGVOID
64
65# Set IEEE_MATH if you need setsticky() calls in your signal handlers
66#
67#IEEE_MATH=-DIEEE_MATH
68IEEE_MATH=
69
70# The -ffloat-store compiler option is necessary for compiling interp.c to
71# prevent spurious "Still changing after x iterations" errors, intermittent
72# problems with the @round function, comparisons failing when they shouldn't,
73# and potentially other similar problems due to FPU registers having greater
74# precision than doubles in memory.  This is known to be necessary for GCC
75# on x86 processors/FPUs, and probably others.
76FLOAT_STORE=-ffloat-store
77
78# Set RINT=-DRINT if you do not have rint() in math.h
79# Set RINT=	on/with (they have rint):
80#	SunOS 4.0.3c compiler
81#	BSD4.4 (reno)
82#RINT=-DRINT
83RINT=
84
85# If your system supports POSIX.2 regular expressions, REGEX should be
86# set to -DREGCOMP.  Otherwise, set REGEX to -DREGCMP if you have the
87# regcmp/regex regular expression routines (most System V based systems
88# do) or to -DRE_COMP if you have the re_comp/re_exec regular expression
89# routines (most BSD based systems do).  If your system has no support for
90# regular expressions, leave REGEX unset.
91#REGEX=
92#REGEX=-DREGCMP
93#REGEX=-DRE_COMP
94REGEX=-DREGCOMP
95
96# This is the name of a pager like "more".
97# "pg" may be appropriate for SYSV.
98#DFLT_PAGER=-DDFLT_PAGER=\"more\"	# generic && reno
99DFLT_PAGER=-DDFLT_PAGER=\"less\"
100
101# This is the name of the history file.  If undefined, the history will
102# not be saved.
103HISTORY_FILE=-DHISTORY_FILE=\"~/.sc_history\"
104
105# this is the name to save back ups in
106SAVE=-DSAVENAME=\"$(NAME).SAVE\"
107
108# path to crypt, do not define if you don't have crypt
109# most systems
110#CRYPT=-DCRYPT_PATH=\"/bin/crypt\"
111# BSD
112CRYPT=-DCRYPT_PATH=\"/usr/bin/crypt\"
113# other people?
114#CRYPT=-DCRYPT_PATH=\"/usr/local/bin/crypt\"
115
116# If you get errors about fmod being undefined when you try to
117# compile, then define NO_FMOD (most likely BSD4.3 and Mt Xinu).
118#FMOD=-DNO_FMOD
119FMOD=
120
121# If your system doesn't have notimeout() in curses define NONOTIMEOUT
122#NO_NOTIMEOUT=-DNONOTIMEOUT
123NO_NOTIMEOUT=
124
125# flags for lint
126LINTFLAGS=-abchxv
127
128# Format of quick reference guide generated by $(name)qref
129# Leave undefined for normal text output.
130#QREF_FMT=
131QREF_FMT=-DTROFF
132
133# *** SPECIAL NOTES ***
134# For ULTRIX: define the BSD4.2 section and SIGVOID above
135#	tdw@cl.cam.ac.uk tested on Ultrix 3.1C-0
136# HP-UX 7.0: Do NOT use -O
137#	(known broken, try sc's boolean operators if you wish)
138#
139# **** SYSV curses bugs... ****
140# Try setting IDLOKBAD to fix (with an empty spreadsheet):
141#	a) Redrawing the bottom half of the screen when you
142#		move between row 9 <-> 10
143#	b) the highlighted row labels being trash when you
144#		move between row 9 <-> 10
145#	c) On an xterm on Esix Rev. D+ from eating lines
146#		 -goto (or move) a few lines (or more) past the bottom
147#		 of the screen, goto (or move) to the top line on the
148#		 screen, move upward and the current line is deleted, the
149#		 others move up even when they should not, check by
150#		 noticing the rows become 2, 3, 40, 41, 42... (etc).
151#	Known systems/terminfos w/ curses problems:
152#	{Esix Rev. D+, AT&T SysV3.2.1}:at386-m,xterm, HP-UX7.0:(not sure)
153#IDLOKISBAD=-DIDLOKBAD
154IDLOKISBAD=
155
156# If you don't have idlok() in your curses define NOIDLOK
157#NO_IDLOK=-DNOIDLOK
158NO_IDLOK=
159
160# If moving right off the screen causes the screen to not redraw
161# properly, define RIGHT_CBUG to get around a curses problem on some
162# boxes, this forces screen redraws when going right off the screen
163#RIGHTBUG=-DRIGHT_CBUG
164RIGHTBUG=
165
166# IF you have problems w/ your yacc try bison, Berkeley yacc, or
167# some other yacc. Some systems don't allow you to
168# increase the number of terminals (mostly AT&T), SCO's does though.
169# YACC=yacc
170# NOTE: Do not use with bison 1.16! Get a new version....
171YACC=yacc
172
173# MS-DOS needs y_tab instead of the normal y.tab
174#YTAB=y_tab
175YTAB=y.tab
176
177# Command to use to make temporary copies of some source files.
178#LN=ln -s
179#LN=cp
180LN=ln
181
182#### SYSTEM DEFINES ####
183
184#########################################
185# Use this for system AIX V3.1
186#CFLAGS= -O -DSYSV2 -DCHTYPE=int -DNLS
187#LDFLAGS=
188#LIB=-lm -lPW -lcurses
189
190#########################################
191# Use this for system V.2 (includes: HP-UX 7.05, UNIXPC)
192#CFLAGS= -O -DSYSV2
193#LDFLAGS=
194#LIB=-lm -lPW -lcurses
195# with gcc on a Sequent also use:
196#CC=att gcc
197#CFLAGS=  -DSYSV2 -g -pipe -traditional
198
199#########################################
200# Use this for system V.3
201#CFLAGS=  -DSYSV3 -O
202#LDFLAGS= -s
203#CFLAGS=  -DSYSV3 -g
204#LDFLAGS= -g
205#LIB=-lm -lncurses -lfl
206# with gcc also use:
207#CC=gcc
208#CFLAGS=  -DSYSV3 -O -pipe
209# debugging bison (bison 1.16 is broken)
210#CFLAGS=  -DSYSV3 -g -pipe -traditional
211#YACC=bison -y -v -t -l
212
213#########################################
214# Use this for system V.4
215#CFLAGS=  -DSYSV4 -DSYSV3 -O
216#LDFLAGS= -s
217#LIB=-lm -lcurses -lgen
218# with gcc also use:
219#CC=gcc
220#CFLAGS=  -DSYSV3 -O -pipe
221
222#########################################
223# Microport
224#CFLAGS= -DSYSV2 -O -DUPORT -Ml
225#LDFLAGS=-Ml
226#LIB=-lm -lcurses -lPW
227
228#########################################
229# Use this for BSD 4.2
230#CFLAGS= -O -DBSD42
231#LDFLAGS=
232#LIB=-lm -lcurses -ltermcap
233# with gcc also use:
234#CC=gcc
235
236#########################################
237# Use this for Sequent boxes
238#CC=atscc
239#CFLAGS=-O -DBSD42
240#LDFLAGS=
241#LIB=-lm -lcurses  -ltermcap
242#PSCLIB=-lseq
243# with gcc also use:
244#CC=gcc
245#CFLAGS= -O -DBSD42 -pipe
246
247#########################################
248# Use this for BSD 4.3
249#CFLAGS= -O -DBSD43	#-O or -g
250#LDFLAGS=	# -lg might help if -g used in CFLAGS
251#LIB=-lm -lcurses -ltermcap
252
253#########################################
254# Use this for SunOS 4.X if you have the System V package installed.
255# This will link with the System V curses which is preferable to the
256# BSD curses (especially helps scrolling on slow (9600bps or less)
257# serial lines).
258#
259# Be sure to define SIGVOID and REGEX (to -DRE_COMP) above.
260#
261#CC=/usr/5bin/cc
262#CFLAGS= -O -DSYSV3
263#LDFLAGS=
264#LIB=-lm -lcurses
265
266#########################################
267# Use this for system III (XENIX)
268#CFLAGS= -O -DSYSIII
269#LDFLAGS= -i
270#LIB=-lm -lcurses -ltermcap
271
272#########################################
273# Use this for XENIX Version 2.3
274#CFLAGS= -O -DSYSIII -DXENIX2_3
275#LDFLAGS= -i
276#LIB=-lm -lcurses -ltermcap
277
278#########################################
279# Use this for VENIX
280#CFLAGS= -DVENIX -DBSD42 -DV7
281#LDFLAGS= -z -i
282#LIB=-lm -lcurses -ltermcap
283
284#########################################
285# For SCO Unix V rel. 3.2.0
286#       -compile using rcc, cc does not cope with gram.c
287#       -edit /usr/include/curses.h, rcc does not understand #error
288#       -link: make CC=cc, rcc's loader gets unresolved __cclass, __range
289#               (rather strange,?)
290#CC=rcc
291#CC=cc
292#CC=gcc -fstrength-reduce
293#SIGVOID=-DSIGVOID
294#CFLAGS= -O -DSYSV3
295#LDFLAGS=
296#LIB=-lm -lcurses -ltinfo -lPW
297#YACC=yacc -Sm10000
298
299#########################################
300# Use this for SCO Unix 3.2.2 and ODT 1.1
301#CC=cc
302#CFLAGS= -O -DSYSV3
303#LDFLAGS=
304#LIB=-lm -lcurses -lPW -lmalloc -lc_s
305#YACC=yacc -Sm10000
306
307#########################################
308# Use this for MS-DOS, Microsoft C 5.1 and NDMAKE
309#CC=cl
310#CFLAGS= -AL -O -Fo$*.o
311#LDFLAGS=/noi /st:0x4000
312#LIB=lcurses
313#YACC=bison -y
314#
315#.SUFFIXES : .o .c
316#.c.o:
317#	$(CC) $(CFLAGS) -c $*.c
318
319#########################################
320# Use this for MS-DOS with DJGPP
321# REGEX should also be undefined (see above) unless a separate REGEX library
322# is installed (gdb includes one, but may result in file conflicts with
323# existing DJGPP files).
324#CC=gcc
325# Only use -Wall for testing, since it produces warnings that are of no
326# real effect on the reliability of the program, but may concern some
327# people who don't understand them.
328#CFLAGS=-DSYSV3 -O2 -Wall -UMSDOS
329#CFLAGS=-DSYSV3 -O2 -UMSDOS
330#LIB=-lm -lpdcurses
331
332#########################################
333# Use this for Linux
334CC=cc
335# Only use -Wall for testing, since it produces warnings that are of no
336# real effect on the reliability of the program, but may concern some
337# people who don't understand them.
338#CFLAGS=-DSYSV3 -O2 -Wall -pipe
339CFLAGS=-DSYSV3 -pipe -I/usr/local/include -I/usr/local/include/ncurses -O2 -fno-strict-aliasing  -O0
340LIB=-lm -lncurses
341
342# All of the source files
343SRC=Makefile abbrev.c cmds.c color.c crypt.c eres.sed frame.c format.c gram.y \
344	help.c interp.c lex.c pipe.c psc.c range.c sc.c sc.h screen.c sort.c \
345	sres.sed version.c vi.c vmtbl.c xmalloc.c
346
347# The objects
348OBJS=abbrev.o cmds.o color.o crypt.o format.o frame.o gram.o help.o interp.o \
349	lex.o pipe.o range.o sc.o screen.o sort.o version.o vi.o vmtbl.o \
350	xmalloc.o
351
352# The documents in the Archive
353DOCS=CHANGES README sc.doc psc.doc tutorial.sc VMS_NOTES torev build.com
354
355all:	$(name) p$(name) $(name)qref
356
357$(name):$(PAR)  $(OBJS)
358	$(CC) ${LDFLAGS} ${OBJS} ${LIB} -o $(name)
359
360# Alternative link for MS-DOS
361#$(name):	$(OBJS)
362#	link ${LDFLAGS} ${OBJS},$(name),,${LIB};
363
364gram.c:	gram.y
365	$(YACC) -d gram.y
366	mv $(YTAB).c gram.c
367
368$(YTAB).h:	gram.y
369
370p$(name):	psc.c pvmtbl.o pxmalloc.o
371	$(CC) $(CFLAGS) ${LDFLAGS} -o p$(name) psc.c pvmtbl.o pxmalloc.o ${PSCLIB}
372
373# Alternative link for MS-DOS (NB: MSC 5.1 has no getopt.c)
374#p$(name):	psc.o pvmtbl.o pxmalloc.o getopt.o
375#	link ${LDFLAGS} psc.o pvmtbl.o pxmalloc.o getopt.o,p$(name);
376
377qhelp.c: help.c
378	-rm -f qhelp.c
379	${LN} help.c qhelp.c
380
381$(name)qref:	qhelp.c sc.h
382	$(CC) $(CFLAGS) $(LDFLAGS) -DQREF $(QREF_FMT) -DSCNAME=\"$(NAME)\" -o $(name)qref qhelp.c
383
384# Alternative link for MS-DOS
385#$(name)qref:	qhelp.c sc.h
386#	$(CC) -AL -O -Foqhelp.o -c -DQREF -DSCNAME=\"$(name)\" qhelp.c
387#	link ${LDFLAGS} qhelp.o,$(name)qref;
388
389pvmtbl.c: vmtbl.c
390	-rm -f pvmtbl.c
391	${LN} vmtbl.c pvmtbl.c
392
393pvmtbl.o: sc.h pvmtbl.c
394	$(CC) ${CFLAGS} -c -DPSC pvmtbl.c
395
396pxmalloc.c: xmalloc.c
397	-rm -f pxmalloc.c
398	${LN} xmalloc.c pxmalloc.c
399
400# Objects
401
402abbrev.o: abbrev.c sc.h
403	$(CC) ${CFLAGS} ${DFLT_PAGER} -c abbrev.c
404
405cmds.o: cmds.c sc.h
406	$(CC) ${CFLAGS} ${DOBACKUPS} ${CRYPT} -c cmds.c
407
408color.o: color.c sc.h
409
410crypt.o: crypt.c sc.h
411	$(CC) ${CFLAGS} ${CRYPT} ${DOBACKUPS} -c crypt.c
412
413format.o: format.c
414
415frame.o: frame.c sc.h
416
417gram.o:	sc.h $(YTAB).h gram.c
418	$(CC) ${CFLAGS} ${USELOCALE} -c gram.c
419	sed < gram.y > experres.h -f eres.sed
420	sed < gram.y > statres.h -f sres.sed
421
422help.o: help.c sc.h
423	$(CC) ${CFLAGS} ${CRYPT} -c help.c
424
425interp.o:	interp.c sc.h
426	$(CC) ${CFLAGS} ${FLOAT_STORE} ${IEEE_MATH} ${SIGVOID} ${RINT} \
427	${REGEX} ${FMOD} -c interp.c
428
429lex.o:	sc.h $(YTAB).h gram.o lex.c
430	$(CC) ${CFLAGS} ${SIMPLE} ${IEEE_MATH} ${LIBRARY} ${SIGVOID} \
431	${NO_NOTIMEOUT} -c lex.c
432
433pipe.o: pipe.c sc.h
434
435pxmalloc.o: sc.h pxmalloc.c
436	$(CC) ${CFLAGS} -c -DPSC pxmalloc.c
437
438qhelp.o: qhelp.c sc.h
439	$(CC) ${CFLAGS} ${CRYPT} -c qhelp.c
440
441range.o: range.c sc.h
442
443sc.o:	sc.h sc.c
444	$(CC) ${CFLAGS} ${DFLT_PAGER} ${SIGVOID} ${SAVE} -c sc.c
445
446screen.o:	sc.h screen.c
447	$(CC) ${CFLAGS} ${BROKENCURSES} ${IDLOKISBAD} ${RIGHTBUG} ${SIGVOID} \
448	${NO_IDLOK} -c screen.c
449
450sort.o: sort.c sc.h
451
452vi.o: vi.c sc.h
453	$(CC) ${CFLAGS} ${REGEX} ${HISTORY_FILE} -c vi.c
454
455# other stuff
456
457clean:
458	rm -f *.o *res.h $(YTAB).h debug core gram.c $(name).1 p$(name).1 \
459	y.output pxmalloc.c pvmtbl.c qhelp.c tags
460
461distclean:
462	rm -f *.o *res.h $(YTAB).h $(name) p$(name) debug core gram.c \
463	$(name).1 $(name).man p$(name).man p$(name).1 y.output $(name)qref \
464	pxmalloc.c pvmtbl.c qhelp.c tags
465
466shar: ${SRC} ${DOCS}
467	shar -c -m 64000 -f shar ${DOCS} ${SRC}
468
469sshar: ${SRC}
470	shar -c -m 1000000 -f shar ${SRC}
471
472lint: sc.h sc.c lex.c gram.c interp.c cmds.c color.c crypt.c frame.c pipe.c \
473	range.c help.c vi.c version.c xmalloc.c format.c vmtbl.c
474	lint ${LINTFLAGS} ${CFLAGS} ${SIMPLE} sc.c lex.c gram.c interp.c \
475	cmds.c color.c crypt.c frame.c pipe.c range.c help.c vi.c version.c \
476	xmalloc.c format.c vmtbl.c -lcurses -lm
477	make lintqref
478
479lintqref: help.c
480	lint ${LINTFLAGS} ${CFLAGS} ${SIMPLE} -DQREF help.c
481
482lintpsc: psc.c vmtbl.c
483	lint ${LINTFLAGS} ${CFLAGS} ${SIMPLE} -DPSC psc.c vmtbl.c
484
485$(name).1:	sc.doc torev
486	name=$(name) NAME=$(NAME) LIBDIR=$(LIBDIR) sh torev sc.doc > $(name).1
487
488$(name).man:	$(name).1
489	nroff -man $(name).1 > $(name).man
490
491p$(name).1:	psc.doc torev
492	name=$(name) NAME=$(NAME) LIBDIR=$(LIBDIR) sh torev psc.doc > p$(name).1
493
494p$(name).man:	p$(name).1
495	nroff -man p$(name).1 > p$(name).man
496
497install: $(EXDIR)/$(name) $(EXDIR)/$(name)qref $(EXDIR)/p$(name) \
498	 $(LIBDIR)/tutorial $(MANDIR)/$(name).$(MANEXT) \
499	 $(MANDIR)/p$(name).$(MANEXT)
500
501$(EXDIR)/$(name): $(name)
502	cp $(name) $(EXDIR)
503	strip $(EXDIR)/$(name)
504
505$(EXDIR)/$(name)qref: $(name)qref
506	cp $(name)qref $(EXDIR)
507	strip $(EXDIR)/$(name)qref
508
509$(EXDIR)/p$(name): p$(name)
510	cp p$(name) $(EXDIR)
511	strip $(EXDIR)/p$(name)
512
513$(LIBDIR)/tutorial: tutorial.sc $(LIBDIR)
514	cp tutorial.sc $(LIBDIR)/tutorial.$(name)
515	chmod $(MANMODE) $(LIBDIR)/tutorial.$(name)
516
517$(LIBDIR):
518	mkdir $(LIBDIR)
519
520$(MANDIR)/$(name).$(MANEXT): $(name).1
521	cp $(name).1 $(MANDIR)/$(name).$(MANEXT)
522	chmod $(MANMODE) $(MANDIR)/$(name).$(MANEXT)
523
524$(MANDIR)/p$(name).$(MANEXT): p$(name).1
525	cp p$(name).1 $(MANDIR)/p$(name).$(MANEXT)
526	chmod $(MANMODE) $(MANDIR)/p$(name).$(MANEXT)
527
528uninstall:
529	rm -f $(EXDIR)/$(name)
530	rm -f $(EXDIR)/$(name)qref
531	rm -f $(EXDIR)/p$(name)
532	rm -rf $(LIBDIR)
533	rm -f $(MANDIR)/$(name).$(MANEXT)
534	rm -f $(MANDIR)/p$(name).$(MANEXT)
535
536files:
537	@find $(DOCS) $(SRC) -print
538