# Copyright (C) 2002  Britton Leo Kerin, see copyright.

# Where to install soundgrab script and its man page.
EXE_DIR = /usr/local/bin
MAN_DIR = /usr/local/man/man1

# Locations in this distribution package of the odd things soundgrab
# depends on.
CPAN_MODS_PATH = odd_things/cpan_modules
HIRES_MOD = Time-HiRes-01.20
READLINE_GNU_MOD = Term-ReadLine-Gnu-1.11
RAWREC_PATH = odd_things/rawrec-0.9.97

# I guess sometime you want to use 'dmake' on 'nmake' with perl
# modules.  Depending on what 'perl -V:make' tells you.  Huh.
PERLS_MAKE = `perl -V:make | perl -p -e "s/make='(.*)';/\\$$1/"`

# Delete out of date targets whose production commands return nonzero.
.DELETE_ON_ERROR:

usage: 
	@echo 'All this makefile does is install things, and you need to give' 
	@echo 'it a specific target, see INSTALL.'

install: 
	install -d $(EXE_DIR)
	install src/soundgrab $(EXE_DIR)
	install -d $(MAN_DIR)
	install --mode='u=rw,go=r' docs/soundgrab.1 $(MAN_DIR)

install_odd_things: install_cpan_modules install_rawrec

install_cpan_modules: install_hires install_readline_gnu

install_hires:
	cd $(CPAN_MODS_PATH) ; tar xzvf $(HIRES_MOD).tar.gz 
	cd $(CPAN_MODS_PATH)/$(HIRES_MOD) ; perl Makefile.PL ; \
		                            $(PERLS_MAKE) ; \
	                                    $(PERLS_MAKE) test ; \
	                                    $(PERLS_MAKE) install

install_readline_gnu:
	cd $(CPAN_MODS_PATH) ; tar xzvf $(READLINE_GNU_MOD).tar.gz
	cd $(CPAN_MODS_PATH)/$(READLINE_GNU_MOD) ; perl Makefile.PL ; \
	                                           $(PERLS_MAKE) ; \
	                                           $(PERLS_MAKE) test ; \
	                                           $(PERLS_MAKE) install

install_rawrec:
	$(MAKE) -C $(RAWREC_PATH)/src install

# This target leaves the tarred gzipped perl modules alone.
totally_clean:
	find . -name "*~" -exec rm -f \{\} \;
	cd $(CPAN_MODS_PATH) ; rm -rf $(HIRES_MOD) $(READLINE_GNU_MOD)
	$(MAKE) -C $(RAWREC_PATH)/src distclean

# Doesn't uninstall anything from the odd_things directory.
uninstall: 
	rm -f $(EXE_DIR)/soundgrab
	rm -r $(MAN_DIR)/soundgrab.1

# Non-file targets.
.PHONY: info install install_odd_things install_cpan_modules install_hires \
                install_readline_gnu install_rawrec uninstall
