#
# Makefile for JNOS 2.0d, by Maiko Langelaar, VE4KLM
#
# based on original makefile for JNOS 1.11f
#

COMPILER=BC3

PROCESSOR=8086

DATASIZE=511

#
#Modify the compiler path if you've installed other than the default
#

CC=bcc +bcc.cfg

CPUCFLAG=
CPUAFLAG=
CPUTYPE=CPU86

DSEGOPT=-Ff=$(DATASIZE)

.autodepend

##############################################################################
# for all Borland (tc and bcc) compilers
TMPNAM=tmpnam

ASM=tasm
LIB=tlib
RM=del
AR=zip

BASECFLAGS=-a -d -f- -w+ -w-par -w-aus -w-use -w-pin -w-asm -DMSDOS
BASEAFLAGS=-mx -t -DMEMMOD=LARGE
MODEL=-ml

PATH=c:\borlandc

CFLAGS=$(BASECFLAGS) $(CPUCFLAG) $(OPT) $(DSEGOPT) -D$(CPUTYPE)
AFLAGS=$(BASEAFLAGS) $(CPUAFLAG)

all: warnings hardware.h bcc.cfg nos.exe

#make the configuration file for the compiler
bcc.cfg: makefile
  copy &&|
$(MODEL) $(CFLAGS)
-I$(PATH)\INCLUDE;.
-L$(PATH)\LIB
| bcc.cfg

#issue some warnings for certain options
warnings:
    @echo Making a $(PROCESSOR) JNOS using $(COMPILER) compiler...
    @echo Datasize is set to $(DATASIZE)

# Define PC-specific include file
hardware.h: pc.h
	copy pc.h hardware.h

#for BC++ 2 & 3 & 4 (not turbo 2.0)
.c.obj:
    $(CC) -c {$< }

.asm.obj:
	$(ASM) $(AFLAGS) $<;

sccvec.obj: sccvec.asm
	$(ASM) $(AFLAGS)  sccvec.asm;

!if ($(TMPNAM) == tmpnam)
mkname.obj: mkname.c global.h
	$(CC) -c -zC_TEXT $*.c
!else
mkname.obj: mkname.c global.h
	$(CC) -c $*.c
!endif

CLIENTS= telnet.obj ftpcli.obj finger.obj smtpcli.obj hop.obj \
        tip.obj nntpcli.obj dialer.obj rlogin.obj callcli.obj \
        mailcli.obj pop2cli.obj pop3cli.obj rdate.obj look.obj

SERVERS= ttylink.obj ftpserv.obj smisc.obj smtpserv.obj convers.obj \
	nntpserv.obj fingerd.obj mboxcmd.obj mailbox.obj mboxfile.obj \
	mboxmail.obj mboxgate.obj mailfor.obj  bmutil.obj forward.obj \
	tipmail.obj mailutil.obj index.obj expire.obj calldbd.obj \
	buckbook.obj pop2serv.obj pop3serv.obj timed.obj sam.obj \
	samlib.obj qrz.obj fbbfwd.obj lzhuf.obj term.obj tcpgate.obj \
        http.obj

BOOTP=  bootp.obj bootpd.obj bootpcmd.obj bootpdip.obj

INTERNET= tcpcmd.obj tcpuser.obj tcptimer.obj tcpout.obj tcpin.obj \
	tcpsubr.obj tcphdr.obj udpcmd.obj udp.obj udphdr.obj \
        domain.obj domhdr.obj ripcmd.obj rip.obj rtdyngw.obj \
	ipcmd.obj ip.obj iproute.obj iphdr.obj \
	icmpcmd.obj icmp.obj icmpmsg.obj icmphdr.obj \
	arpcmd.obj arp.obj arphdr.obj rarp.obj \
	netuser.obj rspf.obj rspfcmd.obj rspfhdr.obj

AX25=   ax25cmd.obj ax25user.obj ax25.obj axheard.obj ax25aar.obj \
	lapbtime.obj lapb.obj kiss.obj kisspoll.obj ax25subr.obj \
        ax25hdr.obj ax25mail.obj axui.obj ax25xdgi.obj

APRS=   aprs.obj aprssrv.obj aprsstat.obj aprsbc.obj aprsdupe.obj \
        aprsmice.obj aprsdigi.obj aprscfg.obj aprswx.obj aprsmsg.obj \
        aprsmsdb.obj aprsmsgr.obj aprspodb.obj

NETROM= nrcmd.obj nr4user.obj nr4timer.obj nr4.obj nr4subr.obj nr4hdr.obj \
	nr3.obj nrs.obj nrhdr.obj nr4mail.obj

INP3=	inp3.obj inp3rtns.obj nrr.obj l3rtt.obj

PPP=    asy.obj ppp.obj pppcmd.obj pppfsm.obj ppplcp.obj \
	ppppap.obj pppipcp.obj pppdump.obj \
	slhc.obj slhcdump.obj slip.obj

NET=    ftpsubr.obj sockcmd.obj sockuser.obj socket.obj sockutil.obj  \
	iface.obj timer.obj ttydriv.obj cmdparse.obj \
	mbuf.obj misc.obj pathname.obj audit.obj files.obj  \
        kernel.obj ksubr.obj alloc.obj getopt.obj wildmat.obj lzw.obj \
        devparam.obj md5.obj

HFDD=	hfdd.obj hfddrtns.obj hfddinit.obj ptcpro.obj kam.obj

DUMP=   trace.obj enetdump.obj arcdump.obj rspfdump.obj  \
	kissdump.obj ax25dump.obj arpdump.obj nrdump.obj rwhodump.obj \
	ipdump.obj icmpdump.obj udpdump.obj tcpdump.obj ripdump.obj

PCOBJS= pc.obj dirutil.obj eccmd.obj ec.obj pktdrvr.obj enet.obj hapn.obj \
	hs.obj pc100.obj eagle.obj drsi.obj drsivec.obj pi.obj mkname.obj \
	z8530.obj i8250.obj ecvec.obj pkvec.obj asyvec.obj hsvec.obj \
	pc100vec.obj eaglevec.obj hapnvec.obj command.obj pivec.obj \
	scc.obj sccvec.obj pcgen.obj sw.obj stopwatc.obj arcnet.obj at.obj \
	gracilis.obj twin_at.obj twin_dr.obj twinvec.obj stktrace.obj \
	xmodem.obj bpq.obj bpqcmd.obj editor.obj ted2.obj

MEMMGR= xms.obj xmsutil.obj memlib.obj

EXPERIMENTS= video.obj test.obj sendfax.obj bmconv.obj dbf.obj

# mail2ind  dumps .ind files, displays highest msgid...
mail2ind: mail2ind.exe
#
mail2ind.exe: mail2ind.obj index.c
    $(CC) -M -DMAIL2IND mail2ind.obj index.c
    del index.obj

# mkdep  produces the program that scans src for include file references
mkdep: mkdep.exe

mkdep.exe: mkdep.c
	$(CC) mkdep.c

# memlog  produces the program that analyzes memlog.dat (see config.h)
memlog: memlog.exe

memlog.exe: memlog.c
	$(CC) memlog.c

# makelist  produces a program to display an include file reference tree, etc.
makelist: makelist.exe

makelist.exe:   makelist.obj getopt.obj
	$(CC) makelist.obj getopt.obj

# dumpdate  produces a program which displays longint dates in several files
dumpdate: dumpdate.exe

dumpdate.exe: dumpdate.obj
    $(CC) dumpdate.obj

# epass  produces a program which converts a challenge and passwd to MD5 format
# In Linux, do: echo "#define MD5AUTHENTICATE">global.h;gcc -O epass.c md5.c -o epass
epass: epass.exe

epass.exe: epass.obj md5.obj
    $(CC) epass.obj md5.obj

# pushmail  produces the program that moves some of mqueue to another system
pushmail: pushmail.exe

pushmail.exe: pushmail.c
	$(CC) pushmail.c

# uudecode  produces the program that uudecodes a file downloaded via DU mbox cmd 
#           Much fancier uudecode programs exist ... this one is adequate.
uudecode: uudecode.exe

uudecode.exe: uudecode.c
	$(CC) uudecode.c

# base64  produces the base64 encoding of username:password for use in access (http)
base64: base64.exe

base64.exe: base64.c
	$(CC) base64.c

# mktl  produces the program that builds a .tl file for use with TLIB
mktl: mktl.exe

mktl.exe: mktl.c
	$(CC) mktl.c

newnos.exe:
    $(CC) -M -f- -enos -ll -lm -ln -ls main.obj config.obj version.obj \
    session.obj *.lib
    
nos.exe: main.obj config.obj session.obj clients.lib servers.lib internet.lib \
    net.lib netrom.lib inp3.lib ax25.lib aprs.lib pc.lib dump.lib ppp.lib \
    bootp.lib hfdd.lib memmgr.lib emmlibl.lib version.obj jlocks.obj
    $(CC) -c version.c
    $(CC) -M -f- -enos -ll -lm -ln -ls main.obj config.obj version.obj session.obj jlocks.obj *.lib

xref.out: main.obj config.obj version.obj session.obj clients.lib servers.lib internet.lib \
	net.lib netrom.lib ax25.lib pc.lib dump.lib ppp.lib
    objxref /Oxref.out $(PATH)\lib\c0l.obj main.obj config.obj version.obj session.obj *.lib $(PATH)\lib\cl.lib

clients.lib: $(CLIENTS) clients.tl
    if exist clients.lib $(RM) clients.lib
	$(LIB) /c clients.lib @clients.tl

servers.lib: $(SERVERS) servers.tl
    if exist servers.lib $(RM) servers.lib
	$(LIB) /c servers.lib @servers.tl

ppp.lib: $(PPP) ppp.tl
    if exist ppp.lib $(RM) ppp.lib
	$(LIB) /c ppp.lib @ppp.tl

bootp.lib: $(BOOTP) bootp.tl
    if exist bootp.lib $(RM) bootp.lib
	$(LIB) /c bootp.lib @bootp.tl

internet.lib: $(INTERNET) internet.tl
    if exist internet.lib $(RM) internet.lib
	$(LIB) /c internet.lib @internet.tl

ax25.lib: $(AX25) ax25.tl
    if exist ax25.lib $(RM) ax25.lib
	$(LIB) /c ax25.lib @ax25.tl

aprs.lib: $(APRS) aprs.tl
    if exist aprs.lib $(RM) aprs.lib
	$(LIB) /c aprs.lib @aprs.tl

netrom.lib: $(NETROM) netrom.tl
    if exist netrom.lib $(RM) netrom.lib
	$(LIB) /c netrom.lib @netrom.tl

inp3.lib: $(INP3) inp3.tl
    if exist inp3.lib $(RM) inp3.lib
	$(LIB) /c inp3.lib @inp3.tl

net.lib: $(NET) net.tl
    if exist net.lib $(RM) net.lib
	$(LIB) /c net.lib @net.tl

hfdd.lib: $(HFDD) hfdd.tl
    if exist hfdd.lib $(RM) hfdd.lib
	$(LIB) /c hfdd.lib @hfdd.tl

dump.lib: $(DUMP) dump.tl
    if exist dump.lib $(RM) dump.lib
	$(LIB) /c dump.lib @dump.tl

pc.lib: $(PCOBJS) pc.tl
    if exist pc.lib $(RM) pc.lib
	$(LIB) /c pc.lib @pc.tl

memmgr.lib: $(MEMMGR) memmgr.tl
    if exist memmgr.lib $(RM) memmgr.lib
    $(LIB) /c memmgr.lib @memmgr.tl

# emmlibl.lib is distributed as emmlibl.bil to avoid accidental deletion!
emmlibl.lib: emmlibl.bil
    copy emmlibl.bil emmlibl.lib

help:
    zip -u help.zip \spool\help\*.hlp

cmdshelp:
    zip -u cmdshelp.zip \help\*

docs:
    zip docs help.zip nos.cfg readme.now mboxcmds.txt cmdsh???.zip

clean:
    if exist *.obj $(RM) *.obj
    if exist *.lib $(RM) *.lib
    $(RM) hardware.h

realclean: clean
    if exist *.exe $(RM) *.exe
    if exist *.map $(RM) *.map

# depend  produces mkdep.srt which is used to update this makefile's dependency list
depend: mkdep hardware.h
    if exist mkdep.tmp $(RM) mkdep.tmp
    mkdep > mkdep.tmp
    grep -v mkname.obj mkdep.tmp > mkdep.txt
    grep -v ".h:" mkdep.txt > mkdep.tmp
    sort mkdep.tmp > mkdep.srt
    $(RM) mkdep.tmp
    $(RM) mkdep.txt
    echo mkdep.srt ready for merging with the makefile

zip: docs
    del *.bak
    copy source.c source
    $(AR) -Jr -o -ex -z -u nossrc.zip makefile.* readme.* mboxcmds.txt nos.cfg\
        *.asm *.c *.h *.tl emmlibl.bil < source
    $(AR) -o -u tools.zip *.bat unlink.c makefile.* docs.zip help.zip
#    $(AR) -o -u nosobj.zip *.obj

dist:
    copy exe.c 1st.txt
    arj a -je jnos 1st.txt docs.zip nos.exe

global.h: config.h
    touch global.h

