~intgr/listen/tweaks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#/usr/bin/make -f
# vim: ts=4
#

VERSION ?= 0.5

# 1 = Add LD_LIBRARY_PATH=/path/to/firefox/mozembed/so/file when listen start 
# to prevent segmentfault on wikipedia and lyrics widget for broken python-gtkmozemebed on some distribution like ubuntu edgy/dapper

USE_MOZEMBED_HACK ?= 0

#0 = don't check dependencies usefull to make distribued packages
CHECK_DEPENDS ?= 1

PYTHON  = python
PREFIX ?= /usr
LIBDIR  = $(PREFIX)/lib/listen
BINDIR  = $(PREFIX)/bin
DATADIR = $(PREFIX)/share
LOCALEDIR = $(DATADIR)/locale
MANDIR  = $(DATADIR)/man
DBUSDIR  = $(DATADIR)/dbus-1

DIST_BUILD_DEB ?= 1

GTKMOZEMBED_PATH = $(shell pkg-config --libs-only-L mozilla-gtkmozembed 2>/dev/null || pkg-config --libs-only-L firefox-gtkmozembed 2>/dev/null | sed -e "s/-L//g" -e "s/[ ]/\,/" -e "s/[  ]//g" )
CONFIGURE_IN_MOZEMBED_HACK= sed -e 's!GTKMOZEMBED_PATH!LD_LIBRARY_PATH=$(GTKMOZEMBED_PATH)!g' 

CONFIGURE_IN = sed -e 's!GTKMOZEMBED_PATH!!g' -e 's!PYTHON!$(PYTHON)!g' -e 's!LIBDIR!$(LIBDIR)!g' -e 's!DATADIR!$(DATADIR)!g' -e 's!PREFIX!$(PREFIX)!g' -e 's!BINDIR!$(BINDIR)!g' -e 's!LOCALEDIR!$(LOCALEDIR)!g'

FILES_IN = misc/listen.in misc/org.gnome.Listen.service.in src/dists.py.in

DIST_DIR = src data misc mmkeys po 
DIST_FILE = check.py copy gpl.txt INSTALL Makefile README TODO
DIST_BLACKLIST = src/gnomevfswrap.py src/gst_daap.py src/daap.py src/md5daap.so src/cairo-test.py

DIST_INSTALL ?= dists/

PO = $(shell find ./po -name *.po -print | sed -e 's!.po!!g')

all: check mmkeys.so po-data
	docbook2x-man misc/listen.1.docbook --to-stdout | gzip > misc/listen.1.gz
	for fn in $(FILES_IN) ; do \
		if [ $(USE_MOZEMBED_HACK) -eq 1 ]; then \
			IN=`cat $$fn | $(CONFIGURE_IN_MOZEMBED_HACK) | $(CONFIGURE_IN)`; \
		else \
			IN=`cat $$fn | $(CONFIGURE_IN)`; \
		fi ;\
		F_OUT=`echo $$fn | sed -e 's/\.in$$//g'`; \
		echo "$$IN" > $$F_OUT; \
	done
	@echo "Done"
	@echo "Type: make install now"

check: 
	@if [ $(CHECK_DEPENDS) -eq 1 ]; then \
		/bin/echo -n "Checking for Python... "; \
		which $(PYTHON) || ( echo "Not found." && /bin/false ); \
		$(PYTHON) ./check.py; \
	fi

daap.py:
	cd daap && $(PYTHON) ./setup.py build  && cd ..
	cp daap/build/lib.*/* src/ -rf

mmkeys.so:
	${MAKE} -C mmkeys
	cp mmkeys/mmkeys.so src/mmkeys.so

clean: po-clean	
	rm -rf build
	rm -f tags
	rm -f misc/listen.1.gz
	rm -rf $(DIST_INSTALL)
	find . -type f -name '*.pyc'  -print | xargs rm -rf
	find . -type f -name '*.pyo'  -print | xargs rm -rf
	rm -f src/*.so
	for fn in $(FILES_IN) ; do \
		F=`echo $$fn | sed -e 's/\.in$$//g'`; \
		rm -f $$F; \
	done
	rm -f listen.1
	${MAKE} -C mmkeys clean

dist-clean: clean 
	rm -f .project  Listen.pida tags
	find . -type d -name '.svn'  -print | xargs rm -rf
	find . -name '*.bak'  -exec rm -rf {} \;
	find . -name '*~'  -exec rm -rf {} \;
	find . -name '.*'  -exec rm -rf {} \; 
	for fn in $(DIST_BLACKLIST); do \
		rm -rf $$fn; \
	done

make-install-dirs:
	mkdir -p $(DESTDIR)$(BINDIR)
	mkdir -p $(DESTDIR)$(LIBDIR)/source
	mkdir -p $(DESTDIR)$(LIBDIR)/library
	mkdir -p $(DESTDIR)$(LIBDIR)/webradio
	mkdir -p $(DESTDIR)$(LIBDIR)/widget/webinfo
	
	mkdir -p $(DESTDIR)$(DATADIR)/listen/img/source
	mkdir -p $(DESTDIR)$(DATADIR)/pixmaps
	mkdir -p $(DESTDIR)$(DATADIR)/applications
	mkdir -p $(DESTDIR)$(DATADIR)/man/man1
	mkdir -p $(DESTDIR)$(DATADIR)/dbus-1/services
	
	for lang in $(PO); do mkdir -p $(DESTDIR)$(LOCALEDIR)/$$lang/LC_MESSAGES; done

install: make-install-dirs
	install -m 644 src/*.py $(DESTDIR)$(LIBDIR)
	install -m 644 src/listen.py $(DESTDIR)$(LIBDIR)
	install -m 644 src/mmkeys.so $(DESTDIR)$(LIBDIR)
	install -m 644 src/source/*.py $(DESTDIR)$(LIBDIR)/source
	install -m 644 src/library/*.py $(DESTDIR)$(LIBDIR)/library
	install -m 644 src/webradio/*.py $(DESTDIR)$(LIBDIR)/webradio
	install -m 644 src/widget/*.py $(DESTDIR)$(LIBDIR)/widget
	install -m 644 src/widget/webinfo/*.py $(DESTDIR)$(LIBDIR)/widget/webinfo
	
	install -m 644 data/*.glade $(DESTDIR)$(DATADIR)/listen
	install -m 644 data/img/*.png $(DESTDIR)$(DATADIR)/listen/img
	install -m 644 data/img/source/*.png $(DESTDIR)$(DATADIR)/listen/img/source
	install -m 644 data/img/listen.png $(DESTDIR)$(DATADIR)/pixmaps/
	
	install -m 644 misc/listen.desktop $(DESTDIR)$(DATADIR)/applications/
	install -m 644 misc/listen.1.gz $(DESTDIR)$(MANDIR)/man1/
	install -m 644 misc/org.gnome.Listen.service $(DESTDIR)$(DBUSDIR)/services
	
	for lang in $(PO); do install -m 644 po/$$lang.mo $(DESTDIR)$(LOCALEDIR)/$$lang/LC_MESSAGES/listen.mo; done
	
	install -m 755 misc/listen $(DESTDIR)$(BINDIR)


po-data:
	for lang in $(PO); do msgfmt po/$$lang.po -o po/$$lang.mo;done
	intltool-merge -d po misc/listen.desktop.in misc/listen.desktop

po-gen:
	intltool-extract --type=gettext/glade data/trackedit.glade
	intltool-extract --type=gettext/ini misc/listen.desktop.in
	xgettext --from-code=UTF-8 -k_ -kN_ -o po/listen.pot src/*.py src/*/*.py data/*.h misc/*.h
	for lang in $(PO); do msgmerge -U po/$$lang.po po/listen.pot; done

po-clean:
	rm -rf data/*.h
	rm -rf misc/*.h
	rm -rf po/*.mo

dist: clean
	mkdir -p $(DIST_INSTALL)
	mkdir -p build/listen-$(VERSION)
	for dir in $(DIST_DIR); do \
		mkdir -p build/listen-$(VERSION)/$$dir/; \
		cp -rf $$dir/ build/listen-$(VERSION)/; \
	done
	cp $(DIST_FILE) build/listen-$(VERSION)
	${MAKE} -C build/listen-$(VERSION)/ dist-clean
	
	@echo Tarring listen-$(VERSION) ...
	@cd build && tar czf ../$(DIST_INSTALL)/listen-$(VERSION).tar.gz listen-$(VERSION)/ 
	@cd build && tar cjf ../$(DIST_INSTALL)/listen-$(VERSION).tar.bz2 listen-$(VERSION)/ 
	
	#For svn version and debian based system only
	if [ -d debian ] && [ $(DIST_BUILD_DEB) -eq 1 ]; then \
		echo Debianize listen-$(VERSION) ...; \
		mkdir -p $(DIST_INSTALL)/packages/; \
		cp -rf debian build/listen-$(VERSION)/debian; \
		${MAKE} -C build/listen-$(VERSION)/ dist-clean; \
		cd build/listen-$(VERSION) && (dpkg-buildpackage -rfakeroot || true) ; \
		cd ../..; \
		mv build/listen_* $(DIST_INSTALL)packages/ ; \
	fi 
	
	rm -rf build

tags:
	python -OO utils/ptags.py $$(find src/ -type f -name '*.py'  -print )

vimrc:
	for f in $$(find src/ -type f -name '*.py'); do \
		tag_path=$$(echo $$f | sed -e 's,^src\(.*\)/[^/]*$$,\1,g' -e 's,\([^/]*\),..,g') ;\
		sed -i -e '/^# vim:/d' $$f ;\
		sed -i -e "/^###$$/{N;N;s,^\(###\n#\n# Listen \),# vim: ts=4\n\1,}" $$f ;\
	done

docs:
	AWK_BLACKLIST=$$(echo "$(DIST_BLACKLIST)" |  sed -e 's/ /\n/g ' | awk '/\.py$$/{  COND="/^"gensub(/\//,"\\\\/",$$0)"$$/"; if (NR==1) {OUT=COND} else {OUT=OUT" || "COND} } END {print OUT}') && find src/ -type f -iname \*.py | sed -e 's/^.\///g'> tmp_modules&& AWK_MODULES=$$(awk "! ($$AWK_BLACKLIST){print \"../\"\$$\$$0}" tmp_modules) && \
	cd src/ && epydoc -o ../doc/ --inheritance "listed" --ignore-param-mismatch -n "Listen $(VERSION)" $$AWK_MODULES 2> doc_error