Make a portable Fcitx

From Fcitx
Jump to navigation Jump to search
This page contains changes which are not marked for translation.


Intro

Portable means extract and run, no extra dependency, all required library is in the tarball. But still, correct environment variables are required to make Fcitx work.

Limitation

  • im module cannot be used, only XIM will work.
  • not all input method support this.

Prepare

  • Get latest source, at least newer than 4.2.1.
  • Make sure all the depdenency is installed.
  • The kernel version of the machine you compile on is the lowest kernel version of this Fcitx can run on, due to glibc limit. So use the linux with oldest kernel you can find to compile.

Compile

Read Compile from source first, and grab all required dependency. Take fcitx 4.2.1 as example.

Warning: There is an existing bug in 4.2.1 that disable pango will trigger it. You should merge this change this change to the code.



mkdir -p $HOME/portable/
cd $HOME/portable/
wget http://fcitx.googlecode.com/files/fcitx-4.2.1_dict.tar.xz
tar xvf fcitx-4.2.1_dict.tar.xz
cd fcitx-4.2.1/
mkdir build
cd build/
#### Disable most dependency ####
cmake -DCMAKE_INSTALL_PREFIX=$HOME/portable/dest -DENABLE_DBUS=Off -DENABLE_PANGO=Off -DENABLE_OPENCC=Off ..
make
make install

Make it portable

In order to make it portable, all rpath need to be reomved, with chrpath, you might not install it, so install it first.

cd $HOME/portable/dest/bin
for f in *; do chrpath -d $f; done
cd $HOME/portable/dest/lib
for f in `find . -name '*.so'`; do chrpath -d $f; done

Next find all required libraries and copy them to the lib directory.

cd $HOME/portable/dest/
filelist=`find . -type f`
lddresult=`for f in $filelist; do ldd $f | grep so; done`
librarylist=`for f in $lddresult
do
echo $f
done | grep '^/' | sort | uniq`
cp $librarylist lib/

And then replace all binary with proper sccript wrapper, but if you only need to run fcitx, you can just do this

cd $HOME/portable/dest/
mv bin/fcitx bin/fcitx.bin

and create bin/fcitx with following content

#!/bin/sh
export FCITXDIR="$( cd "$( dirname "$0" )/.." && pwd )"
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$FCITXDIR/lib
$FCITXDIR/lib/ld-linux-x86-64.so.2 $FCITXDIR/bin/fcitx.bin "$@"

and make it executable

chmod +x bin/fcitx

Then there you go, create a tarball for dest/ directory

cd $HOME/portable/
tar czvf portable.tar.gz dest/

If you wish add additional component to this, consider install other required library and addon to this prefix before "make it portable" step.