# generic Makefile for py_sems applications
.DEFAULT_GOAL := all

COREPATH ?= ../../core
PYSEMSPATH ?= ../py_sems

include $(COREPATH)/../Makefile.defs
include $(PYSEMSPATH)/Makefile.defs

LIB_INSTALLDIR?=$(modules_prefix)/$(py_sems_modules_dir)
TARBALL_PREFIX=sems-app-${NAME}
TARBALL="${TARBALL_PREFIX}-${VERSION}.tar.gz"

BASEDIR?=${basedir}

BIN_PERMISSIONS="755"
LIB_PERMISSIONS="644"

PYCHECKERARGS = --stdlib
PYCHECKERDOCARGS = --classdoc --funcdoc

module_conf_files =  $(notdir $(wildcard etc/*.conf))

.PHONY: all
all: compile

.PHONY: clean
clean:
	find . -iname "*\.pyc" -o -iname "*\.py~" | xargs rm -f
	rm -f ${TARBALL_PREFIX}*.tar.gz

.PHONY: compile
compile: clean
	python${PYTHON_VERSION} $(PYSEMSPATH)/py_comp -q .

.PHONY: install
install: all
	install -d $(DESTDIR)${BASEDIR}/${LIB_INSTALLDIR}
	# note: we're ignoring those and need to skip it with py3k
	#install -m ${LIB_PERMISSIONS}  *.pyc $(DESTDIR)${BASEDIR}/${LIB_INSTALLDIR}
	install -d $(DESTDIR)${BASEDIR}/${LIB_INSTALLDIR}/${LIBDIR}
	# note: we're ignoring those and need to skip it with py3k
	#install -m ${LIB_PERMISSIONS}  ${LIBDIR}/*.pyc $(DESTDIR)${BASEDIR}/${LIB_INSTALLDIR}/${LIBDIR}

.PHONY: install-cfg
install-cfg: 
	mkdir -p $(cfg_target)
	@set -e; \
	for r in $(module_conf_files); do \
			echo installing $$r ;  \
			sed -e "s#/usr/.*lib/sems/audio/#$(audio_target)#g" \
			-e "s#/usr/.*lib/sems/plug-in/#$(modules_target)#g" \
			-e "s#/usr/.*etc/sems/#$(cfg_target)#g" \
			< etc/$$r > $(DESTDIR)$(cfg_target)$$r; \
	done


uninstall: 
	@echo "please remove the files from $(DESTDIR)${LIB_INSTALLDIR} manually."

fulltest: 
	find | grep /Test | grep -v ".svn" | grep \\.py$$ | sed -e "s#^./##g" | bash -e - 

check: 
	find ${LIBDIR}/ | grep \\.py$$ | grep -v Test | PYTHONPATH=$(PYTHONPATH):$(PYSEMSPATH)/moc xargs pychecker ${PYCHECKERARGS} 

doccheck: 
	find ${LIBDIR}/  | grep \\.py$$ | grep -v Test | xargs pychecker ${PYCHECKERARGS} ${PYCHECKERDOCARGS}

dist: all
	tar -cvzf ${TARBALL} . --exclude=*.tar.gz \
				--exclude=.svn \
				--exclude=*~ \
				--exclude=*.pyc



