prefix=@prefix@
exec_prefix=@exec_prefix@
top_builddir=@top_builddir@
mandir=@mandir@
SHELL=@POSIXSHELL@
LIBTOOL=@LIBTOOL@
LIBTOOL_DEPS=@LIBTOOL_DEPS@
LN_S=@LN_S@ -f
INSTALL=@INSTALL@
INSTALL_DATA=@INSTALL_DATA@
INSTALL_PROGRAM=@INSTALL_PROGRAM@
RM=rm -f
TAR=tar
HOTPLUGENABLE=@HOTPLUGENABLE@
HOTPLUGPATH=@HOTPLUGPATH@

all: libtool lib samples filemodes

install: install-lib hotplug

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

install-lib: lib
	cd src && $(MAKE) install prefix=$(prefix) exec_prefix=$(exec_prefix)
	$(INSTALL) -d $(prefix)/lib/pkgconfig
	$(INSTALL_DATA) libnjb.pc $(prefix)/lib/pkgconfig

install-docs:
	$(INSTALL) -d $(mandir)/man3
	$(INSTALL) man/man3/*.3 $(mandir)/man3

install-samples:
	cd sample && $(MAKE) install prefix=$(prefix) exec_prefix=$(exec_prefix)

lib:
	cd src && $(MAKE) prefix=$(prefix) exec_prefix=$(exec_prefix)

samples:
	cd sample && $(MAKE) prefix=$(prefix)

filemodes:
	chmod +x hotplug.sh

hotplug:
	if test \"$(HOTPLUGENABLE)\" = \"yes\"; \
	then $(INSTALL) -d $(HOTPLUGPATH); \
	$(INSTALL) -d $(HOTPLUGPATH)/usb; \
	$(INSTALL) nomadjukebox $(HOTPLUGPATH)/usb; \
	$(INSTALL_DATA) nomad.usermap $(HOTPLUGPATH)/usb; \
	./hotplug.sh; \
	fi

dist: libnjb-@LIBNJB_VERSION@.tar.gz

libnjb-@LIBNJB_VERSION@.tar.gz: libnjb-@LIBNJB_VERSION@
	$(TAR) zcf $@ -X distignore $<

libnjb-@LIBNJB_VERSION@:
	mkdir $@
	cp -R $(filter-out $@, $(wildcard *)) $@
	cd $@ && $(MAKE) distclean

clean:
	cd src && $(MAKE) $@
	cd sample && $(MAKE) $@ 

distclean:
	cd src && $(MAKE) $@
	cd sample && $(MAKE) $@
	$(RM) config.cache config.h src/libnjb.h config.status \
		config.log Makefile nomadjukebox libtool \
		hotplug.sh configure.lineno

.PHONY: all install install-docs install-samples lib samples hotplug \
	dist clean distclean filemodes
