在 Snow Leopard 上编译 php-5.2.8

Snow Leopard 中带的 PHP 是 5.3 的,有点太超前了,还是 php-2.x 用着比较习惯,不过 2.x 版的 php 在 SL 中编译起来有点麻烦,需要手工改 Makefile 才能正确编译(主要就是 libiconv 这个库的问题)。

折腾到半夜,终于搞定了,记录一下:

1. 先用 port 安装一些依赖的库
sudo port -v install t1lib jpeg libpng libmcrypt libxml2 gettext curl

2. configuration
CFLAGS="-arch x86_64 -I/opt/local/include/" LDFLAGS="-L/opt/local/lib" \
./configure --prefix=/usr/local/php \
--with-apxs2=/usr/local/apache/bin/apxs \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--with-openssl=shared,/usr \
--with-zlib=/usr \
--with-zlib-dir=/usr \
--with-xpm-dir=shared,/usr \
--with-gd \
--with-ldap=shared \
--with-xmlrpc \
--enable-exif \
--enable-soap=shared \
--enable-sqlite-utf8 \
--enable-wddx=shared \
--enable-ftp=shared \
--enable-sockets \
--with-bz2=shared,/usr \
--enable-zip=shared \
--enable-pcntl \
--enable-shmop \
--enable-sysvsem=shared \
--enable-sysvshm=shared \
--enable-sysvmsg=shared \
--enable-mbstring \
--enable-bcmath \
--with-libxml-dir=/opt/local \
--with-xsl=/opt/local \
--with-gettext=/opt/local \
--with-png-dir=/opt/local \
--with-jpeg-dir=/opt/local \
--enable-gd-native-ttf \
--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-pdo-mysql=/usr/local/mysql \
--with-mcrypt=/opt/local \
--with-iconv=/opt/local \
--with-t1lib=/opt/local \
--with-curl=/opt/local \
--with-snmp=shared
--enable-cli \
--enable-cgi \
--enable-fastcgi \
--enable-force-cgi-redirect \

3. hack
修改Makefile

(line 19) MH_BUNDLE_FLAGS=... 在 -L/usr/lib 前面添加 -L/opt/local/lib
(line 130) 在EXTRA_LIBS=... 最后添加 -lresolv

4. build
make && make install

在Archlinux上配置Latex+CJK

最近学着用Latex,边看书边用Latex来做读书笔记。当然,要用上Latex,首先就要安装和配置它。
单纯安装Latex是比较简单的,在Arch上直接安装texlive就行了。

# pacman -S texlive-core texlive-bin texlive-langcjk texlive-latex3 texlive-latexextra

如果没有什么特殊需求,上面那几个包就足够了,安装完成之后记得重启一次机器。重启之后,Latex就可以用了,你可以编辑一个简单的tex文件来测试一下:

% hello.tex
\documentclass{article}
\begin{document}
Hello Latex!
\end{document}

然后用 pdflatex hello.tex 来直接编译成pdf文件,然后可以通过pdf查看器来看一下自己的成果 :-)

到目前为止,Latex已经可以用来做英文的写作了,但如果想做中文的内容的话还需要再做一点努力。
目前Tex处理中文的解决方案主要有以下三种:

  1. Latex + CJK
  2. XeTex
  3. ConTex + LuaTex

第一种应该是用的最广泛的,但需要手动生成Tex使用的字体
XeTex可以直接使用系统的字体,也是比较好的选择
对第三种我不太了解

我目前用的是第一种方案,因此需要自己生成一些供Tex使用的中文字体,网上也有现成的字体可用,比如YueWang做的那个中文字体包。
不过当我把YueWang的那个字体下载下来之后,发现这些字体在我的电脑上表现的不好,字体很虚而且字的周围会有杂色。

没办法,只能自己动手编译字体了,从网上找了两篇文章看了看,花了半个下午的时间编译了几种字体(字体编译的速度挺慢的)。
具体编译字体的过程可以参考下面这两篇文章:

在Ubuntu下简易配置Tex UTF-8中文环境

TeXLive 2007 CJK Chinese Howto

我把编译字体的过程写成了个脚本,方便使用,可以在这里下载

下载解压之后,就可以开始编译字体了:

首先把要编译的字体放到解压后的目录里,

cp /path/to/font/wqy-zenhei.ttf  /path/to/font/complie/dir

然后执行 makefont.sh 这个脚本就可以了

./makefont.sh wqy-zenhei.ttf wqyzh

经过漫长的等待之后,字体就编译好了,然后记得执行一下下面的命令来更新字体映射信息:

sudo texhash
updmap --enable Map wqyzh.map