# Makefile for ncurses source code.
#
# This makes the ncurses utility programs.
#
# 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_OBJ_SUBDIR@
srcdir		= @srcdir@
VPATH		= @srcdir@
prefix		= @prefix@
exec_prefix	= @exec_prefix@
bindir		= $(exec_prefix)/bin
includedir	= @includedir@

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

INSTALL		= @INSTALL@
INSTALL_PROGRAM	= @INSTALL_PROGRAM@

AWK		= @AWK@

CC		= @CC@
CFLAGS		= @CFLAGS@

INCDIR		= $(srcdir)/../include
CPPFLAGS	= -I../progs -I$(srcdir) @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@

AUTO_SRC = \
	termsort.c

PROGS = tic infocmp clear tput

TESTPROGS = mvcur tctest hardscroll

# Default library, for linking applications
LIB_CURSES = ../lib/libncurses@DFT_DEP_SUFFIX@

################################################################################
all:	$(AUTO_SRC) $(PROGS) 

install: install.progs 

# this line simplifies the configure-script
install.libs:

install.progs: $(PROGS) $(bindir)
	$(INSTALL_PROGRAM) tic $(bindir)/tic
	$(INSTALL_PROGRAM) infocmp $(bindir)/infocmp
	$(INSTALL_PROGRAM) clear $(bindir)/clear
	$(INSTALL_PROGRAM) tput $(bindir)/tput
	@echo "linking captoinfo to tic"
	-@rm -f $(bindir)/captoinfo
	-@ln $(bindir)/tic $(bindir)/captoinfo

$(bindir) :
	$(srcdir)/../mkinstalldirs $@

#
# Utilities normally built by make all start here
#

DEPS_TIC = \
	$(MODEL)/comp_main.o \
	$(MODEL)/dump_entry.o \
	$(MODEL)/write_entry.o \
	$(LIB_CURSES)
tic: $(DEPS_TIC)
	$(LINK) $(CFLAGS_DEFAULT) $(DEPS_TIC) $(LDFLAGS) -o $@

DEPS_CLEAR = \
	$(MODEL)/clear.o \
	$(LIB_CURSES)
clear: $(DEPS_CLEAR)
	$(LINK) $(CFLAGS_DEFAULT) $(DEPS_CLEAR) $(LDFLAGS) -o $@

DEPS_TPUT = \
	$(MODEL)/tput.o \
	$(LIB_CURSES)
tput: $(DEPS_TPUT)
	$(LINK) $(CFLAGS_DEFAULT) $(DEPS_TPUT) $(LDFLAGS) -o $@

DEPS_INFOCMP = \
	$(MODEL)/infocmp.o \
	$(MODEL)/dump_entry.o \
	$(LIB_CURSES)
infocmp: $(DEPS_INFOCMP)
	$(LINK) $(CFLAGS_DEFAULT) $(DEPS_INFOCMP) $(LDFLAGS) -o $@

termsort.c: ../include/Caps.filtered $(srcdir)/termsort.sh
	sh -c "$(srcdir)/termsort.sh $(AWK) ../include/Caps.filtered" >$@

#
# Test programs (not normally built by make all) start here.
#

# Cursor movement optimization tester. Use -g for debugging but -O if you're
# profiling with intent to determine COMPUTE_OVERHEAD
MVFLAGS = -O
DEPS_MVCUR = \
	$(srcdir)/../ncurses/lib_mvcur.c \
	$(MODEL)/dump_entry.o \
	$(LIB_CURSES)
mvcur: $(DEPS_MVCUR)
	$(LINK) $(CCFLAGS) -DTRACE -DMAIN $(MVFLAGS) $(DEPS_MVCUR) $(LDFLAGS) -o $@

# Termcap-conversion tester
DEPS_TCTEST = \
	$(srcdir)/../ncurses/captoinfo.c \
	$(LIB_CURSES)
tctest: $(DEPS_TCTEST)
	$(LINK) $(CCFLAGS) -DTRACE -DMAIN $(DEPS_TCTEST) $(LDFLAGS) -o $@

# Demonstrator/tester for hardware-scrolling algorithm.
hardscroll: \
		$(srcdir)/../ncurses/hardscroll.c
	$(LINK) $(CCFLAGS) -DMAINDEBUG $(srcdir)/../ncurses/hardscroll.c $(LDFLAGS) -o $@

#
# Utility productions start here
#

tags:
	ctags *.[ch]

TAGS:
	etags *.[ch]

clean ::
	-rm -f tags TAGS do.tic *~
	-rm -f $(AUTO_SRC) $(TESTPROGS)
	-rm -f $(PROGS)

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)
$(LIB_CURSES) :
	cd ../ncurses; $(MAKE) $(NC_MFLAGS)

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