Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idea: make it easy to add custom steps during the build process #2979

Open
darealshinji opened this issue May 3, 2023 · 0 comments
Open

Comments

@darealshinji
Copy link
Contributor

I wanted to keep track of installed files and added these 'hooks' to the Makefile:

--- a/Makefile
+++ b/Makefile
@@ -790,6 +790,9 @@ $(PREFIX)/$(3)/installed/$(1): $(PKG_MAKEFILES) \
 	        @echo $(1)~$(3) > '$(PREFIX)/$(3)/lib/$(1).dry-run'
 	        @touch '$(PREFIX)/$(3)/installed/$(1)'
 	    $(else),
+ifdef HOOK_PRE
+	        @$(call HOOK_PRE,$(1),$(3))
+endif
 	        @$(PRINTF_FMT) '[build]'    '$(1)' '$(3)' | $(RTRIM)
 	        @[ -d '$(LOG_DIR)/$(TIMESTAMP)' ] || mkdir -p '$(LOG_DIR)/$(TIMESTAMP)'
 	        @touch '$(LOG_DIR)/$(TIMESTAMP)/$(1)_$(3)'
@@ -812,6 +815,9 @@ $(PREFIX)/$(3)/installed/$(1): $(PKG_MAKEFILES) \
 	        fi
 	        @$(PRINTF_FMT) '[done]' '$(1)' '$(3)' "`grep -a '^du:.*KiB$$\' '$(LOG_DIR)/$(TIMESTAMP)/$(1)_$(3)' | cut -d ':' -f2 | tail -1`" \
 	                                          "`grep -a '^real.*m.*s$$\' '$(LOG_DIR)/$(TIMESTAMP)/$(1)_$(3)' | tr '\t' ' ' | cut -d ' ' -f2 | tail -1`"
+ifdef HOOK_POST
+	        @$(call HOOK_POST,$(1),$(3))
+endif
 	    )
 	$(else),
 	    @$(PRINTF_FMT) '[$(or $($(PKG)_TYPE),disabled)]' '$(1)' '$(3)' | $(RTRIM)

This allows me to easily add my own code through settings.mk:

.NOTPARALLEL:

define HOOK_PRE
	@find '$(PREFIX)' | $(SORT) > '$(MXE_TMP)/tmp-$(1)-$(2).pre'
endef

define HOOK_POST
	@find '$(PREFIX)' | $(SORT) > '$(MXE_TMP)/tmp-$(1)-$(2).post'
	@diff '$(MXE_TMP)/tmp-$(1)-$(2).pre' '$(MXE_TMP)/tmp-$(1)-$(2).post' | grep '^>' > '$(PREFIX)/$(2)/installed/$(1)'
	@rm -f '$(MXE_TMP)/tmp-$(1)-$(2).pre' '$(MXE_TMP)/tmp-$(1)-$(2).post'
endef

Do you think it would be a good idea to add such hooks? I can image someone could also use it for notifications, to backup a config file before the build directory gets deleted, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant