#
#  Copyright 1999, Mike Glover
#  All rights reserved.
#
#  Redistribution and use in source and binary forms, with or without
#  modification, are permitted provided that the following conditions
#  are met:
#  1. Redistributions of source code must retain the above copyright
#     notice, this list of conditions and the following disclaimer.
#  2. Redistributions in binary form must reproduce the above copyright
#     notice, this list of conditions and the following disclaimer in the
#     documentation and/or other materials provided with the distribution.
#  3. All advertising materials mentioning features or use of this software
#     must display the following acknowledgment:
# 	This product includes software developed by Mike Glover
# 	and contributors.
#  4. Neither the name of Mike Glover, nor the names of contributors
#     may be used to endorse or promote products derived from this software
#     without specific prior written permission.
#
#  THIS SOFTWARE IS PROVIDED BY MIKE GLOVER AND CONTRIBUTORS ``AS IS'' AND
#  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
#  ARE DISCLAIMED.  IN NO EVENT SHALL MIKE GLOVER OR CONTRIBUTORS BE LIABLE
#  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
#  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
#  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
#  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
#  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
#  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
#  SUCH DAMAGE.
#
SHELL		= /bin/sh

CDKLIB		= @LIB_PREFIX@cdk.a
VERSION		= 4.9.9

prefix		= @prefix@
exec_prefix	= @exec_prefix@

srcdir		= @srcdir@
VPATH		= $(srcdir)

DESTDIR		=
includedir	= $(DESTDIR)@includedir@
libdir		= $(DESTDIR)@libdir@
mandir		= $(DESTDIR)@mandir@

INCLUDE_DIR	= $(includedir)/cdk
LIB_DIR		= $(libdir)
MAN_DIR		= $(mandir)/man3

CFLAGS		= @CFLAGS@
CPPFLAGS	= -I./include -I$(srcdir)/include @CPPFLAGS@ @DEFS@
EXTRA_CFLAGS	= @EXTRA_CFLAGS@
CC		= @CC@
LDFLAGS		= @LDFLAGS@
LIBS		= @LIBS@
RANLIB		= @RANLIB@

RM		= rm -f

INSTALL		= @INSTALL@
INSTALL_PROGRAM	= @INSTALL_PROGRAM@
INSTALL_DATA	= @INSTALL_DATA@

default:: cdklib

#
# Create the file lists.
#
CDKHDR		= \
		alphalist.h \
		binding.h \
		buttonbox.h \
		calendar.h \
		cdk.h \
		cdk_config.h \
		cdk_objs.h \
		cdk_util.h \
		cdkscreen.h \
		curdefs.h \
		dialog.h \
		draw.h \
		entry.h \
		fselect.h \
		graph.h \
		histogram.h \
		itemlist.h \
		label.h \
		marquee.h \
		matrix.h \
		mentry.h \
		menu.h \
		radio.h \
		scale.h \
		scroll.h \
		selection.h \
		slider.h \
		swindow.h \
		template.h \
		viewer.h

CDKSRC		= \
		alphalist.c \
		binding.c \
		buttonbox.c \
		calendar.c \
		cdk.c \
		cdkscreen.c \
		debug.c \
		dialog.c \
		draw.c \
		entry.c \
		fselect.c \
		graph.c \
		histogram.c \
		itemlist.c \
		label.c \
		marquee.c \
		matrix.c \
		mentry.c \
		menu.c \
		position.c \
		radio.c \
		scale.c \
		scroll.c \
		selection.c \
		slider.c \
		swindow.c \
		template.c \
		viewer.c

CDKMAN		= \
		cdk_alphalist.3 \
		cdk_binding.3 \
		cdk_buttonbox.3 \
		cdk_calendar.3 \
		cdk_cdk.3 \
		cdk_dialog.3 \
		cdk_display.3 \
		cdk_entry.3 \
		cdk_fselect.3 \
		cdk_graph.3 \
		cdk_histogram.3 \
		cdk_itemlist.3 \
		cdk_label.3 \
		cdk_marquee.3 \
		cdk_matrix.3 \
		cdk_mentry.3 \
		cdk_menu.3 \
		cdk_misc.3 \
		cdk_radio.3 \
		cdk_scale.3 \
		cdk_screen.3 \
		cdk_scroll.3 \
		cdk_selection.3 \
		cdk_slider.3 \
		cdk_swindow.3 \
		cdk_template.3 \
		cdk_viewer.3

CDKREADME	= BUGS EXPANDING NOTES TODO COPYING INSTALL README

CDKOBJS		= $(CDKSRC:.c=.o)

$(CDKOBJS) :	include/cdk_config.h

#
# Standard library directive.
#
cdklib $(CDKLIB): $(CDKOBJS)
	$(AR) -cr $(CDKLIB) $(CDKOBJS)
	$(RANLIB) $(CDKLIB)

#
# Make the examples directory.
#
examples::
	@(cd examples; make)

#
# Make the demos directory.
#
demos::
	@(cd demos; make)

#
# The 'install' target installs all of the CDK library release.
# There are separate targets for each type of file.
#

#
# This installs the header files.
#
install \
installCDKHeaderFiles:: $(INCLUDE_DIR)
	@echo "Installing CDK header files in $(INCLUDE_DIR)..."
	@for i in $(CDKHDR); do \
	   echo "	... include/$$i"; \
	   $(INSTALL_DATA) include/$$i $(INCLUDE_DIR)/$$i; \
	done

#
# This installs the informational readme files.
#
install \
installCDKReadme::
	@echo "Installing CDK Readme files in $(INCLUDE_DIR)..."
	@for i in $(CDKREADME); do \
	   echo "	... $$i"; \
	   $(INSTALL_DATA) $$i $(INCLUDE_DIR)/$$i; \
	done

#
# This installs the CDK library.
#
install \
installCDKLibrary:: $(LIB_DIR) $(CDKLIB)
	@echo "Installing CDK library"
	@echo "	$(INSTALL_DATA) $(CDKLIB) $(LIB_DIR)"
	@$(INSTALL_DATA) $(CDKLIB) $(LIB_DIR)

#
# This installs the CDK man pages.
#
install \
installCDKManPages:: $(MAN_DIR)
	@echo "Installing the CDK man pages in $(MAN_DIR) ..."
	@for i in $(CDKMAN); do \
	   echo "	... man/$$i"; \
	   $(INSTALL_DATA) man/$$i $(MAN_DIR)/$$i; \
	done

#
# Clean up after ourselves...
#
clean::
	$(RM) *.o $(CDKLIB) core tags *~

realclean:: clean
	cd examples	&& make clean
	cd demos	&& make clean

#
# Use this to clean the distribution.
#
distclean:: realclean
	$(RM) config.cache config.log config.status
	cd examples	&& $(RM) Makefile
	cd demos	&& $(RM) Makefile
	$(RM) include/cdk_config.h
	$(RM) Makefile

#
# Standard .c to .o compile line.
#
.c.o:
@RULE_CC@
	@ECHO_CC@$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CPPFLAGS) -c $<

#
# Set up our PHONY tags.
#
.PHONY: examples
.PHONY: demos

$(INCLUDE_DIR) \
$(LIB_DIR) \
$(MAN_DIR) : ; $(srcdir)/mkdirs.sh $@
