#
# $VER: tin_makefile 2.3 (13.06.99)
#
# This is especially for use with the SAS/C developing system
# version 6.55 and above
#
# (w) 1994 by Reinhard Luebke (rel)
# expanded by Volker Barthelmann (vb) and Oliver Warzecha (obw)
#

AMIDIR   = /amiga
SRCDIR   = /src
INCDIR   = /include
OBJDIR   = /obj
REDIR    = /pcre

# Timezone stuff for faster spool access (obw)
TZSET    = $(OBJDIR)/_tzset.o
TZSOURCE = sc:source/_tzset.c

# Include the next two lines to enable an NNTP version of TIN.
# To use AS225 rather than AmiTCP, also include "def AS225".

# /*vb*/
NNTPDEF  = def NNTP_ABLE def DOMAIN_NAME="UULIB:news/whoami" \
 def UNISTD_H def CLIB_NETLIB_PROTOS_H

PROJECT  = $(AMIDIR)/tin.exe
ACTIVED  = $(AMIDIR)/actived
GSTFILE  = $(AMIDIR)/tin.gst

#
# compile & link flags
#

# set parameters here, e.g. CPU and additional includes for your TCP/IP stack
/*vb*/
#SCOPTIONS = strmer data=near parms=register nover errrexx ignore=85,93,104,105 \
#                    idir=netinclude: idir=$(INCDIR) gst=$(GSTFILE) cpu=$(CPU)
SCOPTIONS = strmer nover ignore=85,93,104,105 \
 idir=netinclude: idir=$(INCDIR) idir=$(REDIR) gst=$(GSTFILE) data=far

# comment the next two lines, for the final release

# DEBUG     = debug=line stkchk def MEM_DEBUG def DEBUG
# LDEBUG    = debug=sym

# optimization should always be disabled while debugging
# uncomment the following only for the final version

# OPTIMIZE  = opt optpeep optglobal optinlocal optinline optloop opttime

# special defines for generating the gst file

GSTDEFS    = def __USE_SYSBASE

# read the docs (/INSTALL & /doc/HACKERS) for compiler defines

DEFINES   = def M_AMIGA def NO_SHELL_ESCAPE def NO_LOCALE \
 def LIBDIR="uulib:" def DONT_LOG_USER def SPOOLDIR="uunews:" \
 def HAVE_COLOR def HAVE_REF_THREADING \
 def DONT_REREAD_ACTIVE_FILE $(GSTDEFS) $(NNTPDEF) $(TINDDEF)

# build the final compile and link flags

CFLAGS    = $(SCOPTIONS) $(OPTIMIZE) $(DEFINES) $(DEBUG)
LDFLAGS   = link $(SCOPTIONS) $(LDEBUG)

#
# there is no internal rule in smake for yacc files
# so, here it comes
#
YACC = bison --yacc

# /*vb*/ eeek! ugly!

.y.c:
        $(YACC) ..$<
        @rename y.tab.c $@

#
# rule for all C sources
#
# We need to redefine the internal rule because we are using
# smakes local input file facility. In fact, we must use it
# because the v6.51 SC command was linked with the wrong startup
# which caused the number of commandline arguments to be limited
# to 30 entries.
#
.c.o:
        $(CC) $(CFLAGS) $*.c objname=$@

#
# list of header files
#
# /*vb*/
HEADERS = \
        $(AMIDIR)/amiga.h \
        $(AMIDIR)/amigatcp.h \
        $(INCDIR)/config.h \
        $(INCDIR)/extern.h \
        $(INCDIR)/menukeys.h \
        $(INCDIR)/nntplib.h \
        $(REDIR)/pcre.h \
        $(INCDIR)/proto.h \
        $(INCDIR)/stpwatch.h \
        $(INCDIR)/tin.h \
        $(INCDIR)/version.h \
#/*vb*/  $(INCDIR)/conf.h \

#
# list object files
#
# /*vb*/
OBJECTS = \
        $(OBJDIR)/active.o \
        $(OBJDIR)/amiga.o \
        $(OBJDIR)/amigatcp.o \
        $(OBJDIR)/art.o \
        $(OBJDIR)/attrib.o \
        $(OBJDIR)/auth.o \
        $(OBJDIR)/charset.o \
        $(OBJDIR)/chartables.o \
        $(OBJDIR)/color.o \
        $(OBJDIR)/config.o \
        $(OBJDIR)/curses.o \
        $(OBJDIR)/debug.o\
        $(OBJDIR)/envarg.o \
        $(OBJDIR)/feed.o \
        $(OBJDIR)/filter.o \
        $(OBJDIR)/getline.o \
        $(OBJDIR)/group.o \
        $(OBJDIR)/hashstr.o \
        $(OBJDIR)/header.o \
        $(OBJDIR)/help.o\
        $(OBJDIR)/inews.o \
        $(OBJDIR)/init.o \
        $(OBJDIR)/joinpath.o \
        $(OBJDIR)/lang.o \
        $(OBJDIR)/list.o \
        $(OBJDIR)/mail.o \
        $(OBJDIR)/main.o \
        $(OBJDIR)/memory.o \
        $(OBJDIR)/misc.o \
        $(OBJDIR)/newsrc.o\
        $(OBJDIR)/nntplib.o \
        $(OBJDIR)/nrctbl.o \
        $(OBJDIR)/open.o \
        $(OBJDIR)/page.o \
        $(OBJDIR)/parsdate.o \
        $(OBJDIR)/pcre.o \
        $(OBJDIR)/pgp.o \
        $(OBJDIR)/post.o \
        $(OBJDIR)/prompt.o\
        $(OBJDIR)/read.o \
        $(OBJDIR)/refs.o \
        $(OBJDIR)/regex.o \
        $(OBJDIR)/rfc1521.o \
        $(OBJDIR)/rfc1522.o \
        $(OBJDIR)/save.o \
        $(OBJDIR)/screen.o \
        $(OBJDIR)/search.o \
        $(OBJDIR)/select.o \
        $(OBJDIR)/sigfile.o \
        $(OBJDIR)/signal.o \
        $(OBJDIR)/strftime.o \
        $(OBJDIR)/string.o \
        $(OBJDIR)/study.o \
        $(OBJDIR)/thread.o \
        $(OBJDIR)/wildmat.o \
        $(OBJDIR)/xref.o \
# (obw)  $(OBJDIR)/_tzset.o \
#        $(OBJDIR)/parsdate.c \


#
# actions to be performed when something went wrong during build
#
.ONERROR:
#        -@delete #?.lnk $(PROJECT) ram:temp_smk.tmp
        -@gst $(GSTFILE) unload

#
# targets
#

all: $(PROJECT) $(ACTIVED) $(GSTFILE)

$(PROJECT):     $(OBJDIR) $(OBJECTS) $(TZSET)
        $(CC) $(LDFLAGS) pname=$@ <with <(ram:tmp)
        $(OBJECTS) $(TZSET)
        <

$(TZSET): $(TZSOURCE) $(OBJDIR)
        $(CC) $(SCOPTIONS) $(DEBUG) $(OPTIMIZE) def LESS_GETENV PARMS=BOTH $(TZSOURCE) objname=$@

$(ACTIVED): $(OBJDIR)/activeda.o $(GSTFILE)
        $(CC) $(LDFLAGS) pname=$@ $(OBJDIR)/activeda.o

$(GSTFILE): $(HEADERS)
        -gst $(GSTFILE) unload
        $(CC) $(CFLAGS) noobjname makegst=$@ $(AMIDIR)/amiga.c

$(OBJDIR):
        -@makedir $(OBJDIR)

$(REDIR)/chartables.c: dftables
        dftables >$(REDIR)/chartables.c

dftables: $(OBJDIR)/maketables.o $(OBJDIR)/dftables.o $(GSTFILE)
        $(CC) $(LDFLAGS) pname=$@ $(OBJDIR)/dftables.o

#/*vb*/
makecfg: $(OBJDIR)/makecfg.o $(OBJDIR)/amiga.o $(GSTFILE)
        $(CC) $(LDFLAGS) pname=$@ $(OBJDIR)/makecfg.o $(OBJDIR)/amiga.o
/*vb*/
$(INCDIR)/tincfg.h: $(SRCDIR)/tincfg.tbl makecfg
        makecfg $(SRCDIR)/tincfg.tbl $(INCDIR)/tincfg.h

clean:
        -gst $(GSTFILE) unload
        -delete $(OBJDIR)/\#?.o \#?.lnk
        -delete $(GSTFILE)(%|.info) $(ACTIVED)(%|.info) $(PROJECT)(%|.info)
	-delete $(INCDIR)/tincfg.h
        -delete $(SRCDIR)/parsdate.c

dist-clean: clean
	-delete $(REDIR)/chartables.c

#
# dependencies
#

$(OBJDIR)/activeda.o:           $(AMIDIR)/actived.c $(GSTFILE)
$(OBJDIR)/active.o:             $(SRCDIR)/active.c $(GSTFILE)
$(OBJDIR)/amiga.o:              $(AMIDIR)/amiga.c $(GSTFILE)
$(OBJDIR)/amigatcp.o:           $(AMIDIR)/amigatcp.c $(GSTFILE)
$(OBJDIR)/art.o:                $(SRCDIR)/art.c $(GSTFILE)
$(OBJDIR)/attrib.o:             $(SRCDIR)/attrib.c $(GSTFILE)
$(OBJDIR)/auth.o:               $(SRCDIR)/auth.c $(GSTFILE)
$(OBJDIR)/charset.o:            $(SRCDIR)/charset.c $(GSTFILE)
$(OBJDIR)/chartables.o:         $(REDIR)/chartables.c $(GSTFILE)
$(OBJDIR)/color.o:              $(SRCDIR)/color.c $(GSTFILE)
$(OBJDIR)/config.o:             $(SRCDIR)/config.c $(GSTFILE) $(INCDIR)/tincfg.h
$(OBJDIR)/curses.o:             $(SRCDIR)/curses.c $(GSTFILE)
$(OBJDIR)/dftables.o:           $(REDIR)/dftables.c $(GSTFILE)
$(OBJDIR)/debug.o:              $(SRCDIR)/debug.c $(GSTFILE)
$(OBJDIR)/envarg.o:             $(SRCDIR)/envarg.c $(GSTFILE)
$(OBJDIR)/feed.o:               $(SRCDIR)/feed.c $(GSTFILE)
$(OBJDIR)/filter.o:             $(SRCDIR)/filter.c $(GSTFILE)
$(OBJDIR)/getline.o:            $(SRCDIR)/getline.c $(GSTFILE)
$(OBJDIR)/group.o:              $(SRCDIR)/group.c $(GSTFILE)
$(OBJDIR)/hashstr.o:            $(SRCDIR)/hashstr.c $(GSTFILE)
$(OBJDIR)/header.o:             $(SRCDIR)/header.c $(GSTFILE)
$(OBJDIR)/help.o:               $(SRCDIR)/help.c $(GSTFILE)
$(OBJDIR)/inews.o:              $(SRCDIR)/inews.c $(GSTFILE)
$(OBJDIR)/init.o:               $(SRCDIR)/init.c $(GSTFILE)
$(OBJDIR)/joinpath.o:           $(SRCDIR)/joinpath.c $(GSTFILE)
$(OBJDIR)/lang.o:               $(SRCDIR)/lang.c $(GSTFILE)
$(OBJDIR)/list.o:               $(SRCDIR)/list.c $(GSTFILE)
$(OBJDIR)/mail.o:               $(SRCDIR)/mail.c $(GSTFILE)
$(OBJDIR)/main.o:               $(SRCDIR)/main.c $(GSTFILE)
$(OBJDIR)/makecfg.o:            $(SRCDIR)/makecfg.c $(GSTFILE)
$(OBJDIR)/maketables.o:         $(REDIR)/maketables.c $(GSTFILE)
$(OBJDIR)/memory.o:             $(SRCDIR)/memory.c $(GSTFILE)
$(OBJDIR)/misc.o:               $(SRCDIR)/misc.c $(GSTFILE)
$(OBJDIR)/newsrc.o:             $(SRCDIR)/newsrc.c $(GSTFILE)
$(OBJDIR)/nntplib.o:            $(SRCDIR)/nntplib.c $(GSTFILE)
$(OBJDIR)/nrctbl.o:             $(SRCDIR)/nrctbl.c $(GSTFILE)
$(OBJDIR)/open.o:               $(SRCDIR)/open.c $(GSTFILE)
$(OBJDIR)/page.o:               $(SRCDIR)/page.c $(GSTFILE)
#$(OBJDIR)/parsdate.o:           $(AMIDIR)/parsdate.c $(GSTFILE)
$(OBJDIR)/parsdate.o:           $(SRCDIR)/parsdate.c $(GSTFILE)
$(SRCDIR)/parsdate.c:           $(SRCDIR)/parsdate.y $(GSTFILE)
$(OBJDIR)/pcre.o:               $(REDIR)/pcre.c $(GSTFILE)
$(OBJDIR)/pgp.o:                $(SRCDIR)/pgp.c $(GSTFILE)
$(OBJDIR)/post.o:               $(SRCDIR)/post.c $(GSTFILE)
$(OBJDIR)/prompt.o:             $(SRCDIR)/prompt.c $(GSTFILE)
$(OBJDIR)/read.o:               $(SRCDIR)/read.c $(GSTFILE)
$(OBJDIR)/refs.o:               $(SRCDIR)/refs.c $(GSTFILE)
$(OBJDIR)/regex.o:              $(SRCDIR)/regex.c $(GSTFILE)
$(OBJDIR)/rfc1521.o:            $(SRCDIR)/rfc1521.c $(GSTFILE)
$(OBJDIR)/rfc1522.o:            $(SRCDIR)/rfc1522.c $(GSTFILE)
$(OBJDIR)/save.o:               $(SRCDIR)/save.c $(GSTFILE)
$(OBJDIR)/screen.o:             $(SRCDIR)/screen.c $(GSTFILE)
$(OBJDIR)/search.o:             $(SRCDIR)/search.c $(GSTFILE)
$(OBJDIR)/select.o:             $(SRCDIR)/select.c $(GSTFILE)
$(OBJDIR)/sigfile.o:            $(SRCDIR)/sigfile.c $(GSTFILE)
$(OBJDIR)/signal.o:             $(SRCDIR)/signal.c $(GSTFILE)
$(OBJDIR)/strftime.o:           $(SRCDIR)/strftime.c $(GSTFILE)
$(OBJDIR)/string.o:             $(SRCDIR)/string.c $(GSTFILE)
$(OBJDIR)/study.o:              $(REDIR)/study.c $(GSTFILE)
$(OBJDIR)/thread.o:             $(SRCDIR)/thread.c $(GSTFILE)
$(OBJDIR)/wildmat.o:            $(SRCDIR)/wildmat.c $(GSTFILE)
$(OBJDIR)/xref.o:               $(SRCDIR)/xref.c $(GSTFILE)
