How to add my own software to a Buildroot Linux package?

In general, the sources for buildroot packages are taken from a (downloaded) tarball. What you are doing right now (placing the sources inside package/HelloWorld) is not the right way to proceed.

Buildroot does have provisions for 'local' package sources, which you could use if you really need to. You'll need the HELLOWORLD_SITE_METHOD variable for that.

Please refer to http://buildroot.uclibc.org/downloads/manual/manual.html#adding-packages for more information.

Also, you don't need to define HELLOWORLD_DIR, HELLOWORLD_BINARY, HELLOWORLD_TARGET_BINARY.

Update: regarding your additional question:

UPDATE: The program builds and install at the desired location but when I try to run it like so: ./helloworld, I get: bash: ./helloworld: No such file or directory, it has execution rights.. what is the matter with it? (I try to run it after I mount the rootfs.ext2 into a ubuntu directory, the target arch for buildroot is i368, so it should be ok, right?)

No, it does not work like that. You can't just mount rootfs.ext2 and expect to run programs from it. This is, among others, because the programs inside rootfs.ext2 are compiled against the libraries also inside rootfs.ext2, but if you run it like that it will use the libraries in /usr/lib. You either have to boot your system entirely with the rootfs.ext2, use qemu, or use a chroot environment. For chroot, you should use the 'tar' filesystem format, not ext2. See also here: http://buildroot.uclibc.org/downloads/manual/manual.html#_chroot


Minimal tested example on top of 2016.05

GitHub upstream: https://github.com/cirosantilli/buildroot/tree/in-tree-package-2016.05

This example adds the package source in-tree, which is simple for educational purposes and the way to go if you want to merge back (kudos!),

If you do not intend on merging back (booooh!), it is more likely that you will want to use Buildroot as a git submodule and either:

  • an out of tree package with BR2_EXTERNAL as shown at: https://github.com/cirosantilli/buildroot/tree/out-of-tree-2016.05
  • *_OVERRIDE_SRCDIR + other git submodules as explained at: How to modify the source of Buildroot packages for package development?

Files modified:

package/Config.in

menu "Misc"
    source "package/hello/Config.in"
endmenu

package/hello/Config.in

config BR2_PACKAGE_HELLO
    bool "hello"
    help
        Hello world package.

        http://example.com

package/hello/hello.mk

################################################################################
#
# hello
#
################################################################################

HELLO_VERSION = 1.0
HELLO_SITE = ./package/hello/src
HELLO_SITE_METHOD = local

define HELLO_BUILD_CMDS
    $(MAKE) CC="$(TARGET_CC)" LD="$(TARGET_LD)" -C $(@D)
endef

define HELLO_INSTALL_TARGET_CMDS
    $(INSTALL) -D -m 0755 $(@D)/hello $(TARGET_DIR)/usr/bin
endef

$(eval $(generic-package))

package/hello/src/.gitignore

hello

package/hello/src/Makefile

CC = gcc

.PHONY: clean

hello: hello.c
    $(CC) -o '$@' '$<'

clean:
    rm hello

package/hello/src/hello.c

#include <stdio.h>

int main(void) {
    puts("hello");
}

Usage:

make qemu_x86_64_defconfig
echo 'BR2_PACKAGE_HELLO=y' >> .config
make BR2_JLEVEL=2
qemu-system-x86_64 -M pc -kernel output/images/bzImage -drive file=output/images/rootfs.ext2,if=virtio,format=raw -append root=/dev/vda -net nic,model=virtio -net user

From inside qemu:

hello

Expected output:

hello

Tested in Ubuntu 16.04.