Skip to contentSkip to conversation

Add TARGET_FINALIZE_HOOKS

PATCH New Fabio Porcedda 2 participants 9 messages Jun 27, 2014 – Jul 4, 2014 Kbuild

lore
Share & tools
lore
#0 lore raw

v3 cover Add TARGET_FINALIZE_HOOKS

This patch set add TARGET_FINALIZE_HOOKS and use it for system.mk recipies.

The changelog is on each patch.

Best regards
Fabio Porcedda (5):
Makefile: target-finalize: add TARGET_FINALIZE_HOOKS
system: convert "system.mk" recipes to "target-finalize" hooks
Makefile: convert "toolchain-eclipse-register" to a hook
Makefile: convert "target-generatelocales" to a hook
Makefile: do not add to targets common dependencies

 Makefile         | 88 +++++++++++++++++++++++++++-----------------------------
 system/system.mk | 80 +++++++++++++++++++++++++++------------------------
 2 files changed, 85 insertions(+), 83 deletions(-)
Signature · 1 line
2.0.0
#1 lore raw

PATCH v3 1/5 Makefile: target-finalize: add TARGET_FINALIZE_HOOKS

From: Fabio Porcedda <[email protected]>

Add TARGET_FINALIZE_HOOKS to the "target-finalize" rule to be able to add to it commands as needed.
This is useful for having a nicer output because commands are executed after the "target-finalize" initial message, also it is useful to ensure an executing order even when top-level parallel makefile is being used.

Also convert "TARGET_PURGE_LOCALES" to a hook that uses "TARGET_FINALIZE_HOOKS".

---

Notes:
v3:
- Add in the description a note about TARGET_PURGE_LOCALES (Arnout)
- Add Reviewed-by: Arnout

 Makefile | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Makefile +3 -2
index af694b9..3e845f6 100644
@@ -513,7 +513,7 @@ ifeq ($(BR2_ENABLE_LOCALE_PURGE),y)
 LOCALE_WHITELIST = $(BUILD_DIR)/locales.nopurge
 LOCALE_NOPURGE = $(call qstrip,$(BR2_ENABLE_LOCALE_WHITELIST))
 
-define TARGET_PURGE_LOCALES
+define PURGE_LOCALES
 	rm -f $(LOCALE_WHITELIST)
 	for i in $(LOCALE_NOPURGE); do echo $$i >> $(LOCALE_WHITELIST); done
 
@@ -525,13 +525,14 @@ define TARGET_PURGE_LOCALES
 		done; \
 	done
 endef
+TARGET_FINALIZE_HOOKS += PURGE_LOCALES
 endif
 
 $(TARGETS_ROOTFS): target-finalize
 
 target-finalize: $(TARGETS)
 	@$(call MESSAGE,"Finalizing target directory")
-	$(TARGET_PURGE_LOCALES)
+	$(foreach hook,$(TARGET_FINALIZE_HOOKS),$($(hook))$(sep))
 	rm -rf $(TARGET_DIR)/usr/include $(TARGET_DIR)/usr/share/aclocal \
 		$(TARGET_DIR)/usr/lib/pkgconfig $(TARGET_DIR)/usr/share/pkgconfig \
 		$(TARGET_DIR)/usr/lib/cmake $(TARGET_DIR)/usr/share/cmake
Signature · 1 line
2.0.0
#2 lore raw

PATCH v3 2/5 system: convert "system.mk" recipes to "target-finalize" hooks

In reply to Fabio Porcedda

From: Fabio Porcedda <[email protected]>

Convert "system.mk" recipes to "target-finalize" hooks in order to:
- Ensure an ordering even if top-level parallel make is being used.
- Execute "system.mk" commands after the "target-finalize" initial message is printed so they can be clearly distinguished from packages building.

---

Notes:
v3:
- Shortened hooks names: SYSTEM_GENERIC_* -> SYSTEM_*
- use a common name for hooks variants: SYSTEM_REMOUNT_RW & SYSTEM_GETTY (Arnout)

v2:
- use hooks

 system/system.mk | 80 ++++++++++++++++++++++++++++++--------------------------
 1 file changed, 43 insertions(+), 37 deletions(-)
system/system.mk +43 -37
index 01a6c3a..b614615 100644
@@ -7,68 +7,74 @@ TARGET_GENERIC_GETTY_BAUDRATE = $(call qstrip,$(BR2_TARGET_GENERIC_GETTY_BAUDRAT
 TARGET_GENERIC_GETTY_TERM = $(call qstrip,$(BR2_TARGET_GENERIC_GETTY_TERM))
 TARGET_GENERIC_GETTY_OPTIONS = $(call qstrip,$(BR2_TARGET_GENERIC_GETTY_OPTIONS))
 
-target-generic-securetty:
+ifeq ($(BR2_TARGET_GENERIC_GETTY),y)
+define SYSTEM_SECURETTY
 	grep -q '^$(TARGET_GENERIC_GETTY_PORT)$$' $(TARGET_DIR)/etc/securetty || \
 		echo '$(TARGET_GENERIC_GETTY_PORT)' >> $(TARGET_DIR)/etc/securetty
+endef
+TARGET_FINALIZE_HOOKS += SYSTEM_SECURETTY
+endif
 
-target-generic-hostname:
+ifneq ($(TARGET_GENERIC_HOSTNAME),)
+define SYSTEM_HOSTNAME
 	mkdir -p $(TARGET_DIR)/etc
 	echo "$(TARGET_GENERIC_HOSTNAME)" > $(TARGET_DIR)/etc/hostname
 	$(SED) '$$a \127.0.1.1\t$(TARGET_GENERIC_HOSTNAME)' \
 		-e '/^127.0.1.1/d' $(TARGET_DIR)/etc/hosts
+endef
+TARGET_FINALIZE_HOOKS += SYSTEM_HOSTNAME
+endif
 
-target-generic-issue:
+ifneq ($(TARGET_GENERIC_ISSUE),)
+define SYSTEM_ISSUE
 	mkdir -p $(TARGET_DIR)/etc
 	echo "$(TARGET_GENERIC_ISSUE)" > $(TARGET_DIR)/etc/issue
+endef
+TARGET_FINALIZE_HOOKS += SYSTEM_ISSUE
+endif
 
 ifneq ($(TARGET_GENERIC_ROOT_PASSWD),)
-target-root-passwd: host-mkpasswd
+TARGETS += host-mkpasswd
 endif
-target-root-passwd:
+
+ifeq ($(BR2_ROOTFS_SKELETON_DEFAULT),y)
+
+define SYSTEM_ROOT_PASSWD
 	[ -n "$(TARGET_GENERIC_ROOT_PASSWD)" ] && \
 		TARGET_GENERIC_ROOT_PASSWD_HASH=$$($(MKPASSWD) -m "$(TARGET_GENERIC_PASSWD_METHOD)" "$(TARGET_GENERIC_ROOT_PASSWD)"); \
 	$(SED) "s,^root:[^:]*:,root:$$TARGET_GENERIC_ROOT_PASSWD_HASH:," $(TARGET_DIR)/etc/shadow
+endef
+TARGET_FINALIZE_HOOKS += SYSTEM_ROOT_PASSWD
 
-target-generic-getty-busybox:
-	$(SED) '/# GENERIC_SERIAL$$/s~^.*#~$(TARGET_GENERIC_GETTY_PORT)::respawn:/sbin/getty -L $(TARGET_GENERIC_GETTY_OPTIONS) $(TARGET_GENERIC_GETTY_PORT) $(TARGET_GENERIC_GETTY_BAUDRATE) $(TARGET_GENERIC_GETTY_TERM) #~' \
-		$(TARGET_DIR)/etc/inittab
-
+ifeq ($(BR2_TARGET_GENERIC_GETTY),y)
+ifeq ($(BR2_PACKAGE_SYSVINIT),y)
 # In sysvinit inittab, the "id" must not be longer than 4 bytes, so we
 # skip the "tty" part and keep only the remaining.
-target-generic-getty-sysvinit:
+define SYSTEM_GETTY
 	$(SED) '/# GENERIC_SERIAL$$/s~^.*#~$(shell echo $(TARGET_GENERIC_GETTY_PORT) | tail -c+4)::respawn:/sbin/getty -L $(TARGET_GENERIC_GETTY_OPTIONS) $(TARGET_GENERIC_GETTY_PORT) $(TARGET_GENERIC_GETTY_BAUDRATE) $(TARGET_GENERIC_GETTY_TERM) #~' \
 		$(TARGET_DIR)/etc/inittab
+endef
+else
+# Add getty to busybox inittab
+define SYSTEM_GETTY
+	$(SED) '/# GENERIC_SERIAL$$/s~^.*#~$(TARGET_GENERIC_GETTY_PORT)::respawn:/sbin/getty -L $(TARGET_GENERIC_GETTY_OPTIONS) $(TARGET_GENERIC_GETTY_PORT) $(TARGET_GENERIC_GETTY_BAUDRATE) $(TARGET_GENERIC_GETTY_TERM) #~' \
+		$(TARGET_DIR)/etc/inittab
+endef
+endif
+TARGET_FINALIZE_HOOKS += SYSTEM_GETTY
+endif
 
+ifeq ($(BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW),y)
 # Find commented line, if any, and remove leading '#'s
-target-generic-do-remount-rw:
+define SYSTEM_REMOUNT_RW
 	$(SED) '/^#.*# REMOUNT_ROOTFS_RW$$/s~^#\+~~' $(TARGET_DIR)/etc/inittab
-
+endef
+else
 # Find uncommented line, if any, and add a leading '#'
-target-generic-dont-remount-rw:
+define SYSTEM_REMOUNT_RW
 	$(SED) '/^[^#].*# REMOUNT_ROOTFS_RW$$/s~^~#~' $(TARGET_DIR)/etc/inittab
-
-ifeq ($(BR2_TARGET_GENERIC_GETTY),y)
-TARGETS += target-generic-securetty
-endif
-
-ifneq ($(TARGET_GENERIC_HOSTNAME),)
-TARGETS += target-generic-hostname
-endif
-
-ifneq ($(TARGET_GENERIC_ISSUE),)
-TARGETS += target-generic-issue
+endef
 endif
+TARGET_FINALIZE_HOOKS += SYSTEM_REMOUNT_RW
 
-ifeq ($(BR2_ROOTFS_SKELETON_DEFAULT),y)
-TARGETS += target-root-passwd
-
-ifeq ($(BR2_TARGET_GENERIC_GETTY),y)
-TARGETS += target-generic-getty-$(if $(BR2_PACKAGE_SYSVINIT),sysvinit,busybox)
-endif
-
-ifeq ($(BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW),y)
-TARGETS += target-generic-do-remount-rw
-else
-TARGETS += target-generic-dont-remount-rw
-endif
-endif
+endif # BR2_ROOTFS_SKELETON_DEFAULT
Signature · 1 line
2.0.0
#3 lore raw

PATCH v3 2/5 system: convert "system.mk" recipes to "target-finalize" hooks

Dear Fabio Porcedda,

system/system.mk TARGET_GENERIC_GETTY_BAUDRATE = $(call qstrip,$(BR2_TARGET_GENERIC_GETTY_BAUDRAT · line 37

Quoted 3 lines · Fabio Porcedda

ifneq ($(TARGET_GENERIC_ROOT_PASSWD),)

system/system.mk +1 -1
-target-root-passwd: host-mkpasswd
+TARGETS += host-mkpasswd

Actually, I was wondering how this could work in the context of top-level parallel build, but looking more closely, target-finalize has $(TARGETS) in its dependencies, so we indeed have the guarantee that host-mkpasswd will be built before the SYSTEM_ROOT_PASSWD hook is executed.

So in fact, I don't have any comment about PATCH 2 :-)

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#4 lore raw

PATCH v3 2/5 system: convert "system.mk" recipes to "target-finalize" hooks

Quoted 14 lines · Thomas Petazzoni

Dear Fabio Porcedda,

system/system.mk TARGET_GENERIC_GETTY_BAUDRATE = $(call qstrip,$(BR2_TARGET_GENERIC_GETTY_BAUDRAT · line 37

Quoted 3 lines · Fabio Porcedda

ifneq ($(TARGET_GENERIC_ROOT_PASSWD),)

system/system.mk +1 -1
-target-root-passwd: host-mkpasswd
+TARGETS += host-mkpasswd

Actually, I was wondering how this could work in the context of top-level parallel build, but looking more closely, target-finalize has $(TARGETS) in its dependencies, so we indeed have the guarantee that host-mkpasswd will be built before the SYSTEM_ROOT_PASSWD hook is executed.

Quoted 1 line

So in fact, I don't have any comment about PATCH 2 :-)

Yes, it's exactly as you said.

Adding a dependency to TARGETS it's like adding to an hypothetical TARGET_FINALIZE_DEPENDENCIES variable.

BR

Signature · 1 line
Fabio Porcedda
#5 lore raw

PATCH v3 3/5 Makefile: convert "toolchain-eclipse-register" to a hook

In reply to Fabio Porcedda

For consinstency sake convert the "toolchain-eclipse-register" to a TARGET_FINALIZE_HOOKS hook.

---

Notes:
v3:
- add this patch (Arnout)

 Makefile | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
Makefile +8 -7
index 3e845f6..c790f7a 100644
@@ -396,10 +396,6 @@ TARGETS += target-generatelocales
 endif
 endif
 
-ifeq ($(BR2_ECLIPSE_REGISTER),y)
-TARGETS += toolchain-eclipse-register
-endif
-
 TARGETS_SOURCE := $(patsubst %,%-source,$(TARGETS))
 TARGETS_DIRCLEAN := $(patsubst %,%-dirclean,$(TARGETS))
 
@@ -509,6 +505,14 @@ STRIP_FIND_CMD += -type f \( -perm /111 -o -name '*.so*' \)
 #   done for kernel modules with incorrect permissions.
 STRIP_FIND_CMD += -not \( $(call findfileclauses,libpthread*.so* *.ko $(call qstrip,$(BR2_STRIP_EXCLUDE_FILES))) \) -print
 
+ifeq ($(BR2_ECLIPSE_REGISTER),y)
+define TOOLCHAIN_ECLIPSE_REGISTER
+	./support/scripts/eclipse-register-toolchain `readlink -f $(O)` \
+		$(notdir $(TARGET_CROSS)) $(BR2_ARCH)
+endef
+TARGET_FINALIZE_HOOKS += TOOLCHAIN_ECLIPSE_REGISTER
+endif
+
 ifeq ($(BR2_ENABLE_LOCALE_PURGE),y)
 LOCALE_WHITELIST = $(BUILD_DIR)/locales.nopurge
 LOCALE_NOPURGE = $(call qstrip,$(BR2_ENABLE_LOCALE_WHITELIST))
@@ -628,9 +632,6 @@ target-post-image: $(TARGETS_ROOTFS) target-finalize
 		$(call MESSAGE,"Executing post-image script $(s)"); \
 		$(EXTRA_ENV) $(s) $(BINARIES_DIR) $(call qstrip,$(BR2_ROOTFS_POST_SCRIPT_ARGS))$(sep))
 
-toolchain-eclipse-register: toolchain
-	./support/scripts/eclipse-register-toolchain `readlink -f $(O)` $(notdir $(TARGET_CROSS)) $(BR2_ARCH)
-
 source: $(TARGETS_SOURCE) $(HOST_SOURCE)
 
 external-deps:
Signature · 1 line
2.0.0
#6 lore raw

PATCH v3 4/5 Makefile: convert "target-generatelocales" to a hook

In reply to Fabio Porcedda

For consinstency sake convert the "target-generatelocales" rule to a TARGET_FINALIZE_HOOKS hook.

---

Notes:
v3:
- add this patch (Arnout)

 Makefile | 64 +++++++++++++++++++++++++++++++---------------------------------
 1 file changed, 31 insertions(+), 33 deletions(-)
Makefile +31 -33
index c790f7a..95ad1f4 100644
@@ -324,9 +324,6 @@ HOST_DIR := $(call qstrip,$(BR2_HOST_DIR))
 # Quotes are needed for spaces and all in the original PATH content.
 BR_PATH = "$(HOST_DIR)/bin:$(HOST_DIR)/sbin:$(HOST_DIR)/usr/bin:$(HOST_DIR)/usr/sbin:$(PATH)"
 
-# locales to generate
-GENERATE_LOCALE = $(call qstrip,$(BR2_GENERATE_LOCALE))
-
 TARGET_SKELETON = $(TOPDIR)/system/skeleton
 
 # Location of a file giving a big fat warning that output/target
@@ -390,12 +387,6 @@ include fs/common.mk
 
 include $(BR2_EXTERNAL)/external.mk
 
-ifeq ($(BR2_TOOLCHAIN_USES_GLIBC),y)
-ifneq ($(GENERATE_LOCALE),)
-TARGETS += target-generatelocales
-endif
-endif
-
 TARGETS_SOURCE := $(patsubst %,%-source,$(TARGETS))
 TARGETS_DIRCLEAN := $(patsubst %,%-dirclean,$(TARGETS))
 
@@ -513,6 +504,37 @@ endef
 TARGET_FINALIZE_HOOKS += TOOLCHAIN_ECLIPSE_REGISTER
 endif
 
+# Generate locale data. Basically, we call the localedef program
+# (built by the host-localedef package) for each locale. The input
+# data comes preferably from the toolchain, or if the toolchain does
+# not have them (Linaro toolchains), we use the ones available on the
+# host machine.
+ifeq ($(BR2_TOOLCHAIN_USES_GLIBC),y)
+GENERATE_LOCALE = $(call qstrip,$(BR2_GENERATE_LOCALE))
+ifneq ($(GENERATE_LOCALE),)
+TARGETS += host-localedef
+
+define GENERATE_LOCALES
+	$(Q)mkdir -p $(TARGET_DIR)/usr/lib/locale/
+	$(Q)for locale in $(GENERATE_LOCALE) ; do \
+		inputfile=`echo $${locale} | cut -f1 -d'.'` ; \
+		charmap=`echo $${locale} | cut -f2 -d'.' -s` ; \
+		if test -z "$${charmap}" ; then \
+			charmap="UTF-8" ; \
+		fi ; \
+		echo "Generating locale $${inputfile}.$${charmap}" ; \
+		I18NPATH=$(STAGING_DIR)/usr/share/i18n:/usr/share/i18n \
+		$(HOST_DIR)/usr/bin/localedef \
+			--prefix=$(TARGET_DIR) \
+			--$(call LOWERCASE,$(BR2_ENDIAN))-endian \
+			-i $${inputfile} -f $${charmap} \
+			$${locale} ; \
+	done
+endef
+TARGET_FINALIZE_HOOKS += GENERATE_LOCALES
+endif
+endif
+
 ifeq ($(BR2_ENABLE_LOCALE_PURGE),y)
 LOCALE_WHITELIST = $(BUILD_DIR)/locales.nopurge
 LOCALE_NOPURGE = $(call qstrip,$(BR2_ENABLE_LOCALE_WHITELIST))
@@ -603,30 +625,6 @@ endif
 		$(call MESSAGE,"Executing post-build script $(s)"); \
 		$(EXTRA_ENV) $(s) $(TARGET_DIR) $(call qstrip,$(BR2_ROOTFS_POST_SCRIPT_ARGS))$(sep))
 
-ifneq ($(GENERATE_LOCALE),)
-# Generate locale data. Basically, we call the localedef program
-# (built by the host-localedef package) for each locale. The input
-# data comes preferably from the toolchain, or if the toolchain does
-# not have them (Linaro toolchains), we use the ones available on the
-# host machine.
-target-generatelocales: host-localedef toolchain
-	$(Q)mkdir -p $(TARGET_DIR)/usr/lib/locale/
-	$(Q)for locale in $(GENERATE_LOCALE) ; do \
-		inputfile=`echo $${locale} | cut -f1 -d'.'` ; \
-		charmap=`echo $${locale} | cut -f2 -d'.' -s` ; \
-		if test -z "$${charmap}" ; then \
-			charmap="UTF-8" ; \
-		fi ; \
-		echo "Generating locale $${inputfile}.$${charmap}" ; \
-		I18NPATH=$(STAGING_DIR)/usr/share/i18n:/usr/share/i18n \
-		$(HOST_DIR)/usr/bin/localedef \
-			--prefix=$(TARGET_DIR) \
-			--$(call LOWERCASE,$(BR2_ENDIAN))-endian \
-			-i $${inputfile} -f $${charmap} \
-			$${locale} ; \
-	done
-endif
-
 target-post-image: $(TARGETS_ROOTFS) target-finalize
 	@$(foreach s, $(call qstrip,$(BR2_ROOTFS_POST_IMAGE_SCRIPT)), \
 		$(call MESSAGE,"Executing post-image script $(s)"); \
Signature · 1 line
2.0.0
#7 lore raw

PATCH v3 5/5 Makefile: do not add to targets common dependencies

In reply to Fabio Porcedda

From: Fabio Porcedda <[email protected]>

Remove the rule that adds common dependencies to every target in the "TARGETS" variable, because all those targets are packages that use the package infrastructure or they depend on targets that use the package infrastructure. The package infrastructure already adds common dependencies. Therefore, this rule is useless.

---

Notes:
v3:
- improved the description (Arnout)

 Makefile | 4 ----
 1 file changed, 4 deletions(-)
Makefile +0 -4
index 95ad1f4..4f8f00f 100644
@@ -420,10 +420,6 @@ $(BUILD_DIR)/buildroot-config/auto.conf: $(BR2_CONFIG)
 
 prepare: $(BUILD_DIR)/buildroot-config/auto.conf
 
-# Add base dependencies to all targets even on those not based on the
-# package framework.
-$(TARGETS): dirs prepare dependencies
-
 world: target-post-image
 
 .PHONY: all world toolchain dirs clean distclean source outputmakefile \
Signature · 1 line
2.0.0
#8 lore raw

v3 cover Add TARGET_FINALIZE_HOOKS

In reply to Fabio Porcedda

Dear Fabio Porcedda,

Quoted 5 lines · Fabio Porcedda

This patch set add TARGET_FINALIZE_HOOKS and use it for system.mk recipies.

The changelog is on each patch.

Quoted 7 lines

Best regards
Fabio Porcedda (5):
Makefile: target-finalize: add TARGET_FINALIZE_HOOKS
system: convert "system.mk" recipes to "target-finalize" hooks
Makefile: convert "toolchain-eclipse-register" to a hook
Makefile: convert "target-generatelocales" to a hook
Makefile: do not add to targets common dependencies

Thanks, series applied. I just have one comment on PATCH 2, which I'll make as a reply to the patch.

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com