#
# Makefile for batch directory, the schemas compilers' directory
# Generated from batch/Makefile.in
# Daniel Veillard, 1997
#

.SUFFIXES: .LAN .GRM .c .o

@VPATHOPT@= @srcdir@
THOTDIR = @top_srcdir@

include ../Options

LIBS	= ../thotlib/libThotKernel.a @LIBS@ @EXTRA_LIBS@
INCLUDES= -DHAVE_CONFIG_H -I.. -I@srcdir@/f @THOTINCLUDES@ $(X_FLAGS)

prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
datadir = @datadir@

COMPILERS=../bin/grm ../bin/str ../bin/prs ../bin/tra ../bin/app \
          ../bin/printstr

GRMS     = APP.GRM PRESEN.GRM STRUCT.GRM TRANS.GRM

LANGUAGES=*.GRM *.LAN *.LST

.c.o :
	$(CC) -DCPP="$(CPP)" $(CFLAGS) $(INCLUDES) -c $< -o $@

all : ../bin $(GRMS) $(COMPILERS)

APP.GRM : APP.LAN ../bin/grm
	(DIR=`pwd` ; THOTDIR=$$DIR/$(THOTDIR) ; export THOTDIR ; \
        cd @srcdir@ ; $$DIR/../bin/grm APP)

PRESEN.GRM : PRESEN.LAN ../bin/grm
	(DIR=`pwd` ; THOTDIR=$$DIR/$(THOTDIR) ; export THOTDIR ; \
        cd @srcdir@ ; $$DIR/../bin/grm PRESEN)

STRUCT.GRM : STRUCT.LAN ../bin/grm
	(DIR=`pwd` ; THOTDIR=$$DIR/$(THOTDIR) ; export THOTDIR ; \
        cd @srcdir@ ; $$DIR/../bin/grm STRUCT)

TRANS.GRM : TRANS.LAN ../bin/grm
	(DIR=`pwd` ; THOTDIR=$$DIR/$(THOTDIR) ; export THOTDIR ; \
         cd @srcdir@ ; $$DIR/../bin/grm TRANS)

TYP.GRM : TYP.LAN ../bin/grm
	(DIR=`pwd` ; THOTDIR=$$DIR/$(THOTDIR) ; export THOTDIR ; \
        cd @srcdir@ ; $$DIR/../bin/grm TYP)

force :

../thotlib/libThotKernel.a : force
	@(cd ../thotlib ; $(MAKE) CC="$(CC)" CFLAGS="$(CFLAGS)" libThotKernel)

../bin :
	$(MKDIR) ../bin

#
# grm : compiler
#
GRM_OBJ= \
	../thotlib/base/compilmsg.o \
	parser.o \
	grammar.o 

grm : ../thotlib/libThotKernel.a ../bin ../bin/grm
	

../bin/grm : $(GRM_OBJ) ../thotlib/libThotKernel.a
	$(CC) $(LDFLAGS) -o $@ $(GRM_OBJ) $(LIBS)
	@$(ECHO) "====>" grm is done

#
# str : compiler
#
STR_OBJ = \
        ../thotlib/base/compilmsg.o \
	parser.o \
	writestr.o \
	str.o

str : STRUCT.GRM ../thotlib/libThotKernel.a ../bin ../bin/str
	

../bin/str : $(STR_OBJ) $(GRMS) ../thotlib/libThotKernel.a
	$(CC) $(LDFLAGS) -o $@ $(STR_OBJ) $(LIBS)
	@$(ECHO) "====>" str is done

#
# prs : compiler
#
PRS_OBJ = \
	../thotlib/base/compilmsg.o \
	parser.o \
	writeprs.o \
	prs.o

prs : PRESEN.GRM ../thotlib/libThotKernel.a ../bin ../bin/prs
	

../bin/prs : $(PRS_OBJ) ../thotlib/libThotKernel.a
	$(CC) $(LDFLAGS) -o $@ $(PRS_OBJ) $(LIBS)
	@$(ECHO) "====>" prs is done

#
# typ : compiler
#
TYP_OBJ = \
	../thotlib/base/compilmsg.o \
	parser.o \
	writetyp.o \
	typ.o

typ : TYP.GRM ../thotlib/libThotKernel.a ../bin ../bin/typ
	

../bin/typ : $(TYP_OBJ) ../thotlib/libThotKernel.a
	$(CC) $(LDFLAGS) -o $@ $(TYP_OBJ) $(LIBS)
	@$(ECHO) "====>" typ is done

#
# tra : compiler
#
TRA_OBJ = \
	../thotlib/base/compilmsg.o \
	parser.o \
	writetra.o \
	tra.o

tra : TRANS.GRM ../thotlib/libThotKernel.a ../bin ../bin/tra
	

../bin/tra : $(TRA_OBJ) ../thotlib/libThotKernel.a
	$(CC) $(LDFLAGS) -o $@ $(TRA_OBJ) $(LIBS)
	@$(ECHO) "====>" tra is done

#
# app : compiler
#
APP_OBJ = \
	../thotlib/base/compilmsg.o \
	../thotlib/dialogue/callbackinit.o \
	parser.o \
	writeapp.o \
	app.o

app : APP.GRM ../thotlib/libThotKernel.a ../bin ../bin/app
	

../bin/app : $(APP_OBJ) ../thotlib/libThotKernel.a
	$(CC) $(LDFLAGS) -o $@ $(APP_OBJ) $(LIBS)
	@$(ECHO) "====>" app is done

#
# printstr : decompiler
#
PRINTSTR_OBJ = \
	printstr.o

printstr : ../thotlib/libThotKernel.a ../bin ../bin/printstr
	

../bin/printstr : $(PRINTSTR_OBJ) ../thotlib/libThotKernel.a
	$(CC) $(LDFLAGS) -o $@ $(PRINTSTR_OBJ) $(LIBS)
	@$(ECHO) "====>" printstr is done

#
# printprs : decompiler
#
PRINTPRS_OBJ = \
	../thotlib/document/readprs.o \
	printprs.o

printprs : ../thotlib/libThotKernel.a ../bin ../bin/printprs
	

../bin/printprs : $(PRINTPRS_OBJ) ../thotlib/libThotKernel.a
	$(CC) $(LDFLAGS) -o $@ $(PRINTPRS_OBJ) $(LIBS)
	@$(ECHO) "====>" printprs is done

#
# printtyp : decompiler
#
PRINTTYP_OBJ = \
	../thotlib/document/readtyp.o \
	printtyp.o

printtyp : ../thotlib/libThotKernel.a ../bin ../bin/printtyp
	


../bin/printtyp : $(PRINTTYP_OBJ) ../thotlib/libThotKernel.a
	$(CC) $(LDFLAGS) -o $@ $(PRINTTYP_OBJ) $(LIBS)
	@$(ECHO) "====>" printtyp is done


clean :
	$(RM) -f *.o dns_daemon

install : all
	@(if test ! -d $(datadir) ; then $(MKDIR) $(datadir) ; fi)
	@(if test ! -d $(datadir)/thot ; then $(MKDIR) $(datadir)/thot ; fi)
	@(if test ! -d $(datadir)/thot/batch ; then $(MKDIR) $(datadir)/thot/batch ; fi)
	@(if test ! -d $(datadir)/thot/applis ; then $(MKDIR) $(datadir)/thot/applis ; fi)
	@(if test ! -d $(datadir)/thot/applis/bin ; then $(MKDIR) $(datadir)/thot/applis/bin ; fi)
	@(for i in $(COMPILERS) ; do \
	  $(INSTALL_BIN) $$i $(datadir)/thot/applis/bin ; \
	  $(LN_S) $(datadir)/thot/applis/bin/$$i $(bindir)/ ; \
	  done)
	(for i in $(LANGUAGES) ; do \
	  for file in `$(ECHO) $(THOTDIR)/batch/$$i` ; do \
	    $(INSTALL_DATA) $$file $(datadir)/thot/batch ; \
	  done ; done)

uninstall :
	(for i in $(COMPILERS) ; do \
	  $(RM) $(datadir)/thot/applis/bin/$$i ; done)
	$(RM) -rf $(datadir)/thot/batch

include .depends

../tools/mkdep/mkdep : 
	@(cd ../tools/mkdep ; $(MAKE) CC="$(CC)" CFLAGS="$(CFLAGS)")

.depends depend : ../tools/mkdep/mkdep
	../tools/mkdep/mkdep -relative -vpath $(VPATH) $(INCLUDES) $(VPATH)/*.c  > .depends

CEXTRACT= ../bin/cextract

$(CEXTRACT) :
	@(cd ../tools/cextract-$(CEXTRACT_VER) ; $(MAKE) )

proto : ../bin/cextract
	@(for i in @srcdir@/*.c ; \
	  do \
	  dir=`dirname $$i`;base=`basename $$i .c`; \
	  if [ ! -d $$dir/f ] ; then $(MKDIR) $$dir/f ;fi;\
	  $(CEXTRACT) $(CEXTRACT_FLAGS) -o /tmp/cextract.$$base.$$$$ $$i 2> /dev/null ; \
	  if [ -f $$dir/f/"$$base"_f.h ] ; \
	  then \
	      delta=`$(DIFF) /tmp/cextract.$$base.$$$$ $$dir/f/"$$base"_f.h` ; \
	      if [ "$$delta" != "" ] ; \
	      then \
	          echo "  $$i proto changed" ; \
		  $(MV) /tmp/cextract.$$base.$$$$ $$dir/f/"$$base"_f.h ; \
              else \
	          $(RM) /tmp/cextract.$$base.$$$$ ; \
	      fi ; \
	  else \
	      echo "  $$i proto added" ; \
	      $(MV) /tmp/cextract.$$base.$$$$ $$dir/f/"$$base"_f.h ; \
	  fi ; \
	 done)

