# Makefile for Linux

# General

PLATFORMDEF = -DPLATFORM_WIN32
EXESUFFIX = .exe

BINDIR = ../bin
OBJDIR = obj
INCDIR = ./

OSLIB = oslib_win32/oslib.a
JAMLIB = jamlib/jamlib.a
CMNLLIB = cmnllib/cmnllib.a

# Nodelists

NLDEFS = -DNODELIST_CMNL -DNODELIST_V7P
NLOBJS = obj/nl_v7p.o obj/nl_cmnl.o $(CMNLLIB)

# Messagebases

# *.msg
MBDEFS_MSG = -DMSGBASE_MSG
MBOBJS_MSG = obj/mb_msg.o

# JAM
MBDEFS_JAM = -DMSGBASE_JAM
MBOBJS_JAM = $(OBJDIR)/mb_jam.o $(JAMLIB)

# Sum them up. Only include the messagebases you want to use
MBDEFS = $(MBDEFS_MSG) $(MBDEFS_JAM)
MBOBJS = $(MBOBJS_MSG) $(MBOBJS_JAM)

DEFS = $(PLATFORMDEF) $(MBDEFS) $(NLDEFS)

# Commands

CC = gcc $(DEFS) -I $(INCDIR) -Wall
RM = del
STRIP = strip

# Objects

SHOBJS = $(OBJDIR)/jblist.o \
         $(OBJDIR)/jbstrcpy.o \
         $(OBJDIR)/mystrncpy.o \
         $(OBJDIR)/parseargs.o \
         $(OBJDIR)/node4d.o \
         $(OBJDIR)/expr.o \
         $(OBJDIR)/path.o

CMOBJS = $(OBJDIR)/crashmail.o \
      	$(OBJDIR)/logwrite.o \
			$(OBJDIR)/dupe.o \
			$(OBJDIR)/stats.o \
			$(OBJDIR)/misc.o \
			$(OBJDIR)/safedel.o \
			$(OBJDIR)/toss.o \
			$(OBJDIR)/pkt.o \
			$(OBJDIR)/mb.o \
			$(OBJDIR)/nl.o \
			$(OBJDIR)/handle.o \
			$(OBJDIR)/node4dpat.o \
			$(OBJDIR)/config.o \
			$(OBJDIR)/memmessage.o \
			$(OBJDIR)/scan.o \
			$(OBJDIR)/outbound.o \
			$(OBJDIR)/filter.o \
			$(OBJDIR)/areafix.o

files :  $(BINDIR)/crashmail$(EXESUFFIX) \
         $(BINDIR)/crashstats$(EXESUFFIX) \
			$(BINDIR)/crashlist$(EXESUFFIX) \
    		$(BINDIR)/crashgetnode$(EXESUFFIX) \
         $(BINDIR)/crashmaint$(EXESUFFIX) \
			$(BINDIR)/crashwrite$(EXESUFFIX) \
			$(BINDIR)/crashexport$(EXESUFFIX) \
			$(BINDIR)/crashlistout$(EXESUFFIX)

$(BINDIR)/crashmail$(EXESUFFIX) : $(CMOBJS) $(SHOBJS) $(NLOBJS) $(MBOBJS) $(OSLIB)
	$(CC) -o $(BINDIR)/crashmail$(EXESUFFIX) $(CMOBJS) $(SHOBJS) $(NLOBJS) $(MBOBJS) $(OSLIB)
	$(STRIP) $(BINDIR)/crashmail$(EXESUFFIX)

$(BINDIR)/crashstats$(EXESUFFIX) : tools/crashstats.c $(SHOBJS) $(OSLIB)
	$(CC) -o $(BINDIR)/crashstats$(EXESUFFIX) tools/crashstats.c $(SHOBJS) $(OSLIB)
	$(STRIP) $(BINDIR)/crashstats$(EXESUFFIX)

$(BINDIR)/crashlist$(EXESUFFIX) : tools/crashlist.c $(SHOBJS) $(OSLIB)
	$(CC) -o $(BINDIR)/crashlist$(EXESUFFIX) tools/crashlist.c $(SHOBJS) $(OSLIB)
	$(STRIP) $(BINDIR)/crashlist$(EXESUFFIX)

$(BINDIR)/crashgetnode$(EXESUFFIX) : tools/crashgetnode.c $(SHOBJS) $(CMNLLIB) $(OSLIB)
	$(CC)  -o $(BINDIR)/crashgetnode$(EXESUFFIX) tools/crashgetnode.c $(SHOBJS) $(CMNLLIB) $(OSLIB)
	$(STRIP) $(BINDIR)/crashgetnode$(EXESUFFIX)

$(BINDIR)/crashmaint$(EXESUFFIX) : tools/crashmaint.c $(SHOBJS) $(OSLIB) $(JAMLIB)
	$(CC) -o $(BINDIR)/crashmaint$(EXESUFFIX) tools/crashmaint.c $(SHOBJS) $(OSLIB) $(JAMLIB)
	$(STRIP) $(BINDIR)/crashmaint$(EXESUFFIX)

$(BINDIR)/crashwrite$(EXESUFFIX) : tools/crashwrite.c $(SHOBJS) $(OSLIB)
	$(CC) -o $(BINDIR)/crashwrite$(EXESUFFIX) tools/crashwrite.c $(SHOBJS) $(OSLIB)
	$(STRIP) $(BINDIR)/crashwrite$(EXESUFFIX)

$(BINDIR)/crashexport$(EXESUFFIX) : tools/crashexport.c $(SHOBJS) $(OSLIB)
	$(CC) -o $(BINDIR)/crashexport$(EXESUFFIX) tools/crashexport.c $(SHOBJS) $(OSLIB)
	$(STRIP) $(BINDIR)/crashexport$(EXESUFFIX)

$(BINDIR)/crashlistout$(EXESUFFIX) : tools/crashlistout.c $(SHOBJS) $(OSLIB)
	$(CC) -o $(BINDIR)/crashlistout$(EXESUFFIX) tools/crashlistout.c $(SHOBJS) $(OSLIB)
	$(STRIP) $(BINDIR)/crashlistout$(EXESUFFIX)

# crashmail

$(OBJDIR)/crashmail.o : crashmail/crashmail.c
	$(CC) -c crashmail/crashmail.c -o $(OBJDIR)/crashmail.o

$(OBJDIR)/logwrite.o : crashmail/logwrite.c
	$(CC) -c crashmail/logwrite.c -o $(OBJDIR)/logwrite.o

$(OBJDIR)/dupe.o : crashmail/dupe.c
	$(CC) -c crashmail/dupe.c -o $(OBJDIR)/dupe.o

$(OBJDIR)/stats.o : crashmail/stats.c 
	$(CC) -c crashmail/stats.c -o $(OBJDIR)/stats.o

$(OBJDIR)/misc.o : crashmail/misc.c 
	$(CC) -c crashmail/misc.c -o $(OBJDIR)/misc.o
 
$(OBJDIR)/safedel.o : crashmail/safedel.c 
	$(CC) -c crashmail/safedel.c -o $(OBJDIR)/safedel.o

$(OBJDIR)/toss.o : crashmail/toss.c 
	$(CC) -c crashmail/toss.c -o $(OBJDIR)/toss.o

$(OBJDIR)/scan.o : crashmail/scan.c 
	$(CC) -c crashmail/scan.c -o $(OBJDIR)/scan.o

$(OBJDIR)/pkt.o : crashmail/pkt.c
	$(CC) -c crashmail/pkt.c -o $(OBJDIR)/pkt.o

$(OBJDIR)/memmessage.o : crashmail/memmessage.c 
	$(CC) -c crashmail/memmessage.c -o $(OBJDIR)/memmessage.o

$(OBJDIR)/handle.o : crashmail/handle.c
	$(CC) -c crashmail/handle.c -o $(OBJDIR)/handle.o

$(OBJDIR)/node4dpat.o : crashmail/node4dpat.c
	$(CC) -c crashmail/node4dpat.c -o $(OBJDIR)/node4dpat.o

$(OBJDIR)/config.o : crashmail/config.c
	$(CC) -c crashmail/config.c -o $(OBJDIR)/config.o

$(OBJDIR)/outbound.o : crashmail/outbound.c
	$(CC) -c crashmail/outbound.c -o $(OBJDIR)/outbound.o

$(OBJDIR)/filter.o : crashmail/filter.c
	$(CC) -c crashmail/filter.c -o $(OBJDIR)/filter.o

$(OBJDIR)/areafix.o : crashmail/areafix.c
	$(CC) -c crashmail/areafix.c -o $(OBJDIR)/areafix.o

# shared

$(OBJDIR)/jblist.o : shared/jblist.c
	$(CC) -c shared/jblist.c -o $(OBJDIR)/jblist.o

$(OBJDIR)/jbstrcpy.o : shared/jbstrcpy.c
	$(CC) -c shared/jbstrcpy.c -o $(OBJDIR)/jbstrcpy.o

$(OBJDIR)/mystrncpy.o : shared/mystrncpy.c
	$(CC) -c shared/mystrncpy.c -o $(OBJDIR)/mystrncpy.o

$(OBJDIR)/parseargs.o : shared/parseargs.c
	$(CC) -c shared/parseargs.c -o $(OBJDIR)/parseargs.o

$(OBJDIR)/path.o : shared/path.c
	$(CC) -c shared/path.c -o $(OBJDIR)/path.o

$(OBJDIR)/node4d.o : shared/node4d.c
	$(CC) -c shared/node4d.c -o $(OBJDIR)/node4d.o

$(OBJDIR)/expr.o : shared/expr.c
	$(CC) -c shared/expr.c -o $(OBJDIR)/expr.o

# mb

$(OBJDIR)/mb.o : crashmail/mb.c
	$(CC) -c crashmail/mb.c -o $(OBJDIR)/mb.o

$(OBJDIR)/mb_msg.o : crashmail/mb_msg.c
	$(CC) -c crashmail/mb_msg.c -o $(OBJDIR)/mb_msg.o

$(OBJDIR)/mb_jam.o : crashmail/mb_jam.c
	$(CC) -c crashmail/mb_jam.c -o $(OBJDIR)/mb_jam.o

# nl

$(OBJDIR)/nl.o : crashmail/nl.c
	$(CC) -c crashmail/nl.c -o $(OBJDIR)/nl.o

$(OBJDIR)/nl_cmnl.o : crashmail/nl_cmnl.c
	$(CC) -c crashmail/nl_cmnl.c -o $(OBJDIR)/nl_cmnl.o

$(OBJDIR)/nl_v7p.o : crashmail/nl_v7p.c
	$(CC) -c crashmail/nl_v7p.c -o $(OBJDIR)/nl_v7p.o

# Clean

clean :
	$(RM) $(OBJDIR)/*.o

