#!/usr/bin/make -f
# debian/rules for the VideoLAN Client - uses debhelper.
# based on Joey Hess's one.

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# This is the debhelper compatability version to use.
export DH_COMPAT=3

# Compilation options
export CONFIG_FLAGS="--enable-release --prefix=/usr --enable-gnome --enable-gtk --enable-fb --enable-ggi --enable-sdl --enable-esd --enable-qt --enable-mad --enable-arts --enable-alsa --enable-lirc --enable-a52 --enable-aa --enable-dvbpsi"
# Remove --without-dvdcss here in non-totalitarian countries
export DVDCSS_FLAGS="--enable-dvd --without-dvdcss"

export VIDDIR="usr/share/vlc"
export PIXDIR="usr/share/pixmaps"
export GNOMEDIR="usr/share/gnome/apps/Multimedia"

build: build-stamp
build-stamp:
	dh_testdir

	case $(DEB_BUILD_ARCH) in \
	i386) \
		ARCH_FLAGS="--enable-glide" ;; \
	*) \
		ARCH_FLAGS="" ;; \
	esac ;\
	./configure $$ARCH_FLAGS --mandir=$${prefix}/share/man \
		--infodir=$${prefix}/share/info \
		$(shell echo $(CONFIG_FLAGS)) $(shell echo $(DVDCSS_FLAGS))

	$(MAKE)

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp

	-$(MAKE) distclean

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	DESTDIR=`pwd`/debian/vlc/ $(MAKE) install prefix=/usr

	# make symlinks for packages and install plugins
	case $(DEB_BUILD_ARCH) in \
	i386) \
		ARCH_ALIASES="ggi gtk gnome esd sdl qt arts mad alsa lirc aa glide" ;; \
	*) \
		ARCH_ALIASES="ggi gtk gnome esd sdl qt arts mad alsa lirc aa" ;; \
	esac ;\
	for alias in $$ARCH_ALIASES ; do \
		ln -s vlc debian/vlc-$$alias/usr/share/doc/vlc-$$alias ; \
		mv debian/vlc/usr/lib/vlc/$$alias.so \
			debian/vlc-$$alias/usr/lib/vlc/ ; done

	mv debian/vlc/usr/bin/gvlc debian/vlc-gtk/usr/bin/
	mv debian/vlc/usr/bin/gnome-vlc debian/vlc-gnome/usr/bin/
	mv debian/vlc/usr/bin/qvlc debian/vlc-qt/usr/bin/
	#mv debian/vlc/usr/bin/kvlc debian/vlc-kde/usr/bin/

	mv debian/vlc/$(VIDDIR)/vlc48x48.png debian/vlc/$(PIXDIR)/vlc.png
	mv debian/vlc/$(VIDDIR)/gvlc32x32.xpm debian/vlc-gtk/$(VIDDIR)/gvlc.xpm
	mv debian/vlc/$(VIDDIR)/gvlc48x48.png debian/vlc-gtk/$(PIXDIR)/gvlc.png
	mv debian/vlc/$(VIDDIR)/gnome-vlc32x32.xpm debian/vlc-gnome/$(VIDDIR)/gnome-vlc.xpm
	mv debian/vlc/$(VIDDIR)/gnome-vlc48x48.png debian/vlc-gnome/$(PIXDIR)/gnome-vlc.png
	mv debian/vlc/$(VIDDIR)/qvlc32x32.xpm debian/vlc-qt/$(VIDDIR)/qvlc.xpm
	mv debian/vlc/$(VIDDIR)/qvlc48x48.png debian/vlc-qt/$(PIXDIR)/qvlc.png
	#mv debian/vlc/$(VIDDIR)/kvlc32x32.xpm debian/vlc-kde/$(VIDDIR)/kvlc.xpm
	#mv debian/vlc/$(VIDDIR)/kvlc48x48.png debian/vlc-kde/$(PIXDIR)/kvlc.png

	cp debian/vlc.desktop debian/vlc/$(GNOMEDIR)
	cp debian/gvlc.desktop debian/vlc-gtk/$(GNOMEDIR)
	cp debian/gnome-vlc.desktop debian/vlc-gnome/$(GNOMEDIR)

	#gzip -9 < doc/vlc.1 >| debian/vlc/usr/share/man/man1/vlc.1.gz
	ln -s vlc.1.gz debian/vlc-gtk/usr/share/man/man1/gvlc.1.gz
	ln -s vlc.1.gz debian/vlc-gnome/usr/share/man/man1/gnome-vlc.1.gz
	ln -s vlc.1.gz debian/vlc-qt/usr/share/man/man1/qvlc.1.gz
	#ln -s vlc.1.gz debian/vlc-kde/usr/share/man/man1/kvlc.1.gz

# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: build install
#	dh_testversion
	dh_testdir
	dh_testroot
#	dh_installdebconf	
	dh_installdocs
#	dh_installexamples
	dh_installmenu
#	dh_installemacsen
#	dh_installpam
#	dh_installinit
#	dh_installcron
	dh_installman doc/vlc.1
#	dh_installinfo
#	dh_undocumented
	dh_installchangelogs -Nvlc-gnome -Nvlc-gtk -Nvlc-ggi -Nvlc-glide -Nvlc-esd -Nvlc-alsa -Nvlc-sdl -Nvlc-qt -Nvlc-arts -Nvlc-mad -Nvlc-lirc -Nvlc-aa ChangeLog
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_makeshlibs
	dh_installdeb
#	dh_perl

	case $(DEB_BUILD_ARCH) in \
	i386) \
		ARCH_EXCLUDE="" ;; \
	*) \
		ARCH_EXCLUDE="-Nvlc-glide" ;; \
	esac ;\
	dh_shlibdeps $$ARCH_EXCLUDE ;\
	dh_gencontrol $$ARCH_EXCLUDE ;\
	dh_md5sums $$ARCH_EXCLUDE ;\
	dh_builddeb $$ARCH_EXCLUDE

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install

