# Makefile for slrn                               -*- sh -*-
# Makefile for CYGWIN32 or MINGW32

CC = gcc
CCFLAGS = -O2 -fno-strength-reduce -W -Wall
LDFLAGS = -Wl,--subsystem,console
MISCLIBS = -lwsock32 -lwinspool

#-----------------------------------------------------------------------------
#   Directory where the slang library, slanglib.a, is located.
#   BUILD SLANG FIRST!!!!  If you do not have it, get it from the same place
#   you picked up slrn.  The current home is space.mit.edu:/pub/davis/slang.
#-----------------------------------------------------------------------------
SDIR = ../../slang/src#                  Location of slang.h
SLIBDIR = $(SDIR)/gw32objs#              Location of w32slang.a

#-----------------------------------------------------------------------------
#   Location where object files are placed.
#-----------------------------------------------------------------------------
OBJDIR = gw32objs#

#-----------------------------------------------------------------------------
#   Misc Programs
#-----------------------------------------------------------------------------
TOUCH = touch
#CP = copy
CP = cp
RM = rm

#----------------------------------------------------------------------------
#   Nothing below here should require changing.
#----------------------------------------------------------------------------

OBJS = $(OBJDIR)/art.o \
       $(OBJDIR)/chmap.o \
       $(OBJDIR)/editscore.o \
       $(OBJDIR)/group.o \
       $(OBJDIR)/hash.o \
       $(OBJDIR)/help.o \
       $(OBJDIR)/interp.o \
       $(OBJDIR)/menu.o \
       $(OBJDIR)/mime.o \
       $(OBJDIR)/misc.o \
       $(OBJDIR)/post.o \
       $(OBJDIR)/score.o \
       $(OBJDIR)/server.o \
       $(OBJDIR)/slrn.o \
       $(OBJDIR)/sortdate.o \
       $(OBJDIR)/startup.o \
       $(OBJDIR)/ttymsg.o \
       $(OBJDIR)/util.o \
       $(OBJDIR)/uudecode.o \
       $(OBJDIR)/slrndir.o \
       $(OBJDIR)/version.o \
       $(OBJDIR)/print.o \
       $(OBJDIR)/xover.o

OBJSpull = \
	$(OBJDIR)/version.o \
	$(OBJDIR)/util.o \
	$(OBJDIR)/ttymsg.o \
	$(OBJDIR)/slrnpull.o \
	$(OBJDIR)/sltcp.o \
	$(OBJDIR)/slrndir.o \
	$(OBJDIR)/nntplib.o

CFLAGS = $(CCFLAGS) -I$(SDIR) $(SLRNLIBDIR)

slrn.exe: $(OBJDIR) config.h slangversion $(OBJS)
	$(CC) $(OBJS) -o slrn.exe $(LDFLAGS) -L$(SLIBDIR) -lslang $(MISCLIBS)

slrnpull.exe: $(OBJDIR) config.h slangversion $(OBJSpull)
	$(CC) $(OBJSpull) -o slrnpull.exe -L$(SLIBDIR) -lslang $(MISCLIBS)

uudecode.exe: $(OBJDIR)/uudecode1.o $(OBJDIR)/util.o
	$(CC) $(CFLAGS) -o uudecode.exe $(OBJDIR)/uudecode1.o \
 $(OBJDIR)/util.o $(OBJDIR)/ttymsg.o -L$(SLIBDIR) -lslang

all:      slrn.exe slrnpull.exe uudecode.exe

$(OBJDIR):
	@mkdir $(OBJDIR)

config.h: slrnconf.h
	$(CP) slrnconf.h config.h

$(OBJDIR)/art.o: art.c config.h slrnfeat.h jdmacros.h slrn.h group.h server.h \
                 nntpcodes.h art.h misc.h ttymsg.h post.h startup.h hash.h \
                 score.h menu.h util.h xover.h chmap.h uudecode.h mime.h
	$(CC) -c $(CFLAGS) -o $(OBJDIR)/art.o art.c
$(OBJDIR)/chmap.o: chmap.c config.h slrnfeat.h jdmacros.h misc.h ttymsg.h \
                 util.h chmap.h group.h art.h charmaps.h
	$(CC) -c $(CFLAGS) -o $(OBJDIR)/chmap.o chmap.c
$(OBJDIR)/editscore.o: editscore.c config.h slrnfeat.h jdmacros.h group.h \
                 art.h startup.h misc.h ttymsg.h score.h util.h
	$(CC) -c $(CFLAGS) -o $(OBJDIR)/editscore.o editscore.c
$(OBJDIR)/group.o: group.c config.h slrnfeat.h jdmacros.h slrn.h group.h \
                 art.h misc.h ttymsg.h post.h server.h nntpcodes.h hash.h \
                 score.h menu.h util.h startup.h
	$(CC) -c $(CFLAGS) -o $(OBJDIR)/group.o group.c
$(OBJDIR)/hash.o: hash.c config.h slrnfeat.h jdmacros.h hash.h
	$(CC) -c $(CFLAGS) -o $(OBJDIR)/hash.o hash.c
$(OBJDIR)/help.o: help.c config.h slrnfeat.h jdmacros.h slrn.h misc.h \
                 ttymsg.h util.h
	$(CC) -c $(CFLAGS) -o $(OBJDIR)/help.o help.c
$(OBJDIR)/interp.o: interp.c config.h slrnfeat.h jdmacros.h slrn.h group.h \
                 art.h misc.h ttymsg.h startup.h server.h nntpcodes.h menu.h \
                 interp.h util.h
	$(CC) -c $(CFLAGS) -o $(OBJDIR)/interp.o interp.c
$(OBJDIR)/menu.o: menu.c config.h slrnfeat.h jdmacros.h slrn.h menu.h misc.h \
                 ttymsg.h
	$(CC) -c $(CFLAGS) -o $(OBJDIR)/menu.o menu.c
$(OBJDIR)/mime.o: mime.c config.h slrnfeat.h jdmacros.h server.h nntpcodes.h \
                 slrn.h misc.h ttymsg.h group.h art.h util.h mime.h
	$(CC) -c $(CFLAGS) -o $(OBJDIR)/mime.o mime.c
$(OBJDIR)/misc.o: misc.c config.h slrnfeat.h jdmacros.h misc.h ttymsg.h \
                 group.h slrn.h post.h server.h nntpcodes.h util.h chmap.h \
                 mime.h
	$(CC) -c $(CFLAGS) -o $(OBJDIR)/misc.o misc.c
$(OBJDIR)/post.o: post.c config.h slrnfeat.h jdmacros.h slrn.h server.h \
                 nntpcodes.h misc.h ttymsg.h post.h group.h art.h uudecode.h \
                 util.h chmap.h mime.h
	$(CC) -c $(CFLAGS) -o $(OBJDIR)/post.o post.c
$(OBJDIR)/score.o: score.c config.h slrnfeat.h jdmacros.h slrn.h group.h \
                 misc.h ttymsg.h server.h nntpcodes.h hash.h util.h art.h \
                 xover.h score.h
	$(CC) -c $(CFLAGS) -o $(OBJDIR)/score.o score.c
$(OBJDIR)/server.o: server.c config.h slrnfeat.h jdmacros.h slrn.h server.h \
                 nntpcodes.h misc.h ttymsg.h util.h startup.h spool.c
	$(CC) -c $(CFLAGS) -o $(OBJDIR)/server.o server.c
$(OBJDIR)/slrn.o: slrn.c config.h slrnfeat.h jdmacros.h server.h nntpcodes.h \
                 slrn.h group.h misc.h ttymsg.h startup.h art.h score.h \
                 util.h chmap.h interp.h
	$(CC) -c $(CFLAGS) -o $(OBJDIR)/slrn.o slrn.c
$(OBJDIR)/sortdate.o: sortdate.c config.h slrnfeat.h slrn.h util.h
	$(CC) -c $(CFLAGS) -o $(OBJDIR)/sortdate.o sortdate.c
$(OBJDIR)/startup.o: startup.c config.h slrnfeat.h jdmacros.h slrn.h group.h \
                 misc.h ttymsg.h art.h post.h startup.h score.h util.h \
                 uudecode.h mime.h interp.h server.h nntpcodes.h chmap.h
	$(CC) -c $(CFLAGS) -o $(OBJDIR)/startup.o startup.c
$(OBJDIR)/ttymsg.o: ttymsg.c config.h ttymsg.h
	$(CC) -c $(CFLAGS) -o $(OBJDIR)/ttymsg.o ttymsg.c
$(OBJDIR)/util.o: util.c config.h jdmacros.h util.h ttymsg.h
	$(CC) -c $(CFLAGS) -o $(OBJDIR)/util.o util.c
$(OBJDIR)/uudecode.o: uudecode.c config.h slrnfeat.h uudecode.h util.h \
                 ttymsg.h jdmacros.h slrn.h misc.h
	$(CC) -c $(CFLAGS) -o $(OBJDIR)/uudecode.o uudecode.c
$(OBJDIR)/uudecode1.o: uudecode.c config.h slrnfeat.h uudecode.h util.h \
                 ttymsg.h jdmacros.h slrn.h misc.h
	$(CC) -c $(CFLAGS) -DSTANDALONE -o $(OBJDIR)/uudecode1.o uudecode.c
$(OBJDIR)/xover.o: xover.c config.h slrnfeat.h jdmacros.h util.h ttymsg.h \
                 hash.h group.h art.h xover.h server.h nntpcodes.h
	$(CC) -c $(CFLAGS) -o $(OBJDIR)/xover.o xover.c
$(OBJDIR)/slrndir.o: slrndir.c config.h slrnfeat.h jdmacros.h util.h ttymsg.h \
                 hash.h group.h art.h slrndir.h server.h nntpcodes.h
	$(CC) -c $(CFLAGS) -o $(OBJDIR)/slrndir.o slrndir.c
$(OBJDIR)/slrnpull.o: slrnpull.c config.h slrnfeat.h jdmacros.h ttymsg.h \
                 util.h sltcp.h nntplib.h nntpcodes.h score.c art.h xover.h \
                 score.h xover.c hash.h hash.c
	$(CC) -c $(CFLAGS) -o $(OBJDIR)/slrnpull.o slrnpull.c
$(OBJDIR)/sltcp.o: sltcp.c config.h sltcp.h
	$(CC) -c $(CFLAGS) -o $(OBJDIR)/sltcp.o sltcp.c
$(OBJDIR)/nntplib.o: nntplib.c config.h jdmacros.h sltcp.h nntpcodes.h \
                 nntplib.h util.h ttymsg.h
	$(CC) -c $(CFLAGS) -o $(OBJDIR)/nntplib.o nntplib.c
$(OBJDIR)/version.o: version.c version.h
	$(CC) -c $(CFLAGS) -o $(OBJDIR)/version.o version.c
$(OBJDIR)/print.o: print.c config.h
	$(CC) -c $(CFLAGS) -o $(OBJDIR)/print.o print.c

slangversion: $(OBJDIR)/chkslang.exe
	./$(OBJDIR)/chkslang.exe slrn 10003

$(OBJDIR)/chkslang.exe: $(OBJDIR)/chkslang.o
	$(CC) $(OBJDIR)/chkslang.o -o $(OBJDIR)/chkslang.exe

$(OBJDIR)/chkslang.o: chkslang.c config.h jdmacros.h
	$(CC) -c -I$(SDIR) chkslang.c -o $(OBJDIR)/chkslang.o
clean:
	rm -rf *.o *~ $(OBJDIR) slrn.exe uudecode.exe *.log \
	core out out.* typescript files.pck* config.h

