#
# if you do not have flex available, deactivate the definitions of
# LEX and LEXLIB; The program compiled with flex works also with the
# standard lex library (-ll).

PROGS= asc2iso
# Name of the resulting program

CC=gcc
# use of different C-compilers has not been tested

CFLAGS=-O6
# best optimization

LEXLIB=-lfl
# make LEXLIB=-ll or make LEXLIB="$HOME/lib/libfl.a" may override this

TESTFILE=test-file
# make TESTFILE=mytestfile may override this

AR=ar

RANLIB=ranlib

DIFF=diff
# it is assumed that this is GNU-diff.  If GNU-diff is named gnudiff
# on your system use make DIFF=gnudiff.

DIFFOPTS=--text
# With this option GNU-diff is forced to understand the tested files
# als text files which might not happen otherwise since they must
# contain 8-bit characters for a test that deserves its name.  If you
# do not have GNU-diff, use make DIFFOPTS= and be happy if there is no
# output and be unhappy with the output "`binary files differ"'.

RM=rm

CP=cp

BINDIR=/usr/local/bin

 
all: $(PROGS)
 
asc2iso: asc2iso.o asc2iso-aux.o libtmp.a
	$(CC) $(CFLAGS) $(DEFINES) -o $@ asc2iso-aux.o asc2iso.o $(LEXLIB) libtmp.a

asc2iso-aux.o: asc2iso-aux.h asc2iso-aux.c
	$(CC) $(CFLAGS) $(DEFINES) -c asc2iso-aux.c

asc2iso.o: asc2iso.c asc2iso-aux.h
	$(CC) $(CFLAGS) $(DEFINES) -c asc2iso.c

asc2iso.c: asc2iso.l
	flex $(LFLAGS) asc2iso.l
	mv lex.yy.c asc2iso.c

libtmp.a: flex-2.4.5-liballoc.o
	$(AR) cru libtmp.a flex-2.4.5-liballoc.o
	$(RANLIB) libtmp.a

flex-2.4.5-liballoc.o: flex-2.4.5-liballoc.c
	$(CC) $(CFLAGS) $(DEFINES) -c flex-2.4.5-liballoc.c
	

strip: asc2iso
	strip asc2iso

ss-filter: sz-filter.c
	$(CC) -Dss sz-filter.c -o ss-filter

sz-filter: sz-filter.c
	$(CC) -Dsz sz-filter.c -o sz-filter

check: ss-filter sz-filter $(PROGS) $(TESTFILE)
	ss-filter < $(TESTFILE) | asc2iso > $(TESTFILE).ss
	sz-filter < $(TESTFILE) | asc2iso > $(TESTFILE).sz
	$(DIFF) $(DIFFOPTS) $(TESTFILE) $(TESTFILE).ss | tee $(TESTFILE).ss-diff
	$(DIFF) $(DIFFOPTS) $(TESTFILE) $(TESTFILE).sz | tee $(TESTFILE).sz-diff
	$(RM) $(TESTFILE).ss $(TESTFILE).sz

install: $(PROGS)
	$(CP) $(PROGS) $(BINDIR)
 
clean:
	$(RM) -f $(PROGS) s?-filter core *.o *.a *~ \#* *.ss *.sz *.ss-diff *.sz-diff
 
tgz:
	tar cfv - asc2iso.l asc2iso.c asc2iso-aux.c asc2iso-aux.h Makefile ChangeLog | gzip -9 > asc2iso.tgz
