Matty
Matty

Reputation: 13

How to run external build script in buildroot package

In buildroot I created a package that fetches a tool from github. However this tool was made to be build using buildroot, but not from within buildroot, so the typical flow on how to build it with buildroot is something like this:

cd github/tool
export BUILDROOT_TOPDIR=$HOME/buildroot
source tool_setup.sh 
tool_install_dependencies #Fetches more github dependencies based on git tags defined inside the setenv.sh, and builds them using buildroot
tool_build #Builds the tool and links dependencies

However just doing it like this within the package file does not work, as the aliases and git tags from tool_setup.sh are not sourced, example package

TOOL_VERSION_VERSION = main
TOOL_VERSION_SITE = [email protected]:tool.git
TOOL_VERSION_SITE_METHOD = git
TOOL_VERSION_INSTALL_TARGET = YES


define TOOL_VERSION_BUILD_CMDS
    cd github/tool
    export BUILDROOT_TOPDIR=$(PWD)
    source tool_setup.sh 
    tool_install_dependencies
    tool_build
endef

define TOOL_VERSION_INSTALL_TARGET_CMDS
    $(INSTALL) -D -m 0755 $(@D)/output/tool $(TARGET_DIR)/sbin/
endef

$(eval $(generic-package))

Will fail with /bin/bash: tool_install_dependencies: command not found, and using cmake-package will fail because the CMakelists.txt can't find the variables containing the git tags for the dependencies.

Upvotes: 1

Views: 1319

Answers (1)

Thomas Petazzoni
Thomas Petazzoni

Reputation: 5956

I think you're taking this at the wrong level. I would rather recommend to look at what tool_install_dependencies and tool_build do in your tools_setup.sh script, and replicate that in the Buildroot package.

Based on its name, the tool_install_dependencies is particularly scary, as you definitely don't want a Buildroot package to install dependencies by itself.

Other than that, to directly answer your question: like in all Makefiles, each line of your rule is executed in a separate shell, so your "source tool_setup.sh" runs in a separate shell from "tool_install_dependencies", which explains why it doesn't work. If you want them to run in the same shell, do "source tool_setup.sh; tool_install_dependencies; tool_build".

But again, this smells like a very, very, very, very bad thing to do.

Upvotes: 1

Related Questions