FPCのインストールと開発版のビルド

FreePascalのインストールと開発版(2.7.x)のビルド手順についてメモ書き。
環境はUbuntu12.04 64bit。

Ubuntuのパッケージを使う場合

Ubuntuのaptでインストールできるパッケージは2.4.4と少し古い。このバージョンをインストールする場合はfp-compiler-2.4.4(コンパイラのみ)かfpc-2.4.4(全部入りのメタパッケージ)を指定する。

$ sudo aptitude install fpc-2.4.4

最新の安定版(2.6.0)のインストール

Free Pascalのダウンロードページから2.6.0のバイナリをダウンロードする。
Free Pascal - Download
今回は環境に合わせてx86_64のLinux用のtarアーカイブをダウンロードした。
aptでインストールした2.4.4を置き換えたくなかったので、ホームディレクトリにインストールする。
tarを展開し、その中のinstall.shを実行する。インストール先やライブラリ、パッケージ、ドキュメント、デモをインストールするかを聞かれるのでY/nで選択する。

$ tar xf fpc-2.6.0.x86_64-linux.tar
$ cd fpc-2.6.0.x86_64-linux
$ ./install.sh
This shell script will attempt to install the Free Pascal Compiler
version 2.6.0 with the items you select

Install prefix (/usr or /usr/local)  [/home/tokibito/fpc-2.6.0] : 
Installing compiler and RTL for x86_64-linux...
Installing utilities...
Install Textmode IDE (Y/n) ? n
Install FCL (Y/n) ? Y

(中略)

Install packages (Y/n) ? Y

(中略)

Install documentation (Y/n) ? Y
Installing documentation in /home/tokibito/fpc-2.6.0/share/doc/fpc-2.6.0 ...
Done.

Install demos (Y/n) ? n

Running on linux
No write premission in /etc.
Writing sample configuration file to /home/tokibito/.fpc.cfg

End of installation.

Refer to the documentation for more information.

これでインストールは完了となる。

$ ~/fpc-2.6.0/bin/fpc
Free Pascal Compiler version 2.6.0 [2011/12/23] for x86_64
Copyright (c) 1993-2011 by Florian Klaempfl and others
/home/tokibito/fpc-2.6.0/lib/fpc/2.6.0/ppcx64 [options] <inputfile> [options]
(以下略)

必要に応じてPATHの設定をして使用する感じ。

開発版(2.7.1)のビルド

FreePascalの開発版のソースコードは、DEVELOPMENTページからダウンロードできる。
Free Pascal - Development
fpcbuild.zipをダウンロードしてunzipし、make linuxでビルド、インストールする。
開発版のビルドにはFPC2.6.0が必要なので、前述のインストールしたパスを指定する。
インストール先はINSTALL_PREFIXで指定できる。

$ unzip fpcbuild.zip
$ cd fpcbuild/
$ INSTALL_PREFIX=/home/tokibito/fpc-dev PATH=/home/tokibito/fpc-2.6.0/bin/:$PATH make linux

makeを実行した際に、以下のエラーが出る場合は、aptでlibgdb-devを入れておくかNOGDB=1を指定する。

Makefile:2223: *** No libgdb.a found, supply NOGDB=1 to disable debugger support.  Stop.

これで/home/tokibito/fpc-dev以下にビルドされたバイナリが配置された状態になる。
この状態では、コンパイラの実行ファイル本体(ppcx64)がbin以下になく、他のバージョンが参照されてしまうので、シンボリックリンクを作成する。

$ cd ~/fpc-dev/bin/
$ ln -s ../lib/fpc/2.7.1/ppcx64

これでfpc-dev/bin/fpcから開発版を使用できるようになる。

$ ~/fpc-dev/bin/fpc
Free Pascal Compiler version 2.7.1 [2013/01/13] for x86_64
Copyright (c) 1993-2012 by Florian Klaempfl and others
/home/tokibito/fpc-dev/bin/fpc [options] <inputfile> [options]
(以下略)