2022-05-31に更新

Building packages

Using Termux build environment

A recommended way of building is to use official build environment available on Github: https://github.com/termux/termux-packages. See Termux Developer's Wiki for tips about its usage.

On-device usage

It is possible to use our build environment directly on device without Docker image or VM setup. You need only to:

  1. Clone the git repository:
git clone https://github.com/termux/termux-packages
  1. Execute setup script:
cd termux-packages
./scripts/setup-termux.sh

Packages are built by executing./build-package.sh -I package_name. Note that option "-I" tells build-package.sh to download and install dependency packages automatically instead of building them which makes build a lot faster.

By default, with Termux build environment you can build only existing packages. If package is not exist in ./packages directory, then you will have to write its build.sh manually.

If you managed to successfully build a new package, consider to make a pull request.

Some notes about on-device building:

  • Some packages are considered as unsafe for building on device as they remove stuff from $PREFIX.
  • During build process, the compiled stuff is installed directly to $PREFIX and is not tracked by dpkg. This is expected behaviour. If you don't want this stuff, install generated deb files and uninstall.
  • Some packages may throw errors when building on device. This is known issue and tracked in https://github.com/termux/termux-packages/issues/4157.
  • On-device package building for android-5 branch is not tested well.

Manually building packages

There no universal guide about building/porting packages in Termux, especially since Termux isn't a standard platform.

Though you can follow some recommendations mentioned here:

  1. Make sure that minimal set of build tools is installed:

    pkg install build-essential
    
  2. After extracting package source code, check for files named like "README" or "INSTALL". They usually contain information about how to build a package.

  3. Autotools based projects (have ./configure script in project's root) in most cases can be built with the following commands:

 ./configure --prefix=$PREFIX
 make && make install

It is highly recommended to check the accepted configuration options by executing ./configure --help.

In case of configuration failure, read the output printed on screen and check the file config.log (contains a lot of text, but all information about error's source exist in it).

  1. CMake based projects (have CMakeLists in project's root) should be possible to build with:
 mkdir build
 cd build
 cmake -DCMAKE_INSTALL_PREFIX="${PREFIX}" ..
 make
 make install

Be careful when running make install as it will unconditionally write files to $PREFIX. Never execute any of build commands as root.

Note about "bug reports": if you trying to build custom package and it fails, do not submit bug reports regarding it.

Note about "package requests": if you decided to submit a package request for package that you can't build, make sure this package will be useful for others. Otherwise such requests will be just rejected.

https://rentry.co/termux


Termuxのビルド環境を利用する

Githubで公開されている公式のビルド環境(https://github.com/termux/termux-packages)を使ってビルドすることをお勧めします。使い方のコツは Termux Developer's Wiki を参照してください。

https://github.com/termux/termux-packages/wiki/Build-environment - ビルド環境を構築する。
https://github.com/termux/termux-packages/wiki/Building-packages](https://github.com/termux/termux-packages/wiki/Building-packages)) - パッケージをビルドする方法。
https://github.com/termux/termux-packages/wiki/Creating-new-package - パッケージスクリプト(build.sh)の書き方についての情報です。

デバイス上での使用

DockerイメージやVMのセットアップをせずに、デバイス上で直接ビルド環境を使用することができます。必要な作業は以下の通りです。

git リポジトリをクローンする。

git clone https://github.com/termux/termux-packages

セットアップスクリプトを実行する。

cd termux-packages
./scripts/setup-termux.sh

を実行します。
パッケージのビルドは、./build-package.sh -I package_name を実行します。I" オプションは build-package.sh が依存パッケージを自動的にダウンロードし、インストールすることを意味し、ビルドを高速化します。

Termuxのビルド環境では、デフォルトで既存のパッケージのみをビルドすることができます。もしパッケージが ./packages ディレクトリに存在しない場合は、手動で build.sh を作成する必要があります。

もし、新しいパッケージのビルドに成功した場合は、プルリクエストを作成することを検討してください。

デバイス上でのビルドに関するいくつかの注意点。

  • パッケージの中には、$PREFIX にあるものを削除してしまうものがあり、デバイス上でビルドするには安全でないと考えられています。
  • ビルド中に、コンパイルされたものが $PREFIX に直接インストールされ、dpkg によって追跡されることはありません。これは予想された動作です。このようなものが不要な場合は、生成された deb ファイルをインストールしてからアンインストールしてください。
  • パッケージによっては、デバイス上でビルドする際にエラーが発生することがあります。これは既知の問題であり、https://github.com/termux/termux-packages/issues/4157 で追跡されています。
  • android-5 ブランチのデバイス上でのパッケージのビルドはうまくテストされていません。

手動でパッケージをビルドする

Termuxは標準的なプラットフォームではないため、パッケージのビルドやポーティングに関する普遍的なガイドはありません。

しかし、ここに書かれているいくつかの推奨事項に従うことができます。

  1. 最小限のビルドツールがインストールされていることを確認してください。
pkg install build-essential
  1. パッケージのソースコードを展開したら、"README" や "INSTALL" といった名前のファイルがあるかどうか確認してください。これらは通常、パッケージのビルド方法に関する情報を含んでいます。
  2. Autotoolsベースのプロジェクト(プロジェクトのルートに./configureスクリプトがある)は、ほとんどの場合、次のコマンドでビルドすることができます。
./configure --prefix=$PREFIX
make && make install

./configure --helpを実行して、受け入れられる設定オプションを確認することを強くお勧めします。

設定に失敗した場合は、画面に表示される出力を読み、config.log ファイルを確認します (多くのテキストが含まれていますが、エラーの原因に関するすべての情報が含まれています)。

  1. CMakeベースのプロジェクト(プロジェクトのルートにCMakeListsがある)では、ビルドが可能なはずです。
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX="${PREFIX}" ....
make
make install

make installを実行すると、無条件で$PREFIX にファイルを書き込んでしまうので、注意してください。また、ビルドコマンドは絶対にroot権限で実行しないでください。

バグレポートに関する注意: カスタムパッケージをビルドしようとして失敗した場合、それに関するバグレポートを提出しないでください。

パッケージ要求に関する注意: もし、あなたがビルドできないパッケージのパッケージ要求を提出することに決めたなら、そのパッケージが他の人にとって有用であることを確認してください。そうでなければ、そのような要求は単に拒否されるだけでしょう。

https://rentry.co/c92nx

ツイッターでシェア
みんなに共有、忘れないようにメモ

tomato

Crieitは誰でも投稿できるサービスです。 是非記事の投稿をお願いします。どんな軽い内容でも投稿できます。

また、「こんな記事が読みたいけど見つからない!」という方は是非記事投稿リクエストボードへ!

有料記事を販売できるようになりました!

こじんまりと作業ログやメモ、進捗を書き残しておきたい方はボード機能をご利用ください。
ボードとは?

コメント