#
# vi:set ts=8:

PYTHON = python
PYCOMP = 'import py_compile, sys; map(py_compile.compile, sys.argv[1:])'
INSTALL= installmod.py
RM = rm -f
# could use GNU tar
TAR = tar
TAROPTS =
TARARGS =
GZIP = gzip

PYSRC = \
  mimecntl.py

TARFILE=mimecntl.tar
TARCONTENTS = \
  Makefile \
  installmod.py \
  mimecntl.html \
  mimecntl.py \
  mimecntl.pyc

.SUFFIXES: .tgz .tar .pyc .py

.py.pyc:
	$(PYTHON) -c $(PYCOMP) $<
.tar.tgz:
	$(GZIP) -c $< > $@ 

all: $(PYSRC:.py=.pyc)

install: all .instloc
uninstall: clean-.instloc

.instloc:
	$(INSTALL) $(PYSRC) $(PYSRC:.py=.pyc) > $@
clean-.instloc:
	$(INSTALL) -u $(@:clean-%=%)
	@$(RM) $(@:clean-%=%)

clean:
	$(RM) *.pyc core

dist: all gztarfile
gztarfile: $(TARFILE).gz   ## $(TARFILE:.tar=.tgz)
$(TARFILE).gz: $(TARFILE)
	$(GZIP) $(TARFILE)
tarfile: $(TARFILE)
$(TARFILE):
	$(RM) $(TARFILE)
	name=`basename \`pwd\``; cd ..; \
	$(TAR) cf$(TAROPTS) $$name/$(TARFILE) $(TARARGS) \
	  $(TARCONTENTS:%=$$name/%)

clean-dist: clean-tarfile clean
clean-tarfile: clean-$(TARFILE)
clean-$(TARFILE):
	$(RM) $(@:clean-%=%) $(@:clean-%=%).gz
	$(RM) $(@:clean-%.tar=%.tgz)

.PHONY: all install uninstall dist gztarfile tarfile clean
