#	This file is part of the software similarity tester SIM.
#	Written by Dick Grune, Vrije Universiteit, Amsterdam.
#

BINDIR = /user1/dick/bin#		# where to put the binary (sim)
MANDIR = /user1/dick/man#		# where to put the manual page (sim.1)

CFLAGS= 

#
#	Each module (set of programs that together perform some function)
#	has the following sets defined for it:
#		FLS	all files of that module, for, e.g.,
#			printing, sharring, inventory, etc.
#		SRC	the source files, from which other files derive
#		CFS	the C-files, from which the object files derive
#		OBJ	objects
#		GRB	garbage produced by compiling the module
#
#	(This is a feeble attempt at software-engineering a Makefile.)
#

TEST =	pass3.c#			# guinea pig

all:	sim.res lang.res

# The C Language module
CLN_OBJ =	clang.o
CLN_CFS =	clang.c
CLN_SRC =	clang.l
CLN_FLS =	$(CLN_SRC)

clang.c:	clang.l
	lex -t clang.l >clang.c
CLN_GRB =	clang.c

# Common modules:
COM_OBJ =	stream.o idf.o buff.o error.o
COM_CFS =	stream.c idf.c buff.c error.c
COM_SRC =	$(COM_CFS)
COM_FLS =	stream.h idf.h buff.h $(COM_SRC)

# The top-package:
TOP_OBJ =	top.o
TOP_CFS =	top.c
TOP_SRC =	$(TOP_CFS)
TOP_FLS =	top.p top.g top.h $(TOP_SRC)

# The similarity tester:
SIM_OBJ =	sim.o pass1.o hash.o compare.o add_run.o pass2.o pass3.o
SIM_CFS =	sim.c pass1.c hash.c compare.c add_run.c pass2.c pass3.c
SIM_SRC =	$(SIM_CFS)
SIM_FLS =	params.h text.h debug.h $(SIM_SRC)

SIM =	$(CLN_OBJ) $(COM_OBJ) $(TOP_OBJ) $(SIM_OBJ)
CFS =	$(CLN_CFS) $(COM_CFS) $(TOP_CFS) $(SIM_CFS)

sim:	$(SIM)
	$(CC) $(SIM) -o sim

sim.res:	sim $(TEST)
	sim -hr 20 $(TEST)

lint:	$(CFS)
	lint -xa $(CFS)
SIM_GRB =	sim

# The language streamliner as a main program:
STR_OBJ =	main.o
STR_CFS =	main.c
STR_SRC =	$(STR_CFS)
STR_FLS =	$(STR_SRC)

LANG_CFS =	$(CLN_CFS) $(STR_CFS) $(COM_CFS)
LANG_OBJ =	$(CLN_OBJ) $(STR_OBJ) $(COM_OBJ)
lang:	$(LANG_OBJ)
	$(CC) $(LANG_OBJ) -o lang

lang.res:	lang $(TEST)
	lang -1 $(TEST) >lang1.res
	lang -2 $(TEST) >lang2.res
	wc lang[12].res $(TEST)
LANG_GRB =	lang lang1.res lang2.res

lang.lint:
	lint -xa $(LANG_CFS)

# various other entries
FLS =	READ_ME Makefile sim.1 \
	$(COM_FLS) $(TOP_FLS) $(SIM_FLS) $(STR_FLS) $(CLN_FLS)
SRC =	$(COM_SRC) $(TOP_SRC) $(SIM_SRC) $(STR_SRC) $(CLN_SRC)
OBJ =	$(COM_OBJ) $(TOP_OBJ) $(SIM_OBJ) $(STR_OBJ) $(CLN_OBJ)

print:	$(FLS)
	pr $(FLS) >print
PRINT_GRB =	print

shar:	$(FLS)
	shar $(FLS) >shar

files:	Makefile
	ls $(FLS) >files

cchk:
	cchk $(CFS)

simsim:	sim
	sim -hfr 20 $(SRC)

simsimx:	sim
	sim -hfxr 20 $(SRC)

tags:	$(SRC)
	ctags $(SRC)

install:	$(BINDIR)/sim $(MANDIR)/sim.1

$(BINDIR)/sim:	sim
	cp sim $(BINDIR)/sim

$(MANDIR)/sim.1:	sim.1
	cp sim.1 $(MANDIR)/sim.1

clean:
	rm -f $(OBJ) $(CLN_GRB) $(SIM_GRB) $(LANG_GRB) $(PRINT_GRB) \
		a.out core

#------------------------------------------------------------------------
add_run.o: buff.h text.h top.p top.h
buff.o: buff.h
clang.o: idf.h stream.h
compare.o: buff.h text.h top.p top.h
hash.o: buff.h text.h
idf.o: idf.h
pass1.o: buff.h text.h
pass2.o: text.h top.p top.h debug.h
pass3.o: params.h text.h top.p top.h debug.h buff.h
sim.o: params.h
stream.o: stream.h
top.o: text.h top.p top.h top.g
