I have a few times missed running the other X11 app on my iPhone. Recently i found iX11 that actually is a local X server for the iPhone. Then, there’s nothing missing. All we have to do is to start compiling.

As always, all kudos goes to Saurik for his awsome work on porting the userland.
I still run a 2.x version of the iPhone OS because I like to sync music and stuff from Linux. The following may not work at all on 3.x. You also need a jailbroken iPhone. Nothing of this will work on a “clean” phone. You will probably also use the ssh server to upload source files and run commands. Doing this with a local terminal is possible, though extremely cumbersome.
The following will give you some basic X11 apps, running locally on your iPhone. You will need some basic UNIX skills, like knowing how to unpack and compile a source package. There’s no deep magic involved, though. If this breaks your phone in any way, you’ll keep all the parts. You’re on your own. Don’t blame anyone but yourself.
Video uploaded to YouTube
Install the following packages with apt-get. Don’t bother to start up cydia. That will only slow you down
iphone-gcc
com.bigboss.20toolchain
x11 xeyes xau xcb xcb-proto xext xextproto xmu xproto xt xtrans
ldid make gawk ed sed vim wget gzip tar
I also tend to use the backgrounder quite a lot, to start up things without using an external shell. Use apt-get again, and install
jp.ashikase.backgrounder
For source archives, I extracted sources from Fedora 11′s source packages, as they were handy, though I guess upstream sources would work as well.
Before you start, run the following as root to to turn off code signing checks.
sysctl -w security.mac.proc_enforce=0
sysctl -w security.mac.vnode_enforce=0
Now log in or su to the build user (ie. mobile). Download all the source packages to a convenient directory, like /var/mobile/src. I started out with the following packages:
libXdmcp and xauth – to test apps from another X workstation.
libXpm and libXaw – these are basic building blocks
xterm xbitmaps xsetroot twm – some basic user apps
Before compiling, the tool chain needs to find your local header files and stuff. The straigtforward approach is as follows:
export CPPFLAGS=-I/var/include
export CPP=/usr/bin/cpp
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
./configure -build=arm-apple-darwin9.4.1
make
su root -c "make install"
Start by compiling and installing libXdmcp and xauth. Then as root, cp xauth to /usr/bin. Now you can test xeyes on a X workstation.
$ ssh -X mobile@iphone xeyes
If this works, you’ll get four bonus points, and may take a break. Then compile and install libXpm and libXaw. This will take some time, perhaps an hour or more. There is a missing link in /usr/local/lib, so symlink libXaw.a to libXaw7.a. Does this mean that dynamically linking does not work? I don’t know. You may answer in the comments below.
Now, fire up vim and patch /usr/include/X11/Xpoll.h to ignore the tests on CSRG_BASED and BSD, and always ‘include <sys/param.h>’ and ‘typedef long fd_mask’. Simple!
Then you can build some user apps, xterm, xbitmaps, xsetroot, twm. Finally, since Christmas is coming, compile xsnow:
wget http://dropmix.xs4all.nl/rick/Xsnow/xsnow-1.42.tar.gz
tar xvzf xsnow-1.42.tar.gz; cd xsnow-1.42
gcc -O2 -I/var/include -I/var/include/arm -c -o xsnow.o xsnow.c
gcc -O2 -I/var/include -I/var/include/arm -c -o toon_root.o toon_root.c
gcc -o xsnow -O2 -L/usr/local/lib xsnow.o toon_root.o -lXext -lX11 -lm -lXpm
su root -c "cp xsnow /usr/local/bin"
Remember to ldid the binaries and libraries afterwards, and turn off code signing. in a root shell, do
for i in /usr/bin/xauth /usr/local/bin/* /usr/local/lib/*dylib /usr/local/lib/*la; do ldid -S $i ;done
sysctl -w security.mac.proc_enforce=1
sysctl -w security.mac.vnode_enforce=1
Now make the fun begin: Start iX11, and in another shell, do
export DISPLAY=localhost:0
twm &
xsetroot -solid midnightblue
xsnow &
xterm -bg black -fg wheat &
Next: OpenOffice?
Update: Built fvwm as well. A bit more user friendly than old twm.
Update: Captured a video and posted it on YouTube.