Buildroot external not entering into project source directory specified by HELLO_SITE specified in hello.mk file

27 views Asked by At

I'm trying to build a very simple hello world program using a buildroot external project.

My project structure looks like this from top level.

buildroot hello

inside hello I have this tree

.
├── Config.in
├── external.desc
├── external.mk
├── hello.mk
└── src
    ├── Makefile
    └── hello.c

The contents of those files are as follows.

Config.in

config BR2_PACKAGE_HELLO
    bool "hello"
    help
        Hello world package.
        
        http://example.com

external.desc

name: HELLO

external.mk

#include $(sort $(wildcard $(BR2_EXTERNAL_HELLO_PATH)/hello/*.mk))
$(info inside $(lastword $(MAKEFILE_LIST)))
include $(sort $(wildcard $(BR2_EXTERNAL_HELLO_PATH)/hello.mk))

hello.mk

################################################################################
#
# hello
#
################################################################################
$(info inside $(lastword $(MAKEFILE_LIST)))

HELLO_VERSION=1.0
#I don't understand why but giving site PKG_SITE below
#  makes no difference on @D variable below
#  it always points at base of project why?????
#  But if you don't define it buildroot puts this out... What gives??
#  *** HELLO_SITE cannot be empty when HELLO_SOURCE is not.  
HELLO_SITE=$(TOPDIR)/../hello/src
HELLO_SITE_METHOD=local

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

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

$(eval $(generic-package))

src/Makefile

$(info inside $(lastword $(MAKEFILE_LIST)))

CC = gcc

.PHONY: clean

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

src/hello.c

#include <stdio.h>

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

Inside the buildroot directory I have a local.mk with this line in it

HELLO_OVERRIDE_SRCDIR = ../hello

From the buildroot folder I run

make BR2_EXTERNAL="$(pwd)/../hello" myprj_defconfig
echo 'BR2_PACKAGE_HELLO=y' >> .config
make hello-rebuild all

The hello executable is built. BUT ... the HELLO_SITE=$(TOPDIR)/../hello/src in hello.mk is not taking effect. See comments in hello.mk. The @D variable will not point at what is defined by HELLO_SITE. Though if I remove HELLO_SITE completely buildroot spits out the message in the comments. Also if I assign HELLO_SITE a garbage name it doesn't matter it builds anyhow and does not try to enter the garbage path. It's building with the files above because I appended /src to @D in hello.mk. In the examples I have found online this should not be necessary because HELLO_SITE should make buildroot enter the src folder to run the Makefile. For me this is not working.

From everything I see in google searches and buildroot docs HELLO_SITE should be respected but it's not.

Anybody see what I am doing wrong?

I am using buildroot 2023.02-1.0.

Thank you.

1

There are 1 answers

3
Arnout On

A package must be in a directory with the same name as the package, so in this case hello. In other words, the files should be organized like this:

.
├── Config.in
├── external.desc
├── external.mk
└── hello
    ├── Makefile
    ├── hello.c
    └── hello.mk

(You would typically also put a Config.in in the hello directory, but that's not strictly required.)

In the hello.mk file, you shouldn't use $(TOPDIR) because that points to the Buildroot directory and it's hard to keep track of where the Buildroot directory is relative to the hellodirectory. Instead, use$(BR2_EXTERNAL_HELLO_PATH), like this (assuming the above directory organisation, with Makefilein thehellosubdirectory and nosrc` subdirectory.

################################################################################
#
# hello
#
################################################################################
HELLO_SITE = $(BR2_EXTERNAL_HELLO_PATH)/hello
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))