仙台の山奥で自転車に乗ったり転んだり

愛車の GIOS でサイクリングしたりポタリングしたり、それをブログに記録してみたり。ロードバイクや自転車や坂のことを書いてみたり。ときたまプログラムのことを忘れないようにメモってみたり。

苦し紛れにGDを手作業でコンパイル

リベンジで全てソースからコンパイルしてGD.pmをインストールしてみる。

zlibをインストール

$ cd ~
$ cd src
$ wget http://zlib.net/zlib-1.2.5.tar.gz
$ tar xzvf zlib-1.2.5.tar.gz 
$ cd zlib-1.2.5
$ ./configure --help
$ ./configure --prefix=/usr/local
$ make
$ sudo make install

libpngをインストール

$ cd ~
$ cd src
$ wget http://download.sourceforge.net/libpng/libpng-1.5.1.tar.gz
$ tar xzvf libpng-1.5.1.tar.gz 
$ cd libpng-1.5.1
$ ./configure --help
$ ./configure --prefix=/usr/local
$ make
$ sudo make install

libjpegをインストール

$ cd ~
$ cd src
$ wget http://www.ijg.org/files/jpegsrc.v8c.tar.gz
$ tar xzvf jpegsrc.v8c.tar.gz 
$ cd jpeg-8c
$ ./configure --help
$ ./configure --prefix=/usr/local
$ make
$ sudo make install

FreeType2をインストール
エラーが発生したからconfigファイルを書き換えてみたけど、同じエラーが発生するので意味がなかったぽい。(あきらめ)

$ cd ~
$ cd src
$ wget http://download.savannah.gnu.org/releases/freetype/freetype-2.4.4.tar.gz
$ tar xzvf freetype-2.4.4.tar.gz 
$ cd freetype-2.4.4
$ ./configure --help
$ ./configure --prefix=/usr/local
$ make
$ sudo make install
$ cd include/freetype/config
$ cp ftoption.h ftoption.h.org
$ vim ftoption.h
$ diff -c ftoption.h.org ftoption.h > ftoption.h.patch
$ cat ftoption.h.patch
*** ftoption.h.org	2011-02-08 16:34:20.000000000 +0900
--- ftoption.h	2011-02-08 16:43:41.000000000 +0900
***************
*** 496,502 ****
    /*   Do not #undef this macro here, since the build system might         */
    /*   define it for certain configurations only.                          */
    /*                                                                       */
! #define TT_CONFIG_OPTION_BYTECODE_INTERPRETER
  
  
    /*************************************************************************/
--- 496,502 ----
    /*   Do not #undef this macro here, since the build system might         */
    /*   define it for certain configurations only.                          */
    /*                                                                       */
! #undef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
  
  
    /*************************************************************************/

$ cd ~/src/freetype-2.4.4
$ make clean
$ ./configure --prefix=/usr/local
$ make
$ sudo make install
...
make: [install] Error 1 (ignored)
...

リンクも作成しておく。

$ sudo ln -s /usr/local/include/freetype2/freetype /usr/local/include/freetype

GD2をインストール

$ cd ~
$ cd src
$ wget http://www.libgd.org/releases/gd-2.0.35.tar.gz
$ tar xzvf gd-2.0.35.tar.gz 
$ cd gd-2.0.35
$ ./configure --help
$ ./configure --prefix=/usr/local
$ make
$ make test
$ sudo make install

で、cpanmからインストールしてみるも失敗……。

$ cpanm GD

ヘッダファイルがみつからな

** WARNING: found gd.h header file in /usr/local/includegd.h, but it is expected at /opt/local/include/gd.h. This may cause compile errors! **
** Possible problems found **

テストに失敗

Test Summary Report
-------------------
t/GD.t      (Wstat: 0 Tests: 12 Failed: 1)
  Failed test:  10
Files=2, Tests=13,  0 wallclock secs ( 0.03 usr  0.02 sys +  0.15 cusr  0.04 csys =  0.24 CPU)
Result: FAIL
Failed 1/2 test programs. 1/13 subtests failed.
make: *** [test_dynamic] Error 255

最後の手段、モジュールも手動でインストールしてみる。
探しにいくパスとかも手動で書き換えてみる。

$ cd ~/.cpanm/work/1297152091.60718
$ make clean
$ perl Makefile.PL 
$ cp Makefile Makefile.org
$ vim Makefile
$ diff -c Makefile.org Makefile > Makefile.patch
$ cat Makefile.patch 
$ cat Makefile.patch 
*** Makefile.org	2011-02-08 17:12:39.000000000 +0900
--- Makefile	2011-02-08 17:17:21.000000000 +0900
***************
*** 156,162 ****
  PARENT_NAME = 
  DLBASE = $(BASEEXT)
  VERSION_FROM = GD.pm
! INC =  -I/opt/local/include
  DEFINE =  -DHAVE_JPEG -DHAVE_FT -DHAVE_XPM -DHAVE_GIF -DHAVE_PNG -DHAVE_ANIMGIF -DVERSION_33 -DHAVE_UNCLOSEDPOLY -DHAVE_FONTCONFIG -DHAVE_FTCIRCLE
  OBJECT = $(BASEEXT)$(OBJ_EXT)
  LDFROM = $(OBJECT)
--- 156,162 ----
  PARENT_NAME = 
  DLBASE = $(BASEEXT)
  VERSION_FROM = GD.pm
! INC =  -I/opt/local/include -I/usr/include -I/usr/local/include -I/usr/local/include/gd
  DEFINE =  -DHAVE_JPEG -DHAVE_FT -DHAVE_XPM -DHAVE_GIF -DHAVE_PNG -DHAVE_ANIMGIF -DVERSION_33 -DHAVE_UNCLOSEDPOLY -DHAVE_FONTCONFIG -DHAVE_FTCIRCLE
  OBJECT = $(BASEEXT)$(OBJ_EXT)
  LDFROM = $(OBJECT)
***************
*** 315,324 ****
  # GD might depend on some other libraries:
  # See ExtUtils::Liblist for details
  #
! EXTRALIBS = -L/opt/local/lib -L/opt/local/lib -L/opt/local/lib -L/opt/local/lib -L/opt/local/lib -lXpm -lX11 -ljpeg -lfontconfig -lfreetype -lpng12 -lz -liconv -lgd
! LDLOADLIBS = -L/opt/local/lib -L/opt/local/lib -L/opt/local/lib -L/opt/local/lib -L/opt/local/lib -lXpm -lX11 -ljpeg -lfontconfig -lfreetype -lpng12 -lz -liconv -lgd
  BSLOADLIBS = 
! LD_RUN_PATH = /opt/local/lib
  
  
  # --- MakeMaker const_cccmd section:
--- 315,324 ----
  # GD might depend on some other libraries:
  # See ExtUtils::Liblist for details
  #
! EXTRALIBS = -L/opt/local/lib -L/usr/lib -L/usr/local/lib -L/usr/X11/lib -lXpm -lX11 -ljpeg -lfontconfig -lfreetype -lpng12 -lz -liconv -lgd
! LDLOADLIBS = -L/opt/local/lib -L/usr/lib -L/usr/local/lib -L/usr/X11/lib -lXpm -lX11 -ljpeg -lfontconfig -lfreetype -lpng12 -lz -liconv -lgd
  BSLOADLIBS = 
! LD_RUN_PATH = /opt/local/lib:/usr/lib:/usr/local/lib:/usr/X11/lib
    
  # --- MakeMaker const_cccmd section:
$ make
$ make test
$ sudo make install
$ perl -e 'use GD; print $GD::VERSION,"\n";'
2.45
$ perl -e 'use GD; print GD::Image->can("newFromPng") ? "OK\n": "NG\n";'
OK
$ perl -e 'use GD; print GD::Image->can("newFromJpeg") ? "OK\n": "NG\n";'
OK
$ perl -e 'use GD; print GD::Image->can("newFromGif") ? "OK\n": "NG\n";'
OK

あれ、やっぱりテストは成功しない……
あ、ローカルなのにsudoでインストールしちゃった。