# File:          Makefile-windows-implementation-espeak
#
# Makefile to compile and install eSpeakPackage on a Windows platform
# To utilize, issue the following command to make an appropriate symbolic link
#
# Author:        Henry M. Walker
# Created:       20 September 2013
# Simplified:    28 August 2015
# Revised for Windows:  19-20 November 2020, 23 April 2021
# 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/

#----------------------------------------------------------------------------
# Version details for MyroC

TARGET := MyroC
VERSION = 3
SUBVERSION = 3

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

# Set compilation flags
CFLAGS =  -Wall -Wno-deprecated-declarations -lWs2_32 -pthread
ESPEAKFLAGS = -leSpeakPackage 
MYROCFLAGS = -lMyroC

# Locations to install the eSpeakPackage header and object file
# do NOT include space characters in the INSTALLPATH !!!
INSTALLPATH = /usr/local
ESPEAKINC = $(INSTALLPATH)/include
ESPEAKBIN = $(INSTALLPATH)/bin


#----------------------------------------------------------------------------
# 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 *.a *.so *~ core*

#----------------------------------------------------------------------------
# install shared eSpeakPackage to MyroC library directory
#      basic reference for files:
#      https://forums.ni.com/t5/LabVIEW/create-a-dll-for-windows-with-gcc/td-p/332736?profile.language=en
#    copy header file to include directory
#    compile implementation file to dynamic .o file
#    form dynamic .o files to dynamicly linked .dll file
#    copy .dll file to shared library directory
#    Note:  use /.../bin directories for dynamic .dll files
#           use /.../lib directories for static .d...a files

install/eSpeak:
	# copy eSpeakPackage header file to include directory
	mkdir -p $(ESPEAKINC)   #-p creates directory/path if it does not already exist
	cp eSpeakPackage.h $(ESPEAKINC)/eSpeakPackage.h
	chmod 755 $(ESPEAKINC)/eSpeakPackage.h

	# compile eSpeakPackage implementation file
	$(CC) $(CFLAGS) -fPIC -c eSpeakPackage-windows.c
	mv eSpeakPackage-windows.o eSpeakPackage.o
	gcc -shared -o eSpeakPackage.dll -Wl,--out-implib,libeSpeakPackagedll.a eSpeakPackage.o $(LDFLAGS)

	# copy .dll file to shared library directory
	mkdir -p $(ESPEAKBIN)   #-p creates directory/path if it does not already exist
	cp eSpeakPackage.dll $(ESPEAKBIN)
	chmod 755 $(ESPEAKBIN)/eSpeakPackage.dll

