Patchwork [3/3] wpa_supplicant: introduce macros for editing the .config file

login
register
mail settings
Submitter Sven Neumann
Date Sept. 19, 2012, 10:11 a.m.
Message ID <1348049503-1469-4-git-send-email-s.neumann@raumfeld.com>
Download mbox | patch
Permalink /patch/184964/
State Changes Requested
Headers show

Comments

Sven Neumann - Sept. 19, 2012, 10:11 a.m.
Make the substitutions on the .config file more readable by
introducing macros to enable, disable certain options similar
to the macros we use for editing KConfig files.

Signed-off-by: Sven Neumann <s.neumann@raumfeld.com>
---
 package/wpa_supplicant/wpa_supplicant.mk |   62 ++++++++++++++++++------------
 1 file changed, 37 insertions(+), 25 deletions(-)
Arnout Vandecappelle - Sept. 19, 2012, 8:33 p.m.
On 09/19/12 12:11, Sven Neumann wrote:
> Make the substitutions on the .config file more readable by
> introducing macros to enable, disable certain options similar
> to the macros we use for editing KConfig files.
>
> Signed-off-by: Sven Neumann<s.neumann@raumfeld.com>

  Nice!

  Did you use a sed (or editor) regexp to do the substitution?  If yes,
it makes sense to document that regexp in the commit message.  That
helps to review it, and can also be useful for others who are inspired
to do a similar modification.

> ---
>   package/wpa_supplicant/wpa_supplicant.mk |   62 ++++++++++++++++++------------
>   1 file changed, 37 insertions(+), 25 deletions(-)
>
> diff --git a/package/wpa_supplicant/wpa_supplicant.mk b/package/wpa_supplicant/wpa_supplicant.mk
> index e8d55d3..5337e5f 100644
> --- a/package/wpa_supplicant/wpa_supplicant.mk
> +++ b/package/wpa_supplicant/wpa_supplicant.mk
> @@ -15,49 +15,61 @@ WPA_SUPPLICANT_DBUS_NEW_SERVICE = fi.w1.wpa_supplicant1
>   WPA_SUPPLICANT_CFLAGS = $(TARGET_CFLAGS) -I$(STAGING_DIR)/usr/include/libnl3/
>   WPA_SUPPLICANT_LDFLAGS = $(TARGET_LDFLAGS)
>
> +define WPA_SUPPLICANT_CONFIG_DISABLE
> +	$(SED) 's/^\($(1).*\)/#\1/' $(WPA_SUPPLICANT_CONFIG)
> +endef
> +
> +define WPA_SUPPLICANT_CONFIG_ENABLE
> +	$(SED) 's/#\($(1).*\)/\1/' $(WPA_SUPPLICANT_CONFIG)
> +endef
> +
> +define WPA_SUPPLICANT_CONFIG_SET
> +	echo '$(1)=y'>>  $(WPA_SUPPLICANT_CONFIG)
> +endef
> +
>   ifeq ($(BR2_PACKAGE_LIBNL),y)
>   	WPA_SUPPLICANT_DEPENDENCIES += libnl
>   define WPA_SUPPLICANT_LIBNL_CONFIG
> -	echo 'CONFIG_LIBNL32=y'>>$(WPA_SUPPLICANT_CONFIG)
> +	$(call WPA_SUPPLICANT_CONFIG_SET,CONFIG_LIBNL32)
>   endef
>   else
>   define WPA_SUPPLICANT_LIBNL_CONFIG
> -	$(SED) 's/^\(CONFIG_DRIVER_NL80211.*\)/#\1/' $(WPA_SUPPLICANT_CONFIG)
> +	$(call WPA_SUPPLICANT_CONFIG_DISABLE,CONFIG_DRIVER_NL80211)
>   endef
>   endif

  While you're at it, I'd like to avoid calling sed dozens of times,
by writing it like this:

----
WPA_SUPPLICANT_CONFIG_DISABLE = -e 's/^\($(1).*\)/#\1/'
WPA_SUPPLICANT_CONFIG_ENABLE  = -e 's/#\($(1).*\)/\1/'
WPA_SUPPLICANT_CONFIG_SET     = -e '1i$(1)=y'

ifeq ($(BR2_PACKAGE_LIBNL),y)
WPA_SUPPLICANT_DEPENDENCIES += libnl
WPA_SUPPLICANT_CONFIG_EDITS += $(call WPA_SUPPLICANT_CONFIG_SET,CONFIG_LIBNL32)
else
WPA_SUPPLICANT_CONFIG_EDITS += $(call WPA_SUPPLICANT_CONFIG_DISABLE,CONFIG_LIBNL32)
endif

...

define WPA_SUPPLICANT_CONFIGURE_CMDS
	cp $(@D)/wpa_supplicant/defconfig $(WPA_SUPPLICANT_CONFIG)
	$(SED) $(WPA_SUPPLICANT_CONFIG_EDITS) $(WPA_SUPPLICANT_CONFIG)
endef
----


  Of course, using 'sed 1i...' instead of 'echo ... >>' means those options
will be at the beginning rather than at the end, but I don't think that
should make a difference.


  I just love hacking make, so here's another alternative:

----
ifeq ($(BR2_PACKAGE_LIBNL),y)
WPA_SUPPLICANT_DEPENDENCIES += libnl
WPA_SUPPLICANT_CONFIG_SET += CONFIG_LIBNL32
else
WPA_SUPPLICANT_CONFIG_DISABLE += CONFIG_LIBNL32
endif

...

define WPA_SUPPLICANT_CONFIGURE_CMDS
	cp $(@D)/wpa_supplicant/defconfig $(WPA_SUPPLICANT_CONFIG)
	$(SED) $(patsubst %,-e 's/^\(%\)/#\1/',$(WPA_SUPPLICANT_CONFIG_DISABLE)) \
	       $(patsubst %,-e 's/^#\(%\)/\1/',$(WPA_SUPPLICANT_CONFIG_ENABLE)) \
	       $(patsubst %,-e '1i%=y',$(WPA_SUPPLICANT_CONFIG_SET)) \
	       $(WPA_SUPPLICANT_CONFIG)
endef
----


  Regards,
  Arnout

[snip]

Patch

diff --git a/package/wpa_supplicant/wpa_supplicant.mk b/package/wpa_supplicant/wpa_supplicant.mk
index e8d55d3..5337e5f 100644
--- a/package/wpa_supplicant/wpa_supplicant.mk
+++ b/package/wpa_supplicant/wpa_supplicant.mk
@@ -15,49 +15,61 @@  WPA_SUPPLICANT_DBUS_NEW_SERVICE = fi.w1.wpa_supplicant1
 WPA_SUPPLICANT_CFLAGS = $(TARGET_CFLAGS) -I$(STAGING_DIR)/usr/include/libnl3/
 WPA_SUPPLICANT_LDFLAGS = $(TARGET_LDFLAGS)
 
+define WPA_SUPPLICANT_CONFIG_DISABLE
+	$(SED) 's/^\($(1).*\)/#\1/' $(WPA_SUPPLICANT_CONFIG)
+endef
+
+define WPA_SUPPLICANT_CONFIG_ENABLE
+	$(SED) 's/#\($(1).*\)/\1/' $(WPA_SUPPLICANT_CONFIG)
+endef
+
+define WPA_SUPPLICANT_CONFIG_SET
+	echo '$(1)=y' >> $(WPA_SUPPLICANT_CONFIG)
+endef
+
 ifeq ($(BR2_PACKAGE_LIBNL),y)
 	WPA_SUPPLICANT_DEPENDENCIES += libnl
 define WPA_SUPPLICANT_LIBNL_CONFIG
-	echo 'CONFIG_LIBNL32=y' >>$(WPA_SUPPLICANT_CONFIG)
+	$(call WPA_SUPPLICANT_CONFIG_SET,CONFIG_LIBNL32)
 endef
 else
 define WPA_SUPPLICANT_LIBNL_CONFIG
-	$(SED) 's/^\(CONFIG_DRIVER_NL80211.*\)/#\1/' $(WPA_SUPPLICANT_CONFIG)
+	$(call WPA_SUPPLICANT_CONFIG_DISABLE,CONFIG_DRIVER_NL80211)
 endef
 endif
 
 ifeq ($(BR2_PACKAGE_WPA_SUPPLICANT_EAP),y)
 define WPA_SUPPLICANT_EAP_CONFIG
-	$(SED) 's/#\(CONFIG_EAP_AKA.*\)/\1/' $(WPA_SUPPLICANT_CONFIG)
-	$(SED) 's/#\(CONFIG_EAP_FAST.*\)/\1/' $(WPA_SUPPLICANT_CONFIG)
-	$(SED) 's/#\(CONFIG_EAP_GPSK.*\)/\1/' $(WPA_SUPPLICANT_CONFIG)
-	$(SED) 's/#\(CONFIG_EAP_IKEV2.*\)/\1/' $(WPA_SUPPLICANT_CONFIG)
-	$(SED) 's/#\(CONFIG_EAP_PAX.*\)/\1/' $(WPA_SUPPLICANT_CONFIG)
-	$(SED) 's/#\(CONFIG_EAP_PSK.*\)/\1/' $(WPA_SUPPLICANT_CONFIG)
-	$(SED) 's/#\(CONFIG_EAP_SAKE.*\)/\1/' $(WPA_SUPPLICANT_CONFIG)
-	$(SED) 's/#\(CONFIG_EAP_SIM.*\)/\1/' $(WPA_SUPPLICANT_CONFIG)
-	$(SED) 's/#\(CONFIG_EAP_TNC.*\)/\1/' $(WPA_SUPPLICANT_CONFIG)
+	$(call WPA_SUPPLICANT_CONFIG_ENABLE,CONFIG_EAP_AKA)
+	$(call WPA_SUPPLICANT_CONFIG_ENABLE,CONFIG_EAP_FAST)
+	$(call WPA_SUPPLICANT_CONFIG_ENABLE,CONFIG_EAP_GPSK)
+	$(call WPA_SUPPLICANT_CONFIG_ENABLE,CONFIG_EAP_IKEV2)
+	$(call WPA_SUPPLICANT_CONFIG_ENABLE,CONFIG_EAP_PAX)
+	$(call WPA_SUPPLICANT_CONFIG_ENABLE,CONFIG_EAP_PSK)
+	$(call WPA_SUPPLICANT_CONFIG_ENABLE,CONFIG_EAP_SAKE)
+	$(call WPA_SUPPLICANT_CONFIG_ENABLE,CONFIG_EAP_SIM)
+	$(call WPA_SUPPLICANT_CONFIG_ENABLE,CONFIG_EAP_TNC)
 endef
 else
 define WPA_SUPPLICANT_EAP_CONFIG
-	$(SED) 's/^\(CONFIG_EAP.*\)/#\1/' $(WPA_SUPPLICANT_CONFIG)
+	$(call WPA_SUPPLICANT_CONFIG_DISABLE,CONFIG_EAP)
 endef
 endif
 
 ifeq ($(BR2_PACKAGE_WPA_SUPPLICANT_AP_SUPPORT),y)
 define WPA_SUPPLICANT_AP_CONFIG
-	echo 'CONFIG_AP=y' >>$(WPA_SUPPLICANT_CONFIG)
+	$(call WPA_SUPPLICANT_CONFIG_SET,CONFIG_AP)
 endef
 endif
 
 ifeq ($(BR2_PACKAGE_WPA_SUPPLICANT_WPS),y)
 define WPA_SUPPLICANT_WPS_CONFIG
-	$(SED) 's/#\(CONFIG_WPS.*\)/\1/' $(WPA_SUPPLICANT_CONFIG)
+	$(call WPA_SUPPLICANT_CONFIG_ENABLE,CONFIG_WPS)
 endef
 endif
 
 define WPA_SUPPLICANT_LIBTOMMATH_CONFIG
-	$(SED) 's/#\(CONFIG_INTERNAL_LIBTOMMATH.*\)/\1/' $(WPA_SUPPLICANT_CONFIG)
+	$(call WPA_SUPPLICANT_CONFIG_ENABLE,CONFIG_INTERNAL_LIBTOMMATH)
 endef
 
 # Try to use openssl or gnutls if it's already available
@@ -65,7 +77,7 @@  ifeq ($(BR2_PACKAGE_OPENSSL),y)
 	WPA_SUPPLICANT_DEPENDENCIES += openssl
 define WPA_SUPPLICANT_TLS_CONFIG
 	$(SED) 's/#\(CONFIG_TLS=openssl\)/\1/' $(WPA_SUPPLICANT_CONFIG)
-	$(SED) 's/#\(CONFIG_EAP_PWD.*\)/\1/' $(WPA_SUPPLICANT_CONFIG)
+	$(call WPA_SUPPLICANT_CONFIG_ENABLE,CONFIG_EAP_PWD)
 endef
 else
 ifeq ($(BR2_PACKAGE_GNUTLS),y)
@@ -88,7 +100,7 @@  ifeq ($(BR2_PACKAGE_DBUS),y)
 
 ifeq ($(BR2_PACKAGE_WPA_SUPPLICANT_DBUS_OLD),y)
 define WPA_SUPPLICANT_DBUS_OLD_CONFIG
-	$(SED) 's/#\(CONFIG_CTRL_IFACE_DBUS=\)/\1/' $(WPA_SUPPLICANT_CONFIG)
+	$(call WPA_SUPPLICANT_CONFIG_ENABLE,CONFIG_CTRL_IFACE_DBUS=)
 endef
 define WPA_SUPPLICANT_INSTALL_DBUS_OLD
 	$(INSTALL) -D \
@@ -99,7 +111,7 @@  endif
 
 ifeq ($(BR2_PACKAGE_WPA_SUPPLICANT_DBUS_NEW),y)
 define WPA_SUPPLICANT_DBUS_NEW_CONFIG
-	$(SED) 's/#\(CONFIG_CTRL_IFACE_DBUS_NEW=\)/\1/' $(WPA_SUPPLICANT_CONFIG)
+	$(call WPA_SUPPLICANT_CONFIG_ENABLE,CONFIG_CTRL_IFACE_DBUS_NEW)
 endef
 define WPA_SUPPLICANT_INSTALL_DBUS_NEW
 	$(INSTALL) -D \
@@ -110,7 +122,7 @@  endif
 
 ifeq ($(BR2_PACKAGE_WPA_SUPPLICANT_DBUS_INTROSPECTION),y)
 define WPA_SUPPLICANT_DBUS_INTROSPECTION_CONFIG
-	$(SED) 's/#\(CONFIG_CTRL_IFACE_DBUS_INTRO=\)/\1/' $(WPA_SUPPLICANT_CONFIG)
+	$(call WPA_SUPPLICANT_CONFIG_ENABLE,CONFIG_CTRL_IFACE_DBUS_INTRO)
 endef
 endif
 
@@ -124,12 +136,12 @@  endif
 
 define WPA_SUPPLICANT_CONFIGURE_CMDS
 	cp $(@D)/wpa_supplicant/defconfig $(WPA_SUPPLICANT_CONFIG)
-	$(SED) 's/#\(CONFIG_IEEE80211N.*\)/\1/' $(WPA_SUPPLICANT_CONFIG)
-	$(SED) 's/#\(CONFIG_IEEE80211R.*\)/\1/' $(WPA_SUPPLICANT_CONFIG)
-	$(SED) 's/#\(CONFIG_INTERWORKING.*\)/\1/' $(WPA_SUPPLICANT_CONFIG)
-	$(SED) 's/#\(CONFIG_DELAYED_MIC.*\)/\1/' $(WPA_SUPPLICANT_CONFIG)
-	$(SED) 's/\(CONFIG_DRIVER_ATMEL\)/#\1/' $(WPA_SUPPLICANT_CONFIG)
-	$(SED) 's/\(CONFIG_SMARTCARD\)/#\1/' $(WPA_SUPPLICANT_CONFIG)
+	$(call WPA_SUPPLICANT_CONFIG_ENABLE,CONFIG_IEEE80211N)
+	$(call WPA_SUPPLICANT_CONFIG_ENABLE,CONFIG_IEEE80211R)
+	$(call WPA_SUPPLICANT_CONFIG_ENABLE,CONFIG_INTERWORKING)
+	$(call WPA_SUPPLICANT_CONFIG_ENABLE,CONFIG_DELAYED_MIC)
+	$(call WPA_SUPPLICANT_CONFIG_DISABLE,CONFIG_DRIVER_ATMEL)
+	$(call WPA_SUPPLICANT_CONFIG_DISABLE,CONFIG_SMARTCARD)
 	$(WPA_SUPPLICANT_LIBTOMMATH_CONFIG)
 	$(WPA_SUPPLICANT_TLS_CONFIG)
 	$(WPA_SUPPLICANT_EAP_CONFIG)