PROGRAM=	zsh
#
# ZMailer Shell makefile
#
SHELL=		/bin/sh
CC=		cc # gcc -Wall -pedantic
COPTS=		-g
SHELL=		/bin/sh
MAILBIN=	/local/lib/mail
DEFS=
ZSH_INCL=	
ZSH_LIB=	
#
MAKE=		make
INCL=		-I../include
ZSHDEFS=	-DMAILER
SSL=		../ssl/ssl
LIBNAME=	libsh
RANLIB=		ranlib # : ar does the work of ranlib under System V
LIB=		../lib/libz.a ../libc/libc.a
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 regexp.o zsh.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 regexp.c zsh.c


# keeping zsh.o after the library is important due to the 'rm -f *.o' below...
$(PROGRAM): $(LIBNAME).a version.o $(LIB)
	$(CC) $(CFLAGS) -o $@ main.o version.o $(LIBNAME).a $(LIB) $(ZSH_LIB)

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


$(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.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
	@cp sh.sst.h sh-out.i
	@(echo '1,/Output Tokens/+2d' ; \
	 echo '/lastOfOutputTokens/,$$d' ; \
	 echo '1,$$s/^[ 	]*//' ; \
	 echo '1,$$s/[, 	].*//' ; \
	 echo '1,$$s/s\(.*\)/{	&,	"\1",	0},/' ; \
	 echo w ; echo q ) | /bin/ed - sh-out.i

sh-in.i: sh.sst.h
	@sed -e '1,/Input Tokens/d' -e '/} InputTokens/,$$d' -e '/[ 	]t/!d' \
		-e 's/[ ,].*$$//' -e 's/[ 	]//g' \
		-e 's/.*/case &: return "&";/' < sh.sst.h > 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:
	cd ../lib ; $(MAKE) $(MFLAGS)

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

depend:	sh.entry sh-in.i sh-out.i sh-procs.i
	../bin/mklibdep $(CFLAGS) $(SOURCE)

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

sslwalker.c: ../include/sysprotos.h sh.h sh.sst.h regexp.h ../include/token.h
sslwalker.c: interpret.h sh.h ../include/listutils.h ../include/malloc.h
sslwalker.c: shconfig.h ../include/malloc.h sh.sst.c sh.entry sh-in.i
sslwalker.c: sh-procs.i
	@touch $@
optimizer.c: ../include/sysprotos.h sh.h sh.sst.h regexp.h ../include/token.h
optimizer.c: interpret.h sh.h ../include/listutils.h ../include/malloc.h
optimizer.c: shconfig.h ../include/malloc.h
	@touch $@
interpret.c: ../include/mailer.h ../include/sysprotos.h ../include/libsupport.h
interpret.c: ../include/malloc.h ../include/listutils.h ../include/malloc.h
interpret.c: ../include/token.h ../include/splay.h ../include/rfc822.entry
interpret.c: interpret.h sh.h sh.sst.h regexp.h ../include/token.h interpret.h
interpret.c: ../include/listutils.h ../include/malloc.h io.h shconfig.h
interpret.c: ../include/malloc.h regexp.h sift.h ../include/token.h
	@touch $@
listutils.c: ../include/mailer.h ../include/sysprotos.h ../include/libsupport.h
listutils.c: ../include/malloc.h ../include/listutils.h ../include/malloc.h
listutils.c: ../include/token.h ../include/splay.h ../include/rfc822.entry sh.h
listutils.c: sh.sst.h regexp.h ../include/token.h interpret.h sh.h
listutils.c: ../include/listutils.h ../include/malloc.h io.h shconfig.h
listutils.c: ../include/malloc.h
	@touch $@
builtins.c: ../include/mailer.h ../include/sysprotos.h ../include/libsupport.h
builtins.c: ../include/malloc.h ../include/listutils.h ../include/malloc.h
builtins.c: ../include/token.h ../include/splay.h ../include/rfc822.entry
builtins.c: interpret.h sh.h sh.sst.h regexp.h ../include/token.h interpret.h
builtins.c: ../include/listutils.h ../include/malloc.h io.h shconfig.h
builtins.c: ../include/malloc.h
	@touch $@
io.c: ../include/sysprotos.h shconfig.h ../include/malloc.h
io.c: ../include/libsupport.h io.h
	@touch $@
expand.c: ../include/sysprotos.h ../include/libsupport.h sh.h sh.sst.h regexp.h
expand.c: ../include/token.h interpret.h sh.h ../include/listutils.h
expand.c: ../include/malloc.h flags.h ../include/malloc.h
expand.c: ../include/listutils.h ../include/malloc.h io.h shconfig.h
expand.c: ../include/malloc.h
	@touch $@
mail.c: ../include/sysprotos.h ../include/listutils.h ../include/malloc.h io.h
mail.c: shconfig.h ../include/malloc.h
	@touch $@
path.c: ../include/sysprotos.h shconfig.h ../include/malloc.h flags.h
path.c: interpret.h sh.h sh.sst.h regexp.h ../include/token.h interpret.h
path.c: ../include/listutils.h ../include/malloc.h ../include/listutils.h
path.c: ../include/malloc.h io.h ../include/splay.h
	@touch $@
prompt.c: ../include/sysprotos.h ../include/listutils.h ../include/malloc.h
prompt.c: shconfig.h ../include/malloc.h
	@touch $@
test.c: ../include/sysprotos.h io.h shconfig.h ../include/malloc.h
test.c: ../include/libsupport.h
	@touch $@
trap.c: ../include/sysprotos.h ../include/libsupport.h flags.h
trap.c: ../include/malloc.h ../include/listutils.h ../include/malloc.h io.h
trap.c: shconfig.h ../include/malloc.h
	@touch $@
variables.c: ../include/mailer.h ../include/sysprotos.h ../include/libsupport.h
variables.c: ../include/malloc.h ../include/listutils.h ../include/malloc.h
variables.c: ../include/token.h ../include/splay.h ../include/rfc822.entry sh.h
variables.c: sh.sst.h regexp.h ../include/token.h interpret.h sh.h
variables.c: ../include/listutils.h ../include/malloc.h flags.h shconfig.h
variables.c: ../include/malloc.h sift.h ../include/token.h
	@touch $@
execute.c: ../include/mailer.h ../include/sysprotos.h ../include/libsupport.h
execute.c: ../include/malloc.h ../include/listutils.h ../include/malloc.h
execute.c: ../include/token.h ../include/splay.h ../include/rfc822.entry
execute.c: interpret.h sh.h sh.sst.h regexp.h ../include/token.h interpret.h
execute.c: ../include/listutils.h ../include/malloc.h io.h shconfig.h
execute.c: ../include/malloc.h sift.h ../include/token.h
	@touch $@
jobcontrol.c: ../include/listutils.h ../include/malloc.h io.h shconfig.h
jobcontrol.c: ../include/malloc.h
	@touch $@
regexp.c: ../include/mailer.h ../include/sysprotos.h ../include/libsupport.h
regexp.c: ../include/malloc.h ../include/listutils.h ../include/malloc.h
regexp.c: ../include/token.h ../include/splay.h ../include/rfc822.entry
regexp.c: regexp.h ../include/token.h shconfig.h ../include/malloc.h io.h
	@touch $@
zsh.c: ../include/mailer.h ../include/sysprotos.h ../include/libsupport.h
zsh.c: ../include/malloc.h ../include/listutils.h ../include/malloc.h
zsh.c: ../include/token.h ../include/splay.h ../include/rfc822.entry flags.h
zsh.c: interpret.h sh.h sh.sst.h regexp.h ../include/token.h interpret.h
zsh.c: ../include/listutils.h ../include/malloc.h shconfig.h
zsh.c: ../include/malloc.h ../include/splay.h sh.h sh-out.i
	@touch $@

# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
