Jump to content

How to build third-party sources into deb packages using armbian tools?


midix

Recommended Posts

I don't want to torture my SD card with full OS image rewrites or compilation on the device itself, so I would like to cross-compile.

 

I just set up a ubuntu/bionic64 VirtualBox through Vagrant using https://github.com/armbian/build

 

Currently, I don't want to build entire image or kernel from scratch but I noticed that compile.sh and related scripts contain many convenience functions and tools. I already started compile.sh once to let it prepare the virtual machine for cross-compile tasks and it successfully installed all the dependencies.

 

I got especially interested in extras-buildpkgs folder. As I understand, I can put my own package descriptions there and Armbian tools will find it and offer to create packages for it?

 

Is there any simple way to leverage Armbian tools to create a deb package of a single third party program (ZynAddSubFx, to be more exact - I already have it compiled once directly on an ARM device, so I know it's doable) without compiling the kernel or OS? 

 

Ideally, I would like to get the "make install" results of the software to be collected into a deb package, so I can just install it on the target machine (NanoPi Neo2, to be specific).

Link to comment
Share on other sites

9 hours ago, midix said:

I got especially interested in extras-buildpkgs folder. As I understand, I can put my own package descriptions there and Armbian tools will find it and offer to create packages for it?


This part was not designed for end-user based packages. Absolutely agree that it's nice to have but would require some RFC, while our resources are ATM too low for such changes.

 

Currently, you need to make use of chroot compilation with your own script, this way:
https://docs.armbian.com/Developer-Guide_User-Configurations/#user-provided-image-customization-script

Link to comment
Share on other sites

It would be nice if the SDK could easily build deb packages, similar to openwrt's SDK.  I checked into chroot-buildpackages.sh but didn't mess with distcc setup.  Larger projects will need distcc or much patience.

 

This is sort of what I do to "cross-compile" deb packages.  You still need to build an image but you don't have to use it.  You can just copy your deb packages over to target os.

 

To get make install results into deb package, you need to use some sort of debian package builder.  Many options, guides, and tutorials are available online.  The example below uses dpkg-deb.

 

After you build initial image, you can speed up image building by setting clean level: ./compile CLEAN_LEVEL=""

 

Needs a small patch to SDK, as we need a way to get out the debs (or use another method, like network).

diff --git a/lib/image-helpers.sh b/lib/image-helpers.sh
index a99163e..bea81fc 100644
--- a/lib/image-helpers.sh
+++ b/lib/image-helpers.sh
@@ -110,7 +110,7 @@ customize_image()
        chmod +x $SDCARD/tmp/customize-image.sh
        mkdir -p $SDCARD/tmp/overlay
        # util-linux >= 2.27 required
-       mount -o bind,ro $SRC/userpatches/overlay $SDCARD/tmp/overlay
+       mount -o bind $SRC/userpatches/overlay $SDCARD/tmp/overlay
        display_alert "Calling image customization script" "customize-image.sh" "info"
        chroot $SDCARD /bin/bash -c "/tmp/customize-image.sh $RELEASE $LINUXFAMILY $BOARD $BUILD_DESKTOP"
        umount $SDCARD/tmp/overlay

In userpatches/customize-image.sh, drop your compile code.  Or for multiple packages, do something like:

for FN in /tmp/overlay/packages/*; do
        source $FN
done

Add your compile script.  Here is a hello world example, copy to userpatches/overlay/packages/helloworld:

#!/bin/sh -e
# example based on https://ubuntuforums.org/showthread.php?t=910717

PACKAGE="helloworld"
VERSION="1.0-1"
BDIR="${PACKAGE}_${VERSION}"
ARCH="armhf"
MAINTAINER="lrrr <lrrr@armbian.com>"

cat <<-EOF > /tmp/hw.c
#include <stdio.h>
int main(void){
        printf("Hello world!\n");
        return 0;
}
EOF

mkdir -p ${BDIR}/usr/local/bin
gcc -Wall /tmp/hw.c -o ${BDIR}/usr/local/bin/$PACKAGE

mkdir -p ${BDIR}/DEBIAN
cat <<-EOF > ${BDIR}/DEBIAN/control
Package: $PACKAGE
Version: $VERSION
Section: base
Priority: optional
Architecture: $ARCH
Maintainer: $MAINTAINER
Description: Hello World
 When you need some sunshine, just run this
 small program!
EOF

dpkg-deb --build $BDIR

# requires armbian SDK mod for /tmp/overlay (rw)
mv -v ${BDIR}.deb /tmp/overlay

rm -fr ${BDIR} hw.c

 

Link to comment
Share on other sites

Thanks for the helpful hints.

 

For now, I managed to create something hacky using the following approach:

In debootstrap-ng.sh I commented out the line
# rm -rf $SDCARD

 

So now I had left valid rootfs and I could do

 

armccrootpath=/home/vagrant/armbian/.tmp/rootfs-next-nanopineo2-bionic-no
mount -t proc chproc $armccrootpath/proc
mount -t sysfs chsys $armccrootpath/sys
mount -t devtmpfs chdev $armccrootpath/dev || mount --bind /dev $armccrootpath/dev
mount -t devpts chpts $armccrootpath/dev/pts

cp /usr/bin/qemu-aarch64-static $armccrootpath/usr/bin/
chroot $armccrootpath

 

From there, I continued as usual and was able to compile ZynAddSubFx. I tried to create a deb using checkinstall tool, but unfortunately it failed during tar process and complained about many missing Voice files. So I gave up, zipped entire zynaddsubfx folder with build results and just copied it over to nanopineo2 and ran `make install` there. It worked just fine at the end.

Link to comment
Share on other sites

I usually use the cached rootfs in cache/rootfs.  Extract, then mount pseudo-filesystems and copy over static qemu like you posted.

 

Quick hacks are good if they get the job done.  :)

 

Another easy way to get chroot with customize-image.sh and do things manually:

#!/bin/sh
echo "Entering chroot for $1 $2 $3"
bash

Before you exit chroot, copy your debs/files with another shell, network, etc.

Link to comment
Share on other sites

On 9/26/2018 at 7:50 PM, midix said:

chroot $armccrootpath

 

From there, I continued as usual ...

 

When I try to do the same, chrooting fails with:

chroot: failed to run command ‘/bin/bash’: No such file or directory

 

So I wonder, how that chroot should work anyhow, as in /bin and /usr/bin are now ARM-binaries, while the compiling host needs amd64 binaries.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines