[dpdk-dev] mk: Rework gcc version detection to permit versions newer than 4.x

Message ID 7a06a1e8019a40d4175c6bc2e1d7e62cf956b291.1424261465.git.pmatilai@redhat.com (mailing list archive)
State Superseded, archived
Headers

Commit Message

Panu Matilainen Feb. 18, 2015, 12:11 p.m. UTC
  Separately comparing major and minor versions becomes seriously clumsy
when with major version changes, convert the entire version string into
a numeric value (ie 4.6.0 becomes 460 and 5.0.0 becomes 500) and use
that for comparisons. This simplifies the comparisons and makes
gcc 5.0 naturally recognized at least as capable as newest 4.x.

This three-digit scheme would run into trouble if gcc ever went to
two-digit version segments, but that hasn't happened in the last 10+
years so it seems like a safe assumption.

Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
---
 lib/librte_pmd_fm10k/Makefile            |  2 +-
 lib/librte_pmd_i40e/Makefile             |  2 +-
 lib/librte_pmd_ixgbe/Makefile            |  6 +++---
 lib/librte_pmd_vmxnet3/Makefile          |  2 +-
 mk/toolchain/gcc/rte.toolchain-compat.mk | 22 ++++++++++------------
 5 files changed, 16 insertions(+), 18 deletions(-)
  

Comments

Thomas Monjalon Feb. 20, 2015, 2:04 p.m. UTC | #1
Hi Panu,

2015-02-18 14:11, Panu Matilainen:
> Separately comparing major and minor versions becomes seriously clumsy
> when with major version changes, convert the entire version string into
> a numeric value (ie 4.6.0 becomes 460 and 5.0.0 becomes 500) and use
> that for comparisons. This simplifies the comparisons and makes
> gcc 5.0 naturally recognized at least as capable as newest 4.x.
> 
> This three-digit scheme would run into trouble if gcc ever went to
> two-digit version segments, but that hasn't happened in the last 10+
> years so it seems like a safe assumption.
> 
> Signed-off-by: Panu Matilainen <pmatilai@redhat.com>

Yes this version checking was totally buggy.
Thanks for improving it.

I have a comment about the conversion of old versions checks.

> -ifneq ($(shell test $(GCC_MAJOR_VERSION) -le 4 -a $(GCC_MINOR_VERSION) -le 3 && echo 1), 1)
> +ifneq ($(shell test $(GCC_VERSION) -le 430 && echo 1), 1)

The previous check was a buggy "if not <= 4.3.x"
Your check is "if not <= 4.3.0"
So it's a bit different.
And I think we should remove negation to make it simpler:
	"if >= 4.4.0"

I have the same comment for other changes in the patch.
  
Panu Matilainen Feb. 20, 2015, 3:25 p.m. UTC | #2
On 02/20/2015 04:04 PM, Thomas Monjalon wrote:
> Hi Panu,
>
> 2015-02-18 14:11, Panu Matilainen:
>> Separately comparing major and minor versions becomes seriously clumsy
>> when with major version changes, convert the entire version string into
>> a numeric value (ie 4.6.0 becomes 460 and 5.0.0 becomes 500) and use
>> that for comparisons. This simplifies the comparisons and makes
>> gcc 5.0 naturally recognized at least as capable as newest 4.x.
>>
>> This three-digit scheme would run into trouble if gcc ever went to
>> two-digit version segments, but that hasn't happened in the last 10+
>> years so it seems like a safe assumption.
>>
>> Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
>
> Yes this version checking was totally buggy.
> Thanks for improving it.
>
> I have a comment about the conversion of old versions checks.
>
>> -ifneq ($(shell test $(GCC_MAJOR_VERSION) -le 4 -a $(GCC_MINOR_VERSION) -le 3 && echo 1), 1)
>> +ifneq ($(shell test $(GCC_VERSION) -le 430 && echo 1), 1)
>
> The previous check was a buggy "if not <= 4.3.x"
> Your check is "if not <= 4.3.0"
> So it's a bit different.

Ah, indeed. Thanks for pointing that out.

> And I think we should remove negation to make it simpler:
> 	"if >= 4.4.0"
>
> I have the same comment for other changes in the patch.

Ok, since the change seems welcome I'll fix/simplify the above cases and 
send a new version.

	- Panu -
  

Patch

diff --git a/lib/librte_pmd_fm10k/Makefile b/lib/librte_pmd_fm10k/Makefile
index 986f4ef..dd37f19 100644
--- a/lib/librte_pmd_fm10k/Makefile
+++ b/lib/librte_pmd_fm10k/Makefile
@@ -62,7 +62,7 @@  else
 #
 # CFLAGS for gcc
 #
-ifneq ($(shell test $(GCC_MAJOR_VERSION) -le 4 -a $(GCC_MINOR_VERSION) -le 3 && echo 1), 1)
+ifneq ($(shell test $(GCC_VERSION) -le 430 && echo 1), 1)
 CFLAGS     += -Wno-deprecated
 endif
 CFLAGS_BASE_DRIVER = -Wno-unused-parameter -Wno-unused-value
diff --git a/lib/librte_pmd_i40e/Makefile b/lib/librte_pmd_i40e/Makefile
index 9a0eec8..484379a 100644
--- a/lib/librte_pmd_i40e/Makefile
+++ b/lib/librte_pmd_i40e/Makefile
@@ -69,7 +69,7 @@  CFLAGS_BASE_DRIVER += -Wno-pointer-to-int-cast
 CFLAGS_BASE_DRIVER += -Wno-format-nonliteral
 CFLAGS_BASE_DRIVER += -Wno-format-security
 
-ifeq ($(shell test $(GCC_MAJOR_VERSION) -ge 4 -a $(GCC_MINOR_VERSION) -ge 4 && echo 1), 1)
+ifeq ($(shell test $(GCC_VERSION) -ge 440 && echo 1), 1)
 CFLAGS_BASE_DRIVER += -Wno-unused-but-set-variable
 endif
 
diff --git a/lib/librte_pmd_ixgbe/Makefile b/lib/librte_pmd_ixgbe/Makefile
index d580f62..49ecc2f 100644
--- a/lib/librte_pmd_ixgbe/Makefile
+++ b/lib/librte_pmd_ixgbe/Makefile
@@ -60,18 +60,18 @@  else
 #
 # CFLAGS for gcc
 #
-ifneq ($(shell test $(GCC_MAJOR_VERSION) -le 4 -a $(GCC_MINOR_VERSION) -le 3 && echo 1), 1)
+ifneq ($(shell test $(GCC_VERSION) -le 430 && echo 1), 1)
 CFLAGS     += -Wno-deprecated
 endif
 CFLAGS_BASE_DRIVER = -Wno-unused-parameter -Wno-unused-value
 CFLAGS_BASE_DRIVER += -Wno-strict-aliasing -Wno-format-extra-args
 
-ifeq ($(shell test $(GCC_MAJOR_VERSION) -ge 4 -a $(GCC_MINOR_VERSION) -ge 6 && echo 1), 1)
+ifeq ($(shell test $(GCC_VERSION) -ge 460 && echo 1), 1)
 CFLAGS_ixgbe_common.o += -Wno-unused-but-set-variable
 CFLAGS_ixgbe_x550.o += -Wno-unused-but-set-variable -Wno-maybe-uninitialized
 endif
 
-ifeq ($(shell test $(GCC_MAJOR_VERSION) -le 4 -a $(GCC_MINOR_VERSION) -le 6 && echo 1), 1)
+ifeq ($(shell test $(GCC_VERSION) -le 460 && echo 1), 1)
 CFLAGS_ixgbe_x550.o += -Wno-uninitialized
 CFLAGS_ixgbe_phy.o += -Wno-uninitialized
 endif
diff --git a/lib/librte_pmd_vmxnet3/Makefile b/lib/librte_pmd_vmxnet3/Makefile
index 93e5580..7d7002c 100644
--- a/lib/librte_pmd_vmxnet3/Makefile
+++ b/lib/librte_pmd_vmxnet3/Makefile
@@ -56,7 +56,7 @@  else
 #
 # CFLAGS for gcc
 #
-ifneq ($(shell test $(GCC_MAJOR_VERSION) -le 4 -a $(GCC_MINOR_VERSION) -le 3 && echo 1), 1)
+ifneq ($(shell test $(GCC_VERSION) -le 430 && echo 1), 1)
 CFLAGS     += -Wno-deprecated
 endif
 CFLAGS_BASE_DRIVER = -Wno-unused-parameter -Wno-unused-value
diff --git a/mk/toolchain/gcc/rte.toolchain-compat.mk b/mk/toolchain/gcc/rte.toolchain-compat.mk
index e40e103..9d262c4 100644
--- a/mk/toolchain/gcc/rte.toolchain-compat.mk
+++ b/mk/toolchain/gcc/rte.toolchain-compat.mk
@@ -38,17 +38,15 @@ 
 
 #find out GCC version
 
-GCC_MAJOR_VERSION = $(shell $(CC) -dumpversion | cut -f1 -d.)
+GCC_VERSION = $(subst .,,$(shell $(CC) -dumpversion))
 
-# if GCC is not 4.x
-ifneq ($(GCC_MAJOR_VERSION),4)
+# if GCC is older than 4.x
+ifneq ($(shell test $(GCC_VERSION) -ge 400 && echo 1), 1)
 	MACHINE_CFLAGS =
-$(warning You are not using GCC 4.x. This is neither supported, nor tested.)
+$(warning You are not using GCC >= 4.x. This is neither supported, nor tested.)
 
 
 else
-	GCC_MINOR_VERSION = $(shell $(CC) -dumpversion | cut -f2 -d.)
-
 # GCC graceful degradation
 # GCC 4.2.x - added support for generic target
 # GCC 4.3.x - added support for core2, ssse3, sse4.1, sse4.2
@@ -57,18 +55,18 @@  else
 # GCC 4.6.x - added support for corei7, corei7-avx
 # GCC 4.7.x - added support for fsgsbase, rdrnd, f16c, core-avx-i, core-avx2
 
-	ifeq ($(shell test $(GCC_MINOR_VERSION) -le 7 && echo 1), 1)
+	ifeq ($(shell test $(GCC_VERSION) -le 470 && echo 1), 1)
 		MACHINE_CFLAGS := $(patsubst -march=core-avx-i,-march=corei7-avx,$(MACHINE_CFLAGS))
 		MACHINE_CFLAGS := $(patsubst -march=core-avx2,-march=core-avx2,$(MACHINE_CFLAGS))
 	endif
-	ifeq ($(shell test $(GCC_MINOR_VERSION) -lt 6 && echo 1), 1)
+	ifeq ($(shell test $(GCC_VERSION) -lt 460 && echo 1), 1)
 		MACHINE_CFLAGS := $(patsubst -march=corei7-avx,-march=core2 -maes -mpclmul -mavx,$(MACHINE_CFLAGS))
 		MACHINE_CFLAGS := $(patsubst -march=corei7,-march=core2 -maes -mpclmul,$(MACHINE_CFLAGS))
 	endif
-	ifeq ($(shell test $(GCC_MINOR_VERSION) -lt 5 && echo 1), 1)
+	ifeq ($(shell test $(GCC_VERSION) -lt 450 && echo 1), 1)
 		MACHINE_CFLAGS := $(patsubst -march=atom,-march=core2 -mssse3,$(MACHINE_CFLAGS))
 	endif
-	ifeq ($(shell test $(GCC_MINOR_VERSION) -lt 4 && echo 1), 1)
+	ifeq ($(shell test $(GCC_VERSION) -lt 440 && echo 1), 1)
 		MACHINE_CFLAGS := $(filter-out -mavx -mpclmul -maes,$(MACHINE_CFLAGS))
 		ifneq ($(findstring SSE4_2, $(CPUFLAGS)),)
 			MACHINE_CFLAGS += -msse4.2
@@ -77,12 +75,12 @@  else
 			MACHINE_CFLAGS += -msse4.1
 		endif
 	endif
-	ifeq ($(shell test $(GCC_MINOR_VERSION) -lt 3 && echo 1), 1)
+	ifeq ($(shell test $(GCC_VERSION) -lt 430 && echo 1), 1)
 		MACHINE_CFLAGS := $(filter-out -msse% -mssse%,$(MACHINE_CFLAGS))
 		MACHINE_CFLAGS := $(patsubst -march=core2,-march=generic,$(MACHINE_CFLAGS))
 		MACHINE_CFLAGS += -msse3
 	endif
-	ifeq ($(shell test $(GCC_MINOR_VERSION) -lt 2 && echo 1), 1)
+	ifeq ($(shell test $(GCC_VERSION) -lt 420 && echo 1), 1)
 		MACHINE_CFLAGS := $(filter-out -march% -mtune% -msse%,$(MACHINE_CFLAGS))
 	endif
 endif