#//////////////////////////////////////////////////////////////////////////////
#
# Copyright (c) 2007,2011 Daniel Adler <dadler@uni-goettingen.de>, 
#                         Tassilo Philipp <tphilipp@potion-studios.com>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
#//////////////////////////////////////////////////////////////////////////////

# --- install -----------------------------------------------------------------

# deprecated:

ifdef INCLUDES
$(warn deprecated: INCLUDES, use HEADERS )
HEADERS ?= $(INCLUDES)
endif

ifdef INSTALL_INCLUDES
$(warn deprecated: INSTALL_INCLUDES, use INSTALL_HEADERS )
INSTALL_HEADERS ?= $(INSTALL_INCLUDES)
endif


INSTALL_PARTS = install-app install-dll install-lib install-includes install-man3
.PHONY: install $(INSTALL_PARTS)
$(INSTALL_PARTS): build
install: $(INSTALL_PARTS)

ifdef INSTALL_PREFIX

INSTALL_BINDIR ?= $(DESTDIR)$(INSTALL_PREFIX)/bin
INSTALL_LIBDIR ?= $(DESTDIR)$(INSTALL_PREFIX)/lib
INSTALL_INCDIR ?= $(DESTDIR)$(INSTALL_PREFIX)/include
INSTALL_MANDIR ?= $(DESTDIR)$(INSTALL_PREFIX)/share/man
INSTALL_MAN3DIR ?= $(INSTALL_MANDIR)/man3
$(INSTALL_PREFIX):
	mkdir -p $(INSTALL_PREFIX)
$(INSTALL_BINDIR):
	mkdir -p $(INSTALL_BINDIR)
$(INSTALL_LIBDIR):
	mkdir -p $(INSTALL_LIBDIR)
$(INSTALL_INCDIR):
	mkdir -p $(INSTALL_INCDIR)
$(INSTALL_MANDIR):
	mkdir -p $(INSTALL_MANDIR)
$(INSTALL_MAN3DIR):
	mkdir -p $(INSTALL_MAN3DIR)

endif

ifdef INSTALL_ALL
INSTALL_LIB ?= 1
INSTALL_APP ?= 1
INSTALL_DLL ?= 1
INSTALL_HEADERS ?= 1
endif

ifdef INSTALL_LIB
ifdef LIB_FILE
install-lib: $(INSTALL_LIBDIR)
	install -m 644 $(LIB_FILE) $(INSTALL_LIBDIR)
endif
endif

ifdef INSTALL_APP
ifdef APP_FILE
install-app: $(APP_FILE) $(INSTALL_BINDIR)
	install $(APP_FILE) $(INSTALL_BINDIR)
endif
endif

ifdef INSTALL_DLL
ifdef DLL_FILE
install-dll: $(DLL_FILE) $(INSTALL_BINDIR)
	install -m 644 $(DLL_FILE) $(INSTALL_BINDIR)
endif
endif

ifdef INSTALL_HEADERS
install-includes: $(INSTALL_HEADERS) $(INSTALL_INCDIR)
	install -m 644 $(INSTALL_HEADERS) $(INSTALL_INCDIR)
endif

ifdef INSTALL_MAN3
install-man3: $(INSTALL_MAN3) $(INSTALL_MAN3DIR)
	install -m 644 $(INSTALL_MAN3) $(INSTALL_MAN3DIR)
endif

