0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

buildrootに新規アプリを追加

Last updated at Posted at 2024-10-22

必要なファイル

├─ package
│   ├─ helloworld
│   │   ├─ Config.in
│   │   ├─ Makefile
│   │   ├─ helloworld.mk
│   │   └─ helloworld.c
│   ├─ Config.in
...

package/helloworld/Config.in

config BR2_PACKAGE_HELLOWORLD
    bool "helloworld"
    help
      A simple hello world application.

package/helloworld/Makefile

好きに変更してください。

helloworld:
	$(CC) $(CFLAGS) -o helloworld helloworld.c $(LDFLAGS)

package/helloworld/helloworld.mk

HELLOWORLD_LICENSE = Public Domain

define HELLOWORLD_EXTRACT_CMDS
	cp package/helloworld/* $(@D)
endef

define HELLOWORLD_BUILD_CMDS
	(cd $(@D);CC=$(TARGET_CC) CFLAGS="$(TARGET_CFLAGS)" make)
endef

define HELLOWORLD_INSTALL_TARGET_CMDS
	$(INSTALL) -m 755 -D $(@D)/helloworld $(TARGET_DIR)/usr/bin/helloworld
endef

$(eval $(generic-package))

package/helloworld/helloworld.c

好きに作ってください。

package/Config.in

これだけは新規作成ではなく、
既存ファイルにsource "package/helloworld/Config.in"を追加

diff --git a/package/Config.in b/package/Config.in
index e1ceb81dc0..0c9939c3de 100644
--- a/package/Config.in
+++ b/package/Config.in
@@ -8,6 +8,7 @@ menu "Target packages"
        source "package/skeleton-init-openrc/Config.in"
        source "package/skeleton-init-systemd/Config.in"
        source "package/skeleton-init-sysv/Config.in"
+       source "package/helloworld/Config.in"
 
 menu "Audio and video applications"
        source "package/alsa-utils/Config.in"

menuconfig

Target packages から選択し、有効にする。

image.png

Save -> Exit

ビルド

make

実行

qemuでのコマンド例

$ qemu-system-x86_64 -M q35 -enable-kvm -kernel output/images/bzImage -append "root=/dev/vda console=ttyS0" -drive file=./output/images/rootfs.ext2,if=virtio,format=raw -net nic,model=virtio -display gtk -vga std -serial stdio

image.png

アプリのみ再ビルド

アプリのコードを修正した場合makeだけではアプリが再ビルドされない。

以下で行う。
make [package name]-dirclean;make [package name];make

helloworldの場合は以下

make helloworld-dirclean
make helloworld
make

ライブラリを使用してリポジトリから取得する場合

多分普通の開発だとこのパターンだと思う

package/[パッケージ名]/Config.in

ライブラリの指定はdepends onを使う

例)

config BR2_PACKAGE_PDF_VIEWER
    bool "pdf_viewer"
    help
      PDF Viewer
    depends on BR2_PACKAGE_LIBGTK3
    depends on BR2_PACKAGE_MUPDF

mkファイル

一番楽なのはautotoolsだと思う
他にmesonbuildとかgeneric-packageとかあります
generic-packageは上に記載していますが、手動でガリガリやるパターンです
meson.buildを0から作る方法は自分はわかりません

gitを使う場合はバージョンを指定する必要がある
git tagで設定してgit push [tag]を行うこと

mkファイルの例)

PDF_VIEWER_LICENSE = Public Domain

PDF_VIEWER_VERSION = 0.0.1
PDF_VIEWER_SITE = https://github.com/tyano463/pdf_viewer_gtk
PDF_VIEWER_SITE_VERSION = $(PDF_VIEWER_VERSION)
PDF_VIEWER_SITE_METHOD = git
PDF_VIEWER_AUTORECONF = YES
PDF_VIEWER_AUTORECONF_OPTS = --force

PDF_VIEWER_DEPENDENCIES = mupdf libgtk3

$(eval $(autotools-package))

参考アプリのソースコードは以下参照

一時的にローカルのソースコードにしたい

開発途中など動作確認しながら修正をしたいが
tag付けしたりなどリポジトリの操作をしたく無い場合
mkファイルの以下を変更する

  • [パッケージ名]_SITE をローカルのディレクトリにする
  • [パッケージ名]_SITE_METHODlocalにする

例) 上記参考アプリの場合
package/pdf_viewer/pdf_viewer.mk

PDF_VIEWER_LICENSE = Public Domain

PDF_VIEWER_VERSION = 0.0.1
#PDF_VIEWER_SITE = https://github.com/tyano463/pdf_viewer_gtk
PDF_VIEWER_SITE = /home/tyano/workspace/pdf/viewer_gtk
PDF_VIEWER_SITE_VERSION = $(PDF_VIEWER_VERSION)
#PDF_VIEWER_SITE_METHOD = git
PDF_VIEWER_SITE_METHOD = local
PDF_VIEWER_AUTORECONF = YES
PDF_VIEWER_AUTORECONF_OPTS = --force

PDF_VIEWER_DEPENDENCIES = mupdf libgtk3

$(eval $(autotools-package))

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?