#
#
#  AM --- AmigaMail
#  (C) 1991 by Christian Riede
#
#  AM is distributed in the hope that it will be useful, but WITHOUT ANY
#  WARRANTY.  No author or distributor accepts responsibility to anyone
#  for the consequences of using it or for whether it serves any
#  particular purpose or works at all, unless he says so in writing.
#  Refer to the GNU General Public License, Version 1, for full details.
#
#  Everyone is granted permission to copy, modify and redistribute AM,
#  but only under the conditions described in the GNU General Public
#  License, Version 1.  A copy of this license is supposed to have been
#  given to you along with AM so you can know your rights and responsi-
#  bilities.  It should be in a file named COPYING.  Among other things,
#  the copyright notice and this notice must be preserved on all copies.
#
# 
#
#

# configure code generation:

# normal code (for testing):
#OPTIMIZE = 
#LNFLAGS  = 

# optimized code (for distribution):
OPTIMIZE = -O2
LNFLAGS  = 

# second one to enable debug output
GLOBALCFLAGS = -pedantic -Wall
#GLOBALCFLAGS = -pedantic -Wall -DDEBUG=1

# second for kprintf-style functions (nedded only for debugging)
LIBS =  -lc -lamiga
#LIBS =  -lc -ldebug -lamiga

CFLAGS = $(GLOBALCFLAGS) $(OPTIMIZE) 
CC = gcc
LN = gcc

.c.o:
	$(CC) -c $(CFLAGS) -o $@ $*.c

# the name of the archive and the archivedisk for backups
ARCHIVE = AM1_14beta

#objects for makecontents
MCOBJ =\
	allocammsg.o\
	client.o\
	date.o\
	freecontents.o\
 	makecontents.o\
	readconfig.o\
	tags.o\
	writelog.o\

#objects for am
AMOBJ =\
	action.o\
	address.o\
	allocammsg.o\
 	am.o\
 	checkrrt.o\
	client.o\
	cte.o\
	codes.o\
	colorreq.o\
	date.o\
	delete.o\
	editab.o\
	findnode.o\
	freecontents.o\
	getaddress.o\
	getmail.o\
	getreplyto.o\
	os20stuff.o\
	read.o\
	readconfig.o\
	requestsearchstring.o\
	requeststring.o\
	search.o\
	searchpattern.o\
	select.o\
	send.o\
	show.o\
	sort.o\
	tags.o\
	uue.o\
	writeconfig.o\
	writelog.o

#objects for lmail
LMOBJ =\
	allocammsg.o\
	client.o\
	freecontents.o\
	lmail.o

#objects for contentsserver
SERVOBJ =\
	addmail.o\
	allocammsg.o\
	contentsserver.o\
	date.o\
	freecontents.o\
	headerstrings.o\
	msgid.o\
	notify.o\
	readconfig.o\
	readcontents.o\
	search.o\
	tags.o\
	writecontents.o\
	writelog.o\

# objects for newmail
NEWMOBJ =\
	allocammsg.o\
	client.o\
	freecontents.o\
	newmail.o\
	os20stuff.o

# objects for amkill
AMKOBJ =\
	allocammsg.o\
	client.o\
	amkill.o

#objects for metamail
MMOBJ =\
	metamail.o\
	codes.o\
	uue.o

#objects for test
TESTOBJ =\
	allocammsg.o\
	client.o\
	freecontents.o\
	test.o\
	date.o

all: am metamail makecontents contentsserver lmail newmail amkill am.dvi

$(MCOBJ):    am.h paths.h          amheader.h
$(AMOBJ):    am.h paths.h          amheader.h
$(LMOBJ):    am.h paths.h          amheader.h
$(SERVOBJ):  am.h paths.h server.h amheader.h
$(NEWMOBJ):  am.h paths.h          amheader.h
$(AMKOBJ):   am.h paths.h          amheader.h
$(TESTOBJ):  am.h paths.h          amheader.h

kurt: all
	execute s:kurt

update: all
	copy AM metamail makecontents lmail sendm amkill to uucp:c clone
	copy contentsserver sys:wbstartup clone
	copy newmail sys:wbstartup/newmail_chr clone
	copy newmail sys:wbstartup/newmail_am clone
	copy newmail sys:wbstartup/newmail_postmaster clone
	copy mailcap uulib: clone
	copy hamgif uucp:c
	delete uucp:c/AM_CHR 
	delete uucp:c/AM_AM
	delete uucp:c/AM_postmaster
	delete uucp:c/AM_TEST
	delete uucp:c/AM_TEST1
	makelink uucp:c/AM_CHR         uucp:c/AM 
	makelink uucp:c/AM_AM          uucp:c/AM 
	makelink uucp:c/AM_postmaster  uucp:c/AM 
	makelink uucp:c/AM_TEST        uucp:c/AM 
	makelink uucp:c/AM_TEST1       uucp:c/AM 
	protect uucp:c/sendm s add

backup: 
	delete $(ARCHIVE).LHA
	lha a $(ARCHIVE) "#?"
	lha d $(ARCHIVE) "#?.lha"
	copy $(ARCHIVE).LHA $(ARCHIVE):


##############################################################################                                                                
#   =====> distribution binaries compiled without DEBUG-Options ??? <=====   #
##############################################################################                                                                

dist: all bindist srcdist
	delete amdist:am#?.LHA quiet
	copy $(ARCHIVE)_bin.LHA amdist:
	copy $(ARCHIVE)_src.LHA amdist:
	copy $(ARCHIVE)_bin.LHA bms:pub/AM
	copy $(ARCHIVE)_src.LHA bms:pub/AM

bindist:
	delete $(ARCHIVE)_bin.LHA
	lha a $(ARCHIVE)_bin \
		am\
		am.info\
		metamail\
		makecontents\
		contentsserver\
		contentsserver.info\
		lmail\
		newmail\
		newmail.info\
		amkill\
		test\
		am.tex\
		am.dvi\
		README\
		QUICK-GUIDE\
		COPYING\
		COPYING.LIB\
		aminstall\
		CHANGES\
		AM.config\
		mailcap\
		hamgif\
		ixemul.library\
		KNOWN-BUGS\
		sendm\
		metamail.man\
		sendmail1.02j21.lzh

srcdist:
	delete $(ARCHIVE)_src.LHA
	lha a $(ARCHIVE)_src "#?.c" "#?.h" makefile

newversion:
	delete makefile.tmp
	rename makefile makefile.tmp
	sed -f newversion.sed makefile.tmp >makefile
	rename am.h am.h.tmp
	sed -f newversion.sed am.h.tmp >am.h
	rename README README.tmp
	sed -f newversion.sed README.tmp >README
	rename am.tex am.tex.tmp
	sed -f newversion.sed am.tex.tmp >am.tex
	rename aminstall aminstall.tmp
	sed -f newversion.sed aminstall.tmp >aminstall
	rename QUICK-GUIDE QUICK-GUIDE.tmp
	sed -f newversion.sed QUICK-GUIDE.tmp >QUICK-GUIDE
	rename release-posting release-posting.tmp
	sed -f newversion.sed release-posting.tmp >release-posting
	delete #?.tmp


am: $(AMOBJ)
	$(LN) $(LNFLAGS) -o AM $(AMOBJ) $(LIBS)

metamail: $(MMOBJ)
	$(LN) $(LNFLAGS) -o metamail $(MMOBJ) $(LIBS)

makecontents: $(MCOBJ)
	$(LN) $(LNFLAGS) -o makecontents $(MCOBJ) $(LIBS)

lmail: $(LMOBJ)
	$(LN) $(LNFLAGS) -o lmail $(LMOBJ) $(LIBS)

contentsserver: $(SERVOBJ)
	$(LN) $(LNFLAGS) -o contentsserver $(SERVOBJ) $(LIBS)

newmail: $(NEWMOBJ)
	$(LN) $(LNFLAGS) -o newmail $(NEWMOBJ) $(LIBS)
	
amkill: $(AMKOBJ)
	$(LN) $(LNFLAGS) -o amkill $(AMKOBJ) $(LIBS)

test: $(TESTOBJ)
	$(LN) $(LNFLAGS) -o test $(TESTOBJ) $(LIBS)

am.dvi: am.tex
	virtex &glplain am
	virtex &glplain am
	virtex &glplain am
	delete am.log
	delete am.toc
	delete am.aux


# compile metamail without -pedantic -Wall :-( :-( :-(

metamail.o: metamail.c
	gcc $(OPTIMIZE) -c metamail.c

