new file mode 100644
@@ -0,0 +1,33 @@
+// -*- mode:doc; -*-
+// vim: set syntax=asciidoc:
+
+[[debugging-buildroot]]
+
+Debugging Buildroot
+-------------------
+
+It is possible to instrument the steps +Buildroot+ does when building
+packages. Define the variable +BR2_STEPS_USER_HOOKS+ to contain the path
+of one or more scripts (or other executables), in a space-separated list,
+you want called before and after each step. The script is called with
+three parameters:
+
+ - +start+ or +end+ to denote the start (resp. the end) of a step;
+ - the name of the step about to be started, or which just ended.
+ - the name of the package
+
+For example :
+
+----
+make BR2_STEPS_USER_HOOKS="/path/to/my/script1 /path/to/my/script2"
+----
+
+That script has access to the following variables:
+
+ - +BUILDROOT_CONFIG+: the path to the Buildroot .config file
+ - +HOST_DIR+, +STAGING_DIR+, +TARGET_DIR+: see
+ xref:generic-package-reference[]
+ - +BUILD_DIR+: the directory where packages are extracted and built
+ - +BINARIES_DIR+: the place where all binary files (aka images) are
+ stored
+ - +BASE_DIR+: the base output directory
@@ -13,3 +13,5 @@ include::patch-policy.txt[]
include::download-infra.txt[]
include::board-support.txt[]
+
+include::debugging-buildroot.txt[]
@@ -54,6 +54,15 @@ define step_time
endef
STEP_HOOKS += step_time
+# User-supplied script
+define step_user
+ @$(foreach user_hook, $(BR2_STEPS_USER_HOOKS), \
+ $(USER_HOOKS_EXTRA_ENV) $(user_hook) "$(1)" "$(2)" "$(3)"$(sep))
+endef
+ifneq ($(BR2_STEPS_USER_HOOKS),)
+STEP_HOOKS += step_user
+endif
+
################################################################################
# Implicit targets -- produce a stamp file for each step of a package build
################################################################################