# Top level makefile for ME/MC
# Invokes make in each of the sub-directories to make everything,
#   passing flags down to each sub-directory make.
#
# There are a bunch of targets that build for various platforms, see first:
#   for a list.
#
# To clean up the .o files (leaving libraries): "make clean"
# To remove everything but the source:		"make realclean"
#
# To install:
#   Check the "Installation" section (below) then:  "make install"
#
# If your platform is not in the first: list, and a generic target doesn't
#   work, try configuring the following and "make all_of_ME"
#    util/os.h
#    me/config.h
#    me/Makefile
#    comserver/Makefile
#    ./Makefile (this file!)
#
# Caution: assumes you are using GNUmake. If you are not, you should be!
#	++jrb  bammi@cadence.com
#
# I commented out the GNUmake-isms.  It makes me/Makefile more painful to
#   configure.  Other than that, Atari is only affected if SUBDIRS is not
#   configured correctly.  I marked the changes with "GNUmake:".  --cd
#   Affected Makefiles:  me/Makefile, comserver/Makefile

##########################################################################
##		     start of user configuration			##
##########################################################################

# Choose your compiler
#   For most systems just cc
#   You may prefer to use gcc
#   For the atariST specify your cross or native gcc

CC=cc
#CC=gcc		# gcc unix/atariST
#CC=cgcc	# gcc atariST TOS/MiNT

# Choose the base compile flags for your C compiler. These flags
# are used for everything that is compiled. K&R or ANSI C ok.
#   For HP-UX and ANSI C, use "-O -Aa", else "-O"
#   For Apollo and ANSI C, use "-O -Aansi", else "-O"
#   For everybody else, "-O" should be OK
#   For the atariST:  Use -O2 -fstrength-reduce
#   On a  Sun-sparc with gcc-2.1, I have tested "-O2 -g".
#     For our SpacStation-10, I used "-O" and "-O -Xa".  "-O" was fine.
# Normal case: -O
BASECFLAGS = -O
#BASECFLAGS = -O2 -g		# gcc unix
#BASECFLAGS = -ml -A  -d -f- -N -P-c -w-pia	# Borland C++, no ASM
#BASECFLAGS = -ml -A- -d -f- -N -P-c -w-pia	# Borland C++, using ASM
#BASECFLAGS = -O2 -fomit-frame-pointer -fstrength-reduce   # gcc atariST-TOS
#BASECFLAGS = -O -mint		# gcc atariST-MiNT

# Choose the flags for the loader. These are not applied when compiling.
#   For most unixen use nothing.
#   On the atariST, nothing is fine.
#   -lsocket : Newer Suns.  Use if the loader complains about
#		Undefined Symbol socket.
# LDFLAGS = -lsocket	# Newer Suns
# LDFLAGS = -v		# cc unixen / gcc atariST-TOS
# LDFLAGS = -mint	# gcc atariST-MiNT

# Name of your archiver and ranlib
#   On unixen "ar" and "ranlib"
#   On the atariST car (or gcc-ar on native) and "car s"
#   On newer Suns or systems with no ranlib, use "echo"
AR=ar		# unixen
RANLIB=ranlib	# unixen
# RANLIB = echo	# Newer Suns
# AR = car		# atariST
# RANLIB = car s	# atariST

# The subdirectories in which we are going to make stuff
#   unixen:  util ed mc comserver mutt me
#   atariST: util ed mc mutt me
# Note:  You only need "comserver" if you are going to use the compute
#   server.  If you don't want it (or are having trouble compiling it),
#   remove it from SUBDIRS and turn it off in me/Makefile (set PROCESS to
#   blank) and me/config.h (set COMPUTE_SERVER to 0)
#
SUBDIRS = util ed mc comserver mutt		# unixen
# SUBDIRS = util ed mc 				# atariST -cross
# SUBDIRS = util ed mc mutt 			# atariST -native

# The following should only be defined if you are compiling for the atariST
# (these variables are tested in subdir/Makefiles to test conditions)
#   For unixen don't define them.
#
ATARI=		# unixen
ATARIOS=	# unixen
# ATARI=atariST		# define this if atariST, MiNT or TOS
# ATARIOS=TOS		# define this only if atariST-TOS
# ATARIOS=MiNT		# define this only if atariST-MiNT

# Installation directories:
#  BIN is where to put the binaries (me3 and mc2)
#  MUTTLIB is where to put the ME3 extension libraries.
#    Make sure this directory matches what you have in me/config.h
#  DOC is where to put the documation files.  Normally the same as MUTTLIB
#    because that makes it easy for ME to look for the doc files.
# Normal Unix case:
#   BIN = /usr/local/bin
#   MUTTLIB = /usr/local/me3
#   DOC = $(MUTTLIB)
# Normal MS-DOS case:
#   BIN = C:/bin or whatever you have for a bin directory
#   MUTTLIB = C:/me3
#   DOC = $(MUTTLIB)
BIN = /usr/local/bin
MUTTLIB = /usr/local/me3
DOC = $(MUTTLIB)

##########################################################################
##			End of User Configuration			##
##########################################################################

first: 
	@echo "To compile ME (me/me or me/xme):"
	@echo "Borland C (MS-DOS):  make -f Makefile.bc"
	@echo "Apollo:       make termcap_ME"
	@echo "HP-UX:        make termcap_ME"
	@echo "HP-UX X11:    make HPXme"
	@echo "IBM AIX:      make termcap_ME"
	@echo "IBM AIX X11:  make Xme"
	@echo "Sun BSD:      make bsd"
	@echo "Sun SYSV:     make Sun_sysv"
	@echo "Sun SYSV X11: make Sun_sysv_Xme"
	@echo "If you have configured the Makefiles and want"
	@echo "  use them as they are: make all_of_ME"
	@echo 
	@echo "To install:"
	@echo "Make sure ./Makefile BIN and MUTTLIB are correct"
	@echo "  then make install (you may need to be super-user).
	@echo "(make -f Makefile.bc install on MS-DOS).
	@echo 
	@echo "To clean up:"
	@echo "Remove compile droppings:    make clean"
	@echo "Remove everything but source: make realclean"
	@echo "To clean just the me directory: make clean_me"
	@echo "  (For example, to build the X version after building the termcap version)"
	@echo "(make -f Makefile.bc clean on MS-DOS).
	@echo 

announce:
	@echo ">>>>>>>>>>>>>>>>Building the Mutt World<<<<<<<<<<<<<<<<<<<<<"

##################################################################
####			Build most things		      ####
##################################################################

all_of_ME:
	for dir in $(SUBDIRS) me; do \
	(cd $$dir; \
	$(MAKE) CC="$(CC)" BASECFLAGS="$(BASECFLAGS)" LDFLAGS="$(LDFLAGS)" AR="$(AR)" RANLIB="$(RANLIB)" ATARI="$(ATARI)" ATARIOS="$(ATARIOS)"; \
	) \
	done

all_but_ME:
	for dir in $(SUBDIRS); do \
	(cd $$dir; \
	$(MAKE) CC="$(CC)" BASECFLAGS="$(BASECFLAGS)" LDFLAGS="$(LDFLAGS)" AR="$(AR)" RANLIB="$(RANLIB)" ATARI="$(ATARI)" ATARIOS="$(ATARIOS)"; \
	) \
	done

##################################################################
####			Build X ME			      ####
##################################################################

HPXme: announce all_but_ME
	(cd me; \
	$(MAKE) Xme CC="$(CC)" \
	BASECFLAGS="$(BASECFLAGS) -I/usr/include/X11R5 -DXIO=1" \
	LDFLAGS="$(LDFLAGS) -L/usr/lib/X11R5" AR="$(AR)" RANLIB="$(RANLIB)" \
	ATARI="$(ATARI)" ATARIOS="$(ATARIOS)"; \
	)

Xme: announce all_but_ME
	(cd me; \
	$(MAKE) Xme CC="$(CC)" \
	BASECFLAGS="$(BASECFLAGS) -DXIO=1" \
	LDFLAGS="$(LDFLAGS)" AR="$(AR)" RANLIB="$(RANLIB)" \
	ATARI="$(ATARI)" ATARIOS="$(ATARIOS)"; \
	)

##################################################################
####			Build Termcap ME		      ####
##################################################################

termcap_ME: announce all_but_ME
	(cd me; \
	$(MAKE) termcap_ME CC="$(CC)" \
	BASECFLAGS="$(BASECFLAGS)" \
	LDFLAGS="$(LDFLAGS)" AR="$(AR)" RANLIB="$(RANLIB)" \
	ATARI="$(ATARI)" ATARIOS="$(ATARIOS)"; \
	)

##################################################################
####			Build on Suns			      ####
##################################################################

SunSysV: announce 
	for dir in $(SUBDIRS); do \
	(cd $$dir; \
	$(MAKE) CC="$(CC)" BASECFLAGS="-O -Xa -DSYSV_OS=1" \
	LDFLAGS="-lsocket" AR="ar" RANLIB="echo" ATARI="" ATARIOS=""; \
	) \
	done

Sun_sysv: SunSysV
	(cd me; \
	$(MAKE) termcap_ME CC="$(CC)" BASECFLAGS="-O -Xa -DSYSV_OS=1" \
	LDFLAGS="-lsocket" AR="ar" RANLIB="echo" ATARI="" ATARIOS=""; \
	)

Sun_sysv_Xme: SunSysV
	(cd me; \
	$(MAKE) Xme CC="$(CC)" \
	BASECFLAGS="-O -Xa -DSYSV_OS=1 -DXIO=1 -I/usr/openwin/share/include" \
	LDFLAGS="-lsocket -L/usr/openwin/lib -R/usr/openwin/lib" \
	AR="ar" RANLIB="echo" ATARI="" ATARIOS=""; \
	)


BSD: announce 
	for dir in $(SUBDIRS); do \
	(cd $$dir; \
	$(MAKE) CC="$(CC)" BASECFLAGS="-O -DBSD_OS=1" \
	LDFLAGS="" AR="ar" RANLIB="ranlib" ATARI="" ATARIOS=""; \
	) \
	done

bsd: BSD
	(cd me; \
	$(MAKE) termcap_ME CC="$(CC)" BASECFLAGS="-O -DBSD_OS=1" \
	LDFLAGS="" AR="ar" RANLIB="ranlib" ATARI="" ATARIOS=""; \
	)

##################################################################
####			Clean Up			      ####
##################################################################

# clean: just cleans up objects
clean:
	for dir in $(SUBDIRS) me; do \
	(cd $$dir; $(MAKE) clean; ) \
	done

# realclean: cleanup objects, libraries, executables and .mco's
realclean:
	for dir in $(SUBDIRS) me; do \
	( cd $$dir; $(MAKE) realclean; ) \
	done

clean_me:
	( cd me; $(MAKE) clean; )

##################################################################
####			Install ME			      ####
##################################################################

install:
	-cp me/me me/xme mc/mc2 $(BIN)
#	ln -s $(BIN)/me3 $(BIN)/me
	@-mkdir -p $(MUTTLIB)
	cp mutt/package/*.mco $(MUTTLIB)
	@-mkdir -p $(DOC)
	cp doc/*.doc doc/web.idx $(DOC)
