[dpdk-dev,v3] mk: fix FreeBSD build

Message ID 1468935637-39937-1-git-send-email-sergio.gonzalez.monroy@intel.com (mailing list archive)
State Accepted, archived
Headers

Commit Message

Sergio Gonzalez Monroy July 19, 2016, 1:40 p.m. UTC
  The sed syntax of '0,/regexp/' is GNU specific and fails with
non GNU sed in FreeBSD.

To solve the issue we can use awk instead to remove duplicates.

The awk script basically keeps the last config value, while
maintaining order and comments from original config file.

Fixes: b2063f104db7 ("mk: filter duplicate configuration entries")

Signed-off-by: Sergio Gonzalez Monroy <sergio.gonzalez.monroy@intel.com>
---
 mk/rte.sdkconfig.mk | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
  

Comments

Christian Ehrhardt July 19, 2016, 2:30 p.m. UTC | #1
Hi,
the order changed, but IMHO actually it improved.
Things are now at the place they were before, but with the overwriting
config value that came later - that is the best of both worlds.

Tested a few config runs pre/post patch and compared them sorted (equal)
and unsorted - now configs slotted in where they belong.
Thanks for updating Sergio

Acked-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>

Christian Ehrhardt
Software Engineer, Ubuntu Server
Canonical Ltd

On Tue, Jul 19, 2016 at 3:40 PM, Sergio Gonzalez Monroy <
sergio.gonzalez.monroy@intel.com> wrote:

> The sed syntax of '0,/regexp/' is GNU specific and fails with
> non GNU sed in FreeBSD.
>
> To solve the issue we can use awk instead to remove duplicates.
>
> The awk script basically keeps the last config value, while
> maintaining order and comments from original config file.
>
> Fixes: b2063f104db7 ("mk: filter duplicate configuration entries")
>
> Signed-off-by: Sergio Gonzalez Monroy <sergio.gonzalez.monroy@intel.com>
> ---
>  mk/rte.sdkconfig.mk | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/mk/rte.sdkconfig.mk b/mk/rte.sdkconfig.mk
> index e93237f..5c94edf 100644
> --- a/mk/rte.sdkconfig.mk
> +++ b/mk/rte.sdkconfig.mk
> @@ -88,11 +88,13 @@ $(RTE_OUTPUT)/.config: $(RTE_CONFIG_TEMPLATE) FORCE |
> $(RTE_OUTPUT)
>                 $(CPP) -undef -P -x assembler-with-cpp \
>                 -ffreestanding \
>                 -o $(RTE_OUTPUT)/.config_tmp $(RTE_CONFIG_TEMPLATE) ; \
> -               for config in $$(grep -v "^#" $(RTE_OUTPUT)/.config_tmp |
> cut -d"=" -f1 | sort | uniq -d); do \
> -                       while [ $$(grep "^$${config}="
> $(RTE_OUTPUT)/.config_tmp -c ) -gt 1 ]; do \
> -                               sed -i "0,/^$${config}=/{//d}"
> $(RTE_OUTPUT)/.config_tmp; \
> -                       done; \
> -               done; \
> +               config=$$(cat $(RTE_OUTPUT)/.config_tmp) ; \
> +               echo "$$config" | awk -F '=' 'BEGIN {i=1} \
> +                       /^#/ {pos[i++]=$$0} \
> +                       !/^#/ {if (!s[$$1]) {pos[i]=$$0; s[$$1]=i++} \
> +                               else {pos[s[$$1]]=$$0}} END \
> +                       {for (j=1; j<i; j++) print pos[j]}' \
> +                       > $(RTE_OUTPUT)/.config_tmp ; \
>                 if ! cmp -s $(RTE_OUTPUT)/.config_tmp
> $(RTE_OUTPUT)/.config; then \
>                         cp $(RTE_OUTPUT)/.config_tmp $(RTE_OUTPUT)/.config
> ; \
>                         cp $(RTE_OUTPUT)/.config_tmp
> $(RTE_OUTPUT)/.config.orig ; \
> --
> 2.4.11
>
>
  
Ferruh Yigit July 19, 2016, 3:04 p.m. UTC | #2
On 7/19/2016 3:30 PM, Christian Ehrhardt wrote:
> Hi,
> the order changed, but IMHO actually it improved.
> Things are now at the place they were before, but with the overwriting
> config value that came later - that is the best of both worlds.

Agreed, this is a good solution. Also fixes multiple copy of file
comment issue ...

> 
> Tested a few config runs pre/post patch and compared them sorted (equal)
> and unsorted - now configs slotted in where they belong.
> Thanks for updating Sergio
> 
> Acked-by: Christian Ehrhardt <christian.ehrhardt@canonical.com
> <mailto:christian.ehrhardt@canonical.com>>
> 
> Christian Ehrhardt
> Software Engineer, Ubuntu Server
> Canonical Ltd
>
  
Thomas Monjalon July 21, 2016, 8:27 a.m. UTC | #3
> > The sed syntax of '0,/regexp/' is GNU specific and fails with
> > non GNU sed in FreeBSD.
> >
> > To solve the issue we can use awk instead to remove duplicates.
> >
> > The awk script basically keeps the last config value, while
> > maintaining order and comments from original config file.
> >
> > Fixes: b2063f104db7 ("mk: filter duplicate configuration entries")
> >
> > Signed-off-by: Sergio Gonzalez Monroy <sergio.gonzalez.monroy@intel.com>
> 
> Hi,
> the order changed, but IMHO actually it improved.
> Things are now at the place they were before, but with the overwriting
> config value that came later - that is the best of both worlds.
> 
> Tested a few config runs pre/post patch and compared them sorted (equal)
> and unsorted - now configs slotted in where they belong.
> Thanks for updating Sergio
> 
> Acked-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>

Applied, thanks
  

Patch

diff --git a/mk/rte.sdkconfig.mk b/mk/rte.sdkconfig.mk
index e93237f..5c94edf 100644
--- a/mk/rte.sdkconfig.mk
+++ b/mk/rte.sdkconfig.mk
@@ -88,11 +88,13 @@  $(RTE_OUTPUT)/.config: $(RTE_CONFIG_TEMPLATE) FORCE | $(RTE_OUTPUT)
 		$(CPP) -undef -P -x assembler-with-cpp \
 		-ffreestanding \
 		-o $(RTE_OUTPUT)/.config_tmp $(RTE_CONFIG_TEMPLATE) ; \
-		for config in $$(grep -v "^#" $(RTE_OUTPUT)/.config_tmp | cut -d"=" -f1 | sort | uniq -d); do \
-			while [ $$(grep "^$${config}=" $(RTE_OUTPUT)/.config_tmp -c ) -gt 1 ]; do \
-				sed -i "0,/^$${config}=/{//d}" $(RTE_OUTPUT)/.config_tmp; \
-			done; \
-		done; \
+		config=$$(cat $(RTE_OUTPUT)/.config_tmp) ; \
+		echo "$$config" | awk -F '=' 'BEGIN {i=1} \
+			/^#/ {pos[i++]=$$0} \
+			!/^#/ {if (!s[$$1]) {pos[i]=$$0; s[$$1]=i++} \
+				else {pos[s[$$1]]=$$0}} END \
+			{for (j=1; j<i; j++) print pos[j]}' \
+			> $(RTE_OUTPUT)/.config_tmp ; \
 		if ! cmp -s $(RTE_OUTPUT)/.config_tmp $(RTE_OUTPUT)/.config; then \
 			cp $(RTE_OUTPUT)/.config_tmp $(RTE_OUTPUT)/.config ; \
 			cp $(RTE_OUTPUT)/.config_tmp $(RTE_OUTPUT)/.config.orig ; \