# Makefile for cdplayer full installation

SUBDIRS=src doc

TOP=$(shell pwd)

include $(TOP)/Makefile.conf

UNINSTALL-FILE-NAME=uninstall-cdplayer
ifdef UNINSTALLDIR
	UNINSTALL-FILE=$(UNINSTALLDIR)/$(UNINSTALL-FILE-NAME)
else
	UNINSTALL-FILE=$(shell pwd)/$(UNINSTALL-FILE-NAME)
endif

nothing:
	-@echo "This makefile install the cdplayer in your system."
	-@echo "You can set the followings environmental variables: "
	-@echo "  PREFIX   where to install files (default $$HOME)"
	-@echo "           binaries  -> $$PREFIX/bin"
	-@echo "           includes  -> $$PREFIX/include"
	-@echo "           libraries -> $$PREFIX/lib"
	-@echo "           man pages -> $$PREFIX/man"
	-@echo
	-@echo "  OWNER    user ownership of the installed files (default you)"
	-@echo "           (you should be root to set user different from you)"
	-@echo
	-@echo "  GROUP    group ownership of the installed files (default your)"
	-@echo "           (you should be root to set group different from yours)"
	-@echo
	-@echo "  NOBACKUP if set don't make backup of old installed files"
	-@echo
	-@echo "  UNINSTALLDIR"
	-@echo "           create the uninstall file in this directory."
	-@echo
	-@echo "  TRASH"
	-@echo "           set the file used for trash. Usually you do not have"
	-@echo "           to set this and the /dev/null device is used. If you"
	-@echo "           don't have write access on this device set a file"
	-@echo "           elsewhere as temporary file."
	-@echo
	-@echo "  SETGID"
	-@echo "           if this variable is set then the executable is given"
	-@echo "           the setgid flags. This is useful to let users to"
	-@echo "           access the CD even if they can't write that device."
	-@echo "           I'm doing my best to make the program secure, but"
	-@echo "           PLEASE don't give this program the setuid for the"
	-@echo "           superuser! It could be enough to give it the setgid"
	-@echo "           for the group disk or whatever group you CD device"
	-@echo "           is owned by."
	-@echo
	-@echo "You should install binaries in a directory contained in PATH."
	-@echo "You have to install includes in a directory read by compiler for"
	-@echo "includes (/usr/include or /usr/local/include) or contained"
	-@echo "in C_INCLUDE_PATH."
	-@echo "You have to install libraries in a directory read by dynamic loader"
	-@echo "for libraries (/lib, /usr/lib, or /usr/local/lib) or contained"
	-@echo "in LD_LIBRARY_PATH."
	-@echo "Also the compile wants to find libraries so you have to add your"
	-@echo "libraries' directory to LIBRARY_PATH too (if it's not a default"
	-@echo "one)."
	-@echo "You have to install manpages in a directory read by man program"
	-@echo "for man pages (/usr/man or /usr/local/man) or contained"
	-@echo "in MANPATH."
	-@echo "You have to set these environmental variable properly before"
	-@echo "installation."
	-@echo
	-@echo "These are current settings:"
	-@echo
	-@echo "  installing binaries in $(bindir)"
	-@echo "  installing includes in $(incdir)"
	-@echo "  installing libraries in $(libdir)"
	-@echo "  installing man pages in $(mandir)"
	-@echo "  set user ownership to $(owner-name)"
	-@echo "  set group ownership to $(group-name)"
ifdef NOBACKUP
	-@echo "  skipping backups"
else
	-@echo "  doing backups"
endif
	-@echo "  uninstall file is $(UNINSTALL-FILE)"
ifdef SETGID
	-@echo "  setting the setgid flag to the executable"
endif
	-@echo
	-@echo "Type:"
	-@echo
	-@echo "# make configure"
	-@echo
	-@echo "  to let the program try to understand how your system"
	-@echo "  has to be configured."
	-@echo
	-@echo "# make build"
	-@echo
	-@echo "  to build the program."
	-@echo
	-@echo "# make install"
	-@echo
	-@echo "  to install the program."
	-@echo
	-@echo "See INSTALL for more informations."
	
install:
	@if [ -e $(UNINSTALL-FILE) ]; then \
		echo "\"$(UNINSTALL-FILE)\" already exists."; \
		echo "Remove it before installing."; \
		exit 1; \
	fi
	@for DIR in $(SUBDIRS); do \
		$(MAKE) -C $$DIR TOP=$(TOP) UNINSTALL-FILE=$(UNINSTALL-FILE) install; \
	done
	@if [ -f $(UNINSTALL-FILE) ]; then \
		$(REMOVE-FILE) \$$0 $(UNINSTALL-FILE); \
		chmod 755 $(UNINSTALL-FILE); \
		echo; \
		echo "\"$(UNINSTALL-FILE)\" created."; \
		echo; \
		echo "Execute this file to uninstall cdplayer from your system"; \
		echo "(if PREFIX is set to a relative path then the uninstall"; \
		echo "have to be executed from this directory, else you can put"; \
		echo "it where you want)."; \
	else\
		echo "Uninstall file \"$(UNINSTALL-FILE)\" couldn't be created."; \
	fi

build:
	@for DIR in $(SUBDIRS); do \
		$(MAKE) -C $$DIR TOP=$(TOP) UNINSTALL-FILE=$(UNINSTALL-FILE) build; \
	done
	
clean:
	@for DIR in $(SUBDIRS); do \
		$(MAKE) -C $$DIR TOP=$(TOP) clean; \
	done

distclean:
	@for DIR in $(SUBDIRS); do \
		$(MAKE) -C $$DIR TOP=$(TOP) distclean; \
	done

configure:
	./configure
