# Source Makefile for tin
# - for configuration options read the ../doc/INSTALL file.
#
# Updated: 2024-11-22
#
# Copyright (c) 1995-2024 Thomas E. Dickey <dickey@invisible-island.net>
# 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. Neither the name of the copyright holder nor the names of its
#    contributors may be used to endorse or promote products derived from
#    this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# 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 THE COPYRIGHT HOLDER 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.
#

PACKAGE = @PACKAGE@
VERSION = @VERSION@

SHELL		= /bin/sh
prefix		= @prefix@
exec_prefix	= @exec_prefix@
datarootdir	= @datarootdir@
top_srcdir	= @top_srcdir@
top_builddir	= ..
srcdir		= @srcdir@
VPATH		= $(srcdir)

# Compiler, linker & parser commands
CC		= @CC@
CPP		= @CPP@
PRELIB		= @LIB_PREFIX@

x		= @EXEEXT@
o		= .@OBJEXT@

DEBUG		= @ENABLE_DEBUG@ -DDEBUG # -DPROFILE # -DINLINE_DEBUG_MIME
FEATURES	= # -DREPRODUCIBLE_BUILD # -DALLOW_FWS_IN_NEWSGROUPLIST # -DEVIL_INSIDE # -DMAXARTNUM
INTL_CPPFLAGS	= -DLOCALEDIR=\"$(prefix)/@DATADIRNAME@/locale\"
PCRE_CPPFLAGS	= @PCREDIR_CPPFLAGS@ @PCREDIR_MAKE@ -I$(top_builddir)/pcre -I$(top_srcdir)/pcre

CAN_CPPFLAGS	= @CANDIR_MAKE@ @CAN_CPPFLAGS@

CPPFLAGS	= @DEFS@ -I. -I../include $(PCRE_CPPFLAGS) $(CAN_CPPFLAGS) $(INTL_CPPFLAGS) -I$(INCDIR) $(DEBUG) $(FEATURES) @CPPFLAGS@
CFLAGS		= @CFLAGS@

LDFLAGS		= @LDFLAGS@
YACC		= @YACC@

BUILD_CC	= @BUILD_CC@
BUILD_CFLAGS	= @BUILD_CFLAGS@
BUILD_CPPFLAGS	= @DEFS@ @BUILD_CPPFLAGS@ $(PCRE_CPPFLAGS)
BUILD_LDFLAGS	= @BUILD_LDFLAGS@
BUILD_LIBS	= @BUILD_LIBS@
X		= $(BUILD_EXEEXT)

CANLIB		= @CANLIBS@
PCRE_LIBS	= @PCREDIR_LIBS@ @PCREDIR_MAKE@ -L../pcre -lpcre
LIBS		= @LIBS@
LINK_LIBS	= $(PCRE_LIBS) $(CANLIB) @LIBS@

# Where do you want the binary & manual page installed?
DESTDIR		= @DESTDIR@
INS_BINARY_DIR	= @bindir@
INS_MANUAL_DIR	= @mandir@/man
INS_SYSDEF_DIR	= @TIN_DEFAULTS_DIR@
INS_MANUAL_EXT	= 1
INS_OLD_SUFFIX	= old

REMAKE		= $(MAKE) @cf_cv_makeflags@ DESTDIR="$(DESTDIR)"

MAN_LINGUAS = de en_GB es

# Project
PROJECT	= `echo @PACKAGE@|sed '@program_transform_name@'`
PROJEXE = $(PROJECT)$x
EXE	= @PACKAGE@$x
VER	= @VERSION@

# directory structure
DOCDIR	= $(top_srcdir)/doc
INCDIR	= $(top_srcdir)/include
BINDIR	= .
OBJDIR	= .
SRCDIR	= $(srcdir)
TOLDIR	= $(top_srcdir)/tools

# standard commands
CD	= cd
CHMOD	= chmod
CP	= cp
ECHO	= echo
LS	= ls
MV	= mv
RM	= rm
SED	= sed
CFLOW	= cflow
CSCOPE	= cscope
TAGS	= ctags
ETAGS	= etags
LINT	= @LINT@
LN	= @LN_S@
INSTALL	= @INSTALL@
@SET_MAKE@

HFILES	= \
	../include/autoconf.h \
	$(INCDIR)/bool.h \
	$(INCDIR)/bugrep.h \
	$(INCDIR)/debug.h \
	$(INCDIR)/extern.h \
	$(INCDIR)/keymap.h \
	$(INCDIR)/newsrc.h \
	$(INCDIR)/nntplib.h \
	$(INCDIR)/policy.h \
	$(INCDIR)/proto.h \
	$(INCDIR)/rfc2046.h \
	$(INCDIR)/snprintf.h \
	$(INCDIR)/stpwatch.h \
	$(INCDIR)/tin.h \
	$(INCDIR)/tinrc.h \
	$(INCDIR)/tnntp.h \
	$(INCDIR)/tnntps.h \
	$(INCDIR)/version.h

CFILES	= \
	$(SRCDIR)/active.c \
	$(SRCDIR)/art.c \
	$(SRCDIR)/attrib.c \
	$(SRCDIR)/auth.c \
	$(SRCDIR)/charset.c \
	$(SRCDIR)/color.c \
	$(SRCDIR)/config.c \
	$(SRCDIR)/cook.c \
	$(SRCDIR)/curses.c \
	$(SRCDIR)/debug.c \
	$(SRCDIR)/envarg.c \
	$(SRCDIR)/feed.c \
	$(SRCDIR)/filter.c \
	$(SRCDIR)/getline.c \
	$(SRCDIR)/global.c \
	$(SRCDIR)/group.c \
	$(SRCDIR)/hashstr.c \
	$(SRCDIR)/header.c \
	$(SRCDIR)/help.c \
	$(SRCDIR)/inews.c \
	$(SRCDIR)/init.c \
	$(SRCDIR)/joinpath.c \
	$(SRCDIR)/keymap.c \
	$(SRCDIR)/lang.c \
	$(SRCDIR)/langinfo.c \
	$(SRCDIR)/list.c \
	$(SRCDIR)/lock.c \
	$(SRCDIR)/mail.c \
	$(SRCDIR)/main.c \
	$(SRCDIR)/memory.c \
	$(SRCDIR)/mimetypes.c \
	$(SRCDIR)/misc.c \
	$(SRCDIR)/my_tmpfile.c \
	$(SRCDIR)/newsrc.c \
	$(SRCDIR)/nntplib.c \
	$(SRCDIR)/nntps.c \
	$(SRCDIR)/nrctbl.c \
	$(SRCDIR)/options_menu.c \
	$(SRCDIR)/page.c \
	$(SRCDIR)/parsdate.y \
	$(SRCDIR)/pgp.c \
	$(SRCDIR)/post.c \
	$(SRCDIR)/prompt.c \
	$(SRCDIR)/read.c \
	$(SRCDIR)/refs.c \
	$(SRCDIR)/regex.c \
	$(SRCDIR)/rfc1524.c \
	$(SRCDIR)/rfc2045.c \
	$(SRCDIR)/rfc2046.c \
	$(SRCDIR)/rfc2047.c \
	$(SRCDIR)/save.c \
	$(SRCDIR)/screen.c \
	$(SRCDIR)/search.c \
	$(SRCDIR)/select.c \
	$(SRCDIR)/sigfile.c \
	$(SRCDIR)/signal.c \
	$(SRCDIR)/snprintf.c \
	$(SRCDIR)/strftime.c \
	$(SRCDIR)/string.c \
	$(SRCDIR)/tags.c \
	$(SRCDIR)/tcurses.c \
	$(SRCDIR)/thread.c \
	$(SRCDIR)/version.c \
	$(SRCDIR)/wildmat.c \
	$(SRCDIR)/xref.c

EXTRA_PCREHDRS = @PCREDIR_MAKE@ ../pcre/pcre.h
EXTRA_PCRELIBS = @PCREDIR_MAKE@ ../pcre/$(PRELIB)pcre.a
EXTRA_CANLIBS = @CANDIR_MAKE@ ../libcanlock/$(PRELIB)canlock.a
EXTRALIBS = $(EXTRA_PCRELIBS) $(EXTRA_CANLIBS)

OFILES	= @ALLOCA@ @EXTRAOBJS@ \
	$(OBJDIR)/active$o \
	$(OBJDIR)/art$o \
	$(OBJDIR)/attrib$o \
	$(OBJDIR)/auth$o \
	$(OBJDIR)/charset$o \
	$(OBJDIR)/color$o \
	$(OBJDIR)/config$o \
	$(OBJDIR)/cook$o \
	$(OBJDIR)/curses$o \
	$(OBJDIR)/debug$o \
	$(OBJDIR)/envarg$o \
	$(OBJDIR)/feed$o \
	$(OBJDIR)/filter$o \
	$(OBJDIR)/getline$o \
	$(OBJDIR)/global$o \
	$(OBJDIR)/group$o \
	$(OBJDIR)/hashstr$o \
	$(OBJDIR)/header$o \
	$(OBJDIR)/help$o \
	$(OBJDIR)/inews$o \
	$(OBJDIR)/init$o \
	$(OBJDIR)/joinpath$o \
	$(OBJDIR)/keymap$o \
	$(OBJDIR)/lang$o \
	$(OBJDIR)/langinfo$o \
	$(OBJDIR)/list$o \
	$(OBJDIR)/lock$o \
	$(OBJDIR)/mail$o \
	$(OBJDIR)/main$o \
	$(OBJDIR)/memory$o \
	$(OBJDIR)/mimetypes$o \
	$(OBJDIR)/misc$o \
	$(OBJDIR)/my_tmpfile$o \
	$(OBJDIR)/newsrc$o \
	$(OBJDIR)/nntplib$o \
	$(OBJDIR)/nntps$o \
	$(OBJDIR)/nrctbl$o \
	$(OBJDIR)/options_menu$o \
	$(OBJDIR)/page$o \
	$(OBJDIR)/parsdate$o \
	$(OBJDIR)/pgp$o \
	$(OBJDIR)/post$o \
	$(OBJDIR)/prompt$o \
	$(OBJDIR)/read$o \
	$(OBJDIR)/refs$o \
	$(OBJDIR)/regex$o \
	$(OBJDIR)/rfc1524$o \
	$(OBJDIR)/rfc2045$o \
	$(OBJDIR)/rfc2046$o \
	$(OBJDIR)/rfc2047$o \
	$(OBJDIR)/save$o \
	$(OBJDIR)/screen$o \
	$(OBJDIR)/search$o \
	$(OBJDIR)/select$o \
	$(OBJDIR)/sigfile$o \
	$(OBJDIR)/signal$o \
	$(OBJDIR)/snprintf$o \
	$(OBJDIR)/strftime$o \
	$(OBJDIR)/string$o \
	$(OBJDIR)/tags$o \
	$(OBJDIR)/tcurses$o \
	$(OBJDIR)/thread$o \
	$(OBJDIR)/version$o \
	$(OBJDIR)/wildmat$o \
	$(OBJDIR)/xref$o

ALL_FILES = $(HFILES) $(CFILES)

LINTFLAGS = @LINTFLAGS@ $(CPPFLAGS)

all : $(BINDIR)/$(EXE)

.SUFFIXES : .i

.c$o :
	@SHOW_CC@
	@ECHO_CC@$(CC) $(CPPFLAGS) $(CFLAGS) -c $(srcdir)/$*.c

.c.i :
	@SHOW_CC@
	@ECHO_CC@$(CPP) -C $(CPPFLAGS) $*.c >$@

# explicit rules to allow running lint, and to accommodate older 'make' programs
$(OBJDIR)/parsdate$o : $(SRCDIR)/parsdate.y
	@$(ECHO) "expect 6 shift/reduce conflicts ..."
	$(YACC) $(SRCDIR)/parsdate.y
	$(MV) -f y.tab.c $(OBJDIR)/parsdate.c
	@SHOW_CC@
	@ECHO_CC@$(CC) $(CPPFLAGS) $(CFLAGS) -c $(OBJDIR)/parsdate.c

$(OBJDIR)/parsdate.c : $(SRCDIR)/parsdate.y
	@$(ECHO) "expect 6 shift/reduce conflicts ..."
	$(YACC) $(SRCDIR)/parsdate.y
	$(MV) -f y.tab.c $(OBJDIR)/parsdate.c

$(BINDIR)/$(EXE) : $(OFILES) $(EXTRALIBS)
	@$(ECHO) "Linking $(EXE) v$(VER) ..."
	$(CC) $(LDFLAGS) -o $(BINDIR)/$(EXE) $(OFILES) $(LINK_LIBS)
	@$(LS) -l $(BINDIR)/$(EXE)

help :
	@$(ECHO) "This Makefile offers the following options:"
	@$(ECHO) " "
	@$(ECHO) "    make [all]                 [ Build the binary for your OS ]"
	@$(ECHO) "    make [un]install           [ [Un]install the binaries & manual pages ]"
	@$(ECHO) "      make [un]install_helpers [ [Un]install helper applications ]"
	@$(ECHO) "      make [un]install_manpage [ [Un]install the manual pages ]"
	@$(ECHO) "      make [un]install_nls     [ [Un]install native language files ]"
	@$(ECHO) "      make [un]install_nls_man [ [Un]install native language manual pages ]"
	@$(ECHO) "    make [un]install_sysdefs   [ [Un]install the system-wide defaults file ]"
	@$(ECHO) "    make clean                 [ Delete all object files ]"
	@$(ECHO) "    make help                  [ Show this text ]"
	@$(ECHO) " "

$(DESTDIR)$(INS_MANUAL_DIR)$(INS_MANUAL_EXT) \
$(DESTDIR)$(INS_MANUAL_DIR)5 \
$(DESTDIR)$(INS_BINARY_DIR) \
$(DESTDIR)$(INS_SYSDEF_DIR) :
	mkdir -p $@

install_manpage : $(DESTDIR)$(INS_MANUAL_DIR)$(INS_MANUAL_EXT) $(DESTDIR)$(INS_MANUAL_DIR)5
	@$(ECHO) "Installing $(PROJECT) manual pages to $(DESTDIR)$(INS_MANUAL_DIR) ..."
	@$(INSTALL) -m 444 $(DOCDIR)/tin.1 $(DESTDIR)$(INS_MANUAL_DIR)$(INS_MANUAL_EXT)/$(PROJECT).$(INS_MANUAL_EXT)
	@( $(CD) $(DESTDIR)$(INS_MANUAL_DIR)$(INS_MANUAL_EXT) && $(RM) -f r$(PROJECT).$(INS_MANUAL_EXT) && $(LN) $(PROJECT).$(INS_MANUAL_EXT) r$(PROJECT).$(INS_MANUAL_EXT) )
	@$(INSTALL) -m 444 $(DOCDIR)/tin.5 $(DESTDIR)$(INS_MANUAL_DIR)5/$(PROJECT).5
	@-$(RM) -f $(DESTDIR)$(INS_MANUAL_DIR)5/r$(PROJECT).5
	@$(ECHO) ".so $(INS_MANUAL_DIR)5/$(PROJECT).5" > $(DESTDIR)$(INS_MANUAL_DIR)5/r$(PROJECT).5
	@$(CHMOD) 444 $(DESTDIR)$(INS_MANUAL_DIR)5/r$(PROJECT).5
	@-if test ! -f $(DESTDIR)$(INS_MANUAL_DIR)5/mbox.5 ; then $(INSTALL) -m 444 $(DOCDIR)/mbox.5 $(DESTDIR)$(INS_MANUAL_DIR)5/mbox.5 ; else $(ECHO) "  ... skipping $(DESTDIR)$(INS_MANUAL_DIR)5/mbox.5 - file already exists" ; fi
	@-if test ! -f $(DESTDIR)$(INS_MANUAL_DIR)5/mmdf.5 ; then $(INSTALL) -m 444 $(DOCDIR)/mmdf.5 $(DESTDIR)$(INS_MANUAL_DIR)5/mmdf.5 ; else $(ECHO) "  ... skipping $(DESTDIR)$(INS_MANUAL_DIR)5/mmdf.5 - file already exists" ; fi

uninstall_manpage :
	@$(ECHO) "Uninstalling $(PROJECT) manual page in $(DESTDIR)$(INS_MANUAL_DIR)$(INS_MANUAL_EXT) ..."
	@-$(RM) -f $(DESTDIR)$(INS_MANUAL_DIR)$(INS_MANUAL_EXT)/$(PROJECT).$(INS_MANUAL_EXT)
	@-$(RM) -f $(DESTDIR)$(INS_MANUAL_DIR)$(INS_MANUAL_EXT)/r$(PROJECT).$(INS_MANUAL_EXT)
	@-$(RM) -f $(DESTDIR)$(INS_MANUAL_DIR)5/$(PROJECT).5
#	@-$(RM) -f $(DESTDIR)$(INS_MANUAL_DIR)5/mbox.5
#	@-$(RM) -f $(DESTDIR)$(INS_MANUAL_DIR)5/mmdf.5

install_nls_man :
	@-for manext in $(INS_MANUAL_EXT) 5 ; do \
		for lang in $(MAN_LINGUAS) ; do \
			if test -e $(DOCDIR)/l10n/$${lang}/$(PROJECT).$${manext} ; then \
				$(INSTALL) -D -m 444 $(DOCDIR)/l10n/$${lang}/$(PROJECT).$${manext} $(DESTDIR)@mandir@/$${lang}/man$${manext}/$(PROJECT).$${manext}; \
			fi; \
		done; \
	done

uninstall_nls_man :
	@-for manext in $(INS_MANUAL_EXT) 5 ; do \
		for lang in $(MAN_LINGUAS) ; do \
			$(RM) -f $(DESTDIR)@mandir@/$${lang}/man$${manext}/$(PROJECT).$${manext}; \
		done; \
	done

install_sysdefs : $(DESTDIR)$(INS_SYSDEF_DIR)
	@$(ECHO) "Installing system-wide defaults to $(DESTDIR)$(INS_SYSDEF_DIR) ..."
	@-if test -f $(DESTDIR)$(INS_SYSDEF_DIR)/tin.defaults ; then $(ECHO) "  ... backing up existing tin.defaults file to tin.defaults.$(INS_OLD_SUFFIX)" ; $(MV) -f $(DESTDIR)$(INS_SYSDEF_DIR)/tin.defaults $(DESTDIR)$(INS_SYSDEF_DIR)/tin.defaults.$(INS_OLD_SUFFIX) ; fi
	@-if test -f $(DESTDIR)$(INS_SYSDEF_DIR)/mime.types ; then $(ECHO) "  ... backing up existing mime.types file to mime.types.$(INS_OLD_SUFFIX)" ; $(MV) -f $(DESTDIR)$(INS_SYSDEF_DIR)/mime.types $(DESTDIR)$(INS_SYSDEF_DIR)/mime.types.$(INS_OLD_SUFFIX) ; fi
	@$(INSTALL) -m 644 $(DOCDIR)/tin.defaults $(DESTDIR)$(INS_SYSDEF_DIR)/tin.defaults
	@$(INSTALL) -m 644 $(DOCDIR)/mime.types $(DESTDIR)$(INS_SYSDEF_DIR)/mime.types

uninstall_sysdefs :
	@$(ECHO) "Uninstalling system-wide defaults in $(DESTDIR)$(INS_SYSDEF_DIR) ..."
	@-$(RM) -f $(DESTDIR)$(INS_SYSDEF_DIR)/tin.defaults
	@-$(RM) -f $(DESTDIR)$(INS_SYSDEF_DIR)/mime.types

install_helpers : $(DESTDIR)$(INS_BINARY_DIR) $(DESTDIR)$(INS_MANUAL_DIR)$(INS_MANUAL_EXT)
	@$(ECHO) "Installing helper applications ..."
	@-if test ! -f $(DESTDIR)$(INS_BINARY_DIR)/metamutt ; then $(INSTALL) -m 755 $(TOLDIR)/metamutt $(DESTDIR)$(INS_BINARY_DIR)/metamutt ; fi
	@$(INSTALL) -m 755 $(TOLDIR)/w2r.pl $(DESTDIR)$(INS_BINARY_DIR)/w2r.pl
	@$(INSTALL) -m 755 $(TOLDIR)/opt-case.pl $(DESTDIR)$(INS_BINARY_DIR)/opt-case.pl
	@$(INSTALL) -m 755 $(TOLDIR)/tinews.pl $(DESTDIR)$(INS_BINARY_DIR)/tinews.pl
	@$(INSTALL) -m 755 $(TOLDIR)/url_handler.pl $(DESTDIR)$(INS_BINARY_DIR)/url_handler.pl
	@$(INSTALL) -m 444 $(DOCDIR)/w2r.1 $(DESTDIR)$(INS_MANUAL_DIR)$(INS_MANUAL_EXT)/w2r.pl.$(INS_MANUAL_EXT)
	@$(INSTALL) -m 444 $(DOCDIR)/opt-case.1 $(DESTDIR)$(INS_MANUAL_DIR)$(INS_MANUAL_EXT)/opt-case.pl.$(INS_MANUAL_EXT)
	@$(INSTALL) -m 444 $(DOCDIR)/tinews.1 $(DESTDIR)$(INS_MANUAL_DIR)$(INS_MANUAL_EXT)/tinews.pl.$(INS_MANUAL_EXT)
	@$(INSTALL) -m 444 $(DOCDIR)/url_handler.1 $(DESTDIR)$(INS_MANUAL_DIR)$(INS_MANUAL_EXT)/url_handler.pl.$(INS_MANUAL_EXT)

uninstall_helpers :
	@$(ECHO) "Removing helper applications ..."
	@-$(RM) -f $(DESTDIR)$(INS_BINARY_DIR)/w2r.pl
	@-$(RM) -f $(DESTDIR)$(INS_BINARY_DIR)/opt-case.pl
	@-$(RM) -f $(DESTDIR)$(INS_BINARY_DIR)/tinews.pl
	@-$(RM) -f $(DESTDIR)$(INS_BINARY_DIR)/url_handler.pl
	@-$(RM) -f $(DESTDIR)$(INS_MANUAL_DIR)$(INS_MANUAL_EXT)/w2r.pl.$(INS_MANUAL_EXT)
	@-$(RM) -f $(DESTDIR)$(INS_MANUAL_DIR)$(INS_MANUAL_EXT)/opt-case.pl.$(INS_MANUAL_EXT)
	@-$(RM) -f $(DESTDIR)$(INS_MANUAL_DIR)$(INS_MANUAL_EXT)/tinews.pl.$(INS_MANUAL_EXT)
	@-$(RM) -f $(DESTDIR)$(INS_MANUAL_DIR)$(INS_MANUAL_EXT)/url_handler.pl.$(INS_MANUAL_EXT)

install : $(DESTDIR)$(INS_BINARY_DIR)
	@$(REMAKE) all
	@$(ECHO) "Installing $(EXE) v$(VER) to $(DESTDIR)$(INS_BINARY_DIR)/$(PROJEXE) ..."
	@$(INSTALL) $(BINDIR)/$(EXE) $(DESTDIR)$(INS_BINARY_DIR)/$(PROJEXE)
	@( $(CD) $(DESTDIR)$(INS_BINARY_DIR) && $(RM) -f r$(PROJEXE) && $(LN) $(PROJEXE) r$(PROJEXE) )
	@$(REMAKE) install_helpers
	@$(REMAKE) install_manpage
@MSG_DIR_MAKE@	@$(REMAKE) install_nls

uninstall :
	@$(ECHO) "Uninstalling $(PROJEXE) in $(DESTDIR)$(INS_BINARY_DIR) ..."
	@-$(RM) -f $(DESTDIR)$(INS_BINARY_DIR)/$(PROJEXE)
	@-$(RM) -f $(DESTDIR)$(INS_BINARY_DIR)/r$(PROJEXE)
	@$(REMAKE) uninstall_helpers
	@$(REMAKE) uninstall_manpage
@MSG_DIR_MAKE@	@$(REMAKE) uninstall_nls

install_nls :
@MSG_DIR_MAKE@	@-if test -r ../po/Makefile ; then $(ECHO) "Installing NLS-files" ; $(CD) ../po/ && $(REMAKE) install ; fi

uninstall_nls :
@MSG_DIR_MAKE@	@-if test -r ../po/Makefile ; then $(ECHO) "Uninstalling NLS-files" ; $(CD) ../po/ && $(REMAKE) uninstall ; fi

tags :
	@$(ECHO) "Generating tags (results in ./tags) ..."
	@-$(RM) -f tags
	@$(TAGS) $(HFILES) $(CFILES)

TAGS :
	@$(ECHO) "Generating emacs tags (results in ./TAGS) ..."
	@-$(RM) -f TAGS
	@$(ETAGS) $(HFILES) $(CFILES)

lint :	$(CFILES) $(SRCDIR)/heapsort.c $(SRCDIR)/xface.c $(OBJDIR)/parsdate.c tincfg.h options_menu.h
	@$(ECHO) "Linting source (results in ./LINT) ..."
	@$(LINT) $(LINTFLAGS) `$(ECHO) $(SRCDIR)/heapsort.c $(SRCDIR)/xface.c $(CFILES)|$(SED) -e 's/\.y/.c/'` $(LIBS) 1>LINT 2>&1

clean :
	@$(ECHO) "Cleaning ..."
	@-$(RM) -f $(OFILES)
	@-$(RM) -f $(OBJDIR)/parsdate.c $(OBJDIR)/y.tab.[chi]
	@-$(RM) -f LINT *.ln *.out trace
	@-$(RM) -f makecfg$X makecfg$o tincfg.h options_menu.h
	@-$(RM) -rf makecfg.dSYM
	@-$(RM) -f core *~
	@-$(RM) -f $(EXE)
@PCREDIR_MAKE@	@-if test -r ../pcre/Makefile ; then $(CD) ../pcre && $(ECHO) "Cleaning Philip Hazel's Perl-compatible regular expressions library ..." && $(REMAKE) clean ; fi
@MSG_DIR_MAKE@	@-if test -r ../po/Makefile ; then $(CD) ../po && $(REMAKE) $@ ; fi

laundry \
dirty :
	@$(ECHO) "I'm sorry, this is not supported yet ..."

distclean \
clobber :: clean
	@$(ECHO) "Clobbering ..."
	@-$(RM) -f $(OFILES) $(BINDIR)/$(EXE) tags TAGS LINT cflow.$(PACKAGE)

distclean ::
@MSG_DIR_MAKE@	@-$(CD) ../po && $(REMAKE) clean

cflow :
	@$(ECHO) "Creating cflow for $(PACKAGE) ..."
@PCREDIR_MAKE@	@$(CFLOW) -I$(INCDIR) -I$(SRCDIR) -I../pcre $(CFILES) > cflow.$(PACKAGE)

cscope :
	@$(ECHO) "Creating cscope database $(PACKAGE) ..."
	@$(CSCOPE) $(ALL_FILES)

@PCREDIR_MAKE@../pcre/pcre.h ../pcre/$(PRELIB)pcre.a :
@PCREDIR_MAKE@	@$(ECHO) "Building Philip Hazel's Perl regular expressions library ..."
@PCREDIR_MAKE@	@$(CD) ../pcre && $(REMAKE) $(PRELIB)pcre.a

@CANDIR_MAKE@../libcanlock/$(PRELIB)canlock.a :
@CANDIR_MAKE@	@$(ECHO) "Building Cancel-Lock library ..."
@CANDIR_MAKE@	@$(CD) ../libcanlock && $(REMAKE) lib

options_menu.h :		$(SRCDIR)/tincfg.tbl \
				makecfg$X
	./makecfg $(SRCDIR)/tincfg.tbl tincfg.h

tincfg.h :			$(SRCDIR)/tincfg.tbl \
				makecfg$X
	./makecfg $(SRCDIR)/tincfg.tbl $@

makecfg$X :			$(SRCDIR)/makecfg.c \
				Makefile \
				../include/autoconf.h
	@SHOW_CC@
	@ECHO_CC@$(BUILD_CC) $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) $(BUILD_LDFLAGS) -o $@ $(SRCDIR)/makecfg.c

TIN_DEP	= \
	Makefile \
	options_menu.h \
	$(INCDIR)/tin.h \
	$(INCDIR)/tinrc.h \
	../include/autoconf.h \
	$(INCDIR)/bool.h \
	$(INCDIR)/debug.h \
	$(INCDIR)/extern.h \
	$(INCDIR)/nntplib.h \
	$(INCDIR)/tcurses.h \
	$(INCDIR)/proto.h $(EXTRA_PCREHDRS)

$(OBJDIR)/active$o :		$(SRCDIR)/active.c $(TIN_DEP) \
				$(INCDIR)/stpwatch.h
$(OBJDIR)/art$o :		$(SRCDIR)/art.c $(TIN_DEP) \
				$(INCDIR)/newsrc.h \
				$(INCDIR)/stpwatch.h
$(OBJDIR)/attrib$o :		$(SRCDIR)/attrib.c $(TIN_DEP) \
				$(INCDIR)/version.h
$(OBJDIR)/auth$o :		$(SRCDIR)/auth.c $(TIN_DEP)
$(OBJDIR)/charset$o :		$(SRCDIR)/charset.c $(TIN_DEP)
$(OBJDIR)/color$o :		$(SRCDIR)/color.c $(TIN_DEP)
$(OBJDIR)/config$o :		$(SRCDIR)/config.c $(TIN_DEP) \
				$(INCDIR)/tnntp.h \
				$(INCDIR)/version.h
$(OBJDIR)/cook$o :		$(SRCDIR)/cook.c $(TIN_DEP) \
				$(INCDIR)/rfc2046.h
$(OBJDIR)/curses$o :		$(SRCDIR)/curses.c $(TIN_DEP) \
				$(INCDIR)/missing_fd.h \
				$(INCDIR)/tnntp.h
$(OBJDIR)/debug$o :		$(SRCDIR)/debug.c $(TIN_DEP) \
				$(INCDIR)/newsrc.h
$(OBJDIR)/envarg$o :		$(SRCDIR)/envarg.c $(TIN_DEP)
$(OBJDIR)/feed$o :		$(SRCDIR)/feed.c $(TIN_DEP) \
				$(INCDIR)/keymap.h \
 				$(INCDIR)/rfc2046.h
$(OBJDIR)/filter$o :		$(SRCDIR)/filter.c $(TIN_DEP) \
				$(INCDIR)/keymap.h \
				$(INCDIR)/version.h
$(OBJDIR)/getline$o :		$(SRCDIR)/getline.c $(TIN_DEP)
$(OBJDIR)/global$o :		$(SRCDIR)/global.c $(TIN_DEP) \
				$(INCDIR)/keymap.h
$(OBJDIR)/group$o :		$(SRCDIR)/group.c $(TIN_DEP) \
				$(INCDIR)/keymap.h
$(OBJDIR)/hashstr$o :		$(SRCDIR)/hashstr.c $(TIN_DEP)
$(OBJDIR)/header$o :		$(SRCDIR)/header.c $(TIN_DEP) \
				$(INCDIR)/tnntp.h
$(OBJDIR)/help$o :		$(SRCDIR)/help.c $(TIN_DEP) \
				$(INCDIR)/keymap.h
$(OBJDIR)/inews$o :		$(SRCDIR)/inews.c $(TIN_DEP) \
				$(INCDIR)/tnntp.h
$(OBJDIR)/init$o :		$(SRCDIR)/init.c $(TIN_DEP) \
				$(INCDIR)/bugrep.h \
				$(INCDIR)/keymap.h \
				$(INCDIR)/tnntp.h \
				$(INCDIR)/version.h
$(OBJDIR)/joinpath$o :		$(SRCDIR)/joinpath.c $(TIN_DEP)
$(OBJDIR)/keymap$o :		$(SRCDIR)/keymap.c $(TIN_DEP) \
				$(INCDIR)/keymap.h \
				$(INCDIR)/version.h
$(OBJDIR)/lang$o :		$(SRCDIR)/lang.c $(TIN_DEP) \
				$(INCDIR)/tnntps.h
$(OBJDIR)/langinfo$o :		$(SRCDIR)/langinfo.c $(TIN_DEP)
$(OBJDIR)/list$o :		$(SRCDIR)/list.c $(TIN_DEP)
$(OBJDIR)/lock$o :		$(SRCDIR)/lock.c $(TIN_DEP)
$(OBJDIR)/mail$o :		$(SRCDIR)/mail.c $(TIN_DEP) \
				$(INCDIR)/tnntp.h
$(OBJDIR)/main$o :		$(SRCDIR)/main.c $(TIN_DEP) \
				$(INCDIR)/tnntp.h \
				$(INCDIR)/version.h
$(OBJDIR)/memory$o :		$(SRCDIR)/memory.c $(TIN_DEP) \
				$(INCDIR)/rfc2046.h
$(OBJDIR)/mimetypes$o :		$(SRCDIR)/mimetypes.c $(TIN_DEP)
$(OBJDIR)/misc$o :		$(SRCDIR)/misc.c $(TIN_DEP) \
				$(INCDIR)/policy.h \
				$(INCDIR)/rfc2046.h \
				$(INCDIR)/version.h
$(OBJDIR)/my_tmpfile$o :	$(SRCDIR)/my_tmpfile.c $(TIN_DEP)
$(OBJDIR)/newsrc$o :		$(SRCDIR)/newsrc.c $(TIN_DEP) \
				$(INCDIR)/newsrc.h \
				$(INCDIR)/tnntp.h
$(OBJDIR)/nntplib$o :		$(SRCDIR)/nntplib.c $(TIN_DEP) \
				$(INCDIR)/tnntp.h
$(OBJDIR)/nntps$o :		$(SRCDIR)/nntps.c $(TIN_DEP) \
				$(INCDIR)/tnntps.h
$(OBJDIR)/nrctbl$o :		$(SRCDIR)/nrctbl.c $(TIN_DEP) \
				$(INCDIR)/keymap.h \
				$(INCDIR)/tnntp.h \
				$(INCDIR)/version.h
$(OBJDIR)/options_menu$o :	$(SRCDIR)/options_menu.c $(TIN_DEP) \
				tincfg.h \
				$(INCDIR)/keymap.h
$(OBJDIR)/page$o :		$(SRCDIR)/page.c $(TIN_DEP) \
				$(INCDIR)/keymap.h \
				$(INCDIR)/rfc2046.h
$(OBJDIR)/parsdate$o :		$(OBJDIR)/parsdate.y $(TIN_DEP)
$(OBJDIR)/pgp$o :		$(SRCDIR)/pgp.c $(TIN_DEP) \
				$(INCDIR)/keymap.h
$(OBJDIR)/post$o :		$(SRCDIR)/post.c $(TIN_DEP) \
				$(INCDIR)/keymap.h \
				$(INCDIR)/rfc2046.h \
				$(INCDIR)/version.h
$(OBJDIR)/prompt$o :		$(SRCDIR)/prompt.c $(TIN_DEP) \
				$(INCDIR)/keymap.h
$(OBJDIR)/read$o :		$(SRCDIR)/read.c $(TIN_DEP) \
				$(INCDIR)/missing_fd.h \
				$(INCDIR)/keymap.h \
				$(INCDIR)/tnntp.h
$(OBJDIR)/refs$o :		$(SRCDIR)/refs.c $(TIN_DEP)
$(OBJDIR)/regex$o :		$(SRCDIR)/regex.c $(TIN_DEP)
$(OBJDIR)/rfc1524$o :		$(SRCDIR)/rfc1524.c $(TIN_DEP) \
				$(INCDIR)/rfc2046.h
$(OBJDIR)/rfc2045$o :		$(SRCDIR)/rfc2045.c $(TIN_DEP)
$(OBJDIR)/rfc2046$o :		$(SRCDIR)/rfc2046.c $(TIN_DEP) \
				$(INCDIR)/rfc2046.h
$(OBJDIR)/rfc2047$o :		$(SRCDIR)/rfc2047.c $(TIN_DEP) \
				$(INCDIR)/rfc2046.h
$(OBJDIR)/save$o :		$(SRCDIR)/save.c $(TIN_DEP) \
				$(INCDIR)/keymap.h \
				$(INCDIR)/rfc2046.h
$(OBJDIR)/screen$o :		$(SRCDIR)/screen.c $(TIN_DEP) \
				$(INCDIR)/tnntp.h
$(OBJDIR)/search$o :		$(SRCDIR)/search.c $(TIN_DEP) \
				$(INCDIR)/keymap.h
$(OBJDIR)/select$o :		$(SRCDIR)/select.c $(TIN_DEP) \
				$(INCDIR)/keymap.h
$(OBJDIR)/sigfile$o :		$(SRCDIR)/sigfile.c $(TIN_DEP)
$(OBJDIR)/signal$o :		$(SRCDIR)/signal.c $(TIN_DEP) \
				$(INCDIR)/version.h
$(OBJDIR)/snprintf$o :	$(SRCDIR)/snprintf.c $(TIN_DEP) \
				$(INCDIR)/snprintf.h
$(OBJDIR)/strftime$o :		$(SRCDIR)/strftime.c $(TIN_DEP)
$(OBJDIR)/string$o :		$(SRCDIR)/string.c $(TIN_DEP)
$(OBJDIR)/tags$o :		$(SRCDIR)/tags.c $(TIN_DEP)
$(OBJDIR)/tcurses$o :		$(SRCDIR)/tcurses.c $(TIN_DEP)
$(OBJDIR)/thread$o :		$(SRCDIR)/thread.c $(TIN_DEP) \
				$(INCDIR)/keymap.h
$(OBJDIR)/version$o :		$(SRCDIR)/version.c $(TIN_DEP) \
				$(INCDIR)/keymap.h \
				$(INCDIR)/version.h
$(OBJDIR)/wildmat$o :		$(SRCDIR)/wildmat.c $(TIN_DEP)
$(OBJDIR)/xref$o :		$(SRCDIR)/xref.c $(TIN_DEP) \
				$(INCDIR)/newsrc.h
@EXTRAO_DEP@@EXTRAOBJS@ :	$(TIN_DEP)
