# $Log: Makefile,v $
# Revision 1.10  2006/04/24 20:00:20  khlut
# baze support for mozilla streams
#
# Revision 1.9  2006/04/09 19:08:12  khlut
# plugin config files ~/.mozilla/genres/genres.conf or /etc/genres.conf are supported
# new config parameter "debuglevel" (now is only two debug levels)
# javascript control for debug level is temporary switched off
# string analyse is reordered
#
# Revision 1.8  2006/03/26 10:32:46  khlut
# added support for audio mime types
# bug fixed in makefile local-install rule
#
# Revision 1.7  2006/03/24 20:07:55  khlut
# new mime types added, tuning for slow internet
#
# Revision 1.6  2006/03/19 20:14:31  khlut
# Release number substitution automated
#
# Revision 1.5  2006/02/26 10:25:29  khlut
# mime-type application/x-elphel-ogm added
#
# Revision 1.4  2006/02/26 09:42:26  khlut
# added -fPIC flag for relocatable code, which need for some architectures
#
# Revision 1.3  2005/11/08 21:29:54  khlut
# issues with make of debian package fixed
#
# Revision 1.2  2005/11/04 19:31:40  khlut
# mozilla-conf path autodetection
#
# Revision 1.1.1.1  2005/11/04 09:07:01  khlut
# Release 0.7
# First CVS submition
# Many bugs were fixed
# All source files edited to conform to GPL (copyright and license notices were added)
# GenReS was moved to savannah.nongnu.org
#
RELEASE=$(shell awk -F '[()]' '/\(.*\)/ { print $$2; exit; }' <debian/changelog)
PATH:=${PATH}:/usr/local/mozilla/bin:/usr/lib/mozilla/bin:/opt/mozilla/bin
CFLAGS= -Wall -Os -DXP_UNIX -DMOZ_X11 -DXTHREADS ` mozilla-config --cflags xpcom` -fPIC -DRELEASE="\"${RELEASE}\""
OBJ=main_thread.o observer_thread.o threadqueue.o slavesdir.o storage.o settings.o
INSTALL=install -Dp -g root -o root
LIBPREFIX=$(DESTDIR)/usr/lib
ifdef DESTDIR
MOZILLAD=$(LIBPREFIX)/mozilla
FIREFOXD=$(LIBPREFIX)/mozilla-firefox
LNMF=ln -sf ../../mozilla/plugins/genres.so $(FIREFOXD)/plugins/genres.so
else
MOZILLAD=$(shell mozilla --help | head -1 | sed -e 's/[^ ]\+ //' -e 's|/[^/ ]\+ .*||')
FIREFOXD=$(shell firefox --help | head -1 | sed -e 's/[^ ]\+ //' -e 's|/[^/ ]\+ .*||')
LNMF=ln -sf $(MOZILLAD)/plugins/genres.so $(FIREFOXD)/plugins/genres.so
endif

CXXFLAGS=${CFLAGS}

all: genres.so

genres.so : $(OBJ)
	$(CC) -shared -o $@ $^ $(CFLAGS)

local-install: genres.so
	mkdir -p ~/.mozilla/plugins/
	for i in `sed -e 's!\([^ ]*\)/[^ ]*!\1!g' -e 's! !\n!g' < mplayer-mime-types | sort | uniq` ; do \
	mkdir -p ~/.mozilla/genres/slaves/$$i ; done	
	cp -dpf genres.so ~/.mozilla/plugins/
	cp -dpf config.pl ~/.mozilla/genres/
	cp -dpf slaves/video/mplayer.pl ~/.mozilla/genres/
	for i in `cat mplayer-mime-types` ; do \
	ln -sf ../../mplayer.pl ~/.mozilla/genres/slaves/$$i ; done

install: genres.so mplayer-mime-types
	for i in `sed -e 's!\([^ ]*\)/[^ ]*!\1!g' -e 's! !\n!g' < mplayer-mime-types | sort | uniq` ; do \
	mkdir -p $(LIBPREFIX)/genres/slaves/$$i ; done
	test -z "$(MOZILLAD)" || $(INSTALL) genres.so $(MOZILLAD)/plugins/genres.so
	test -z "$(FIREFOXD)" || $(INSTALL) -d $(FIREFOXD)/plugins
	test -z "$(FIREFOXD)" -o -z "$(MOZILLAD)" || $(LNMF)
	test -z "$(FIREFOXD)" -o ! -z "$(MOZILLAD)"|| $(INSTALL) genres.so $(FIREFOXD)/plugins/genres.so
	$(INSTALL) config.pl $(LIBPREFIX)/genres/config.pl
	$(INSTALL) slaves/video/mplayer.pl $(LIBPREFIX)/genres/mplayer.pl
	for i in `cat mplayer-mime-types` ; do \
	ln -sf ../../mplayer.pl $(LIBPREFIX)/genres/slaves/$$i ; done

clean:
	rm -f *.o genres.so

${OBJ}: genres.h
