$OpenBSD: patch-src_Makefile,v 1.10 2013/03/27 15:33:32 ajacoutot Exp $
--- src/Makefile.orig	Mon Mar 18 01:51:31 2013
+++ src/Makefile	Wed Mar 27 16:10:39 2013
@@ -1,8 +1,8 @@
 # remove -fno-exceptions  if it causes problems with stdio library on some platforms (ARM)
 
-DATADIR=/usr/share/espeak-data
+DATADIR=$(PREFIX)/share/espeak-data
 
-PREFIX=/usr
+PREFIX ?=/usr
 BINDIR=$(PREFIX)/bin
 INCDIR=$(PREFIX)/include/espeak
 LIBDIR=$(PREFIX)/lib
@@ -12,9 +12,11 @@ BIN_NAME = speak
 BIN2_NAME = espeak
 LIB_NAME = libespeak.so
 STATIC_LIB_NAME = libespeak.a
-LIB_VERSION = 1
-LIBTAG = $(LIB_VERSION).$(RELEASE)
+LIB_VERSION = ${LIBespeak_VERSION}
+LIBTAG = $(LIB_VERSION)
 
+LPATH= -L${LOCALBASE}/lib -Wl,-R${LOCALBASE}/lib
+
 # Use SONAME_OPT=-Wl,h, on Solaris
 SONAME_OPT=-Wl,-soname,
 
@@ -45,7 +47,7 @@ USE_AUDIO=-DUSE_PULSEAUDIO
 else
 ifeq ($(AUDIO),portaudio)
 WAVE=wave.cpp
-LIB_AUDIO=-lportaudio
+LIB_AUDIO=-L$(LOCALBASE)/lib -lportaudio
 USE_AUDIO=-DUSE_PORTAUDIO
 else
 ifeq ($(AUDIO),portaudio0)
@@ -91,9 +93,8 @@ LIBS2=-lstdc++ $(LIB_AUDIO) -lpthread
 
 SRCS3 = espeak.cpp
 OBJS3=$(patsubst %.cpp,%.o,$(SRCS3))
-LIBS3=-lstdc++ -L . -lespeak
+LIBS3=-lstdc++ -L . -lespeak -L${LOCALBASE}/lib
 
-CXXFLAGS=-O2
 
 
 all: $(BIN_NAME) $(LIB_NAME) $(STATIC_LIB_NAME) $(BIN2_NAME)
@@ -102,7 +103,7 @@ all: $(BIN_NAME) $(LIB_NAME) $(STATIC_LIB_NAME) $(BIN2
 	$(CXX) $(CXXFLAGS) $(USE_AUDIO) -D PATH_ESPEAK_DATA=\"$(DATADIR)\" -Wall -pedantic -I. -c -fno-exceptions  $<
 
 $(BIN_NAME): $(OBJS1)
-	$(CXX) $(LDFLAGS) -o $@ $(OBJS1) $(LIBS1)
+	$(CXX) $(LDFLAGS) -o $@ $(EXTRA_FLAGS) $(OBJS1) $(LIBS1)
 
 $(BIN2_NAME): $(OBJS3) $(LIB_NAME)
 	$(CXX) $(LDFLAGS) -o $@ $(OBJS3) $(LIBS3)
@@ -110,15 +111,13 @@ $(BIN2_NAME): $(OBJS3) $(LIB_NAME)
 
 
 x_%.o: %.cpp
-	$(CXX) $(CXXFLAGS) $(USE_AUDIO) -D PATH_ESPEAK_DATA=\"$(DATADIR)\" -Wall -fpic -fvisibility=hidden -pedantic \
+	$(CXX) $(CXXFLAGS) $(USE_AUDIO) -D PATH_ESPEAK_DATA=\"$(DATADIR)\" -Wall -fPIC -DPIC -pedantic \
 	-I. -D LIBRARY -c -fno-exceptions  $<  -o x_$*.o
 
 $(LIB_NAME): $(OBJS2)
-	$(CXX) $(LDFLAGS) -shared $(SONAME_OPT)$(LIB_NAME).$(LIB_VERSION) -o $@ \
-	$(OBJS2) $(LIBS2)
+	$(CXX) $(LDFLAGS) -shared -fPIC -o $@ \
+	$(OBJS2) $(LIBS2) $(EXTRA_FLAGS)
 	mv $(LIB_NAME) $(LIB_NAME).$(LIBTAG)
-	$(LN_SF) $(LIB_NAME).$(LIBTAG) $(LIB_NAME).$(LIB_VERSION)
-	$(LN_SF) $(LIB_NAME).$(LIB_VERSION) $(LIB_NAME)
 
 $(STATIC_LIB_NAME): $(OBJS2)
 	$(AR) cqs $(STATIC_LIB_NAME) $(OBJS2)
@@ -144,10 +143,8 @@ install: all
 	$(INSTALL) -m 755 $(LIB_NAME).$(LIBTAG) $(DESTDIR)$(LIBDIR)
 	# Install static library
 	$(INSTALL) -m 755 $(STATIC_LIB_NAME) $(DESTDIR)$(LIBDIR)
-	$(LN_SF) $(LIB_NAME).$(LIBTAG) $(DESTDIR)$(LIBDIR)/$(LIB_NAME).$(LIB_VERSION)
-	$(LN_SF) $(LIB_NAME).$(LIB_VERSION) $(DESTDIR)$(LIBDIR)/$(LIB_NAME)
 	# Install development headers
 	$(INSTALL) -pm 644 speak_lib.h $(DESTDIR)$(INCDIR)
 	# Install data files
-	cp -prf ../espeak-data/* $(DESTDIR)$(DATADIR)
+	cp -pRf ../espeak-data/* $(DESTDIR)$(DATADIR)
 
