#!/bin/sh

#--enable-malloc0returnsnull 加了此项就不用去改configure, 相当于
#vi configure to find "cannot run test program while cross compiling"
#modify { (exit 1); exit 1; }; } to }

##编译环境: ubuntu 8.04 LTS / cross compile=arm-linux-xxx-4.1.2
#TinyX 移植步骤


mkdir ~/xroot/soft -p
cd ~/xroot/soft

wget -c http://xmlsoft.org/sources/libxml2-2.6.32.tar.gz                                #00
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/proto/inputproto-1.4.2.1.tar.bz2                #01
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/proto/kbproto-1.0.3.tar.bz2                #02
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/proto/bigreqsproto-1.0.2.tar.bz2                #03
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/proto/xproto-7.0.10.tar.bz2                #04
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/proto/xextproto-7.0.2.tar.bz2                #05
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/proto/xcmiscproto-1.1.2.tar.bz2                #06
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/proto/xf86bigfontproto-1.1.2.tar.bz2            #07
wget -c http://xorg.freedesktop.org/releases/X11R7.2/src/everything/xtrans-X11R7.2-1.0.3.tar.bz2            #08
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/lib/libXau-1.0.3.tar.bz2                    #09
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/lib/libXdmcp-1.0.2.tar.bz2                    #10
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/everything/util-macros-1.1.5.tar.bz2            #11
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/everything/libX11-1.1.3.tar.bz2                #12
wget -c ftp://ftp.tw.freebsd.org/pub/ FreeBSD/distfiles/xorg/lib/libX11-1.1.2.tar.bz2                #another 12
wget -c http://www.zlib.net/zlib-1.2.3.tar.bz2                                        #13
wget -c http://download.berlios.de/tslib/tslib-1.0.tar.bz2                                #14
wget -c http://download.savannah.gnu.org/releases/freetype/freetype-2.3.5.tar.bz2                    #15
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/proto/compositeproto-0.4.tar.bz2                #16
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/proto/damageproto-1.1.0.tar.bz2                #17
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/proto/fixesproto-4.0.tar.bz2                #18
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/proto/recordproto-1.13.2.tar.bz2                #19
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/proto/resourceproto-1.0.2.tar.bz2                #20
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/proto/scrnsaverproto-1.1.0.tar.bz2            #21
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/proto/xineramaproto-1.1.2.tar.bz2                #22
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/proto/videoproto-2.2.2.tar.bz2                #23
git clone git://git.freedesktop.org/git/xorg/proto/calibrateproto.git                            #24
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/proto/fontsproto-2.0.2.tar.bz2                #25
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/proto/fontcacheproto-0.1.2.tar.bz2            #26
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/proto/randrproto-1.2.1.tar.bz2                #27
wget -c http://xorg.freedesktop.org/releases/X11R7.2/src/proto/renderproto-X11R7.0-0.9.2.tar.bz2            #28
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/proto/renderproto-0.9.3.tar.bz2                #28 2rd
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/proto/xf86miscproto-0.9.2.tar.bz2                #29
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/proto/xf86vidmodeproto-2.2.2.tar.bz2            #30
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/proto/xf86dgaproto-2.0.3.tar.bz2                #31
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/lib/libxkbfile-1.0.4.tar.bz2                #32
git clone git://git.freedesktop.org/git/xorg/lib/libXCalibrate.git                            #33
wget -c http://xorg.freedesktop.org/releases/individual/lib/libXrender-0.9.2.tar.bz2                #34
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/lib/libXrender-0.9.4.tar.bz2                #34 2nd
wget -c http://xorg.freedesktop.org/releases/individual/lib/libXrandr-1.2.1.tar.bz2                    #35
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/lib/libXrandr-1.2.2.tar.bz2                #35 2nd
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/lib/libfontenc-1.0.4.tar.bz2                #36
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/lib/libXfont-1.3.1.tar.bz2                    #37
wget -c http://xorg.freedesktop.org/releases/individual/xserver/xorg-server-1.3.0.0.tar.bz2            #38
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/xserver/xorg-server-1.4.tar.bz2                #38 2nd
wget -c http://x.cybermirror.org/pub/individual/lib/libXext-1.0.3.tar.bz2                        #39
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/everything/libXext-1.0.2.tar.bz2                #39 2nd
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/everything/libXi-1.1.3.tar.bz2                #40

wget -c http://x.cybermirror.org/pub/individual/lib/libXi-1.1.2.tar.bz2                        #41
wget -c http://downloads.sourceforge.net/expat/expat-2.0.0.tar.gz                            #41 2nd
wget -c ftp://ftp.vcu.edu/pub/gnu+linux/puppylinux/pupget_packages-1/expat-2.0.0.tar.gz
wget -c ftp://ftp.linux.ee/pub/gentoo/distfiles/distfiles/fontconfig-2.4.2.tar.gz                    #42
wget -c http://www.ijg.org/files/jpegsrc.v6b.tar.gz                                    #43
wget -c ftp://ftp.uu.net/graphics/jpeg/jpegsrc.v6b.tar.gz
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/proto/fixesproto-4.0.tar.bz2                #51=18
wget -c ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng-1.2.33.tar.bz2                     #44
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/lib/libICE-1.0.4.tar.bz2                    #45
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/lib/libSM-1.0.3.tar.bz2                    #46
wget -c http://www.cairographics.org/releases/cairo-1.4.14.tar.gz                            #47
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/lib/libXft-2.1.12.tar.bz2                    #48
wget -c http://ftp.gnome.org/pub/gnome/sources/glib/2.14/glib-2.14.6.tar.bz2                        #49
wget -c http://ftp.gnome.org/pub/gnome/sources/pango/1.18/pango-1.18.3.tar.bz2                    #50
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/lib/libXinerama-1.0.2.tar.bz2                #53
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/proto/xineramaproto-1.1.2.tar.bz2                #52=22
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/lib/libXfixes-4.0.3.tar.bz2                #54
wget -c http://mirrors.rootmode.com/ftp.gnupg.org/libgpg-error/libgpg-error-1.0.tar.gz                #55
wget -c ftp://ftp.gnupg.org/gcrypt/libgcrypt/libgcrypt-1.2.3.tar.gz                            #56
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/lib/libXcomposite-0.4.0.tar.bz2                #57
wget -c http://ftp.gnome.org/pub/gnome/sources/atk/1.20/atk-1.20.0.tar.bz2                        #58
wget -c http://xorg.freedesktop.org/releases/X11R7.2/src/lib/libXcursor-X11R7.2-1.1.8.tar.bz2            #59
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/lib/libXcursor-1.1.9.tar.bz2                #59 2nd
wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/lib/libXdamage-1.0.4.tar.bz2                #60
wget -c http://xorg.freedesktop.org/releases/individual/lib/libXdamage-1.1.1.tar.bz2                #61
wget -c http://ftp.gnome.org/pub/gnome/sources/gtk+/2.12/gtk+-2.12.7.tar.bz2                        #61 2nd
wget -c http://ftp.gnome.org/pub/gnome/sources/gtk+/2.14/gtk+-2.14.4.tar.bz2                        #61
wget -c ftp://ftp.gnome.org/mirror/gnome.org/sources/libglade/2.6/libglade-2.6.3.tar.gz                #62


wget -c http://xorg.freedesktop.org/releases/X11R7.3/src/everything/xtrans-1.0.4.tar.bz2

#补丁下载
#至http://www.pokylinux.org/ download pinky-3.1.1
#在pinky-3.1.1/meta/packages patch可用
#svn co http://svn.o-hand.com/repos/poky/trunk poky 其中也有部分的patch可用

mkdir ~/xroot/soft/patches
cd ~/xroot/soft/patches
svn co http://svn.o-hand.com/repos/poky/trunk poky

wget -c http://pokylinux.org/releases/poky-pinky-3.1.1.tgz
tar zxf poky-pinky-3.1.1.tgz
cd pinky-3.1.1/meta/packages/; ls


#准备编译
#step 1: Cross环境设定
export XROOT=$HOME/xroot
export PREFIX=$XROOT
export LD_LIBRARY_PATH=$PREFIX/lib
export PKG_CONFIG_PATH=$LD_LIBRARY_PATH/pkgconfig
export HOST=arm-linux
export BUILD=i686-linux

export CC=arm-linux-gcc
export CXX=arm-linux-g++
export AR=arm-linux-ar
export RANLIB=arm-linux-ranlib
export NM=arm-linux-nm
export AS=arm-linux-as
export LD=arm-linux-ld
export STRIP=arm-linux-strip
export READELF=arm-linux-readelf
export STRINGS=arm-linux-strings
export SIZE=arm-linux-size
export ADDR2LINE=arm-linux-addr2line

#编译相关库
mkdir ~/xroot/build_tmp
cd ~/xroot/build_tmp

#外部依赖于libxml2, 需要额外编译。
tar zxf ../soft/libxml2-2.6.32.tar.gz
cd libxml2-2.6.32
./configure --host=$HOST --build=$BUILD --prefix=$PREFIX
make all; make install


#step 2: 移植X11
# 01-    inputproto-1.4.2.1
tar jxf ../soft/inputproto-1.4.2.1.tar.bz2
cd inputproto-1.4.2.1
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD
make install

#02-    kbproto-1.0.3
tar jxf ../soft/kbproto-1.0.3.tar.bz2
cd kbproto-1.0.3
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD
make install # or make; make install

#03-    bigreqsproto-1.0.2
tar jxf ../soft/bigreqsproto-1.0.2.tar.bz2
cd bigreqsproto-1.0.2
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD
make install # or make; make install


#04-    xproto-7.0.10
tar jxf ../soft/xproto-7.0.10.tar.bz2
cd xproto-7.0.10
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD
make install # or make; make install

#05-    xextproto-7.0.2
tar jxf ../soft/xextproto-7.0.2.tar.bz2
cd xextproto-7.0.2
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD
make install # or make; make install

#06-    xcmiscproto-1.1.2
tar jxf ../soft/xcmiscproto-1.1.2.tar.bz2
cd xcmiscproto-1.1.2
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD
make install # or make; make install

#07-    xf86bigfontproto-1.1.2
tar jxf ../soft/xf86bigfontproto-1.1.2.tar.bz2
cd xf86bigfontproto-1.1.2
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD
make install # or make; make install

#08-    xtrans-X11R7.2-1.0.3
tar jxf ../soft/xtrans-X11R7.2-1.0.3.tar.bz2
cd xtrans-X11R7.2-1.0.3
patch -Np1 -i $XROOT/soft/patches/pinky-3.1.1/meta/packages/xorg-lib/xtrans/fix-missing-includepath.patch
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD
make install # or make; make install

#09-    libXau-1.0.3
tar jxf ../soft/libXau-1.0.3.tar.bz2
cd libXau-1.0.3
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD --enable-static=yes --enable-shared=yes --enable-malloc0returnsnull
make all; make install

#10-    libXdmcp-1.0.2
tar jxf ../soft/libXdmcp-1.0.2.tar.bz2
cd libXdmcp-1.0.2
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD --enable-static=yes --enable-shared=yes --enable-malloc0returnsnull
make all; make install

#11-    util-macros-1.1.5
tar jxf ../soft/util-macros-1.1.5.tar.bz2
cd util-macros-1.1.5
patch -Np1 -i $XROOT/soft/patches/pinky-3.1.1/meta/packages/xorg-util/files/unbreak_cross_compile.patch
./configure --build=$BUILD --host=$HOST --prefix=$PREFIX
make install


#12-    libX11-1.1.2
tar jxf ../soft/libX11-1.1.2.tar.bz2
cd libX11-1.1.2
patch -Np1 -i $XROOT/soft/patches/pinky-3.1.1/meta/packages/xorg-lib/libx11/include_fix.patch
patch -Np1 -i $XROOT/soft/patches/pinky-3.1.1/meta/packages/xorg-lib/libx11/x11_disable_makekeys.patch
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD --enable-static=yes --enable-shared=yes --enable-malloc0returnsnull --without-xcb --with-keysymdef=$PREFIX/include/X11/keysymdef.h

vi ./src/Makefile
#编辑ks_tables.h的依赖关系:要注释的内容如下。
#    ks_tables.h: $(KEYSYMDEF) $(top_builddir)/src/util/makekeys$(EXEEXT)
#        # $(top_builddir)/src/util/makekeys < $(KEYSYMDEF) > ks_tables_h
#        # mv ks_tables_h $@

#把  src/util/makekeys 文件用gcc编译[ gcc -o makekeys makekeys.c],执行 makekeys <> ks_tables_h, 把生成的 ks_tables_h 文件放在 src 目录下
cd src/util
make clean; gcc -o makekeys makekeys.c
./makekeys <$PREFIX/include/X11/keysymdef.h> ks_tables_h
mv ks_tables_h ../ks_tables.h

cd ../../
make all; make install



#step 3: Xserver (Kdrive)移植

#13-    zlib-1.2.3 //对于交叉编译已有此libz.so.1.2.3的,此步无须编译。
tar jxf ../soft/zlib-1.2.3.tar.bz2
cd zlib-1.2.3
patch -Np1 -i $XROOT/soft/patches/pinky-3.1.1/meta/packages/zlib/files/visibility.patch
./configure --prefix=$PREFIX --shared
make all; make install

#14-    tslib-1.0
tar jxf ../soft/tslib-1.0.tar.bz2
cd tslib-1.0
patch -Np1 -i $XROOT/soft/patches/pinky-3.1.1/meta/packages/tslib/tslib/fix_version.patch
./autogen.sh
#修改./etc/ts.conf 开放 module_raw input

./configure --prefix=$PREFIX --host=$HOST --build=$BUILD --enable-shared=yes --enable-static=yes --enable-ucb1x00=no --enable-corgi=no --enable-collie=no --enable-h3600=no --enable-mk712=no --enable-arctic2=no --enable-input

#修改 在config.h里加上#undef rpl_malloc, 同时封掉  /* #define malloc rpl_malloc */
make all; make install

#15-    freetype-2.3.5
tar jxf ../soft/freetype-2.3.5.tar.bz2
cd freetype-2.3.5

patch -Np1 -i $XROOT/soft/patches/pinky-3.1.1/meta/packages/freetype/freetype-2.3.5/fix-x86_64-build.patch
patch -Np1 -i $XROOT/soft/patches/pinky-3.1.1/meta/packages/freetype/files/no-hardcode.patch

./configure --prefix=$PREFIX --host=$HOST --build=$BUILD

make all; make install


#16-    compositeproto-0.4
tar jxf ../soft/compositeproto-0.4.tar.bz2
cd compositeproto-0.4
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD
make install


#17-    damageproto-1.1.0
tar jxf ../soft/damageproto-1.1.0.tar.bz2
cd damageproto-1.1.0
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD
make install 


#18-    fixesproto-4.0
tar jxf ../soft/fixesproto-4.0.tar.bz2
cd fixesproto-4.0
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD
make install


#19-    recordproto-1.13.2
tar jxf ../soft/recordproto-1.13.2.tar.bz2
cd recordproto-1.13.2
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD
make install


#20-    resourceproto-1.0.2
tar jxf ../soft/resourceproto-1.0.2.tar.bz2
cd resourceproto-1.0.2
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD
make install


#21-    scrnsaverproto-1.1.0
tar jxf ../soft/scrnsaverproto-1.1.0.tar.bz2
cd scrnsaverproto-1.1.0
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD
make install

#22-    xineramaproto-1.1.2
tar jxf ../soft/xineramaproto-1.1.2.tar.bz2
cd xineramaproto-1.1.2
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD
make install

#23-    videoproto-2.2.2
tar jxf ../soft/videoproto-2.2.2.tar.bz2
cd videoproto-2.2.2
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD
make install

#24-    calibrateproto
tar jxf ../soft/calibrateproto.tar.bz2
cd calibrateproto
./autogen
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD
make install

#25-    fontsproto-2.0.2
tar jxf ../soft/fontsproto-2.0.2.tar.bz2
cd fontsproto-2.0.2
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD
make install

#26-    fontcacheproto-0.1.2
tar jxf ../soft/fontcacheproto-0.1.2.tar.bz2
cd fontcacheproto-0.1.2
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD
make install

#27-    randrproto-1.2.1
tar jxf ../soft/randrproto-1.2.1.tar.bz2
cd randrproto-1.2.1
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD
make install

#28-    renderproto-X11R7.0-0.9.2
tar jxf ../soft/renderproto-X11R7.0-0.9.2.tar.bz2
cd renderproto-X11R7.0-0.9.2
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD
make install

#29-    xf86miscproto 0.9.2
tar jxf ../soft/xf86miscproto-0.9.2.tar.bz2
cd xf86miscproto-0.9.2
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD
make install

#30-    xf86vidmodeproto 2.2.2
tar jxf ../soft/xf86vidmodeproto-2.2.2.tar.bz2
cd xf86vidmodeproto-2.2.2
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD
make install

#31-    xf86dgaproto 2.0.3
tar jxf ../soft/xf86dgaproto-2.0.3.tar.bz2
cd xf86dgaproto-2.0.2
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD
make install

#32-    libxkbfile-1.0.4
tar jxf ../soft/libxkbfile-1.0.4.tar.bz2
cd libxkbfile-1.0.4
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD --enable-static=yes --enable-shared=yes
make all; make install


#39-    libXext-1.0.3
tar jxf ../soft/libXext-1.0.3.tar.bz2
cd libXext-1.0.3
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD --enable-static=yes --enable-shared=yes --enable-malloc0returnsnull
make all; make install

#33-    libXCalibrate
tar jxf ../soft/libXCalibrate.tar.bz2
cd libXCalibrate
./autogen
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD --enable-static=yes --enable-shared=yes
make all; make install

#34-    libXrender-0.9.2
tar jxf ../soft/libXrender-0.9.2.tar.bz2
cd libXrender-0.9.2
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD --enable-static=yes --enable-shared=yes --enable-malloc0returnsnull
make all; make install

#35-    libXrandr-1.2.1
tar jxf ../soft/libXrandr-1.2.1.tar.bz2
cd libXrandr-1.2.1
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD --enable-static=yes --enable-shared=yes --enable-malloc0returnsnull
make all; make install

#36-    libfontenc-1.0.4
tar jxf ../soft/libfontenc-1.0.4.tar.bz2
cd libfontenc-1.0.4
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD --enable-shared=yes --enable-static=yes
#vi ./src/Makefile 修改 DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) -I$(PREFIX)/include
make all; make install

#37-    libXfont-1.3.1
tar jxf ../soft/libXfont-1.3.1.tar.bz2
cd libXfont-1.3.1

./configure --prefix=$PREFIX --host=$HOST --build=$BUILD --enable-shared=yes --enable-static=yes
make all; make install

#38-    xorg-server-1.3.0.0
tar jxf ../soft/xorg-server-1.3.0.0.tar.bz2
cd xorg-server-1.3.0.0


#修改configure 尋找cannot check for file existence when cross compiling  把{ (exit 1); exit 1; };} 改成}
#25363 修改configure加入tslib路径

#LDFLAGS="-L${XROOT}/lib -lfreetype -lts -lz -lXfont"
#TSLIB_LIBS="-L${XROOT}/lib -lts"
#TSLIB_CFLAGS="-I${XROOT}/include"
#FREETYPE_CFLAGS="-I${XROOT}/include/freetype2 -I${XROOT}/include"
#FREETYPE_LIBS="-L${XROOT}/lib -lfreetype"

ac_cv_file__usr_share_X11_sgml_defs_ent=no
#./configure --prefix=$PREFIX --host=$HOST --build=$BUILD --enable-shared=yes --enable-static=yes --enable-composite --enable-kdrive --disable-dga --disable-dri --disable-xinerama --disable-xf86misc --disable-xf86vidmode --disable-xorg --disable-xorgcfg --disable-xkb --disable-xnest --disable-xvfb --disable-xevie --disable-xprint --disable-xtrap --disable-dmx --enable-tslib --enable-xcalibrate -with-default-font-path=built-ins
#或者指定寻找字体的目录
ac_cv_file__usr_share_X11_sgml_defs_ent=no ./configure --prefix=$PREFIX --host=$HOST --build=$BUILD --enable-shared=yes --enable-static=yes --enable-composite --enable-kdrive --disable-dga --disable-dri --disable-xinerama --disable-xf86misc --disable-xf86vidmode --disable-xorg --disable-xorgcfg --disable-xkb --disable-xnest --disable-xvfb --disable-xevie --disable-xprint --disable-xtrap --disable-dmx --enable-tslib --enable-xcalibrate--with-fontdir=${PREFIX}/fonts

make all; make install


####################################################################################################################################################
# 在此处可到开发版上测试 X11 的可用性, 执行 Xfbdev, 如果有出现错误

1.E:     _XSERVTransSocketUNIXCreateListener: ...SocketCreateListener() failed
    _XSERVTransMakeAllCOTSServerListeners: server already running
  R:    rm /tmp/.X11-unix/ -rf   

2.E:    Extended Input Devices not yet supported. Implement it at line 625 in kinput.c
    Could not init font path element /xxx/lib/X11/fonts/misc/, removing from list!
    ... ...
    Could not init font path element /xxx/lib/X11/fonts/75dpi/, removing from list!
    could not open default font 'fixed'
  R:    cp PC机/usr/share/fonts/X11 目录下所有目录到 终端机 /xxx/lib/X11/fonts/下
####################################################################################################################################################

#step 4: libXi 移植

#39-    libXext-1.0.3 被libXCalibrate libXrandr-1.2.1 libfontenc-1.0.4依赖, 先编译

#40-    libXi-1.1.2
tar jxf ../soft/libXi-1.1.2.tar.bz2
cd libXi-1.1.2
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD --enable-static=yes --enable-shared=yes --enable-malloc0returnsnull
make all; make install

#41-    libXi-1.1.2
tar jxf ../soft/libXi-1.1.2.tar.bz2
cd libXi-1.1.2
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD --enable-static=yes --enable-shared=yes --enable-malloc0returnsnull
make all; make install

#以上是X11的移植

#以下是GTK相关的移植

#step 5: Cairo + Pango移植

#42-    expat-2.0.0
tar zxf ../soft/expat-2.0.0.tar.gz
cd expat-2.0.0
./configure --host=$HOST --build=$BUILD --prefix=$PREFIX
make all; make install

#43-    fontconfig-2.4.2
tar zxf ../soft/fontconfig-2.4.2.tar.gz
cd fontconfig-2.4.2
CFLAGS="-I${XROOT}/include -I${XROOT}/include/freetype2/freetype -I${XROOT}/include/freetype2/freetype/config"
LDFLAGS="-L${XROOT}/lib -lfreetype -lxml2"
ARCH=arm
./configure --build=$BUILD --host=$HOST --prefix=$PREFIX --with-freetype-config=$PREFIX/bin/freetype-config --with-arch=$ARCH --enable-libxml2 --disable-docs --enable-static=yes --enable-shared=yes --with-default-fonts=${XROOT}/fonts --with-cache-dir=${XROOT}/fonts/var/cache/fontconfig --with-confdir=${XROOT}/fonts
make all; make install
CFLAGS=
LDFLAGS=
ARCH=

#44-    jpeg-6b ; 需要确认。 这个可能在交叉编译器中存在了,无须在编
tar zxf ../soft/jpegsrc.v6b.tar.gz
cd jpeg-6b
patch -Np1 -i $XROOT/soft/patches/pinky-3.1.1/meta/packages/jpeg/jpeg-6b/ldflags.patch
./ltconfig --disable-static --no-verify ltmain.sh arm-linux

./configure --prefix=$PREFIX --host=$HOST --build=$BUILD --enable-static=yes --enable-shared=yes
#修改Makefile CFLAGS= -O2 -I$(srcdir) 行为 CFLAGS= -O2 -I$(srcdir) -D_REENTRANT
make all; make install; make install-lib; make install-headers

#45-    libpng-1.2.16
tar jxf ../soft/libpng-1.2.33.tar.bz2
cd libpng-1.2.33

#修改configure 把所有行LIBS="-lz $LIBS" 改成 LIBS="${XROOT}/lib -lz $LIBS"
ac_cv_lib_z_zlibVersion=yes
./configure --host=$HOST --build=$BUILD --prefix=$PREFIX --enable-shared=yes --enable-static=yes
#修改Makefile相应项
#DEFAULT_INCLUDES = -I. -I$(srcdir) -I. -I$(PREFIX)/include
#LIBS = -L$(PREFIX)/lib -lz -lm
#LDFLAGS = -L$(PREFIX)/lib -lz -lm
make all; make install

#46-    libICE-1.0.4
tar jxf ../soft/libICE-1.0.4.tar.bz2
cd libICE-1.0.4
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD --enable-shared=yes --enable-static=yes
make all; make install

#47-    libSM-1.0.3
tar jxf ../soft/libSM-1.0.3.tar.bz2
cd libSM-1.0.3
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD --enable-shared=yes --enable-static=yes
make all; make install

#48-    cairo-1.4.14
tar zxf ../soft/cairo-1.4.14.tar.gz
cd cairo-1.4.14
#vi configure 加以下3行
#    ac_cv_lib_z_compress=yes
#    ac_header_compiler=yes
#    ac_header_preproc=yes
#找 unset cairo_cv_backend_xcb_use 下面加
#    cairo_cv_backend_xcb_use=yes
#找 unset cairo_cv_backend_pdf_use 下面加
#    cairo_cv_backend_pdf_use=yes
#找 unset cairo_cv_backend_ps_use 下面加
#    cairo_cv_backend_ps_use=yes

ac_cv_header_zlib_h=yes
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD --enable-static=yes --enable-shared=yes --disable-some-floating-point

make all; make install


#49-    libXft-2.1.12
tar jxf ../soft/libXft-2.1.12.tar.bz2
cd libXft-2.1.12/
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD --enable-shared=yes --enable-static=yes
make all; make install


#50-    glib-2.14.6
tar jxf ../soft/glib-2.14.6.tar.bz2
cd glib-2.14.6
#vi arm-linux.cache 加入一下内容
    ac_cv_type_long_long=yes
    glib_cv_stack_grows=no
    glib_cv_uscore=no
    ac_cv_func_posix_getpwuid_r=no
#具体意义参考http://library.gnome.org/devel/glib/unstable/glib-cross-compiling.html
#vi glib/giounix.c, 添加 #include <bits/posix1_lim.h>

./configure --prefix=$PREFIX --host=$HOST --build=$BUILD --enable-shared=yes --enable-static=yes --cache-file=arm-linux.cache --enable-debug=no --disable-mem-pools
make all; make install

#51-    pango-1.18.3
tar jxf ../soft/pango-1.18.3.tar.bz2http://www.cups.org/software.php?VERSION=1.3.9&FILE=cups/1.4b1/cups-1.4b1-source.tar.bz2
cd pango-1.18.3
patch -Np1 -i $XROOT/soft/patches/pinky-3.1.1/meta/packages/pango/pango-1.18.3/no-tests.patch
patch -Np1 -i $XROOT/soft/patches/pinky-3.1.1/meta/packages/pango/pango-1.18.3/configure_fixes.patch

#修改 configure: line 22225
#    have_cairo=true
#    have_cairo_png=true
#    have_cairo_ps=yes
#    have_cairo_pdf=true
#    have_cairo_xlib=true
#    have_cairo_freetype=true
#    have_cairo_win32=false
#    have_cairo_atsui=false

# 把所有的LIBS="-lxxxx  $LIBS" 改成 LIBS="-L${XROOT}/lib -lxxxx  $LIBS" # xxxx 代表 freetype X11 cairo ICE

LD_LIBRARY_PATH=  #把路径设置为空
ac_cv_lib_cairo_cairo_surface_write_to_png=yes
ac_cv_lib_cairo_cairo_ps_surface_create=yes
ac_cv_lib_cairo_cairo_pdf_surface_create=yes
ac_cv_lib_cairo_cairo_xlib_surface_create=yes
ac_cv_lib_cairo_cairo_ft_scaled_font_lock_face=yes
CAIRO_CFLAGS="-I${XROOT}/include -I${XROOT}/include/cairo"
CAIRO_LIBS="-L${XROOT}/lib -lcairo"
GLIB_CFLAGS="-I${XROOT}/include -I${XROOT}/include/glib-2.0 -I${XROOT}/lib/glib-2.0/include"
GLIB_LIBS="-L${XROOT}/lib -lglib-2.0 -lgmodule-2.0 -lgobject-2.0 -lfontconfig -lxml2 -lfreetype"
FONTCONFIG_CFLAGS="-I${XROOT}/include/fontconfig"
FONTCONFIG_LIBS="-L${XROOT}/lib -lfontconfig"
FREETYPE_CFLAGS="-I${XROOT}/include/freetype2"
FREETYPE_LIBS="-L${XROOT}/lib -lfreetype"
X_CFLAGS="-I${XROOT}/include"
X_LIBS="-L${XROOT}/lib -lpng12 -lexpat -lXext -lxml2 -lX11 -lXft -lXrender"
X_EXTRA_LIBS="-L${XROOT}/lib -lpng12 -lexpat -lXext -lxml2 -lX11 -lXft -lXrender"
X_PRE_LIBS="-L${XROOT}/lib -lSM -lICE"
FREETYPE_CONFIG="${XROOT}/bin/freetype-config"
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD --enable-shared=yes --enable-static=yes --enable-explicit-deps=no --disable-glibtest --disable-debug


make all; make install
PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig #把路径在设置回来

#step 6: GTK 移植
#52-    fixesproto-4.0 = #18
tar jxf ../soft/fixesproto-4.0.tar.bz2
cd fixesproto-4.0
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD
make install


#53-    xineramaproto-1.1.2 = #22
tar jxf ../soft/xineramaproto-1.1.2.tar.bz2
cd xineramaproto-1.1.2
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD
make install


#54-    libXinerama-1.0.2
tar jxf ../soft/libXinerama-1.0.2.tar.bz2
cd libXinerama-1.0.2
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD --enable-shared=yes --enable-static=yes --enable-malloc0returnsnull
make all; make install


#55-    libXfixes-4.0.3
tar jxf ../soft/libXfixes-4.0.3.tar.bz2
cd libXfixes-4.0.3
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD --enable-shared=yes --enable-static=yes
make all; make install


#56-    libgpg-error-1.0
tar zxf ../soft/libgpg-error-1.0.tar.gz
cd libgpg-error-1.0
patch -Np1 -i ${XROOT}/soft/patches/pinky-3.1.1/meta/packages/libgpg-error/libgpg-error-1.0/pkgconfig.patch
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD --enable-shared=yes --enable-static=yes
make all; make install


#57-    libgcrypt-1.2.3
tar zxf ../soft/libgcrypt-1.2.3.tar.gz
cd libgcrypt-1.2.3

./configure --prefix=$PREFIX --host=$HOST --build=$BUILD --enable-shared=yes --enable-static=yes --with-gpg-error-prefix=$PREFIX
#vi tests/Makefile
#修改line:127: 改为 LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
#        $(AM_LDFLAGS) $(LDFLAGS) -L${PREFIX}/lib -lgpg-error -o $@

make all; make install


#58-    libXcomposite-0.4.0
tar jxf ../soft/libXcomposite-0.4.0.tar.bz2
cd libXcomposite-0.4.0
patch -Np1 -i ${XROOT}/soft/patches/pinky-3.1.1/meta/packages/xorg-lib/libxcomposite/change-include-order.patch

./configure --prefix=$PREFIX --host=$HOST --build=$BUILD --enable-shared=yes --enable-static=yes
make all; make install

#59-    atk-1.20.0
tar jxf ../soft/atk-1.20.0.tar.bz2
cd atk-1.20.0
./configure --build=$BUILD --host=$HOST --prefix=$PREFIX --disable-glibtest --enable-static=yes --enable-shared=yes --disable-glibtest
make all; make install

#60-    libXcursor-X11R7.2-1.1.8
tar jxf ../soft/libXcursor-X11R7.2-1.1.8.tar.bz2
cd libXcursor-X11R7.2-1.1.8
./configure --build=$BUILD --host=$HOST --prefix=$PREFIX --disable-glibtest --enable-static=yes --enable-shared=yes
make all; make install

#61-    libXdamage-1.1.1
tar jxf ../soft/libXdamage-1.1.1.tar.bz2
cd libXdamage-1.1.1
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD --enable-shared=yes --enable-static=yes
make all; make install
#62-    gtk+-2.12.7 可以考虑去掉 LD_LIBRARY_PATH 宏
tar jxf ../soft/gtk+-2.12.7.tar.bz2
cd gtk+-2.12.7

patch -Np1 -i ${XROOT}/soft/patches/pinky-3.1.1/meta/packages/gtk+/gtk+-2.12.7/xsettings.patch
patch -Np1 -i ${XROOT}/soft/patches/pinky-3.1.1/meta/packages/gtk+/gtk+-2.12.7/run-iconcache.patch
patch -Np1 -i ${XROOT}/soft/patches/pinky-3.1.1/meta/packages/gtk+/gtk+-2.12.7/disable-print.patch
patch -Np1 -i ${XROOT}/soft/patches/pinky-3.1.1/meta/packages/gtk+/gtk+-2.12.7/hardcoded_libtool.patch
patch -Np1 -i ${XROOT}/soft/patches/pinky-3.1.1/meta/packages/gtk+/gtk+-2.12.7/no-demos.patch
patch -Np1 -i ${XROOT}/soft/patches/pinky-3.1.1/meta/packages/gtk+/gtk+-2.12.7/filesystem-volumes.patch
patch -Np1 -i ${XROOT}/soft/patches/pinky-3.1.1/meta/packages/gtk+/gtk+-2.12.7/filechooser-props.patch
patch -Np1 -i ${XROOT}/soft/patches/pinky-3.1.1/meta/packages/gtk+/gtk+-2.12.7/filechooser-default.patch
patch -Np1 -i ${XROOT}/soft/patches/pinky-3.1.1/meta/packages/gtk+/gtk+-2.12.7/filechooser-sizefix.patch

patch -Np1 -i ${XROOT}/soft/patches/pinky-3.1.1/meta/packages/gtk+/gtk+-2.12.7/menu-deactivate.patch
patch -Np1 -i ${XROOT}/soft/patches/pinky-3.1.1/meta/packages/gtk+/gtk+-2.12.7/hardcoded_libtool.patch

cd gtk
patch -Np1 -i ${XROOT}/soft/patches/pinky-3.1.1/meta/packages/gtk+/gtk+-2.12.7/cellrenderer-cairo.patch
patch -Np1 -i ${XROOT}/soft/patches/pinky-3.1.1/meta/packages/gtk+/gtk+-2.12.7/entry-cairo.patch
patch -Np1 -i ${XROOT}/soft/patches/pinky-3.1.1/meta/packages/gtk+/gtk+-2.12.7/toggle-font.diff

patch -Np1 -i ${XROOT}/soft/patches/pinky-3.1.1/meta/packages/gtk+/gtk+-2.12.7/range-no-redraw.patch
patch -Np1 -i ${XROOT}/soft/patches/pinky-3.1.1/meta/packages/gtk+/gtk+-2.12.7/combo-arrow-size.patch

cd ../gdk/x11
patch -Np1 -i ${XROOT}/soft/patches/pinky-3.1.1/meta/packages/gtk+/gtk+-2.12.7/scrolled-placement.patch #需要输入gdkxsettings.c

cd gtk+-2.12.7

#修改 configure 添加
    #ac_cv_lib_jpeg_jpeg_destroy_decompress=yes
    #ac_cv_func_XOpenDisplay=yes
    #ac_cv_func_XextFindDisplay=yes
    #ac_cv_lib_jpeg_jpeg_simple_progression=yes
    #ac_cv_func_XRenderQueryExtension=yes
#改32579: { (exit 1); exit 1; }; }  为 }


BASE_DEPENDENCIES_CFLAGS="-I$PREFIX/include -I$PREFIX/lib/glib-2.0/include -I$PREFIX/include/glib-2.0 -I$PREFIX/include/pango-1.0 -I$PREFIX/include/cairo -I$PREFIX/include/atk-1.0"
BASE_DEPENDENCIES_LIBS="-L$PREFIX/lib $PREFIX/lib/libglib-2.0.so $PREFIX/lib/libgobject-2.0.so $PREFIX/lib/libgmodule-2.0.so $PREFIX/lib/libfontconfig.so $PREFIX/lib/libxml2.so"
GLIB_CFLAGS="-I$PREFIX/include -I$PREFIX/lib/glib-2.0/include -I$PREFIX/include/glib-2.0"
GLIB_LIBS="-L$PREFIX/lib $PREFIX/lib/libglib-2.0.so $PREFIX/lib/libgobject-2.0.so $PREFIX/lib/libgmodule-2.0.so $PREFIX/lib/libfontconfig.so $PREFIX/lib/libxml2.so"
PANGO_CFLAGS="-I$PREFIX/include/pango-1.0"
PANGO_LIBS="-L$PREFIX/lib $PREFIX/lib/libpango-1.0.so $PREFIX/lib/libpangoft2-1.0.so $PREFIX/lib/libpangocairo-1.0.so"
GDK_DEP_CFLAGS="-pthread -I$PREFIX/include/glib-2.0 -I$PREFIX/lib/glib-2.0/include -I$PREFIX/include/pango-1.0 -I$PREFIX/include/cairo -I$PREFIX/include -D_REENTRANT -D_GNU_SOURCE "
GDK_DEP_LIBS="-L$PREFIX/lib -lpthread -ldl -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -lpng12  -lXdmcp -lXau -lm"
GDK_PIXBUF_DEP_CFLAGS="-pthread -I$PREFIX/include/glib-2.0 -I$PREFIX/lib/glib-2.0/include -I$PREFIX/include "
GDK_PIXBUF_DEP_LIBS="-L$PREFIX/lib -lgmodule-2.0 -ldl -lgobject-2.0 -lglib-2.0 -lpng12  -lXdmcp -lXau -lm"

GDK_PIXBUF_EXTRA_CFLAGS="-pthread -I$PREFIX/include/glib-2.0 -I$PREFIX/lib/glib-2.0/include -I$PREFIX/include "
GDK_PIXBUF_EXTRA_LIBS="-L$PREFIX/lib -lgmodule-2.0 -ldl -lgobject-2.0 -lglib-2.0 -lpng12  -lXdmcp -lXau -lm"


GTK_DEP_CFLAGS="-pthread -I$PREFIX/include/glib-2.0 -I$PREFIX/lib/glib-2.0/include -I$PREFIX/include/pango-1.0 -I$PREFIX/include/cairo -I$PREFIX/include -D_REENTRANT -D_GNU_SOURCE -I$PREFIX/include/atk-1.0 "
GTK_DEP_LIBS="-L$PREFIX/lib -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0 -lcairo  -lXdmcp -lXau-lpng12 -lm "
GDK_EXTRA_CFLAGS=""
GDK_EXTRA_LIBS="-L$PREFIX/lib -lz -lxml2 -lfreetype -lX11 -lXext -lXrender -lexpat -lcairo -lXdmcp -lXau"
X_CFLAGS="-I$PREFIX/include -I$PREFIX/lib/glib-2.0/include -I$PREFIX/include/glib-2.0 -I$PREFIX/include/pango-1.0 -I$PREFIX/include/cairo -I$PREFIX/include/atk-1.0"
X_LIBS="-L$PREFIX/lib -lz -lxml2 -lfreetype -lX11 -lXext -lXrender -lexpat -lcairo -lXdmcp -lXau"
INCROOT=$PREFIX/include
USRLIBDIR=$PREFIX/lib
LIBDIR=$PREFIX/lib

ac_cv_lib_jpeg_jpeg_destroy_decompress=yes ac_cv_func_XOpenDisplay=yes ac_cv_func_XextFindDisplay=yes ac_cv_lib_jpeg_jpeg_simple_progression=yes ac_cv_func_XRenderQueryExtension=yes ./configure --prefix=$PREFIX --host=$HOST --build=$BUILD --enable-shared=yes --enable-static=yes --without-libtiff --disable-xkb --disable-glibtest --with-gdktarget=x11 --with-xinput=yes --enable-display-migration --enable-pangocairo --x-libraries=${PREFIX}/libs --x-includes=${PREFIX}/includes --disable-cups --without-libjpeg

make all; make install

#63-    libglade-2.6.3 //用于执行 glade或者 anjuta 作的UI界面或者代码
LD_LIBRARY_PATH=
tar zxf ../soft/libglade-2.6.3.tar.gz
cd libglade-2.6.3
./configure --prefix=$PREFIX --host=$HOST --build=$BUILD --enable-shared=yes --enable-static=yes --disable-gtktest
make all; make install


#step 7: 测试

1. 准备好测试用的开发版和对应的linux平台
2. 在linux平台上部署库文件( 基础库 和 XServer库 和 GTK库, 即 /usr/local/arm_4.2.1/tools/arm-linux/lib   $XROOT/lib)
3. 添加字体,(拷贝本PC机上的 /usr/share/fonts/X11/ 目录下所有子目录拷贝到 $XROOT/fonts, [#38-xorg-server-1.3.0.0配置中配置了此目录为X11的字体目录]或者有XFREE86.ORG提供的字体包)
4. 启动XServer: 执行Xfbdev。 看看XServer的画面是否出现。mouse是否可以使用
5. fc-cache -f -v 把字体的cache载入内存。 fc-list 确定字体是否有成功载入。 cache的存放位置为 $fonts/var/cache/fontconfig
6. 确认 $XROOT/lib/xserver/SecurityPolicy 文件存在
   确认 $XROOT/etc/gtk-2.0/gdk-pixbuf.loaders 文件存在 {$XROOT/bin/gdk-pixbuf-query-loaders > gdk-pixbuf.loaders 来生成}
   确认 $XROOT/etc/pango/pango.modules 文件存在 {$XROOT/bin/pango-querymodules > pango.modules 来生成。 此文件会把pango+modules的相关资料调入$XROOT/lib/pango/1.6.0/modules中}
7. 测试步骤:
    Xfbdev &
    export DISPLAY=:0.0
    gtk-deom
    看看GTK界面是否成功。
   

note: if error occured, some steps should be rebuild. another note is if you cancel some enviroment variants such as LD_LIBRARY_PATH, you maybe get the result what you want