Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Arnout Vandecappelle <arnout@mind.be>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH 3/3] wpa_supplicant: introduce macros for editing the .config file
Date: Wed, 19 Sep 2012 22:33:20 +0200	[thread overview]
Message-ID: <505A2C10.8040407@mind.be> (raw)
In-Reply-To: <1348049503-1469-4-git-send-email-s.neumann@raumfeld.com>

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]
-- 
Arnout Vandecappelle                               arnout at mind be
Senior Embedded Software Architect                 +32-16-286540
Essensium/Mind                                     http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium                BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7CB5 E4CC 6C2E EFD4 6E3D A754 F963 ECAB 2450 2F1F

  reply	other threads:[~2012-09-19 20:33 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-13  8:34 [Buildroot] wpa-supplicant: add options to enable the new DBus interface Sven Neumann
2012-09-13  8:34 ` [Buildroot] [PATCH] " Sven Neumann
2012-09-18 22:04   ` Arnout Vandecappelle
2012-09-19 10:11     ` [Buildroot] wpa_supplicant changes Sven Neumann
2012-09-19 10:11       ` [Buildroot] [PATCH 1/3] wpa-supplicant: add options to enable the new DBus interface Sven Neumann
2012-09-19 19:56         ` Arnout Vandecappelle
2012-09-19 19:59           ` Arnout Vandecappelle
2012-09-19 10:11       ` [Buildroot] [PATCH 2/3] wpa_supplicant: remove redundant escaping from sed commands Sven Neumann
2012-09-19 20:06         ` Arnout Vandecappelle
2012-09-19 10:11       ` [Buildroot] [PATCH 3/3] wpa_supplicant: introduce macros for editing the .config file Sven Neumann
2012-09-19 20:33         ` Arnout Vandecappelle [this message]
     [not found]   ` <505810D1.8070806@essensium.com>
2012-09-19  9:02     ` [Buildroot] [PATCH] wpa-supplicant: add options to enable the new DBus interface Sven Neumann
2012-09-19 20:03       ` Arnout Vandecappelle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=505A2C10.8040407@mind.be \
    --to=arnout@mind.be \
    --cc=buildroot@busybox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox