# File:          Makefile
# Author:        Henry M. Walker
# Created:       20 September 2013
# Simplified:    22 September 2013
# Adapted for eSpeakPackage:  1 March 2015
# Acknowledgements:  basic functionality adapted from an example 
#                       by Marge Coahran,
#                    installation functionality modeled by the MyroC Makefile
#                       by David Cowden and Dilan Ustek
#----------------------------------------------------------------------------
# This program and all MyroC software is licensed under the Creative Commons
# Attribution-Noncommercial-Share Alike 4.0 International License.
# Details may be found at http://creativecommons.org/licenses/by-nc-sa/4.0/
#----------------------------------------------------------------------------

# Use the gcc compiler
CC = cc

# Set compilation flags
#   -ansi (check syntax against the American National Standard for C
CFLAGS = -ansi 

# Location to install the eSpeackPackage header and object file to.. #
INSTALLPATH = /usr/local
ESPEAKINC = $(INSTALLPATH)/include
ESPEAKLIB = $(INSTALLPATH)/lib

#----------------------------------------------------------------------------
# build rules:
#
# Each rule takes the following form>  (Note there MUST be a tab,
# as opposed to several spaces, preceeding each command.
#
# target_name:  dependency_list
#	command(s)

#all:  eSpeakPackage.o eSpeakTest
all: eSpeakTest eSpeakExample1
#all: eSpeakTest eSpeakExample1 eSpeakExample2

# List program components, what they depend on, and how to compile each

# base library package
eSpeakPackage.o:  eSpeakPackage.c eSpeakPackage.h
	$(CC) $(CFLAGS) -c eSpeakPackage.c

# test program involving compiled eSpeakPackage only (not MyroC)
eSpeakTest:  eSpeakTest.o eSpeakPackage.h eSpeakPackage.o 
	$(CC) -o eSpeakTest eSpeakTest.c eSpeakPackage.o 

# test program involving installed eSpeak Package only (not MyroC)
eSpeakExample1:  eSpeakExample1
	$(CC) -leSpeakPackage -o eSpeakExample1 eSpeakExample1.c

# test program requiring both eSpeakPackage and installed MyroC library
eSpeakExample2:  eSpeakExample2
	$(CC) -leSpeakPackage -lMyroC -o eSpeakExmaple2 eSpeakExample2.c 


#----------------------------------------------------------------------------
# cleanup rules: To invoke this command, type "make clean".
# Use this target to clean up your directory, deleting (without warning) 
#   object files, old emacs source versions, and core dumps.

clean:
	rm -f *.o *~ core*

#----------------------------------------------------------------------------
# install shared eSpeakPackage to library directories
#    copy header file to include directory
#    make include file public
#    create static implementation file
#    copy static implementation to lib directory
#    make static copy public
#    create shared library
#    copy shared library to lib directory 
#    make shared library public
install/eSpeak:
	 cp eSpeakPackage.h $(ESPEAKINC)/eSpeakPackage.h
	 chmod 755 $(ESPEAKINC)/eSpeakPackage.h
	 $(CC) $(CFLAGS) -fPIC -c eSpeakPackage.c
	 cp eSpeakPackage.o $(ESPEAKLIB)/eSpeakPackage.o
	 chmod 755 $(ESPEAKLIB)/eSpeakPackage.o
	 $(CC) -dynamiclib  -o libeSpeakPackage.dylib eSpeakPackage.o
	 cp libeSpeakPackage.dylib $(ESPEAKLIB)/libeSpeakPackage.dylib
	 chmod 755 $(ESPEAKLIB)/libeSpeakPackage.dylib
