# Makefile for ncurses source code.
#
# This makes the following:
#	programs
#	includes
#	libraries (normal/debug/profile/shared)
#
# The variable 'srcdir' refers to the source-distribution, and can be set with
# the configure script by "--srcdir=DIR".
#
# The rules are organized to produce the libraries for the configured models,
# and the programs with the configured default model.

# turn off _all_ suffix rules; we'll generate our own
.SUFFIXES:

SHELL		= /bin/sh
THIS		= Makefile

NC_MFLAGS 	= @nc_cv_makeflags@
@SET_MAKE@

MODEL		= @DFT_LWR_MODEL@
srcdir		= @srcdir@
VPATH		= @srcdir@
prefix		= @prefix@
exec_prefix	= @exec_prefix@
libdir		= $(exec_prefix)/lib
includedir	= @includedir@

# We'd put terminfo in /usr/share/terminfo, but that's not the convention...
ticdir		= @datadir@

INSTALL		= @INSTALL@
INSTALL_DATA	= @INSTALL_DATA@

AWK		= @AWK@

CC		= @CC@
CFLAGS		= @CFLAGS@

INCDIR		= $(srcdir)/../include
CPPFLAGS	= -I../ncurses @INCLUDES@ \
		  -DHAVE_CONFIG_H -DTERMINFO=\"$(ticdir)\"

CCFLAGS		= $(CPPFLAGS) $(CFLAGS)

CFLAGS_NORMAL	= $(CCFLAGS)
CFLAGS_DEBUG	= $(CCFLAGS) -g -DTRACE
CFLAGS_PROFILE	= $(CCFLAGS) -pg
CFLAGS_SHARED	= $(CCFLAGS) @CC_SHARED_OPTS@

CFLAGS_DEFAULT	= $(CFLAGS_@DFT_UPR_MODEL@)

LINK		= $(CC)
LDFLAGS		= @LDFLAGS@ @LD_MODEL@ @LIBS@

MK_SHARED_LIB	= @MK_SHARED_LIB@

RANLIB		= @RANLIB@

LIBRARIES	= @LIBS_TO_MAKE@

AUTO_SRC = \
	comp_captab.c \
	keys.tries \
	lib_keyname.c \
	names.c

################################################################################
all ::	../lib $(AUTO_SRC) $(LIBRARIES)

../lib : ; mkdir $@

install :: install.libs

install.libs: $(LIBRARIES) $(libdir)
	@for lib in $(LIBRARIES); do \
		out=`echo $${lib} | sed -e s'@^.*/@@'`; \
		echo installing $${lib} as $(libdir)/$${out}; \
		$(INSTALL_DATA) $${lib} $(libdir)/$${out}; \
	done

$(libdir) \
$(ticdir) :
	$(srcdir)/../mkinstalldirs $@

keys.tries: $(srcdir)/keys.list
	$(AWK) -f $(srcdir)/MKkeys.awk $(srcdir)/keys.list > keys.tries

comp_captab.c: \
		../include/hashsize.h \
		../include/Caps.filtered \
		$(srcdir)/MKcaptab.awk
	sh $(srcdir)/MKcaptab.awk $(AWK) ../include/Caps.filtered > $@

lib_keyname.c: $(srcdir)/keys.list $(srcdir)/MKkeyname.awk
	$(AWK) -f $(srcdir)/MKkeyname.awk $(srcdir)/keys.list > $@

names.c: ../include/Caps.filtered $(srcdir)/MKnames.awk
	$(AWK) -f $(srcdir)/MKnames.awk ../include/Caps.filtered
	cat boolnames boolfnames boolcodes numnames numfnames numcodes strnames strfnames strcodes> $@
	-rm -f boolnames boolfnames boolcodes numnames numfnames numcodes strnames strfnames strcodes

tags:
	ctags *.[ch]

TAGS:
	etags *.[ch]

clean ::
	-rm -f tags TAGS *~
	-rm -f $(AUTO_SRC)

distclean: clean
	-rm -f Makefile

mostlyclean: clean

realclean: distclean

# These rules are used to allow "make -n" to work on a clean directory-tree
../include/hashsize.h \
../include/parametrized.h \
../include/term.h \
../include/Caps.filtered :
	cd ../include; $(MAKE) $(NC_MFLAGS)

###############################################################################
# The remainder of this file is automatically generated during configuration
###############################################################################
