INSTALL=install

PRELOADS = -l ./asn1-byteopts.el
BATCHFLAGS = -batch -q -no-site-file

AM=asn1-mode
AD=asn1-diff

SRC=$(AM).el asn1-conf.el asn1-syntax.el 

OBJ=$(AM).elc asn1-conf.elc asn1-syntax.elc 

DST=`echo $(DEST) | sed -e 's:^~:$(HOME):'`

%.elc: %.el
	 EMACS=$(EMACS) $${EMACS:-emacs} $(BATCHFLAGS) $(PRELOADS) \
                        -f batch-byte-compile $<

all: info elc ps html

elc: $(OBJ)

info:
	make -C doc-fr info
	make -C doc-en info

ps:
	make -C doc-fr ps
	make -C doc-en ps

html:
	make -C doc-fr html
	make -C doc-en html

pdf:
	make -C doc-fr pdf
	make -C doc-en pdf

help:
	@echo "Options : all elc info ps html pdf clean distclean"

install: info
	@if [ -z "$(DST)" ]; then \
	  echo "error : DEST is empty. You must type" >&2; \
	  echo "DEST=directory make install" >&2; \
	  echo "to install the files in \"directory\"" >&2; \
	  echo "see INSTALL for more explanations" >&2; \
	  exit 1; \
	 fi
	install -d $(DST)
	install doc-fr/$(AM).info $(DST)/$(AM)-fr.info
	install doc-en/$(AM).info $(DST)/$(AM)-en.info
	install doc-en/$(AM).info $(DST)/$(AM)-en.info
	if [ -f asn1-diff.el ]; then\
	   install doc-en/ $(DST)/$(AD)-en.info; fi
	if [ -f asn1-diff.el ]; then\
	   install doc-fr/ $(DST)/$(AD)-fr.info; fi
	install $(SRC) doc-fr/TUTORIAL $(DST)
	[ -f asn1-mode.elc ] && install *.elc $(DST)
	@echo "-----------------------------------------------------------"
	@echo 'asn1-mode is installed'
	@echo 'Add the following lines in your .emacs :'
	@echo
	@echo '(setq (load-path (cons "$(DST)" load-path)))'
	@echo
	@cat add-to
	@echo
	@echo 'copy the documentation in format you want : ps or hmtl'
	@echo 'Type "cd doc-fr" or "cd doc-en"'
	@echo 'Type "cp *.ps my_doc_dir" or "cp *.html my_doc_dir"'
	@echo "-----------------------------------------------------------"

clean :
	rm -f *~ \#*\# *.cp *.cps *.aux *.fn *.ky *.log *.pg *.toc *.tp\
              *.vr *.bak *.tmp *_toc.html *.texinfo
	make -C doc-fr clean
	make -C doc-en clean

distclean : clean
	rm -f *.ps *.html *.dvi *.info *.elc *.pdf
	make -C doc-fr distclean
	make -C doc-en distclean
