#
# makefile for watcher
#
# SYS should be either BSD or SYSV
SYS = BSD

OBJS = baderr.o check_item.o checkline.o do_args.o doit.o externs.o\
	find_of.o find_pre_cmd.o find_pre_val.o get_col_fld.o tchar.o\
	get_rel_fld.o getargv.o init_sigs.o line_to_vec.o main.o\
	open_cf.o open_hf.o pp.o pp_change.o pp_out.o read_hist.o\
	save_key.o control.o yyerror.o yylex.o abs_check.o xmalloc.o\
	pct_check.o maxmin_check.o str_check.o hist_key.o hist_cmd.o\
	hist_value.o build_abs.o build_cmd.o build_col.o strsave.o\
	build_maxmin.o build_pct.o build_rel.o build_str.o to_double.o\
	chk_rel_item.o chk_col_item.o build_any.o any_check.o to_string.o
#CFLAGS = -O -D$(SYS)
CFLAGS = -g -D$(SYS)

#
# for sending out copies.  
#
# files that should be included
DIST = Makefile Docs Docs/* Support Support/* Ideas
# when making a copy for transfer via ftp or similar means
ARCHIVE = tar
ARCFLAGS = cf -
# when making a copy for net distribution
SHAR = shar
SHARFLAGS =

# the name of a pretty-printer.  choices might include `pr', `vgrind', etc
PPRINT = tgrind

# The following section is generated automatically in the makefile entry.
# SRCBEGIN -- Do not remove this line
C_SRCS = Cyylex.c abs_check.c any_check.c baderr.c build_abs.c build_any.c\
	build_cmd.c build_col.c build_maxmin.c build_pct.c build_rel.c\
	build_str.c check_col_item.c check_item.c check_rel_item.c checkline.c\
	do_args.c doit.c externs.c find_of.c find_pre_cmd.c find_pre_val.c\
	get_col_fld.c get_rel_fld.c getargv.c hist_cmd.c hist_key.c\
	hist_value.c init_sigs.c line_to_vec.c main.c maxmin_check.c open_cf.c\
	open_hf.c pct_check.c pp.c pp_change.c pp_out.c read_hist.c save_key.c\
	str_check.c strsave.c tchar.c to_double.c to_string.c xmalloc.c\
	yyerror.c
H_SRCS = defs.h
L_SRCS = yylex.l
Y_SRCS = control.y
# SRCEND -- Do not remove this line

# $P is for sequent parallel make.  Don't worry if you don't have a sequent.
watcher:$P $(OBJS)
	$(CC) $(CFLAGS) -o watcher $(OBJS) $(LIBS)

clean:
	rm -f a.out core watcher *.o y.tab.c y.tab.h y.output Make.out\
		lex.yy.c Watcher.archive Lint.out control.c

lint:
	lint -x $(CFLAGS) *.c > Lint.out

archive:
	$(ARCHIVE) $(ARCFLAGS) README *.c *.h *.y *.l $(DIST) > Watcher.archive

# Two shar files are made because one is too large for the mailers with
# a 64K limit.
dist distribution shar:
	$(SHAR) $(SHARFLAGS) README *.c > Watcher.dist1
	$(SHAR) $(SHARFLAGS) *.h *.l *.y $(DIST) > Watcher.dist2

print:: $(C_SRCS) $(H_SRCS) $(L_SRCS)
	$(PPRINT) -lC $?

print:: $(Y_SRCS)
	$(PPRINT) -lyacc $?

print::
	touch print

# you should only do this after a make clean; otherwise you'll get the
# files created by yacc included in the source list.
Makefile makefile:
	mv Makefile Makefile.backup
	sed -n '1,/SRCBEGIN/p' Makefile.backup > Makefile
	ls *.c | egrep -v 'y.tab.c|lex.yy.c' | fmt | \
		sed -e '$$!s/$$/\\/' -e '1s/^/C_SRCS = /' -e \
		'2,$$s/^/	/' >> Makefile
	ls *.h | egrep -v y.tab.h | fmt | sed 's/^/H_SRCS = /' >> Makefile
	ls *.l | fmt | sed 's/^/L_SRCS = /' >> Makefile
	ls *.y | fmt | sed 's/^/Y_SRCS = /' >> Makefile
	sed -n '/SRCEND/,$$p' Makefile.backup >> Makefile

control.o y.tab.h: control.y
	-mv y.tab.h y.tab.h.old
	yacc -d control.y
	-if cmp -s y.tab.h y.tab.h.old; then mv y.tab.h.old y.tab.h; \
		else rm y.tab.h.old; fi
	touch y.tab.h
	mv y.tab.c control.c
	$(CC) $(CFLAGS) -c control.c
	rm control.c

# a C version of the lexical analyxer is also supplied as Cyylex.c
yylex.o: yylex.l

checkline.o check_item.o: y.tab.h
$(OBJS): defs.h y.tab.h
