### This file is better used by GNU make.

### User-configurable section

# what emacs is called on your system
#EMACS = emacs

# top of the installation
prefix = /usr/local

# where the Info file should go
INFODIR = ${DEST}/lib/emacs/info

# where the vm.elc, tapestry.elc, etc. files should go
LISPDIR = ${DEST}/lib/emacs/site-lisp

### Nothing should be changed beyond this line

SHELL = /bin/sh

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 $(AD).el

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

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

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

all: elc info

doc: ps html pdf

elc: $(OBJ)

#emacs -batch -q -no-site-file -insert doc-en/asn1-mode.texi -l texinfmt -f texinfo-format-buffer -f save-buffer
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"

test-dest:
	@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: test-dest info
	mkdir -p $(DST)
	cp doc-fr/$(AM).info $(DST)/$(AM)-fr.info
	cp doc-en/$(AM).info $(DST)/$(AM)-en.info
	if [ -f asn1-diff.el ]; then\
	   cp doc-en/$(AD).info $(DST)/$(AD)-en.info; fi
	if [ -f asn1-diff.el ]; then\
	   cp doc-fr/$(AD).info $(DST)/$(AD)-fr.info; fi
	cp $(SRC) doc-fr/TUTORIAL $(DST)
	[ -f asn1-mode.elc ] && cp *.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 'You can copy the documentation in format you want : ps or hmtl'
	@echo 'Type "cd doc-fr" or "cd doc-en"'
	@echo 'Type make ps or make html'
	@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 *.orig *.rej
	$(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
