#	This file is part of the software similarity tester SIM.
#	Written by Dick Grune, Vrije Universiteit, Amsterdam.
#	$Header: Makefile,v 2.5 93/03/24 13:25:03 dick Exp $
#

#	I N S T A L L A T I O N   P A R A M E T E R S

BINDIR =	/home/top/dick/bin.`arch`# where to put the resulting binaries
MANDIR =	/home/top/dick/man/man1# where to put the manual page (sim.1)

#	E N T R Y   P O I N T S

#	Most important entry points:
#		test:		simple test on sim for C (first entry)
#		all:		create all binaries
#		install.all:	install all binaries
#
#		lint:		lint sim for C
#		lint.all:	lint all sims
#		shar:		create shar file
#		tags:		create tags file
#
#		clean:		clean garbage
#		bare:		clean garbage + binaries
#

#	C O M P I L A T I O N   P A R A M E T E R S

CC =		cc#			# the C compiler to be used
#					# do 'make clean' when modifying
CFLAGS =	-O -s#			# the C compiler flags

LINT =		lint#			# the lint program to be used
LINTFLAGS =	-xh#			# the lint flags

RUN =		#			# the run call, if not normal UNIX

#	T E S T   P A R A M E T E R S

# Parameters for two simple test runs, sim.res and lang.res:
TEST_LANG =	#			# empty for C, _X for language X
TEST_OPT =	-r 20#			# options to sim_X
TEST_INP =	pass3.c#		# guinea pig input

#	I N T R O D U C T I O N

#	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.,
#			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:		sim.res lang.res	# two simple tests

#	B I N A R I E S

BINARIES =	sim sim_pasc sim_m2 sim_lisp sim_text

all:		$(BINARIES)

#	C O M P I L A T I O N   R U L E S

.SUFFIXES:	.o
.c.o:
	$(CC) -c $(CFLAGS) $<


#	A U X I L I A R Y   M O D U L E S

# Common modules:
COM_OBJ =	token.o stream.o buff.o show_token.o error.o
COM_CFS =	token.c stream.c buff.c show_token.c error.c
COM_SRC =	cport.h token.h lex.h stream.h buff.h $(COM_CFS)
COM_FLS =	$(COM_SRC)

# The idf module:
IDF_OBJ =	idf.o
IDF_CFS =	idf.c
IDF_SRC =	idf.h $(IDF_CFS)
IDF_FLS =	$(IDF_SRC)

# The algollike module:
ALG_OBJ =	algollike.o
ALG_CFS =	algollike.c
ALG_SRC =	$(ALG_CFS)
ALG_FLS =	$(ALG_SRC)

# The aiso-package:
AISO_OBJ =	aiso.o
AISO_CFS =	aiso.c
AISO_SRC =	aiso.h $(AISO_CFS)
AISO_FLS =	$(AISO_SRC) aiso.spc aiso.bdy

# The linked-list sorting package:
SORT_OBJ =	sortposlist.o
SORT_CFS =	sortposlist.c
SORT_SRC =	sortposlist.h $(SORT_CFS)
SORT_FLS =	$(SORT_SRC) sortlist.spc sortlist.bdy

# The similarity tester as a main program:
SIM_OBJ =	sim.o option.o pass1.o hash.o compare.o add_run.o \
		pass2.o pass3.o lang.o debug.o
SIM_CFS =	sim.c option.c pass1.c hash.c compare.c add_run.c \
		pass2.c pass3.c lang.c debug.c
SIM_SRC =	params.h option.h sim.h private.h debug.h $(SIM_CFS)
SIM_FLS =	$(SIM_SRC)

#	L A N G U A G E S

# The C Language module:					C
CLANG_OBJ =	clang.o
CLANG_CFS =	clang.c
CLANG_SRC =	clang.l
CLANG_FLS =	$(CLANG_SRC)

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

C_OBJ =		$(COM_OBJ) $(AISO_OBJ) $(SORT_OBJ) $(SIM_OBJ) \
		$(IDF_OBJ) $(ALG_OBJ) $(CLANG_OBJ)
C_CFS =		$(COM_CFS) $(AISO_CFS) $(SORT_CFS) $(SIM_CFS) \
		$(IDF_CFS) $(ALG_CFS) $(CLANG_CFS)

sim:	$(C_OBJ)
	$(CC) $(CFLAGS) $(C_OBJ) -o sim

C_GRB =		clang.c sim

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

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

# The Pascal Language module:					Pascal
PASCLANG_OBJ =	pascallang.o
PASCLANG_CFS =	pascallang.c
PASCLANG_SRC =	pascallang.l
PASCLANG_FLS =	$(PASCLANG_SRC)

pascallang.c:	pascallang.l
	lex -t pascallang.l >pascallang.c

PASC_OBJ =	$(COM_OBJ) $(AISO_OBJ) $(SORT_OBJ) $(SIM_OBJ) \
		$(IDF_OBJ) $(ALG_OBJ) $(PASCLANG_OBJ)
PASC_CFS =	$(COM_CFS) $(AISO_CFS) $(SORT_CFS) $(SIM_CFS) \
		$(IDF_CFS) $(ALG_CFS) $(PASCLANG_CFS)

sim_pasc:	$(PASC_OBJ)
	$(CC) $(CFLAGS) $(PASC_OBJ) -o sim_pasc

PASC_GRB =	pascallang.c sim_pasc

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

$(BINDIR)/sim_pasc:	sim_pasc
	cp sim_pasc $(BINDIR)/sim_pasc

# The Modula-2 Language module:					Modula-2
M2LANG_OBJ =	m2lang.o
M2LANG_CFS =	m2lang.c
M2LANG_SRC =	m2lang.l
M2LANG_FLS =	$(M2LANG_SRC)

m2lang.c:	m2lang.l
	lex -t m2lang.l >m2lang.c

M2_OBJ =	$(COM_OBJ) $(AISO_OBJ) $(SORT_OBJ) $(SIM_OBJ) \
		$(IDF_OBJ) $(ALG_OBJ) $(M2LANG_OBJ)
M2_CFS =	$(COM_CFS) $(AISO_CFS) $(SORT_CFS) $(SIM_CFS) \
		$(IDF_CFS) $(ALG_CFS) $(M2LANG_CFS)

sim_m2:	$(M2_OBJ)
	$(CC) $(CFLAGS) $(M2_OBJ) -o sim_m2

M2_GRB =	m2lang.c sim_m2

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

$(BINDIR)/sim_m2:	sim_m2
	cp sim_m2 $(BINDIR)/sim_m2

# The Lisp Language module:					Lisp
LISPLANG_OBJ =	lisplang.o
LISPLANG_CFS =	lisplang.c
LISPLANG_SRC =	lisplang.l
LISPLANG_FLS =	$(LISPLANG_SRC)

lisplang.c:	lisplang.l
	lex -t lisplang.l >lisplang.c

LISP_OBJ =	$(COM_OBJ) $(AISO_OBJ) $(SORT_OBJ) $(SIM_OBJ) \
		$(IDF_OBJ) $(ALG_OBJ) $(LISPLANG_OBJ)
LISP_CFS =	$(COM_CFS) $(AISO_CFS) $(SORT_CFS) $(SIM_CFS) \
		$(IDF_CFS) $(ALG_CFS) $(LISPLANG_CFS)

sim_lisp:	$(LISP_OBJ)
	$(CC) $(CFLAGS) $(LISP_OBJ) -o sim_lisp

LISP_GRB =	lisplang.c sim_lisp

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

$(BINDIR)/sim_lisp:	sim_lisp
	cp sim_lisp $(BINDIR)/sim_lisp

# The Text module:						Text
TEXTLANG_OBJ =	text.o
TEXTLANG_CFS =	text.c
TEXTLANG_SRC =	text.l
TEXTLANG_FLS =	$(TEXTLANG_SRC)

text.c:	text.l
	lex -t text.l >text.c

TEXT_OBJ =	$(COM_OBJ) $(AISO_OBJ) $(SORT_OBJ) $(SIM_OBJ) \
		$(IDF_OBJ) $(TEXTLANG_OBJ)
TEXT_CFS =	$(COM_CFS) $(AISO_CFS) $(SORT_CFS) $(SIM_CFS) \
		$(IDF_CFS) $(TEXTLANG_CFS)

sim_text:	$(TEXT_OBJ)
	$(CC) $(CFLAGS) $(TEXT_OBJ) -o sim_text

TEXT_GRB =	text.c sim_text

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

$(BINDIR)/sim_text:	sim_text
	cp sim_text $(BINDIR)/sim_text

#	T E S T S

# Some simple tests:
sim.res:	sim$(TEST_LANG) $(TEST_INP)
	$(RUN) ./sim$(TEST_LANG) $(TEST_OPT) $(TEST_INP)

lang.res:	sim$(TEST_LANG) $(TEST_INP)
	$(RUN) ./sim$(TEST_LANG) -- $(TEST_INP) >lang.res
	wc lang.res $(TEST_INP)

TEST_GRB =	lang.res

lint:		$(C_CFS)
	$(LINT) $(LINTFLAGS) $(C_CFS)

lint.all:	$(C_CFS) $(PASC_CFS) $(M2_CFS) $(LISP_CFS) $(TEXT_CFS)
	$(LINT) $(LINTFLAGS) $(C_CFS)
	$(LINT) $(LINTFLAGS) $(PASC_CFS)
	$(LINT) $(LINTFLAGS) $(M2_CFS)
	$(LINT) $(LINTFLAGS) $(LISP_CFS)
	$(LINT) $(LINTFLAGS) $(TEXT_CFS)

# More simple tests, on the C version only:
simsim:		sim $(SRC)
	$(RUN) ./sim -fr 20 $(SRC)


#	O T H E R   E N T R I E S

# Sets of files: general, modules, main programs, langauges
FLS =	$(COM_FLS) $(IDF_FLS) $(ALG_FLS) $(AISO_FLS) $(SORT_FLS) $(SIM_FLS) \
	$(CLANG_FLS) $(PASCLANG_FLS) $(M2LANG_FLS) \
	$(LISPLANG_FLS) $(TEXTLANG_FLS)
SRC =	$(COM_SRC) $(IDF_SRC) $(ALG_SRC) $(AISO_SRC) $(SORT_SRC) $(SIM_SRC) \
	$(CLANG_SRC) $(PASCLANG_SRC) $(M2LANG_SRC) \
	$(LISPLANG_SRC) $(TEXTLANG_SRC)
OBJ =	$(COM_OBJ) $(IDF_OBJ) $(ALG_OBJ) $(AISO_OBJ) $(SORT_OBJ) $(SIM_OBJ) \
	$(CLANG_OBJ) $(PASCLANG_OBJ) $(M2LANG_OBJ) \
	$(LISPLANG_OBJ) $(TEXTLANG_OBJ)

ALL_UNIX =	READ_ME Makefile sim.1 $(FLS)
ALL_MSDOS =	READ.ME $(ALL_UNIX) $(CLANG_CFS) $(PASCLANG_CFS) \
		$(M2LANG_CFS) $(LISPLANG_CFS) $(TEXTLANG_CFS)

shar:	$(ALL_UNIX)
	shar $(ALL_UNIX) >shar

SHAR_GRB =	shar

tags:	$(SRC)
	ctags $(SRC)

TAGS_GRB =	

# Create file list for MSDOS
DOSLIST:	Makefile
	echo $(ALL_MSDOS) >DOSLIST

DOS_GRB =	DOSLIST

# Create .EXE archive for MSDOS
DOSARC =	READ.ME SIM.DOC \
		SIM.EXE SIM_PASC.EXE SIM_M2.EXE SIM_LISP.EXE SIM_TEXT.EXE
SIM.ARC:
	arc a SIM.ARC $(DOSARC)

# Install and clean scripts
install.all:	install			# just a synonym
install:	install.sim install.sim_pasc install.sim_m2 \
		install.sim_lisp install.sim_text

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

clean:
	rm -f $(OBJ) \
		$(C_GRB) $(PASC_GRB) $(M2_GRB) $(LISP_GRB) $(TEXT_GRB) \
		$(TEST_GRB) $(SHAR_GRB) $(TAGS_GRB) $(DOS_GRB) \
		a.out core mon.out

bare:		clean
	rm -f $(BINARIES)

#	D E P E N D E N C I E S

#----------------------------------------------------------------
add_run.o: cport.h aiso.h aiso.spc buff.h private.h sim.h token.h
aiso.o: cport.h aiso.bdy aiso.h aiso.spc sim.h
algollike.o: private.h token.h
buff.o: buff.h debug.h private.h sim.h stream.h token.h
clang.o: cport.h idf.h lex.h private.h stream.h token.h
compare.o: buff.h private.h sim.h token.h
debug.o: buff.h debug.h private.h sim.h stream.h token.h
hash.o: buff.h debug.h private.h sim.h token.h
idf.o: idf.h token.h
lang.o: stream.h token.h
lisplang.o: cport.h idf.h lex.h private.h stream.h token.h
m2lang.o: cport.h idf.h lex.h private.h stream.h token.h
option.o: option.h
pascallang.o: cport.h idf.h lex.h private.h stream.h token.h
pass1.o: buff.h debug.h private.h sim.h stream.h token.h
pass2.o: cport.h debug.h private.h sim.h sortlist.spc sortposlist.h stream.h token.h
pass3.o: cport.h aiso.h aiso.spc debug.h params.h private.h sim.h
show_token.o: token.h
sim.o: cport.h option.h params.h private.h
sortposlist.o: cport.h sim.h sortlist.bdy sortlist.spc sortposlist.h
stream.o: stream.h token.h
text.o: idf.h lex.h private.h stream.h token.h
token.o: token.h
