#
# Makefile for Mac OS X for PHYLIP 3.6.

PACKAGE=phylip
VERSION=3.67

# You should not need to change anything, though if you want you could
# change the first (noncomment) statement to some directory location
# that might be more useful.
# The compressed tar archive phylip.tar.Z when uncompressed and extracted
# puts the source code into a directory ./src, and also makes two other
# directories ./exe and ./doc for the final executables and the documentation
# files.  Only change the EXEDIR settings if you want something different
# from that structure.
# If it causes trouble in compiling, the CFLAGS statement below may also need
# to be changed.
#
# It is assumed that the files command.in, Info.plist.in, and the 
# icon files (*.icns) are also in the src/mac directory.
#
#
#  To use the PHYLIP v3.6 Makefile, type
#      make install         to compile the whole package and install
#                           the executables in $(EXEDIR), and then
#                           remove the object files to save space
#
#      make all             to compile the whole package but not install it
#                           or remove the object files. 
#
#      make put             to move the executables into $(EXEDIR)
#
#      make clean           to remove all object files and executables from the
#                           current directory
#
#      make dnaml.app       to compile, link, and make a clickable executable
#                           for one program. The executables will stay
#                           in the src directory.
#
#      make dnaml.install   to compile, link, make a clickable executable, 
#                           for one program and move the executable to the
#                           executables directory
#
# ----------------------------------------------------------------------------
#  (Starting here is the section where you may want to change things)
# ----------------------------------------------------------------------------
#
# these are the statements we have been talking about:
# one of the reasons for changing them would be to put the executables
# and/or the documentation on a different file system.
# The default configuration is to have within the overall PHYLIP
# directory three subdirectories:  "src" for source code, "exe" for the
# executables, and "doc" for the documentation files.
#
# the following specifies the directory where the executables will be placed
EXEDIR  = ../exe
#
# ----------------------------------------------------------------------------
#
# In the following statements (the ones that set CFLAGS, DFLAGS, LIBS
# and DLIBS, CC and DC) you should make sure each is set properly.
# Usually this will simply involve making sure that the proper statement
# has no "#" as its first character and that all other possibilities
# have "#" for their first character.
#
# ----------------------------------------------------------------------------
#
# This is the CFLAGS statement:
#
# if these statements say "-g"  and that causes trouble, remove the "-g"
# if the "-lX11" does not work (X compiling not working), you may want to
# remove that switch or fix it.
#
# Here are some possible CFLAGS statements:
#
#
#A minimal one
#CFLAGS =
#
# A basic one for debugging
#CFLAGS  = -g -Wall
#
# An optimized one for gcc
CFLAGS  = -O3 -fomit-frame-pointer
#
# For some serious debugging using Gnu gcc
#
#CFLAGS=-g -Wall -Wmain -Wmissing-prototypes -Wreturn-type -Wstrict-prototypes  -Wunused -Werror -Wredundant-decls -Waggregate-return -Wcast-align -Wcomment
#
# For Digital Alpha systems with Compaq Tru64 Unix
# (however, be aware that this may cause floating-point problems in programs
#  like Dnaml owing to not using IEEE floating point standards).
#CFLAGS = -fast
#
# For making universal binaries
#CFLAGS = -O3 -Wall -arch ppc -arch i386
#
# For making non-universal binaries in case your system can't handle UB's
CFLAGS = -O3 -Wall
#
# ----------------------------------------------------------------------------
#
# and here are some possible DFLAGS statements:
#
# A minimal one
#DFLAGS  = -DX $(CFLAGS)
#
# A basic one for debugging
#DFLAGS  = -g -DX
#
#
# For Gnu C++ for runs
#DFLAGS  = -I/usr/X11R6/include -O3 -DX -fomit-frame-pointer
#
# For Digital Alpha systems with Compaq Tru64 Unix
#DFLAGS = -DX -fast 
#
# for Linux with X Windows development packages installed
#DFLAGS = -I/usr/X11R6/include
#
# for MacOS X with X Windows installed
DFLAGS =  -DMAC -DOSX_CARBON $(CFLAGS)
CARBON_LIBS=-framework Carbon #-framework AppKit -framework ApplicationServices
#
# ----------------------------------------------------------------------------
#
# These are the libraries for the CC and DC compiles, respectively
#
LIBS    = -lm
#
# if the Xlib library for the X windowing system is somewhere
# unexpected, you may have to change the path /usr/X11R6/lib in this one
#
# For gcc for Linux with X windows development packages installed
# or for MacOS X with X windows installed
#DLIBS= -L/usr/X11R6/lib/ -lX11 -lXaw -lXt
#
# ----------------------------------------------------------------------------
#
# The next two assignments are the invocations of the compiler for the
# ordinary compiles and the tree-drawing programs, CC and DC
#
# This one specifies the "cc" C compiler
CC        = cc
#
#  To use GCC instead, if it is not the compiler that "cc" invokes
#CC        = gcc
#
# This one specifies the "cc" C compiler for the Draw programs
DC        = cc $(DFLAGS)
#
# To use GCC instead, if it is not the compiler that "cc" invokes
#DC        = gcc $(DFLAGS)
#
# ----------------------------------------------------------------------------
#  (After this point there should not be any reason to change anything)
# except for the commands at the bottom which add the icons in Mac OS X
# ----------------------------------------------------------------------------
#
#
# the list of programs
#
PROGS   =          clique consense contml contrast dnacomp dnadist \
                   dnainvar dnaml dnamlk dnamove dnapars dnapenny \
                   dolmove dollop dolpenny factor fitch gendist kitsch \
                   mix move neighbor pars penny proml promlk protdist \
                   protpars restdist restml retree seqboot treedist \
                   drawgram drawtree

APPS    =          clique.app consense.app contml.app contrast.app dnacomp.app \
                   dnadist.app dnainvar.app dnaml.app dnamlk.app dnamove.app \
                   dnapars.app dnapenny.app dollop.app dolmove.app dolpenny.app \
                   drawgram.app drawtree.app factor.app fitch.app gendist.app \
                   kitsch.app mix.app move.app neighbor.app pars.app penny.app \
                   proml.app promlk.app protdist.app protpars.app restdist.app \
                   restml.app retree.app seqboot.app treedist.app 

#
# general commands
#

#  The first target it executed if you just type "make".  It tells you how to
#  use the Makefile.
#
help:
	@echo ""
	@echo " To use the PHYLIP v3.6 Makefile, type"
	@echo "     make install          to compile the whole package and install"
	@echo "                            the executables in $(EXEDIR), and then"
	@echo "                            remove the object files to save space"
	@echo "     make all              to compile the whole package but not install it"
	@echo "                            or remove the object files"
	@echo "     make put              to move the executables into $(EXEDIR)"
	@echo "     make clean            to remove all object files and executables from the"
	@echo "                            current directory"
	@echo "     make dnaml.app        to compile, link, and make a clickable executable"
	@echo "                            for one program (in this example, dnaml)."
	@echo "                            The executables will stay in the src directory."
	@echo "     make dnaml.install    to compile, link, make a clickable executable,"
	@echo "                            for one program and move the executable"
	@echo "                            to the executables directory"
	@echo " "

introduce:
	@echo "Building PHYLIP version $(VERSION)"

all:        introduce $(PROGS)
	@echo "Finished compiling."
	@echo ""

install:        pre-clean apps put clean
	@echo "Done."
	@echo ""

# For making clickable executables.
apps:   $(APPS)

put:
	@echo "Installing PHYLIP v3.6 binaries in $(EXEDIR)"
	@mkdir -p '$(EXEDIR)'
	@for i in $(APPS) ; do \
     rm -rf "$(EXEDIR)/$$i" ; \
   done
	@mv $(APPS) '$(EXEDIR)'
	@for i in $(APPS) ; do \
    $(LSREGISTER) -f "$(EXEDIR)/$$i" ; \
  done
	@echo "Installing font files in $(EXEDIR)"
	@cp font* '$(EXEDIR)'
	@echo "Finished installation."
	@echo ""

pre-clean:
	@echo "Removing preexisting executables"
	@for i in $(APPS) ; do \
    rm -rf "$(EXEDIR)/$$i" ; \
  done
	@echo "Ready for new executables"
	@echo ""

clean:
	@echo "Removing object files to save space"
	@rm -f *.o
	@echo "Finished removing object files.  Now will remove"
	@echo "executable files from the current directory, but not from the"
	@echo "executables directory.  (If some are not here, the makefile"
	@echo "will terminate with an error message but this is not a problem)"
	@echo ""
	@echo "Removing executables from this directory"
	@rm -f $(PROGS)
	@rm -rf $(APPS)
	@echo "Finished cleanup."
	@echo ""

#
# compile object files shared between programs
# (make's implicit rule for %.o will take care of these)
#

phylip.o:     phylip.h
seq.o:        phylip.h seq.h
disc.o:       phylip.h disc.h
discrete.o:   phylip.h discrete.h
dollo.o:      phylip.h dollo.h
wagner.o:     phylip.h wagner.h
dist.o:       phylip.h dist.h
cont.o:       phylip.h cont.h
mlclock.o:    phylip.h mlclock.h
moves.o:      phylip.h moves.h
printree.o:   phylip.h printree.h

#
# compile the individual programs
#

clique.o:       clique.c disc.h phylip.h
	$(CC) $(CFLAGS) -c clique.c

clique:       clique.o clique.c disc.o disc.c phylip.o phylip.c disc.h phylip.h
	$(CC) $(CFLAGS) clique.o disc.o phylip.o $(LIBS) -o clique

cons.o:          cons.c cons.h phylip.h 
	$(CC) $(CFLAGS) -c cons.c

consense.o:     consense.c cons.h phylip.h
	$(CC) $(CFLAGS) -c consense.c

consense:     consense.o consense.c phylip.o phylip.c cons.o cons.c cons.h phylip.h
	$(CC) $(CFLAGS) consense.o cons.o phylip.o $(LIBS) -o consense

contml.o:       contml.c cont.h phylip.h
	$(CC) $(CFLAGS) -c contml.c

contml:       contml.o contml.c cont.o cont.c phylip.o phylip.c cont.h phylip.h
	$(CC) $(CFLAGS) contml.o cont.o phylip.o $(LIBS) -o contml

contrast.o:       contrast.c cont.h phylip.h
	$(CC) $(CFLAGS) -c contrast.c

contrast:       contrast.o contrast.c cont.o cont.c phylip.o phylip.c cont.h phylip.h
	$(CC) $(CFLAGS) contrast.o cont.o phylip.o $(LIBS) -o contrast

dnacomp.o:      dnacomp.c seq.h phylip.h
	$(CC) $(CFLAGS) -c dnacomp.c

dnacomp:      dnacomp.o seq.o phylip.o dnacomp.c seq.c phylip.c seq.h phylip.h
	$(CC) $(CFLAGS) dnacomp.o seq.o phylip.o $(LIBS) -o dnacomp

dnadist.o:      dnadist.c seq.h phylip.h
	$(CC) $(CFLAGS) -c dnadist.c

dnadist:      dnadist.o seq.o phylip.o dnadist.c seq.c phylip.c seq.h phylip.h
	$(CC) $(CFLAGS) dnadist.o seq.o phylip.o $(LIBS) -o dnadist

dnainvar.o:      dnainvar.c seq.h phylip.h
	$(CC) $(CFLAGS) -c dnainvar.c

dnainvar:      dnainvar.o seq.o phylip.o dnainvar.c seq.c phylip.c seq.h phylip.h
	$(CC) $(CFLAGS) dnainvar.o seq.o phylip.o $(LIBS) -o dnainvar

dnaml.o:      dnaml.c seq.h phylip.h
	$(CC) $(CFLAGS) -c dnaml.c

dnaml:      dnaml.o seq.o phylip.o dnaml.c seq.c phylip.c seq.h phylip.h
	$(CC) $(CFLAGS) dnaml.o seq.o phylip.o $(LIBS) -o dnaml

dnamlk.o:      dnamlk.c seq.h phylip.h mlclock.h printree.h
	$(CC) $(CFLAGS) -c dnamlk.c

dnamlk:      dnamlk.o seq.o phylip.o mlclock.o printree.o
	$(CC) $(CFLAGS) $^ $(LIBS) -o dnamlk

dnamove.o:      dnamove.c seq.h moves.h phylip.h
	$(CC) $(CFLAGS) -c dnamove.c

dnamove:      dnamove.o seq.o moves.o phylip.o dnamove.c seq.c phylip.c seq.h phylip.h
	$(CC) $(CFLAGS) dnamove.o seq.o moves.o phylip.o $(LIBS) -o dnamove

dnapenny.o:      dnapenny.c seq.h phylip.h
	$(CC) $(CFLAGS) -c dnapenny.c

dnapenny:      dnapenny.o seq.o phylip.o dnapenny.c seq.c phylip.c seq.h phylip.h
	$(CC) $(CFLAGS) dnapenny.o seq.o phylip.o $(LIBS) -o dnapenny

dnapars.o:      dnapars.c seq.h phylip.h
	$(CC) $(CFLAGS) -c dnapars.c

dnapars:      dnapars.o seq.o phylip.o dnapars.c seq.c phylip.c seq.h phylip.h
	$(CC) $(CFLAGS) dnapars.o seq.o phylip.o $(LIBS) -o dnapars

dolmove.o:       dolmove.c disc.h moves.h dollo.h phylip.h
	$(CC) $(CFLAGS) -c dolmove.c

dolmove:       dolmove.o disc.o moves.o dollo.o phylip.o dolmove.c disc.c moves.c dollo.c phylip.c disc.h moves.h dollo.h phylip.h
	$(CC) $(CFLAGS) dolmove.o disc.o moves.o dollo.o phylip.o $(LIBS) -o dolmove

dollop.o:       dollop.c disc.h dollo.h phylip.h
	$(CC) $(CFLAGS) -c dollop.c

dollop:       dollop.o disc.o dollo.o phylip.o dollop.c disc.c dollo.c phylip.c disc.h dollo.h phylip.h
	$(CC) $(CFLAGS) dollop.o disc.o dollo.o phylip.o $(LIBS) -o dollop

dolpenny.o:       dolpenny.c disc.h dollo.h phylip.h
	$(CC) $(CFLAGS) -c dolpenny.c

dolpenny:       dolpenny.o disc.o dollo.o phylip.o dolpenny.c disc.c dollo.c phylip.c disc.h dollo.h phylip.h
	$(CC) $(CFLAGS) dolpenny.o disc.o dollo.o phylip.o $(LIBS) -o dolpenny

draw.o:   draw.c draw.h phylip.h interface.h
	$(DC) -c draw.c

draw2.o:   draw2.c draw.h phylip.h 
	$(DC) -c draw2.c

drawgram.o:     drawgram.c draw.h phylip.h
	$(DC) -c drawgram.c

drawgram:     drawgram.o draw.o draw2.o interface.o phylip.o drawgram.c draw.c draw2.c draw.h phylip.h
	$(DC) $(DLIBS) draw.o draw2.o drawgram.o interface.o phylip.o $(LIBS) $(CARBON_LIBS) -o drawgram

drawtree.o:     drawtree.c draw.h phylip.h
	$(DC) -c drawtree.c

interface.o: interface.c interface.h draw.h
	$(DC) -c interface.c

drawtree:     drawtree.o draw.o draw2.o interface.o phylip.o
	$(DC) $(DLIBS) draw.o draw2.o drawtree.o interface.o phylip.o $(LIBS) $(CARBON_LIBS) -o drawtree

factor.o:       factor.c phylip.h
	$(CC) $(CFLAGS) -c factor.c

factor:       factor.o phylip.o factor.c phylip.c phylip.h
	$(CC) $(CFLAGS) factor.o phylip.o $(LIBS) -o factor

fitch.o:        fitch.c dist.h phylip.h
	$(CC) $(CFLAGS) -c fitch.c

fitch:        fitch.o dist.o phylip.o fitch.c dist.c phylip.c dist.h phylip.h
	$(CC) $(CFLAGS) fitch.o dist.o phylip.o $(LIBS) -o fitch

gendist.o:      gendist.c phylip.h
	$(CC) $(CFLAGS) -c gendist.c

gendist:      gendist.o phylip.o gendist.c phylip.c phylip.h
	$(CC) $(CFLAGS) gendist.o phylip.o $(LIBS) -o gendist

kitsch.o:        kitsch.c dist.h phylip.h
	$(CC) $(CFLAGS) -c kitsch.c

kitsch:        kitsch.o dist.o phylip.o kitsch.c dist.c phylip.c dist.h phylip.h
	$(CC) $(CFLAGS) kitsch.o dist.o phylip.o $(LIBS) -o kitsch

mix.o:        mix.c disc.h wagner.h phylip.h
	$(CC) $(CFLAGS) -c mix.c

mix:        mix.o disc.o wagner.o phylip.o mix.c disc.c wagner.c phylip.c disc.h wagner.h phylip.h
	$(CC) $(CFLAGS) mix.o disc.o wagner.o phylip.o $(LIBS) -o mix

move.o:        move.c disc.h moves.h wagner.h phylip.h
	$(CC) $(CFLAGS) -c move.c

move:        move.o disc.o moves.o wagner.o phylip.o move.c disc.c moves.c wagner.c phylip.c disc.h moves.h wagner.h phylip.h
	$(CC) $(CFLAGS) move.o disc.o moves.o wagner.o phylip.o $(LIBS) -o move

neighbor.o:        neighbor.c dist.h phylip.h
	$(CC) $(CFLAGS) -c neighbor.c

neighbor:        neighbor.o dist.o phylip.o neighbor.c dist.c phylip.c dist.h phylip.h
	$(CC) $(CFLAGS) neighbor.o dist.o phylip.o $(LIBS) -o neighbor

pars.o:   pars.c discrete.h phylip.h
	$(CC) $(CFLAGS) -c pars.c

pars: pars.o pars.c discrete.o discrete.c phylip.o phylip.c discrete.h phylip.h
	$(CC) $(CFLAGS) pars.o discrete.o phylip.o $(LIBS) -o pars

penny.o:  penny.c disc.h wagner.h phylip.h
	$(CC) $(CFLAGS) -c penny.c

penny:  penny.o disc.o wagner.o phylip.o penny.c disc.c wagner.c disc.h wagner.h phylip.h
	$(CC) $(CFLAGS) penny.o disc.o wagner.o  phylip.o $(LIBS) -o penny

proml.o:      proml.c seq.h phylip.h
	$(CC) $(CFLAGS) -c proml.c

proml:      proml.o seq.o phylip.o proml.c seq.c phylip.c seq.h phylip.h
	$(CC) $(CFLAGS) proml.o seq.o phylip.o $(LIBS) -o proml

promlk.o:      promlk.c seq.h phylip.h mlclock.h printree.h 
	$(CC) $(CFLAGS) -c promlk.c

promlk:      promlk.o seq.o phylip.o mlclock.o printree.o
	$(CC) $(CFLAGS) $^ $(LIBS) -o promlk

protdist.o:      protdist.c seq.h phylip.h
	$(CC) $(CFLAGS) -c protdist.c

protdist:      protdist.o seq.o phylip.o protdist.c seq.c phylip.c seq.h phylip.h
	$(CC) $(CFLAGS) protdist.o seq.o phylip.o $(LIBS) -o protdist

protpars.o: protpars.c seq.h phylip.h
	$(CC) $(CFLAGS) -c protpars.c

protpars: protpars.o seq.o phylip.o protpars.c seq.c phylip.c seq.h phylip.h
	$(CC) $(CFLAGS) protpars.o seq.o phylip.o $(LIBS) -o protpars

restdist.o: restdist.c seq.h phylip.h
	 $(CC) $(CFLAGS) -c restdist.c

restdist: restdist.o seq.o phylip.o restdist.c seq.c phylip.c seq.h phylip.h
	$(CC) $(CFLAGS) restdist.o seq.o phylip.o $(LIBS) -o restdist

restml.o: restml.c seq.h phylip.h
	 $(CC) $(CFLAGS) -c restml.c

restml: restml.o seq.o phylip.o restml.c seq.c phylip.c seq.h phylip.h
	$(CC) $(CFLAGS) restml.o seq.o phylip.o $(LIBS) -o restml

retree.o:       retree.c moves.h phylip.h
	$(CC) $(CFLAGS) -c retree.c

retree:       retree.o moves.o phylip.o retree.c moves.c phylip.c moves.h phylip.h
	$(CC) $(CFLAGS) retree.o moves.o phylip.o $(LIBS) -o retree

seqboot.o:      seqboot.c phylip.h
	$(CC) $(CFLAGS) -c seqboot.c

seqboot:      seqboot.o seq.o phylip.o seqboot.c seq.c phylip.c seq.h phylip.h
	$(CC) $(CFLAGS) seqboot.o seq.o phylip.o $(LIBS) -o seqboot

treedist.o:     treedist.c cons.h phylip.h
	$(CC) $(CFLAGS) -c treedist.c

treedist:     treedist.o phylip.o cons.o
	$(CC) $(CFLAGS) treedist.o cons.o phylip.o $(LIBS) -o treedist

#
# This is where the clickable executables are made for Mac OSX
#
%.app: % mac/Info.plist.in mac/command.in mac/%.icns 
	@rm -rf $@
	/Developer/Tools/Rez -d __DARWIN__ -t APPL Carbon.r -o $<
	/Developer/Tools/SetFile -a C $<
	-mkdir -p $@/Contents/MacOS
	-mkdir -p $@/Contents/Resources
	sed -e "s/IDENTIFIER/$</" \
	-e "s/COMMAND/$<.command/" \
	-e "s/EXECUTABLE/$</" \
	-e "s/ICONNAME/$</" \
	-e "s/VERSION/$(VERSION)/" \
	mac/Info.plist.in > $@/Contents/Info.plist
	sed -e "s/EXECUTABLE/$</" \
	mac/command.in > $@/Contents/MacOS/$<.command
	chmod ug+x $@/Contents/MacOS/$<.command
	echo -n "APPL????" >$@/Contents/PkgInfo
	cp $< $@/Contents/MacOS/$<
	cp -f mac/$<.icns $@/Contents/Resources/$<.icns

# Location of the lsregister command to force re-registration with LaunchServices
LSREGISTER=/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister

%.install:	%.app
	@rm -rf '$(EXEDIR)/$<'
	@mv $< '$(EXEDIR)'
	$(LSREGISTER) -f '$(EXEDIR)/$<'
	
