其实不怎么想继续写安装系列的文章了,但是这玩意安装的时候实在是坑太多,这里留下笔记。

1. 先了解下什么是emacs

GNU Emacs - GNU Project - Free Software Foundation (FSF)

2. 什么是emacspeak

Emacspeak --The Complete Audio Desktop

3. 我参考的安装手册

http://e-mac-speak.googlecode.com/svn/trunk/e-mac-speak-howto.org

下面是全文quote:

* Introduction

This document is a step by step guide showing how to configure emacspeak on a mac.  It includes installation of emacs, emacspeak and the e-mac-server.

These instructions are only one way to achieve the end result of having emacspeak working on a mac.  This is the way I found worked best for me.  For example I have chosen to use "brew" to install emacs, I had no luck with the seemingly popular "macports".  Your mileage may vary.

I have also made assumptions about file paths, feel free to put things where it feels most comfortable.  

I welcome any updates to this document and or questions or issues found when following these instructions.

* Prerequisites

- A mac running a recent version of os x.  I used snow leopard 10.6.7.
- An internet connection so we can download all the required bits.

The version of emacs shipped with snow leopard (22.1) is not recent enough.  We will be installing emacs 24.  It also appears that the emacs shipped with snow leopard only runs in the terminal and not as a standalone app. 

* XCODE4 
To be able to build packages using homebrew you will need to have apple xcode installed.  If you are an apple developer it is a free download or can be purchased for around $5 from the mac appstore if you are not.

It can be installed from the mac app store.

Here is a link to the relevant apple developer page:
http://developer.apple.com/xcode/

It is a rather large download of about 4 gig so may take some time to install depending on your Internet connection speed.

* Homebrew

Homebrew is a package management system for installing unix programs on mac.  You can read all about it at the below URL or the blog post sighted in the following text: 
https://github.com/mxcl/homebrew

These instructions are mostly taken from the blog post at:
http://www.engineyard.com/blog/2010/homebrew-os-xs-missing-package-manager/

To install homebrew, from the terminal run the following commands.  I suggest that if you are at all worried checkout the script that is being run by the curl command so as to not install anything on your system that may be in any way suspicious  .

#Note: I had to create the /usr/local directory on my mac which isn't in the blog post.
# create /usr/local if it doesn't already exist
sudo mkdir -p /usr/local
# Take ownership of /usr/local so you don't have to sudo
sudo chown -R `whoami` /usr/local
# Fix the permissions on your mysql installation, if you have one
sudo chown -R mysql:mysql /usr/local/mysql*
# Download and install Homebrew from github
curl -L http://github.com/mxcl/homebrew/tarball/master | tar xz --strip 1 -C /usr/local

Once this is complete you should now have the "brew" program in your path.

If typing "brew" at the terminal prompt gives a "command not found" error investigate if "/usr/local/bin" is in your PATH environment variable.

If everything has worked up to this point typing "brew" should display an example usage message.

* Install git

Next we will install git as it is required to be able to update homebrew itself as well as to install many homebrew formula.

From the terminal:

brew install git

* Install emacs

This installs the current development branch of emacs24 from  repo.or.cz.

It may be possible to use other emacson such as aquamax or other distributions specifically for the mac.  I had no luck doing so and this was the way that worked for me.

If anyone else is using a different emacs I would love to hear about it so I can add aditional install options here.

To install using brew, issue the following command from the terminal: 
brew install emacs --HEAD --use-git-head --cocoa

You will need to have added /usr/local/bin to the beginning of your PATH environment variable otherwise the shell will find the apple supplied version of emacs.

You can check this has worked by issueing the following command at the terminal:

which emacs

It should report /usr/local/bin/emacs 

* Install emacspeak

We will keep emacspeak in a directory ~/src/emacspeak
# create the ~/src dir if it doesn't exist
mkdir -p ~/src
# changedir to ~/src
cd ~/src
# checkout a copy of emacspeak from the google svn repository
svn co http://emacspeak.googlecode.com/svn/trunk emacspeak

cd emacspeak
make config
make emacspeak

* E-Mac-Speak server prerequisites

You will need to install sox and the pysox library.  These are used to provide extra filters on the tts.  As the set of parameters  available with mac tts engines is limited.

Feedback on this process is most welcome as it's written from memory.

To install sox:
brew install sox

To install pysox:
sudo easy_install pyrex
sudo easy_install pysox

* Test the e-mac-speak server

Before trying to run emacspeak itself we need to verify that the e-mac-speak server is working.

To do this, from the terminal:

# Change to the emacspeak servers directory
cd ~/src/emacspeak/servers
# run the e-mac-speak server
./mac

At this point you should hear the words "emacspeak server" spoken.

If not then we have a problem.

To speak some text enter the following lines.

q {This is a test.}
d

You should hear the words "This is a test."

If all goes well move on to the next step.  If not troubleshoot the issue until the above steps work.

* Emacs initialization

To get emacs to start up loading emacspeak with the e-mac-speak server place the following in your .emacs.d/init.el file.

This is the minimum required to ensure that emacspeak comes up talking.  You will want to investigate further customizations of both emacs and emacspeak as you progress.

You will also want to ajust the paths to reflect where you installed emacspeak.

(setq load-path (cons "~/src/emacspeak/lisp" load-path))
(setq emacspeak-directory "~/src/emacspeak")
(setq dtk-program "mac")
(load-file "~/src/emacspeak/lisp/mac-voices.el")
(setq mac-default-speech-rate 500)
(load-file "~/src/emacspeak/lisp/emacspeak-setup.el")

A good place to look for emacspeak customizations is in the "tvr" directory of the emacspeak source.  This is Raman's emacs customizations.

fixme
* pysox

To compile pysox you will need the sox headers and libraries installed.  They can be installed with:
brew install sox

You can download the pysox package from:
http://pypi.python.org/pypi/pysox

I have found it does not build cleanly for me.

This is how I got it built and installed.

First I run:
python setup.py build
as per the README.

This will fail.
I then took the two build lines and ran them by hand.  On each line I removed the --arch i386.

So the two build lines I ended up with were:
llvm-gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch x86_64 -pipe -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c pysox/combiner.c -o build/temp.macosx-10.7-intel-2.7/pysox/combiner.o
llvm-gcc-4.2 -Wl,-F. -bundle -undefined dynamic_lookup -Wl,-F. -arch x86_64 build/temp.macosx-10.7-intel-2.7/pysox/combiner.o -lsox -o build/lib.macosx-10.7-intel-2.7/pysox/combiner.so

After running these two commands I then was able to run the build again:

python setup.py build
Then to install 
python setup.py install

4. MacPort和Homebrew的差别

因为这篇文章使用的是homebrew这个工具,和我现在在使用的macport非常不同,这里简单介绍下不同点:

MacPort:

macports的工作方式是下载source code然后在本地编译。macport的理念是尽量减少对系统现有库的依赖。
所以,第一次用macport的时候,需要很长时间让macport重新build整个基本库,什么perl啊,python啊的。

代价是较长的编译时间,较多的依赖关系下载。好处是不怎么依赖系统,也就是说,更新Mac OS不会破坏你现有的
package。

另外,macports安装所有的package到/opt/local下面。这样不会和系统现有的/usr/local有什么冲突。

Homebrew:

这个比较新,是在Lion之后才兴起的。
工作方式和macport类似,也是下载source并在本地编译安装。但是和macports有两个根本的区别。

  1. homebrew的理念是尽量使用系统现有的库。这样可以大大的减少编译时间。
  2. package都安装到/usr/local下面。

这两点和macports是完全相反的。结果也是有利有弊。

最大的好处莫过于编译时间变短,安装简单。问题就是和系统紧密依赖。

另外Homebrew假设你的Mac是单用户系统,所以/usr/local的owner应该是你,而不是传统的root。
这个假设在大多数情况下都成立。 (当然你可以改变homebrew的安装路径,然后修改你的PATH)

另外,一个不太重要的区别,macport是用rsync来同步repository tree和获取新的package的。 homebrew是用git来管理repository的。 如果你是在内部网或者firewall后通过proxy使用,这点可能会给你带来影响--一些proxy不支持rsync的。

总结:
  1. 如果你是重量级的Linux用户,希望使用所有的open source package,那么macports是你不二的选择。
  2. 如果你只希望很快的安装一些便利的工具,那么homebrew是个不错的选择。

看完上面的内容你应该就明白了,使用homebrew的时候,安装的sox和python包等,都是安装在/usr/local下面的,在进行emacspeak的包安装的时候不会出现依赖找不到的问题,而使用macport的时候就会出现问题了。

不过实际上我在安装的时候遇到的问题不多。

5. 我的安装步骤

  • XCode肯定是没问题的,我早安装好了
  • Homebrew这步直接跳过
  • git也早就安装好了
  • emacs本体使用macport安装:sudo port -v install emacs
  • emacspeak的安装也是按照介绍的方法安装:拿到源代码,然后make等,细节看上面的guide
  • sox使用macport安装:sudo port -v install sox

步骤到这步都没问题,问题是在下面的python包,pyrex和pysox上。

6. 问题

这里要说明下我安装时候的机器环境问题。因为MAC是默认整合python的,所以我以前使用macport安装的python2.7一直都没有启用(默认的path里的是系统安装的python),这我也是在装这个东西的时候才发现的。

所以理所当然的,所有的python相关的工具和环境都是系统默认的,这在安装本文讨论的emacspeak的时候倒是正好。

安装pyrex的时候,sudo easy_install pyrex,轻松就过了。

但是在安装pysox的时候,sudo easy_install pysox,报编译错误了:

sox.h not found

没办法,想到的解决方案就是自己下载pysox的源码,把sox.h这个文件从别的地方补进去。

pysox的官网在:https://pypi.python.org/pypi/pysox

下载链接:https://pypi.python.org/packages/source/p/pysox/pysox-0.3.6.alpha.tar.gz

下载下来解压,然后去下载sox源码,找sox.h文件。

sox的官网在:http://sox.sourceforge.net/

下载页面在:http://sourceforge.net/projects/sox/files/sox/

然后把sox源码包下的src/sox.h,拷贝到pysox源码包下的pysox/sox.h。

然后去pysox的源码包根目录下运行:python ./setup.py build

发现又报错:

22 warnings generated.
clang -bundle -undefined dynamic_lookup -Wl,-F. -arch i386 -arch x86_64 build/temp.macosx-10.8-intel-2.7/pysox/sox.o -lsox -o build/lib.macosx-10.8-intel-2.7/pysox/sox.so
ld: library not found for -lsox
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command 'clang' failed with exit status 1

这是因为sox我们是使用macport安装的,系统的python是在/usr/local下查找编译后的lib的,所以找不到,解决方法就是做个软连接到/usr/local下:

sudo ln -s /opt/local/lib/libsox.a /usr/lib/libsox.a

事后记得删除。

再运行:python ./setup.py build

继续报错:

2 warnings generated.
clang -bundle -undefined dynamic_lookup -Wl,-F. -arch i386 -arch x86_64 build/temp.macosx-10.8-intel-2.7/pysox/combiner.o -lsox -o build/lib.macosx-10.8-intel-2.7/pysox/combiner.so
ld: warning: ignoring file /usr/lib/libsox.a, file was built for archive which is not the architecture being linked (i386): /usr/lib/libsox.a

将上面的命令中的 -arch i386删除,再运行:python ./setup.py build

下面列出来的o文件就应该都准备好了:

Jonathan-MBP-2:pysox-0.3.6.alpha jonathan$ ll build/temp.macosx-10.8-intel-2.7/pysox/
total 3200
drwxr-xr-x 5 jonathan staff 170B 6 28 15:12 ./
drwxr-xr-x 3 jonathan staff 102B 6 27 22:22 ../
-rw-r--r-- 1 jonathan staff 303K 6 28 15:12 combiner.o
-rw-r--r-- 1 jonathan staff 205K 6 28 15:12 customeffects.o
-rw-r--r-- 1 jonathan staff 1.1M 6 28 11:07 sox.o

这次应该没问题了,运行:python ./setup.py install

Jonathan-MBP-2:pysox-0.3.6.alpha jonathan$ sudo python setup.py install
Building without Cython
running install
running build
running build_py
running build_ext
running install_lib
creating /Library/Python/2.7/site-packages/pysox
copying build/lib.macosx-10.8-intel-2.7/pysox/__init__.py -> /Library/Python/2.7/site-packages/pysox
copying build/lib.macosx-10.8-intel-2.7/pysox/combiner.so -> /Library/Python/2.7/site-packages/pysox
copying build/lib.macosx-10.8-intel-2.7/pysox/csox.pxd -> /Library/Python/2.7/site-packages/pysox
copying build/lib.macosx-10.8-intel-2.7/pysox/customeffects.so -> /Library/Python/2.7/site-packages/pysox
copying build/lib.macosx-10.8-intel-2.7/pysox/sox.pxd -> /Library/Python/2.7/site-packages/pysox
copying build/lib.macosx-10.8-intel-2.7/pysox/sox.so -> /Library/Python/2.7/site-packages/pysox
copying build/lib.macosx-10.8-intel-2.7/pysox/SoxApp.py -> /Library/Python/2.7/site-packages/pysox
byte-compiling /Library/Python/2.7/site-packages/pysox/__init__.py to __init__.pyc
byte-compiling /Library/Python/2.7/site-packages/pysox/SoxApp.py to SoxApp.pyc
running install_egg_info
Writing /Library/Python/2.7/site-packages/pysox-0.3.6.alpha-py2.7.egg-info
---