PROGRAM=	zmsh
#
# ZMailer Shell makefile
#
SHELL=		/bin/sh
CC=		gcc #-traditional
COPTS=		-g -O
CPPDEP= gcc -MM
SHELL=		/bin/sh
MAILBIN=	/usr/local/mail/bin
DEFS=	-DSTDC_HEADERS -DHAVE_STRING_H -DHAVE_ALLOCA_H #-DXMEM -DMALLOC_TRACE
ZSH_INCL=	
ZSH_LIB=	 ../libmalloc/libmalloc_d.a
#
MAKE=		make
INCL=		-I../include
ZSHDEFS=	-DMAILER
SSL=		../ssl/ssl
LIBNAME=	libsh
RANLIB=		ranlib # : ar does the work of ranlib under System V
LIBMALLOC=	-lmalloc_d
LIBMALLOCDEB=	../libs/libmalloc_d.a-a
LIB=		-L../libs -lsh -lz -lzc  $(LIBMALLOC)
LIBDEB=		../lib/libz.a-a ../libc/libzc.a-a $(LIBMALLOCDEB)
CFLAGS=		$(COPTS) $(ZSHDEFS) $(DEFS) $(INCL) $(ZSH_INCL)

OBJS	= sslwalker.o optimizer.o interpret.o listutils.o builtins.o \
	io.o expand.o mail.o path.o prompt.o test.o trap.o variables.o \
	execute.o jobcontrol.o tregexp.o regex.o zmsh.o listtrees.o

SOURCE	= sslwalker.c optimizer.c interpret.c listutils.c builtins.c \
	io.c expand.c mail.c path.c prompt.c test.c trap.c variables.c \
	execute.c jobcontrol.c tregexp.c regex.c zmsh.c listtrees.c


# keeping zmsh.o after the library is important due to the 'rm -f *.o' below...
$(PROGRAM)-a: $(LIBDEB) $(PROGRAM)

$(PROGRAM): ../libs/$(LIBNAME).a version.o $(LIBDEB)
	$(CC) $(CFLAGS) -o $@ main.o version.o $(LIB) $(ZSH_LIB)

.PRECIOUS: ../libs/$(LIBNAME).a

interpret.o: ../include/rfc822.entry ../include/mailer.h

version.c: main.o
	@$(MAKE) $(MFLAGS) -f ../Makefile $@

../libs/libmalloc_d.a-a:
	cd ../libmalloc; $(MAKE) $(MFLAGS)

$(LIBNAME).a: ../libs/$(LIBNAME).a

../libs/$(LIBNAME).a: $(SOURCE)
	$(CC) $(CFLAGS) -c $?
	-rm -f main.o version.o
	ar rv $@ *.o
	-rm -f *.o
	$(RANLIB) $@

lint:
	lint $(CFLAGS) $(SOURCE)
clean:
	-rm -f $(PROGRAM) $(LIBNAME).a sh.sst.c sh.sst.h sh.entry sh.lst \
		tags Makefile.bak
	-rm -f *.o sh-*.i

sh.h:		sh.sst.c sh.sst.h sh.entry
sslwalker.c:	sh.h sh-in.i sh-out.i sh-procs.i

sh.sst.c: sh.ssl $(SSL)
	$(SSL) -D short -l sh.lst sh.ssl

sh.sst.h: sh.ssl $(SSL)
	$(SSL) -D short -l sh.lst sh.ssl

sh.entry: sh.ssl $(SSL)
	$(SSL) -D short -l sh.lst sh.ssl

$(SSL):
	cd ../ssl ; $(MAKE) $(MFLAGS)

sh-out.i: sh.sst.h
	@awk 'BEGIN{delay=2;running=0;}			\
		/Output Tokens/{running+=1;continue;}	\
		/lastOfOutputTokens/{running=-99;continue;}\
		{if (running > 0 && --delay < 0) {		\
			 print;				\
		 } else continue;}' < sh.sst.h |	\
	sed	-e 's/^[	 ]*//'			\
	   	-e 's/[, 	].*//'			\
	   	-e 's/s\(.*\)/{	&,	"\1",	0},/'	> sh-out.i


sh-in.i: sh.sst.h
	@awk 'BEGIN{running=0;}				\
		/Input Tokens/{running+=1;continue;}	\
		/} InputTokens/{running=-99;continue;}	\
		{if (running>0) { print; }}' < sh.sst.h |	\
	sed	-e '/[ 	]t/!d'					\
		-e 's/[ ,].*$$//' -e 's/[ 	]//g'		\
		-e 's/.*/case &: return "&";/'		> sh-in.i

sh-procs.i: sh.entry
	@sed	-e '/^\//d' -e 's:#define.::'			\
		-e 's:[ 	].*::' -e '/SSL/!d' \
		-e 's/SSL_\(.*\)/case &: printf("\1"); break;/' \
		< sh.entry > sh-procs.i

../lib/libz.a-a:
	cd ../lib ; $(MAKE) $(MFLAGS)
../lib/libz.a:
	cd ../lib ; $(MAKE) $(MFLAGS)

../libc/libzc.a-a:
	cd ../libc ; $(MAKE) $(MFLAGS)
../libc/libzc.a:
	cd ../libc ; $(MAKE) $(MFLAGS)

depend:	sh.entry sh-in.i sh-out.i sh-procs.i
	CPPDEP="${CPPDEP}" ../bin/mklibdep $(CFLAGS) $(SOURCE)

# DO NOT DELETE THIS LINE -- mkdep uses it.
# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.

sslwalker.o: sh.h sh.sst.h sh.sst.c sh.entry  sh-in.i sh-procs.i
sslwalker.o: ../include/hostenv.h ../include/libsupport.h \
  ../include/sysprotos.h tregexp.h ../include/token.h interpret.h \
  ../include/listutils.h ../include/malloc.h shconfig.h

optimizer.o: ../include/hostenv.h ../include/libsupport.h \
  ../include/sysprotos.h sh.h sh.sst.h tregexp.h ../include/token.h interpret.h \
  ../include/listutils.h ../include/malloc.h shconfig.h
interpret.o: ../include/hostenv.h ../include/libsupport.h \
  ../include/sysprotos.h ../include/mailer.h ../include/malloc.h \
  ../include/listutils.h ../include/token.h ../include/splay.h \
  ../include/rfc822.entry interpret.h sh.h sh.sst.h regexp.h io.h shconfig.h \
  sift.h
listutils.o: ../include/hostenv.h ../include/libsupport.h \
  ../include/sysprotos.h ../include/mailer.h ../include/malloc.h \
  ../include/listutils.h ../include/token.h ../include/splay.h \
  ../include/rfc822.entry sh.h sh.sst.h regexp.h interpret.h io.h shconfig.h
builtins.o: ../include/hostenv.h ../include/libsupport.h \
  ../include/sysprotos.h ../include/mailer.h ../include/malloc.h \
  ../include/listutils.h ../include/token.h ../include/splay.h \
  ../include/rfc822.entry interpret.h sh.h sh.sst.h regexp.h io.h shconfig.h
io.o: ../include/hostenv.h ../include/libsupport.h ../include/sysprotos.h \
  shconfig.h io.h
expand.o: ../include/hostenv.h ../include/libsupport.h \
  ../include/sysprotos.h sh.h sh.sst.h regexp.h ../include/token.h interpret.h \
  ../include/listutils.h ../include/malloc.h flags.h io.h shconfig.h
mail.o: ../include/hostenv.h ../include/libsupport.h ../include/sysprotos.h \
  ../include/listutils.h ../include/malloc.h io.h shconfig.h
path.o: ../include/hostenv.h ../include/libsupport.h ../include/sysprotos.h \
  shconfig.h flags.h interpret.h sh.h sh.sst.h regexp.h ../include/token.h \
  ../include/listutils.h io.h ../include/splay.h
prompt.o: ../include/hostenv.h ../include/libsupport.h \
  ../include/sysprotos.h ../include/listutils.h ../include/malloc.h \
  shconfig.h
test.o: ../include/hostenv.h ../include/libsupport.h ../include/sysprotos.h \
  io.h shconfig.h
trap.o: ../include/hostenv.h ../include/libsupport.h ../include/sysprotos.h \
  flags.h ../include/malloc.h ../include/listutils.h io.h shconfig.h
variables.o: ../include/hostenv.h ../include/libsupport.h \
  ../include/sysprotos.h ../include/mailer.h ../include/malloc.h \
  ../include/listutils.h ../include/token.h ../include/splay.h \
  ../include/rfc822.entry sh.h sh.sst.h regexp.h interpret.h flags.h shconfig.h \
  sift.h
execute.o: ../include/hostenv.h ../include/libsupport.h \
  ../include/sysprotos.h ../include/mailer.h ../include/malloc.h \
  ../include/listutils.h ../include/token.h ../include/splay.h \
  ../include/rfc822.entry interpret.h sh.h sh.sst.h regexp.h io.h shconfig.h \
  sift.h
jobcontrol.o: ../include/hostenv.h ../include/libsupport.h \
  ../include/sysprotos.h ../include/listutils.h ../include/malloc.h io.h \
  shconfig.h
regexp.o: ../include/hostenv.h ../include/libsupport.h \
  ../include/sysprotos.h ../include/mailer.h ../include/malloc.h \
  ../include/listutils.h ../include/token.h ../include/splay.h \
  ../include/rfc822.entry regexp.h shconfig.h io.h
zmsh.o: ../include/hostenv.h ../include/libsupport.h ../include/sysprotos.h \
  ../include/mailer.h ../include/malloc.h ../include/listutils.h \
  ../include/token.h ../include/splay.h ../include/rfc822.entry flags.h \
  interpret.h sh.h sh.sst.h regexp.h shconfig.h sh-out.i
listtrees.o: ../include/hostenv.h ../include/libsupport.h \
  ../include/sysprotos.h ../include/mailer.h ../include/malloc.h \
  ../include/listutils.h ../include/token.h ../include/splay.h \
  ../include/rfc822.entry

# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
