# File:          Makefile
# Author:        Henry M. Walker
# Created:       20 September 2013
# Simplified:    22 September 2013
# Acknowledgements:  basic functionality adapted from an example 
#                       by Marge Coahran,
#                    installation functionality modeled by the MyroC Makefile
#                       by David Cowden and Dilan Ustek
#----------------------------------------------------------------------------
# Version details for MyroC

TARGET := MyroC
VERSION = 2
SUBVERSION = 4

#----------------------------------------------------------------------------
# Use the gcc compiler
CC = gcc

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

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

# Location to install the MyroC header and object file
MYROCINC = $(INSTALLPATH)/include/MyroC
MYROCLIB = $(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: eSpeakTest

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

eSpeakTest:  eSpeakTest.o eSpeakPackage.o 
	$(CC) -lespeak -o eSpeakTest eSpeakTest.o eSpeakPackage.o 

eSpeakTest.o:  eSpeakTest.c eSpeakPackage.h
	$(CC) $(CFLAGS) -c eSpeakTest.c

eSpeakPackage.o:  eSpeakPackage.c eSpeakPackage.h
	$(CC) $(CFLAGS) -c eSpeakPackage.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 MyroC and MyroCDev 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 eSpeak/eSpeakPackage.h $(ESPEAKINC)/eSpeakPackage.h
	 chmod 755 $(ESPEAKINC)/eSpeakPackage.h
	 $(CC) $(CFLAGS) -fPIC -c eSpeak/eSpeakPackage.c
	 cp eSpeak/eSpeakPackage.o $(ESPEAKLIB)/eSpeakPackage.o
	 chmod 755 $(ESPEAKLIB)/eSpeakPackage.o
	 $(CC) -shared -Wl,-soname,libeSpeakPackage.so -o libeSpeakPackage.so eSpeakPackage.o
	 cp libeSpeakPackage.so $(ESPEAKLIB)/libeSpeakPackage.so
	 chmod 755 $(ESPEAKLIB)/libeSpeakPackage.so

#----------------------------------------------------------------------------
# install new MyroCDev materials to MyroCDev 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
#    create symbolic links from MyroC to MyroC with version and subversion numbes
#    create symbolic link to bluetooth library
install/MyroC:
	 cp MyroC.h $(INSTALLPATH)/include/MyroC/MyroC.h.$(VERSION).$(SUBVERSION)
	 chmod 755 $(INSTALLPATH)/include/MyroC/MyroC.h.$(VERSION).$(SUBVERSION)
	 ln -sf $(INSTALLPATH)/include/MyroC/MyroC.h.$(VERSION).$(SUBVERSION) $(INSTALLPATH)/include/MyroC/MyroC.h.$(VERSION)
	 ln -sf $(INSTALLPATH)/include/MyroC/MyroC.h.$(VERSION) $(INSTALLPATH)/include/MyroC/MyroC.h
	 $(CC) -lbluetooth -fPIC -c MyroC.c
	 cp MyroC.o $(INSTALLPATH)/lib/MyroC.o.$(VERSION).$(SUBVERSION)
	 chmod 755 $(INSTALLPATH)/lib/MyroC.o.$(VERSION).$(SUBVERSION)
	 $(CC) -shared -Wl,-soname,libMyroC.so.$(VERSION).$(SUBVERSION) -o libMyroC.so.$(VERSION).$(SUBVERSION) MyroC.o
	 cp libMyroC.so.$(VERSION).$(SUBVERSION) $(MYROCLIB)/libMyroC.so.$(VERSION).$(SUBVERSION)
	 chmod 755 $(MYROCLIB)/libMyroC.so.$(VERSION).$(SUBVERSION)
	 ln -sf $(MYROCLIB)/libMyroC.so.$(VERSION).$(SUBVERSION) $(MYROCLIB)/libMyroC.so.$(VERSION)
	 ln -sf $(MYROCLIB)/libMyroC.so.$(VERSION) $(MYROCLIB)/libMyroC.so



#	 ln -s /usr/lib/x86_64-linux-gnu/libbluetooth.a $(INSTALLPATH)/lib/libbluetooth.a
#	 ln -s /usr/lib/x86_64-linux-gnu/libbluetooth.so $(INSTALLPATH)/lib/libbluetooth.so
