quinnwencn / blog

Apache License 2.0
0 stars 0 forks source link

04 基于openWRT增加OSTree组件 #12

Open quinnwencn opened 5 months ago

quinnwencn commented 5 months ago

OpenWRT-22.03版本中并没有支持OSTree,因此需要手动支持OSTree,并集成到OpenWRT的menuconfig配置中,这样方便利用OpenWRT的其他库满足OSTree的依赖问题,否则的话,OSTree的多项依赖都需要依靠手动编译解决。 OpenWRT提供了两种不同的方式来继承依赖库,一种是用于集成开源软件的:https://openwrt.org/docs/guide-developer/packages#buildinstall_optional 另一种则是私有代码集成:https://openwrt.org/docs/guide-developer/helloworld/chapter3 OSTree属于开源仓库,因此我们采用第一种方式集成。 按照Makefile的结构,新增加的Makefile内容如下:

include $(TOPDIR)/rules.mk

# Name, version and release number
# The name and version of your package are used to define the variable to point to the build directory of your package: $(PKG_BUILD_DIR)
PKG_NAME:=libostree
PKG_VERSION:=2023.8
PKG_RELEASE:=1

# Source settings (i.e. where to find the source codes)
# This is a custom variable, used below
PKG_BUILD_DIR=${BUILD_DIR}/${PKG_NAME}-${PKG_VERSION}
PKG_SOURCE:=${PKG_NAME}-${PKG_VERSION}.tar.xz
PKG_SOURCE_URL:=https://github.com/ostreedev/ostree/releases/download/v${PKG_VERSION}/
PKG_HASH:=b6fffc267188e40d60755e6d7f2be65831795baa53b0fd9dd6c6809c7e54796d

include $(INCLUDE_DIR)/package.mk

# Package definition; instructs on how and where our package will appear in the overall configuration menu ('make menuconfig')
define Package/${PKG_NAME}
        SECTION:=libs
        CATEGORY:=Libraries
        TITLE:=ostree
        DEPENDS:=+libunistring +libgpgme +libassuan +libcurl +libidn2 +libatomic +libarchive +libnettle +libcharset +libxml2 +liblzma +libiconv +libselinux +libsqlite3  +glib2 +e2fsprogs
endef

# Package description; a more verbose description on what our package does
define Package/${PKG_NAME}/description
        OSTree library.
endef

define Build/Configure
        $(call Build/Configure/Default,)
endef

# Package install instructions; create a directory inside the package to hold our executable, and then copy the executable we built previously into the folder
define Package/${PKG_NAME}/install
        $(INSTALL_DIR) $(1)/usr/bin
        $(INSTALL_BIN) $(PKG_BUILD_DIR)/ostree $(1)/usr/bin
        $(INSTALL_LIB) $(1)/usr/lib
endef

# This command is always the last, it uses the definitions and variables we give above in order to get the job done
$(eval $(call BuildPackage,${PKG_NAME}))

但是,OSTree在配置过程中发生了错误:

configure: error: Package requirements (e2p) were not met:

Package 'e2p', required by 'virtual:world', not found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables OT_DEP_E2P_CFLAGS
and OT_DEP_E2P_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

但是,e2fsprogs已经添加到依赖中了,只是仍然没有解决这个问题。通过查看staging_dir的输出,发现libe2p.so并没有存在,也就是说,e2fsprogs的编译并没有把编译产物输出到staging_dir目录。查看e2fsprogs的源码路径发现,编译产物输出在了lib目录下:

ll /home/quanwen/work/TCU/tcu/openwrt-22.03/build_dir/target-aarch64_generic_glibc/e2fsprogs-1.46.5/lib/
total 5432
drwxr-xr-x  9 quanwen quanwen    4096 1月  29 16:41 ./
drwxr-xr-x 21 quanwen quanwen    4096 1月  29 16:41 ../
-rw-r--r--  1 quanwen quanwen    1340 12月 30  2021 Android.bp
drwxr-xr-x  3 quanwen quanwen    4096 1月  29 16:40 blkid/
-rw-r--r--  1 quanwen quanwen   16237 1月  29 16:40 config.h
-rw-r--r--  1 quanwen quanwen   15455 12月 30  2021 config.h.in
-r--r--r--  1 quanwen quanwen     311 1月  29 16:40 dirpaths.h
-rw-r--r--  1 quanwen quanwen     323 12月 30  2021 dirpaths.h.in
drwxr-xr-x  3 quanwen quanwen    4096 1月  29 16:40 e2p/
drwxr-xr-x  4 quanwen quanwen    4096 1月  29 16:40 et/
drwxr-xr-x  4 quanwen quanwen   12288 1月  29 16:41 ext2fs/
-rw-r--r--  1 quanwen quanwen    2446 12月 30  2021 fpopen.c
-rw-r--r--  2 quanwen quanwen   58896 1月  29 16:40 libcom_err.a
-rwxr-xr-x  4 quanwen quanwen   18120 1月  29 16:40 libcom_err.so*
-rwxr-xr-x  4 quanwen quanwen   18120 1月  29 16:40 libcom_err.so.0*
-rwxr-xr-x  4 quanwen quanwen   18120 1月  29 16:40 libcom_err.so.0.0*
-rw-r--r--  2 quanwen quanwen  264336 1月  29 16:40 libe2p.a
-rwxr-xr-x  4 quanwen quanwen   42696 1月  29 16:40 libe2p.so*
-rwxr-xr-x  4 quanwen quanwen   42696 1月  29 16:40 libe2p.so.2*
-rwxr-xr-x  4 quanwen quanwen   42696 1月  29 16:40 libe2p.so.2.3*
-rw-r--r--  2 quanwen quanwen 2880910 1月  29 16:41 libext2fs.a
-rwxr-xr-x  4 quanwen quanwen  451472 1月  29 16:41 libext2fs.so*
-rwxr-xr-x  4 quanwen quanwen  451472 1月  29 16:41 libext2fs.so.2*
-rwxr-xr-x  4 quanwen quanwen  451472 1月  29 16:41 libext2fs.so.2.4*
-rw-r--r--  2 quanwen quanwen  170888 1月  29 16:40 libss.a
-rwxr-xr-x  4 quanwen quanwen   32944 1月  29 16:40 libss.so*
-rwxr-xr-x  4 quanwen quanwen   32944 1月  29 16:40 libss.so.2*
-rwxr-xr-x  4 quanwen quanwen   32944 1月  29 16:40 libss.so.2.0*
-rw-r--r--  2 quanwen quanwen  384062 1月  29 16:40 libsupport.a
-rw-r--r--  1 quanwen quanwen    1072 12月 30  2021 Makefile.bsd-lib
-rw-r--r--  1 quanwen quanwen     170 12月 30  2021 Makefile.checker
-rw-r--r--  1 quanwen quanwen    1341 12月 30  2021 Makefile.darwin-lib
-rw-r--r--  1 quanwen quanwen    2473 12月 30  2021 Makefile.elf-lib
-rw-r--r--  1 quanwen quanwen     503 12月 30  2021 Makefile.library
-rw-r--r--  1 quanwen quanwen     796 12月 30  2021 Makefile.profile
-rw-r--r--  1 quanwen quanwen    1920 12月 30  2021 Makefile.solaris-lib
drwxr-xr-x  3 quanwen quanwen    4096 1月  29 16:40 ss/
drwxr-xr-x  2 quanwen quanwen    4096 1月  29 16:40 support/
drwxr-xr-x  2 quanwen quanwen    4096 1月  29 16:40 uuid/

e2fsprogs是OpenWRT默认包含的库,因此不打算对他的编译过多参与,只通过上面的提示添加两个环境变量:

export OT_DEP_E2P_CFLAGS="-I${BUILD_DIR}/target-aarch64_generic_glibc/e2fsprogs-1.46.5/lib/e2p"
export OT_DEP_E2P_LIBS="-L{BUILD_DIR}/target-aarch64_generic_glibc/e2fsprogs-1.46.5/lib"

这样,e2p的检查就通过了,但是,却遇到了另外一个问题:

configure: error: Package requirements (fuse >= 2.9.2) were not met:

Package 'fuse', required by 'virtual:world', not found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables BUILDOPT_FUSE_CFLAGS
and BUILDOPT_FUSE_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

这个问题可以通过在Makefile中的DEPENDS增加依赖解决,最后成功编译!完整的Makefile如下:

include $(TOPDIR)/rules.mk

# Name, version and release number
# The name and version of your package are used to define the variable to point to the build directory of your package: $(PKG_BUILD_DIR)
PKG_NAME:=libostree
PKG_VERSION:=2023.8
PKG_RELEASE:=1

PKG_BUILD_DIR=${BUILD_DIR}/${PKG_NAME}-${PKG_VERSION}
PKG_SOURCE:=${PKG_NAME}-${PKG_VERSION}.tar.xz
PKG_SOURCE_URL:=https://github.com/ostreedev/ostree/releases/download/v${PKG_VERSION}/
PKG_HASH:=b6fffc267188e40d60755e6d7f2be65831795baa53b0fd9dd6c6809c7e54796d

include $(INCLUDE_DIR)/package.mk

# for some unknow reason, e2fsprogs dependencies added bellow, but 
export OT_DEP_E2P_CFLAGS="-I${BUILD_DIR}/target-aarch64_generic_glibc/e2fsprogs-1.46.5/lib/e2p"
export OT_DEP_E2P_LIBS="-L{BUILD_DIR}/target-aarch64_generic_glibc/e2fsprogs-1.46.5/lib"

define Package/${PKG_NAME}
        SECTION:=libs
        CATEGORY:=Libraries
        TITLE:=ostree
        DEPENDS:=+libunistring +libgpgme +libassuan +libcurl +libidn2 +libatomic +libarchive +e2fsprogs +libnettle +libcharset +libxml2 +liblzma +libiconv +libselinux +libsqlite3 +glib2 +libfuse
endef

define Package/${PKG_NAME}/description
        OSTree library.
endef

define Build/Configure
        $(call Build/Configure/Default, --prefix=${STAGING_DIR}/usr)
endef

define Package/${PKG_NAME}/install
        $(INSTALL_DIR) $(1)/usr/bin
        $(INSTALL_BIN) $(PKG_BUILD_DIR)/ostree $(1)/usr/bin
        $(INSTALL_BIN) $(PKG_BUILD_DIR)/ostree-prepare-root $(1)/usr/bin
        $(INSTALL_BIN) $(PKG_BUILD_DIR)/rofiles-fuse $(1)/usr/bin
        $(INSTALL_DIR) $(1)/usr/lib
        $(CP) $(PKG_BUILD_DIR)/.libs/libostree*.so* $(1)/usr/lib
        $(CP) $(PKG_BUILD_DIR)/.libs/lib*.a $(1)/usr/lib
endef

$(eval $(call BuildPackage,${PKG_NAME}))

这里的两个环境变量是为了解决e2fsprogs的问题,更好的方式应该是通过增加package的方式。

quinnwencn commented 4 months ago

这样的方式遗留了一个问题,如果有其他组件依赖OSTree,就会遇到找不到头文件和库文件。根据OpenWRT的介绍,如果有其他的包依赖当前编译的包,那么需要定义Build/InstallDev,并将需要的库文件和头文件安装。

Build/InstallDev (optional) For things needed to compile packages against it (static libs, header files), but that are of no use on the target device.

因此,需要将安装方式改为:

define Build/InstallDev
        $(INSTALL_DIR) $(1)/usr/bin
        $(INSTALL_BIN) $(PKG_BUILD_DIR)/.libs/ostree $(1)/usr/bin
        $(INSTALL_BIN) $(PKG_BUILD_DIR)/ostree-prepare-root $(1)/usr/bin
        $(INSTALL_DIR) $(1)/usr/lib
        $(CP) $(PKG_BUILD_DIR)/.libs/lib*.a $(1)/usr/lib
        $(CP) $(PKG_BUILD_DIR)/.libs/lib*.so* $(1)/usr/lib
        $(INSTALL_DIR) $(1)/usr/include
        $(CP) $(PKG_BUILD_DIR)/ipkg-install/usr/include/ostree-1/* $(1)/usr/include
endef

define Package/${PKG_NAME}/install
        $(call Build/Install/Default,)
endef

Ref: github.com/login

quinnwencn commented 9 hours ago

配置内核:

make kernel_menuconfig