##  Master Makefile for SR.



##  Current version number, date, and place of last modification.
#   These are embedded in sr and srl, and in the C code they produce.

VERSION = "SR version 1.1.0 (July, 1989), University of Arizona"



##  Basic configuration parameters.
#   
#   Do not comment the definition lines, and be sure that each directory is an
#   absolute path (beginning with "/").
#
#   CMD, LIB, MAN1, and MAN5 can all be the same directory if you wish.
#   If they're null, the -e option is implied in sr and srl.
#
#	SRC:	SR source hierarchy (the directory containing this Makefile)
#	CMD:	directory in which to install sr(1), srl(1), etc.
#	LIB:	directory in which to install srlib.o and other "hidden" files
#	MAN1:	directory in which to install the man(1) pages
#	MANEXT:	1 or l (one or ell) or 1n extension as appropriate to that dir
#	MAN5:	directory in which to install the srmap(5) man page
#		(extension will be "tr 1 5" of MANEXT)
#	ELISP:	if not null, directory for Lisp code adding sr-mode to GNU Emacs

SRC = /usr/local/src/sr
CMD = /usr/local/bin
LIB = /usr/local/lib/sr
MAN1 = /usr/man/manl
MAN5 = /usr/man/manl
MANEXT = l
ELISP = 



##  VMASK specifies a standard umask(2) for srv and srvi to always use.

VMASK = 0002



##  Absolute paths for programs and files referenced within SR components.
#   These usually require no change, but they're parameterized here in case
#   the given values are inappropriate.  These definitions do not affect the
#   commands issued to *build* SR.
#
#   An alternate C compiler can also be selected here, if it accepts
#   the same parameters as cc(1).

CCPATH = /bin/cc
MKPATH = /bin/make
RSHPATH = /usr/ucb/rsh
#  for HP-UX, use:  RSHPATH = /usr/bin/remsh



##  The vgrind(1) back end, and its macro package; used by srgrind.
#


VFPATH = /usr/lib/vfontedpr
VGMACS = /usr/lib/tmac/tmac.vgrind



##  Commands and flags used for building SR.  These are effective only when
#   running "make" in the main directory (the one containing this Makefile).

CC = cc
LD = ld
AS = as
MAKE = make

CFLAGS = -g
# for HP-UX on series 300 machines:  CFLAGS = -g +Np300


##  Shell for use with the Makefile (for braindamaged version of Make).

SHELL = /bin/sh



#######################  END CONFIGURATION INFORMATION  #######################
#######################   MAKE NO CHANGES BEYOND HERE   #######################



#  build the system

all:	sr srl rts srm srgrind srtex srv doc man

sr:	config	;cd sr;      $(MAKE) $(MFLAGS) CC=$(CC) CFLAGS="$(CFLAGS)"
srl:	config	;cd srl;     $(MAKE) $(MFLAGS) CC=$(CC) CFLAGS="$(CFLAGS)"
rts:	config
	cd rts; $(MAKE) $(MFLAGS) CC=$(CC) CFLAGS="$(CFLAGS)" AS=$(AS) LD=$(LD)
srm:	config	;cd srm;     $(MAKE) $(MFLAGS) CC=$(CC) CFLAGS="$(CFLAGS)"
srgrind:config	;cd srgrind; $(MAKE) $(MFLAGS) CC=$(CC) CFLAGS="$(CFLAGS)"
srtex:	config	;cd srtex;   $(MAKE) $(MFLAGS) CC=$(CC) CFLAGS="$(CFLAGS)"
srv:	config	;cd srv;     $(MAKE) $(MFLAGS) CC=$(CC) CFLAGS="$(CFLAGS)"
doc:	config	;cd doc;     $(MAKE) $(MFLAGS)
man:	config	;cd man;     $(MAKE) $(MFLAGS)


#	pseudo-entry for things the components need.
#	also forces rebuild of "xxx" even when "xxx" is present as a directory.

config:	config.h paths.h paths.sh srsys.h util.h util.o

#	rebuild paths.h only when the significant variables REALLY change

paths.h: paths.tmp
	-if cmp -s paths.tmp paths.h; then :; else cp paths.tmp paths.h; fi
paths.tmp: Makefile
	echo  >paths.tmp '/***** Created by Makefile -- DO NOT EDIT *****/'
	echo >>paths.tmp \
	'#define VERSION $(VERSION)'
	echo >>paths.tmp '#define SRDIR "$(SRC)"'
	echo >>paths.tmp '#define SRCMD "$(CMD)"'
	echo >>paths.tmp '#define SRLIB "$(LIB)"'
	echo >>paths.tmp '#define VMASK $(VMASK)'
	echo >>paths.tmp '#define CCPATH "$(CCPATH)"'
	echo >>paths.tmp '#define MKPATH "$(MKPATH)"'
	echo >>paths.tmp '#define RSHPATH "$(RSHPATH)"'
	echo >>paths.tmp '#define VFPATH "$(VFPATH)"'
	echo >>paths.tmp '#define VGMACS "$(VGMACS)"'

#	paths.sh defines the same variables for use by shell scripts

paths.sh:  Makefile paths.h
	echo "#"						   >paths.sh
	echo "#  CREATED BY MAKEFILE.  DO NOT EDIT THIS FILE."	  >>paths.sh
	echo ""							  >>paths.sh
	sed -n -e 's/ /=/' -e 's/ /=/' -e 's/#define=//p' paths.h >>paths.sh
	echo ""							  >>paths.sh



#  install everything
#  (note: srv isn't installed anywhere because it's just a development tool)

install:  i-sr i-srl i-rts i-map i-srm i-srgrind i-srtex i-lisp i-man

i-sr:	;  cp sr/sr           $(CMD);  strip $(CMD)/sr
i-srl:	;  cp srl/srl         $(CMD);  strip $(CMD)/srl
i-rts:	;  cp srsys.h sr/srgen.h rts/srlib.o rts/srx $(LIB); strip $(LIB)/srx
i-map:	;  cp srmap           $(LIB)
i-srm:	;  cp srm/srm         $(CMD);  strip $(CMD)/srm
i-srtex:;  cp srtex/srtex     $(CMD);  strip $(CMD)/srtex

i-srgrind:
	-if [ ! -z "$(VFPATH)" ]; then cp srgrind/srgrind $(CMD); fi
i-lisp:	
	-if [ ! -z "$(ELISP)" ]; then cp sr-mode.el $(ELISP); fi


i-man:	;  cp man/sr.1        $(MAN1)/sr.$(MANEXT)
	   cp man/srl.1       $(MAN1)/srl.$(MANEXT)
	   cp man/srm.1       $(MAN1)/srm.$(MANEXT)
	   cp man/srtex.1     $(MAN1)/srtex.$(MANEXT)
	   cp man/srmap.5     $(MAN5)/srmap.`echo $(MANEXT) | tr 1 5`
	   -if [ ! -z "$(VFPATH)" ]; \
		then cp man/srgrind.1 $(MAN1)/srgrind.$(MANEXT); fi



# discard unneeded files  (warning: VERY aggressive)

clean:
	rm -f paths.tmp paths.h paths.sh util.o
	cd sr;      $(MAKE) clean
	cd srl;     $(MAKE) clean
	cd rts;     $(MAKE) clean
	cd srm;     $(MAKE) clean
	cd srgrind; $(MAKE) clean
	cd srtex;   $(MAKE) clean
	cd srv;     $(MAKE) clean
	find . '('  \
	    -name '*~'	\
	    -o -name '.[BC]K.*'	\
	    -o -name '.emacs_*'	\
	    -o -name '.nfs*'	\
	    -o -name '*.orig'	\
	    -o -name '*.org'	\
	    -o -name '*.old'	\
	    -o -name '*.bak'	\
	    -o -name '*.new'	\
	    -o -name '*.dif'	\
	    -o -name '*.out'	\
	    -o -name '*.raw'	\
	    -o -name '*.rej'	\
	    -o -name '*.v?'	\
	    -o -name core	\
	    -o -name 'x?'	\
	    -o -type d -name Interfaces	\
	    ')' -print -exec rm -rf '{}' \;
	find vsuite -type f '('	\
	    -perm 777 -o -perm 775	\
	    -o -perm 755 -o -perm 770	\
	    -o -perm 750 -o -perm 700	\
	    -o -name '*.[cehos]'	\
	    -o -name Makefile		\
	    -o -name '[CL]*er.std' -size 0	\
	    ')' -print -exec rm -f '{}' \;


# discard even needed files that can be rebuilt

cleanx:	
	rm -f sr/sr srl/srl rts/srlib.o rts/srx srm/srm \
		srgrind/srgrind srtex/srtex srv/srv srv/srvi
	$(MAKE) clean


# remove postscript files to force a rebuild

cleanps:
	find doc man -name '*.ps' -print -exec rm -f '{}' \;



#  rebuild Makefile dependencies

depend:	paths.h
	cd sr;	    $(MAKE) $(MFLAGS) "CC=$(CC)" depend
	cd srl;	    $(MAKE) $(MFLAGS) "CC=$(CC)" depend
	cd rts;	    $(MAKE) $(MFLAGS) "CC=$(CC)" depend
	cd srm;	    $(MAKE) $(MFLAGS) "CC=$(CC)" depend
	cd srgrind; $(MAKE) $(MFLAGS) "CC=$(CC)" depend
	cd srtex;   $(MAKE) $(MFLAGS) "CC=$(CC)" depend
	cd srv;	    $(MAKE) $(MFLAGS) "CC=$(CC)" depend



#  run lint in all subdirectories

lint:	paths.h
	cd sr;	    $(MAKE) $(MFLAGS) lint
	cd srl;	    $(MAKE) $(MFLAGS) lint
	cd rts;	    $(MAKE) $(MFLAGS) lint
	cd srm;	    $(MAKE) $(MFLAGS) lint
	cd srgrind; $(MAKE) $(MFLAGS) lint
	cd srtex;   $(MAKE) $(MFLAGS) lint
	cd srv;	    $(MAKE) $(MFLAGS) lint



#  find files with strange protection modes

prot:
	find * '!' -perm 0775 '!' -perm 0664 '!' -perm -02664 \
		'!' -type l -exec ls -ld '{}' \;



# list verification suite  (note: output is in find order, each dir unsorted)

vlist:
	@find vsuite/* -name Script -print | sed -e s.vsuite/.. -e s./Script..



# make tar(1) or ascii cpio(1) files ON STANDARD OUTPUT
# (make cleanx first if you want to minimize the size)
# note: cpio loses symbolic link to examples
#
#	tar / cpio:	everything
#	qtar / qcpio:	omit vsuite except for vsuite/{quick,examples}
#	ttar:		also omit doc, man
#	vtar / vcpio:	full vsuite (only)

VSMIN=vsuite/quick vsuite/examples

tar:	; @tar cBf - .
qtar:	; @tar cBf - `ls | grep -v vsuite` $(VSMIN)
ttar:	; @tar cBf - `ls | egrep -v 'doc|man|vsuite'` $(VSMIN)
vtar:	; @tar cBf - ./vsuite

cpio:	; @find * -print | cpio -oc
qcpio:	; @find `ls | grep -v vsuite` $(VSMIN) -print | cpio -oc
vcpio:	; @find vsuite -print | cpio -oc



# collect *.sr files from verification suite on standard output

EQ = ====================
vsrc:	; @cd vsuite; find * -name '*.sr' -print \
	  | while read fname; do echo $(EQ) $$fname $(EQ); cat $$fname; done

# similarly, collect the scripts

EQ = ====================
vscripts:  ; @cd vsuite; find * -name Script -print | sed s./Script.. \
	   | while read dir; do echo $(EQ) $$dir $(EQ); cat $$dir/Script; done



# special verification runs

vsrm:	; srv/srv $(VFLAGS) srm quick/gries \
		capvar/4 capvar/struct_equiv/1 interfaces/bad/3
