いくやの斬鉄日記

オープンソースからハイスクールフリート、The Beatlesまで何でもありの自称エンターテインメント日記。

Ubuntuで動作するRStudio用fcitx-qt5をビルドする方法 完全版

2016年12月17日 01時26分25秒 | RStudio
この投稿はRStudio Advent Calendar 2016 17日目の記事です。

Ubuntu 16.04 + Fcitx + RStudio 1.0で日本語を入力する方法で簡単なビルド方法を書きましたが、もう少し詳細に解説を加えながらビルドする方法をお伝えします。

1. Qtを取得する
Qtをダウンロードするシェルスクリプトを読めば取得方法はすぐにわかりますが、今回は64bit版を例にします。

$ wget https://s3.amazonaws.com/rstudio-buildtools/QtSDK-5.4.0-x86_64.tar.gz

2. 展開する
別にどこでもいいんですけど、今回は/opt以下にしました。

$ sudo tar xf QtSDK-5.4.0-x86_64.tar.gz -C /opt

3. fcitx-qt5のソースコードをダウンロード

$ sudo apt source fcitx-qt5

4. ビルドに必要なパッケージをインストールする
これでいいはずですが検証していません。ついでにカレントフォルダーを移動します。

$ sudo apt install build-essential
$ sudo apt build-dep fcitx-qt5
$ cd fcitx-qt5-(バージョン)

5. debian/以下のファイルを変更する

5.1 debian/contorl
diff -urN fcitx-qt5-1.0.5/debian/control fcitx-qt5-1.0.5-rstudio/debian/control
--- fcitx-qt5-1.0.5/debian/control	2015-10-30 18:38:17.000000000 +0900
+++ fcitx-qt5-1.0.5-rstudio/debian/control	2016-11-02 18:58:13.248813895 +0900
@@ -8,19 +8,17 @@
                extra-cmake-modules (>= 1.4.0),
                fcitx-libs-dev (>= 1:4.2.8),
                intltool,
-               pkg-config,
-               qtbase5-dev,
-               qtbase5-private-dev
+               pkg-config
 Standards-Version: 3.9.6
 Homepage: http://www.fcitx-im.org
 Vcs-Git: git://anonscm.debian.org/pkg-ime/fcitx-qt5.git
 Vcs-Browser: http://anonscm.debian.org/gitweb/?p=pkg-ime/fcitx-qt5.git
 
-Package: fcitx-frontend-qt5
+Package: fcitx-frontend-qt5-rstudio
 Architecture: any
 Multi-Arch: same
 Pre-Depends: ${misc:Pre-Depends}
-Depends: fcitx-module-dbus, ${misc:Depends}, ${shlibs:Depends}
+Depends: fcitx-module-dbus, ${misc:Depends}, ${shlibs:Depends}, rstudio, libfcitx-qt5-1-rstudio
 Description: Free Chinese Input Toy of X - Qt5 IM Module frontend
  Fcitx is the Free Chinese Input Toy of X, which was initially designed
  for Chinese users, and used XIM protocol. Now it has already evolved
@@ -45,7 +43,7 @@
 Description: transitional dummy package
  This is a transitional dummy package. It can safely be removed.
 
-Package: libfcitx-qt5-1
+Package: libfcitx-qt5-1-rstudio
 Architecture: any
 Multi-Arch: same
 Pre-Depends: ${misc:Pre-Depends}

今回は吊るしのQtは使用しないので、ビルドに必要な依存関係(Build-dep)から外しています。あっても大して問題があるわけではありません。どうせ使いませんし。
また、パッケージ名はオリジナルと被らないようにfcitx-frontend-qt5-rstudioとlibfcitx-qt5-1-rstudioに変更し、前者のDependsをいじってrstudioそのものと後者に依存させています。
とはいえ、ここは本当はもう少しいじらないとダメなところのような気もします。後者から前者に依存させるとか。
まぁ今回はそんなに厳密にやらんでもいいでしょう。

5.2 debian/fcitx-frontend-qt5-rstudio.install
diff -urN fcitx-qt5-1.0.5/debian/fcitx-frontend-qt5-rstudio.install fcitx-qt5-1.0.5-rstudio/debian/fcitx-frontend-qt5-rstudio.install
--- fcitx-qt5-1.0.5/debian/fcitx-frontend-qt5-rstudio.install	1970-01-01 09:00:00.000000000 +0900
+++ fcitx-qt5-1.0.5-rstudio/debian/fcitx-frontend-qt5-rstudio.install	2016-11-02 18:28:49.644966838 +0900
@@ -0,0 +1 @@
+opt/Qt5.4.0/5.4/gcc_64/plugins/platforminputcontexts/libfcitxplatforminputcontextplugin.so usr/lib/rstudio/bin/plugins/platforminputcontexts/

パッケージ名.install(生成されるパッケージが単一の場合はただのinstall)には、パッケージに含めるファイルを記載します。
スペースで区切り、前はファイルの在り処、後はインストールしたいフォルダーです。
先頭に"/"を入れないのがコツです。
元のフォルダーにはこんなものはないので(そらそうだ)、ファイルスタンプはおかしなことになります。

5.3 debian/ libfcitx-qt5-1-rstudio.install
diff -urN fcitx-qt5-1.0.5/debian/fcitx-frontend-qt5.install fcitx-qt5-1.0.5-rstudio/debian/fcitx-frontend-qt5.install
--- fcitx-qt5-1.0.5/debian/fcitx-frontend-qt5.install	2015-10-30 18:38:17.000000000 +0900
+++ fcitx-qt5-1.0.5-rstudio/debian/fcitx-frontend-qt5.install	1970-01-01 09:00:00.000000000 +0900
@@ -1 +0,0 @@
-usr/lib/*/qt5

ファイル名を変更したのでなくなっています。

5.4 debian/ibfcitx-qt5-1-rstudio.install
diff -urN fcitx-qt5-1.0.5/debian/libfcitx-qt5-1-rstudio.install fcitx-qt5-1.0.5-rstudio/debian/libfcitx-qt5-1-rstudio.install
--- fcitx-qt5-1.0.5/debian/libfcitx-qt5-1-rstudio.install	1970-01-01 09:00:00.000000000 +0900
+++ fcitx-qt5-1.0.5-rstudio/debian/libfcitx-qt5-1-rstudio.install	2016-11-02 18:50:49.061389459 +0900
@@ -0,0 +1 @@
+usr/lib/*/libFcitxQt5*.so.* usr/lib/rstudio/bin/

5.1に準じますが、RStudioのフォルダーに入れていることがわかるかと思います。

5.5 debian/libfcitx-qt5-1.install
diff -urN fcitx-qt5-1.0.5/debian/libfcitx-qt5-1.install fcitx-qt5-1.0.5-rstudio/debian/libfcitx-qt5-1.install
--- fcitx-qt5-1.0.5/debian/libfcitx-qt5-1.install	2015-10-30 18:38:17.000000000 +0900
+++ fcitx-qt5-1.0.5-rstudio/debian/libfcitx-qt5-1.install	1970-01-01 09:00:00.000000000 +0900
@@ -1 +0,0 @@
-usr/lib/*/libFcitxQt5*.so.*

5.3と同じです。

5.6 debian/rules
diff -urN fcitx-qt5-1.0.5/debian/rules fcitx-qt5-1.0.5-rstudio/debian/rules
--- fcitx-qt5-1.0.5/debian/rules	2015-10-30 18:38:17.000000000 +0900
+++ fcitx-qt5-1.0.5-rstudio/debian/rules	2016-11-02 18:14:55.890254321 +0900
@@ -9,5 +9,9 @@
 %:
 	dh $@ --parallel --fail-missing
 
+override_dh_auto_configure:
+	dh_auto_configure -- \
+	-DCMAKE_PREFIX_PATH=/opt/Qt5.4.0/5.4/gcc_64/
+
 override_dh_strip:
 	dh_strip --dbg-package=libfcitx-qt5-dbg

ここが最大のポイントです。fcitx-qt5はcmakeでビルドできるようになっていますが、このようなオプションをつければもともとのconfigureオプションに"CMAKE_PREFIX_PATH"を追加することができます。
それにより、吊るしのQt5を使わなくなるという按配です。

6. ビルドする
依存関係に問題がなく、また上記の修正を適切に施していればパッケージがビルドできます。

$ dpkg-buildpackage -r -uc -b

7. RStudioを動作させるUbuntuに生成したパッケージをインストールする
インストールするパッケージはfcitx-frontend-qt5-rstudio_1.0.5-1_amd64.debとlibfcitx-qt5-1-rstudio_1.0.5-1_amd64.debだけです。これ以外は絶対にインストールしないでください。

というわけで、やっていることは
・ もとのパッケージ名と被らないように変更
・ インストールするパスをRStudioに合わせて変更
・ RStudioと同じバージョンのQtでビルドできるように変更
のたった3つで、パッケージングの知識があれば全く難しくないことであることがお分かりいただけたと思います。もちろんRStudioユーザーにその手のことが詳しい人なんてなかなかいないでしょうから、このようにRStudio Advent Calendar 2016に参加したというわけですが。

ちなみにRStudioそのものを吊るしのQt(とPandoc)でビルドしたいという場合は、Vine Linuxのリポジトリにあるsrpmが参考になると思います。
コメント (3)    この記事についてブログを書く
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする
« 最近軍歌・戦時歌謡をよく聴... | トップ | Ubuntu Weekly Recipe 第451... »
最新の画像もっと見る

3 コメント

コメント日が  古い順  |   新しい順
Unknown (ikuya)
2017-03-22 20:11:28
I am sorry for late reply.

> Is this means I have to cd to the folder with the right name of QT version?
No. It is version of fcitx-qt5. If you use Ubuntu 16.04, it is 1.0.5.
返信する
Need help (mashiro)
2017-03-17 23:53:18
In step 4: $ cd fcitx-qt5-(バージョン)
Is this means I have to cd to the folder with the right name of QT version? I cannot find this folder however...
返信する
Need help (mashiro)
2017-03-17 23:48:30
自分の日本語はよくありません。でも、私はまた、fcitxの問題は、スポトされていません遭遇しました。だから、英語を使って私を助けてもらえますか?
本当にありがとうございます!
返信する

コメントを投稿

RStudio」カテゴリの最新記事