############################################################
# Copyright (C) 2007-2008 Masahiko SAWAI All Rights Reserved. 
############################################################

############################################################
# Configuration
############################################################

# package name
package = libwiiremote
version = 0.1.4

# for build
srcdir = .
top_srcdir = .
top_builddir = $(top_srcdir)

# for install
prefix = /usr/local
exec_prefix = ${prefix}
bindir = ${exec_prefix}/bin
includedir = ${prefix}/include
libdir = ${exec_prefix}/lib
datarootdir = ${prefix}/share
datadir = ${datarootdir}
sysconfdir = ${prefix}/etc

pkgdatadir = ${datarootdir}/libwiiremote
pkgsysconfdir = ${prefix}/etc/libwiiremote

LIBTOOL = $(SHELL) $(top_builddir)/libtool
LIBTOOL_DEPS = ./ltmain.sh

INSTALL = /usr/bin/install -c
INSTALL_PROGRAM = ${INSTALL}
INSTALL_DATA = ${INSTALL} -m 644

MAKE = make 

############################################################
# Files
############################################################
# for packaging
DISTDIR = $(package)-$(version)
SNAPSHOTDIR=$(package)-`date +%Y%m%d`

DIST_SUBDIRS = doc src test 
EXTRA_DIST = Makefile Makefile.in \
	README COPYING WhatsNew \
	config.sub config.guess configure.in configure \
	aclocal.m4 ltmain.sh install-sh \
	VisualC.zip \
	Xcode.tar.gz \

ALL_DIST_FILES = \
	$(DIST_SUBDIRS) \
	$(EXTRA_DIST) \

############################################################
# rules
############################################################
all : libtool
	cd src; $(MAKE) $@
	cd test; $(MAKE) $@

apidoc : 
	cd doc; $(MAKE) $@

libtool: $(LIBTOOL_DEPS)
	$(SHELL) ./config.status --recheck

## install rules
install: 
	cd src; $(MAKE) $@

## distribution rules
dist : dist-targz 
	cd doc; $(MAKE) $@

dist-dir : distclean 
	if [ -x $(DISTDIR) ] ; then \
		rm -rf $(DISTDIR) ;\
	fi;
	mkdir $(DISTDIR)
	cp -pLR $(ALL_DIST_FILES) $(DISTDIR)
	rm -rf `find $(DISTDIR) -name .svn`

dist-targz : dist-dir
	if [ -f $(DISTDIR).tar.gz ] ; then \
		rm $(DISTDIR).tar.gz ;\
	fi;
	if [ -f $(DISTDIR).tar ] ; then \
		rm $(DISTDIR).tar ;\
	fi;
	tar cvf $(DISTDIR).tar $(DISTDIR)
	gzip -9 $(DISTDIR).tar 
	rm -rf $(DISTDIR)

dist-bzip2 : dist-dir
	if [ -f $(DISTDIR).tar.bz2 ] ; then \
		rm $(DISTDIR).tar.bz2 ;\
	fi;
	if [ -f $(DISTDIR).tar ] ; then \
		rm $(DISTDIR).tar ;\
	fi;
	tar cvf $(DISTDIR).tar $(DISTDIR)
	bzip2 -9 $(DISTDIR).tar 
	rm -rf $(DISTDIR)

snapshot-dir : distclean 
	if [ -x $(SNAPSHOTDIR); ] ; then \
		rm -rf $(SNAPSHOTDIR) ;\
	fi;
	mkdir $(SNAPSHOTDIR)
	cp -pLR $(ALL_DIST_FILES) $(SNAPSHOTDIR)
	rm -rf `find $(DISTDIR) -name .svn`

snapshot: snapshot-dir
	if [ -f $(SNAPSHOTDIR).tar.gz ] ; then \
		rm $(SNAPSHOTDIR).tar.gz ;\
	fi;
	if [ -f $(SNAPSHOTDIR).tar ] ; then \
		rm $(SNAPSHOTDIR).tar ;\
	fi;
	-tar cvf $(SNAPSHOTDIR).tar $(SNAPSHOTDIR)
	-gzip -9 $(SNAPSHOTDIR).tar 
	-rm -rf $(SNAPSHOTDIR)

rpm : dist
	rpm -ta $(DISTDIR).tar.gz 


distclean : clean
	-rm config.cache config.log  config.status 
	cd doc; $(MAKE) $@

clean :
	cd src; $(MAKE) $@
	cd test; $(MAKE) $@

