#
#
#  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.
#
# 
#
#

# This Makefile works with GCC (V2.2) and Aztec make


# 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 -DAMIGA
#GLOBALCFLAGS = -pedantic -Wall -DAMIGA -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

.SUFFIXES: .c .o

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

#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\
	client.o\
	cte.o\
	codes.o\
	colorreq.o\
	date.o\
	delete.o\
	editab.o\
	findnode.o\
	freecontents.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\
	strip7.o\
	tags.o\
	uue.o\
	writeconfig.o\
	writelog.o

#objects for lmail
LMOBJ =\
	allocammsg.o\
	client.o\
	freecontents.o\
	lmail.o\
	writelog.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 richtext
RTOBJ =\
	richtext.o\
	richlex.o

#objects for ezview
EZOBJ =\
	ezview.o\
	unscribe.o\
	ulstrcmp.o

# objects for savefile
SAVEOBJ=\
	os20stuff.o\
	savefile.o

#objects for showpartial
SPOBJ =\
	showpartial.o

#objects for splitmail
SMOBJ =\
	splitmail.o

SHMOBJ =\
	os20stuff.o\
	showmail.o

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

all:\
	am\
	savefile\
	contentsserver\
	amkill\
	lmail\
	newmail\
	makecontents\
	metamail\
	showmail\
	richtext\
	ezview\
	showpartial\
	splitmail\
	am.doc\
	am.guide\
	am.inf\
	am.dvi\
	test


$(MCOBJ):    am.h amheader.h paths.h 
$(AMOBJ):    am.h amheader.h paths.h 
$(LMOBJ):    am.h amheader.h paths.h 
$(SERVOBJ):  am.h amheader.h paths.h server.h
$(NEWMOBJ):  am.h amheader.h paths.h 
$(AMKOBJ):   am.h amheader.h paths.h 
$(TESTOBJ):  am.h amheader.h paths.h 
$(MMOBJ):    am.h amheader.h config.h
$(RTOBJ):    am.h amheader.h config.h richlex.h
$(EZOBJ):    am.h amheader.h config.h mail.h andrewos.h util.h
$(SPOBJ):    am.h amheader.h config.h
$(SMOBJ):    am.h amheader.h config.h
$(SAVEOBJ):  am.h amheader.h
$(SHMOBJ):   am.h amheader.h
send.o:      config.h

update: all
	delete uucp:c/AM_CHR quiet
	delete uucp:c/AM_AM quiet
 	delete uucp:c/AM_postmaster quiet
	delete uucp:c/AM_TEST quiet
	delete uucp:c/AM_TEST1 quiet
	copy\
		AM\
		metamail \
		lmail\
		amkill\
		to uucp:c clone
	copy\
		savefile\
		richtext\
		ezview\
		showpartial\
		splitmail\
		makecontents\
		sendm\
		playUlawSound\
		showJPEG\
		showPBM\
		showPGM\
		showXWD\
		showILBM\
		showGIF\
		showRT\
		showPS\
		showDVI\
		showTEXT\
		DisplayMail\
		to uucp:c clone
	copy contentsserver contentsserver.info newmail newmail.info to sys:wbstartup clone
	copy mailcap uulib: clone
	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
	protect uucp:c/playUlawSound s add
	protect uucp:c/showJPEG s add
	protect uucp:c/showPBM s add
	protect uucp:c/showPGM s add
	protect uucp:c/showXWD s add
	protect uucp:c/showILBM s add
	protect uucp:c/showGIF s add
	protect uucp:c/showRT s add
	protect uucp:c/showDVI s add
	protect uucp:c/showTEXT s add
	copy am.inf gnuemacs:info/am

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


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

dist: all $(ARCHIVE)_bin.LHA srcdist contribdist
	copy $(ARCHIVE)_bin.LHA bms:pub/net/mail/AM clone
	copy $(ARCHIVE)_src.LHA bms:pub/net/mail/AM clone
	copy $(ARCHIVE)_contrib.LHA bms:pub/net/mail/AM clone
	copy contrib/#? bms:pub/net/mail/am/contrib all clone

BINDIST1 = \
		am\
		AM.config\
		am.doc\
		am.info\
		aminstall\
		amkill\
		CHANGES\
		contentsserver\
		contentsserver.info\
		COPYING\
		ezview\
		KNOWN-BUGS\
		lmail\
		mailcap\
		makecontents\
		metamail\
		metamail.man\
		newmail\
		newmail.info\
		QUICK-GUIDE\
		README

BINDIST2 = \
		richtext\
		savefile\
		sendm\
		show-startup\
		showpartial\
		splitmail

$(ARCHIVE)_bin.LHA: $(BINDIST1) $(BINDIST2)
	delete $(ARCHIVE)_bin.LHA quiet
	lha a $(ARCHIVE)_bin $(BINDIST1)
	lha a $(ARCHIVE)_bin $(BINDIST2)

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

contribdist:
	delete $(ARCHIVE)_contrib.LHA quiet
	lha a $(ARCHIVE)_contrib contrib/#?
	
newversion:
	delete makefile.tmp quiet
	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.texinfo am.texinfo.tmp
	sed -f newversion.sed am.texinfo.tmp >am.texinfo
	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 quiet


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)
#	amkill

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

richtext: $(RTOBJ)
	$(LN) $(LNFLAGS) -o richtext $(RTOBJ) $(LIBS)

ezview: $(EZOBJ)
	$(LN) $(LNFLAGS) -o ezview $(EZOBJ) $(LIBS)

showpartial: $(SPOBJ)
	$(LN) $(LNFLAGS) -o showpartial $(SPOBJ) $(LIBS)

splitmail: $(SMOBJ)
	$(LN) $(LNFLAGS) -o splitmail $(SMOBJ) $(LIBS)

savefile: $(SAVEOBJ)
	$(LN) $(LNFLAGS) -o savefile $(SAVEOBJ) $(LIBS)

showmail: $(SHMOBJ)
	$(LN) $(LNFLAGS) -o showmail $(SHMOBJ) $(LIBS)

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

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

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

richtext.o:	richtext.c richlex.h
	gcc $(OPTIMIZE) -DAMIGA -c richtext.c

richlex.o:	richlex.c richlex.h
	gcc $(OPTIMIZE) -DAMIGA -c richlex.c

ezview.o: ezview.c
	gcc $(OPTIMIZE) -DAMIGA -c ezview.c

unscribe.o: unscribe.c
	gcc $(OPTIMIZE) -DAMIGA -c unscribe.c

ulstrcmp.o: ulstrcmp.c
	gcc $(OPTIMIZE) -DAMIGA -c ulstrcmp.c

showpartial.o: showpartial.c
	gcc $(OPTIMIZE) -DAMIGA -c showpartial.c

splitmail.o: splitmail.c
	gcc $(OPTIMIZE) -DAMIGA -c splitmail.c

am.dvi: am.texinfo
	virtex &plain am.texinfo
	virtex &plain am.texinfo
	virtex &plain am.texinfo
	delete am.log quiet
	delete am.toc quiet
	delete am.aux quiet

am.guide: am.texinfo
	makeinfo --verbose --amiga -o am.guide am.texinfo

am.doc: am.texinfo
	makeinfo --verbose --no-headers --amiga -o am.doc am.texinfo

am.inf: am.texinfo
	makeinfo --verbose -o am.inf am.texinfo
