# Location to install the eSpeackPackage header and object file to.. #
INSTALLPATH = /usr/local
# the followng path is used for installation on MathLAN at Grinnell College
#INSTALLPATH = /home/walker/MyroC
#INSTALLPATH = ./practice

ESPEAKINC = $(INSTALLPATH)/include
ESPEAKLIB = $(INSTALLPATH)/lib
ESPEAKBIN = $(INSTALLPATH)/bin

CC = gcc

CFLAGS = -lespeak -DBIN_DIRECTORY='"$(ESPEAKBIN)"'
LDFLAGS = -L$(ESPEAKLIB) -leSpeakPackage

# Since eSpeak can be misused by remote loggins, the eSpeaPackage can beinstalled
# in either of two modes:
#   1.  in a lab environment, in which users are authorized to log into multiple workstations
#   2.  on a private computer, in which only the owner has an account
#
# To anticipate troubles with eSpeak in the lab environment, a parameter "computer=shared"
#   can be included as a parameter to prevent remote the use of the eSpeakPackage
#   from remote loggins.  Thus,
#       make computer=shared install/espeak
#   will install the eSpeakPackage in a behind-the-scenes check that the user is
#   is not logged in remotely.  In contrast,
#       make install/espeak
#   installs the eSpeakPackage without the overhead from this login check.
#
#----------------------------------------------------------------------------
# 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-----install/espeak-----install/espeak-----install/espeak---
install/espeak:
	mkdir -p $(ESPEAKINC)
	mkdir -p $(ESPEAKBIN)
	mkdir -p $(ESPEAKLIB)
	cp eSpeakPackage.h $(ESPEAKINC)/eSpeakPackage.h
	chmod 755 $(ESPEAKINC)/eSpeakPackage.h
# compile, based on the "computer=shared" command-line parameter
ifeq ($(computer), shared)
	$(CC) $(CFLAGS) -DCOMPUTER_SHARED -fPIC -c eSpeakPackage.c
else
	$(CC) $(CFLAGS) -fPIC -c eSpeakPackage.c
endif
	cp 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
	$(CC) -I$(ESPEAKINC) -o textlines-to-speech textlines-to-speech.c -lespeak
	cp textlines-to-speech $(ESPEAKBIN)/textlines-to-speech
	chmod 755 $(ESPEAKBIN)/textlines-to-speech
ifeq ($(computer), shared)
	cp startPulseAudio  $(ESPEAKBIN)/startPulseAudio
	chmod 755 $(ESPEAKBIN)/startPulseAudio
	cp stopPulseAudio  $(ESPEAKBIN)/stopPulseAudio
	chmod 755 $(ESPEAKBIN)/stopPulseAudio
 endif
