GTK+-2.14.6 / Win32 cross build environment on MacOS X

I also have to have GTK/Windows building environment… I have an old one on my MacBook, but I decided to make a new environment on my MacBook (with Leopard / Core2Duo processor) from scratch.
[ Prepare ]
Here’s what I’ve downloaded.
– MinGW runtime (mingwrt-3.15.1-mingw32.tar.gz)
– MinGW Win32 API (w32api-3.13-mingw32-dev.tar.gz)
– Win32 developer’s all-in-one bundle from GTK Website here.
– binutils-2.19.tar.bz2, gcc-core-4.2.4.tar.bz2, gcc-g++-4.2.4.tar.bz2
[ Unpack basic packages ]
% cd mingw
% tar xzf archives/mingwrt-3.15.1-mingw32.tar.gz
% tar xzf archives/w32api-3.13-mingw32-dev.tar.gz
[ Unpack GTK ]
% mkdir GTK
% cd GTK
% unzip ../archives/gtk+-bundle_2.14.6-20081216_win32.zip
Fix pkg-config .pc files for my directory configuration:
% cd GTK/lib/pkgconfig
% foreach i ( *.pc )
foreach? sed -e “/^prefix/c\\
prefix=/Users/yasu/mingw/GTK” -i \~ $i
foreach? end
[ build binutils ]
I did this at outside my mingw root.
% mkdir build-binutils-2.19
% cd build-binutils-2.19/
% ../binutils-2.19/configure –prefix=/Users/yasu/mingw –target=i386-pc-mingw32
% make && make install
[ build gcc + g++ ]
% mkdir build-gcc-4.2.4
% cd build-gcc-4.2.4
% ../gcc-4.2.4/configure –program-prefix=i386-pc-mingw32- –program-suffix=-4.2.4 –with-gcc –with-gnu-ld –with-gnu-as –target=i386-pc-mingw32 –prefix=/Users/yasu/mingw –enable-threads –disable-nls –enable-languages=c,c++ –disable-win32-registry –disable-shared –enable-sjis-exceptions –with-headers=/Users/yasu/mingw/include –with-libs=/Users/yasu/mingw/lib –with-build-time-tools=/Users/yasu/mingw/bin
% make && make install
This may require automake, autoconf and bison. I have them build with MacPorts.
I hope all these stuff work, but I’m not tested yet.

GTK+-2.4.16 Universal Package: Now trying again.

Now try with native 10.4/ppc & 10.4/i386 Macs. Thanks to Prof. Sakakibara: he’s contributed a CoreDuo Mac for my software development.
[ Contents ]
Here’s the list of what I’ve downloaded (most links are to Japanese mirrors).
pkg-config-0.23
libiconv-1.12
gettext-0.17
libxml2-2.6.30
glib-2.18.3
atk-1.25.2
libpng-1.2.34
jpeg.v6b
tiff-3.8.2
pixman-0.13.2
freetype-2.3.7
fontconfig-2.6.0
renderext-0.9
renderproto-0.9.3
libXrender-0.9.4
libXft-2.1.13
cairo-1.8.6
jasper-1.900.1
pango-1.22.4
gtk+-2.4.16
[ Patches & Workarounds ]
jpeg & jasper: included libtool is too old… replacing by libtool bundled in MacOS X.
% cp /usr/bin/glibtool libtool
% ./configure (maybe we don’t need this)
% ./configure –enable-shared –prefix=/opt/gtk
It is reasonable that jpeg.v6b includes an old libtool, but I can’t understand why jasper has…
libXrender: MacOS X 10.4 doesn’t provide x11.pc nor xproto.pc. Also it doesn’t have Xregion.h (but MacPorts has).
% sed -i \~ -e “/Requires.private: x11/d;s/ *x11//g;s/ *xproto//g;/^Cflags/s/$/ -I\/usr\/X11R6\/include/;/^Libs/s/$/ -L\/usr\/X11R6\/lib -lX11/” xrender.pc.in
% cp /opt/local/var/macports/sources/rsync.macports.org/release/ports/x11/xrender/files/include/X11/Xregion.h /opt/gtk/include/X11
I’ve already wrote an automated script to build them all, and trying to extend it to an automated “universal” build script.
More to come soon!

Build Universal GTK+-2 Package for Mac

** I’ve given up to build 10.4u libraries on 10.5… This article is not completed. **
I’m trying to build a universal GTK+ package for MacOS X 10.4 & 10.4, to release my software. This article is the build log from scratch. My current environment is a PPC Mac mini, running MacOS X 10.4 + XCode 2.5.
Note for Leopard macs: According to an article in Apple mailing list, “-mmacosx-version-min=10.4” is necessary to avoid linking libcrt1.10.5.o when using “-isysroot /Developer/SDKs/MacOSX10.4u.sdk”. However, I’ve given up to build on a Leopard/Intel MacBook because GTK+ can’t be built after my 2-days war.
% setenv CFLAGS ‘-isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4 -arch ppc -I/opt/gtk/include’ ; setenv CXXFLAGS “$CFLAGS” ; setenv LDFLAGS ‘-L/opt/gtk/lib -mmacosx-version-min=10.4 -arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk ‘; setenv CPPFLAGS ‘-I/opt/gtk/include’
% set path = ( /opt/gtk/bin $path )
% ./configure –prefix=/opt/gtk –with-x-includes=/Developer/SDKs/MacOSX10u.sdk/usr/X11R6/include/ –with-x-libraries=/Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/lib/
(add –host=i386-apple-darwin8 for i386)
pkg-config-0.19 : should be always native since it must executable! I’ve built for ppc.
libiconv-1.12
gettext-0.17
libxml2-2.6.30
glib-2.18.3 : how about “gtkdoc-rebase: command not found” error?
atk-1.25.2
libpng-1.2.32
jpeg.v6b
tiff-3.8.2
pixman-0.13.2
freetype-2.3.7
fontconfig-2.6.0
renderext-0.9
libXrender-0.9.0
libXft-2.1.13
cairo-1.8.6
pango-1.22.4
gtk+-2.4.16
Hmm, gtk build stops on Leopard/i386 Mac: “gtk-update-icon-cache: The generated cache was invalid.” This may because of incorrect detection of endianness by glib, however I couldn’t find the way out.
[ NOTES ]
glib: crosscompiling glib requires a small hack since ./configure script can’t run several test programs. see: Glib manual. Another issue is that we have to have a native glib-genmarshal in PATH (also, genmarshal is required by ATK and some other stuff).
Configuration for i386 Mac (that I’ve tested with native build on Leopard) is:
glib_cv_long_long_format=ll
glib_cv_stack_grows=no
glib_cv_uscore=no
ac_cv_func_posix_getgrgid_r=yes
ac_cv_func_posix_getpwuid_r=yes
ac_cv_func_posix_memalign=no
And one more thing, make will fail because of an empty command in libtool. This is because global_pipe_symbol is “”. I think this should be:
global_pipe_symbol=”sed -n -e ‘s/^.*[ ]\\([BCDEGRST][BCDEGRST]*\\)[ ][ ]*_\\([_A-Za-z][_A-Za-z0-9]*\\)\$/\\1 _\\2 \\2/p'”
and it looks ok.
jpeg-6b: included libtool is too old… replacing by libtool bundled in MacOS X, but need one more hack.
% cp /usr/bin/glibtool libtool
% vi libtool : allow_undefined_flag=”$FLAGS” (a stupid patch but it works :p)
% ./configure (maybe we don’t need this)
% ./configure –enable-shared –prefix=/opt/gtk
Carbon Framework, libSystem.B.dylib and MacOSX10.4u.sdk problem: http://www.red-sweater.com/blog/246/missing-link

MacBook その後

実は先月、新しいモデルの MacBook を購入した。お金ないけど。
私費で Mac を買うのは 2 年ぶりくらいかな?
今度のモデルはかなりしっかりした作りになっており、丈夫そうなので長く使えそう、ということで、4GB のメモリと英語キーボード、それに珍しく Applecare Protection Plan をオプションでお願いした。いや、いままで PowerBook とか MacBook (Pro) とか使っていた方が、実際に今度のモデルに触れられたらおわかりいただけると思うが、ほんとにこれなら第一線で 3 年くらい使い倒せるでしょ、という感じ。ディスクの交換も簡単だしね。
で、発売直後だったので、US English のキーボードがまだ入荷しておらず、日本語キーボードのままで、キーボードは後日交換、ということだった。しかし、一ヶ月近くたっても連絡がないので、そろそろかな、と思って昨日銀座の Apple Store を訪れてみたところ、「ちょうど今日入荷しましたよ!」とのこと。たぶん、この新しい筐体はアルミの削りだし (といっているが、鍛造 + 削りだしなんじゃないかと思うんだよね… さすがに) 工程に手間と時間がかかるので、遅れていたのではないか、と思う。
で、これも注意深く観察すればわかるのだが、キーボード交換はかなり大きな作業だ。なにしろ、本体の底面カバー以外の外装をまるごと交換することになるわけだから。そういうわけで、その日から作業をするのだが、ほぼ交換第一号なので慎重を期したい、ということでひと晩 Apple Store に預けてきた。
今日はいろいろと忙しく、結局夜8時くらいにお伺いしてピックアップ。
日本語キーボードだと、記号の場所が違ってて全然打てなかったり、Command キーが左に寄っていたり、Fn キーの位置が違ったり、いろいろ不愉快だったのですが、もう、最高です。ひゃほーい。

iPhone の電源

iPhone を使うようになって1週間くらいたつのだが、メールを頻繁にやりとりしたりすると、けっこうな勢いで電池がなくなる。そこで、携帯用の充電器を持ち歩かなければならないわけだが、
– Li-ion 電池を内蔵したLinkage の ACL-40G
– 単3のNi-MH電池を使う Panasonic の BQ-600
を手に入れた。前者は 1300mAh で 5V 750mA, 後者は 2000mAh x 2 で 5.2V 500mA だ。ACL-40G はコンセントに直接挿して充電して、取り外して持ち歩けるところがかっこいいし、動作も安定しているが、空っぽになった iPhone を満充電までもっていくパワーはないみたい。電池の容量的には単3を2本使うほうが圧倒的に有利なのだけれど、どうしても大電流がとりづらいらしく、iPhone の電池がほとんど空 (赤い表示) だったり、もうすこしで満充電、というところではうまく動かないことがあるのが残念。あ、これらは、使いながら充電する、という前提の話なので、iPhone の電源を切って充電するならば、必要なのは充電に必要な電力だけになるので、話が変わるはずです。
肝心の iPhone だが、とても幸せです。

Memo: Boost C++ lib for Universal-binary HOWTO

% vi tools/build/v2/user-config.jam
using gcc : 4.0 : g++-4.0 : <compileflags>”-arch ppc” <linkflags>”-arch ppc” ;
% bjam toolset=gcc-4.0 –with-regex –with-filesystem –with-iostreams install –prefix=/Users/osana/work-dna/boost/ppc –build-type=complete
[ check the library’s target processor ]
% ar -t libboost_system-gcc40.a
__.SYMDEF SORTED
error_code.o
% ar -x libboost_system-gcc40.a error_code.o
% file error_code.o
error_code.o: Mach-O object ppc
% rm error_code.o
[ cleanup ]
% rm -rf bin.v2
this may sufficient to build another target.

iPhone in Japan!

ソフトバンクモバイルから iPhone が出ることになったんだけど、買うか、といわれると、正直、んー、という感じ。
いまは Nokia の端末を使っていて、BluePhone Elite2 というソフトウェアのおかげでSMS とか通話は Bluetooth 経由で Mac を使って全部こなすことができる。これは仕事中にくるメールや電話をやっつけるコストを激減させてくれる (だって、携帯電話を手に取る必要がないのだから!) ので、とっても気に入っている。
BluePhone Elite2 は iPhone にも対応しているんだけど、Nokia に比べると限定的なサポートになる感じ。
いやでも、そのうち買う気がしますけれど (笑)。

Portable process killer with GLib

Since Windows API (and MinGW) doesn’t have fork() / exec() calls, I love GLib’s g_spawn_sync() and its friends to spawn child process in portable (and Unix like) way.
However, GLib provides nothing like kill() to terminate processes. So I have to find a way to kill a process by myself. As a portable process identifier, g_spawn_sync() gives GPid. This is defined in GLIB_PREFIX/lib/glib-2.0/include/glibconfig.h as:
– Unix: typedef int GPid;
– Win32: typedef void * GPid;
The one for Unix is equal to pid, and the one for Win32 is equal to HANDLE (defined in winnt.h, as “typedef void *HANDLE;”).
So, a process launched by g_spawn_sync() may be killed by:
kill(GPid p, 15);
TerminateProcess(GPid p, UINT return_code);
MSDN document says “The state of global data maintained by dynamic-link libraries (DLLs) may be compromised if TerminateProcess is used rather than ExitProcess.”
Source code of a Gimp plugin gives a good example, but I haven’t tested it yet. Hope this works…

.Mac bookmark

家の iMac G5 (Leopard) だけ、.Mac で何度同期しても Safari の bookmarks が古いままで更新されず、なんでかなー、と思っていた。
ふと思い立って、bookmarks を全部削除したらあらふしぎ、.Mac な bookmarks が現れました。
なんでー!?!?!?
まあ、ちゃんとみられるようになったから、いいのだ。