Skip to contentSkip to conversation

cc-version not available to change EXTRA_CFLAGS

PATCH Olaf Hering 2 participants 11 messages Jan 21, 2006 – Jul 23, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

I want to add a gcc version check for reiserfs, on akpms request. This one doesnt work with 2.6.16rc1, havent checked if it ever worked.

make -kj14 O=../O-powerpc-ppc64-defconfig arch/powerpc/mm/mem.o
GEN /home/olaf/kernel/olh/ppc64/O-powerpc-ppc64-defconfig/Makefile
scripts/kconfig/conf -s arch/powerpc/Kconfig
arch/powerpc/platforms/83xx/Kconfig:10:warning: 'select' used by config symbol 'MPC834x_SYS' refer to undefined symbol 'DEFAULT_UIMAGE' #

# using defaults found in .config
#
make[3]: `.kernelrelease' is up to date.
  SPLIT   include/linux/autoconf.h -> include/config/*
+ '[' -lt 0400 ']'
/bin/sh: line 1: [: -lt: unary operator expected
make[2]: `arch/powerpc/mm/mem.o' is up to date.
olaf@pomegranate:~/kernel/olh/ppc64/linux-2.6.16-rc1-olh> quilt diff
Index: linux-2.6.16-rc1-olh/arch/powerpc/mm/Makefile
===================================================================
--- linux-2.6.16-rc1-olh.orig/arch/powerpc/mm/Makefile
+++ linux-2.6.16-rc1-olh/arch/powerpc/mm/Makefile
@@ -5,6 +5,7 @@
 ifeq ($(CONFIG_PPC64),y)
 EXTRA_CFLAGS   += -mno-minimal-toc
 endif
+GCC_BROKEN_VEC := $(shell set -x ; if [ $(call cc-version) -lt 0400 ] ; then echo "y"; fi)

obj-y := fault.o mem.o lmb.o
obj-$(CONFIG_PPC32) += init_32.o pgtable_32.o mmu_context_32.o

fs/reiserfs/Makefile +1 -1
Index: linux-2.6.16-rc1-olh/fs/reiserfs/Makefile
===================================================================
@@ -28,7 +28,7 @@ endif
 # will work around it. If any other architecture displays this behavior,
 # add it here.
 ifeq ($(CONFIG_PPC32),y)
-EXTRA_CFLAGS := -O1
+EXTRA_CFLAGS := $(shell set -x ; if [ $(call cc-version) -lt 0402 ] ; then echo $(call cc-option,-O1); fi ;)
 endif
 
 TAGS:
Signature · 2 lines
short story of a lazy sysadmin:
 alias appserv=wotan
#1 lore raw
Quoted 3 lines · Olaf Hering

I want to add a gcc version check for reiserfs, on akpms request. This one doesnt work with 2.6.16rc1, havent checked if it ever worked.

...

fs/reiserfs/Makefile endif · line 32

Quoted 11 lines

Index: linux-2.6.16-rc1-olh/fs/reiserfs/Makefile
===================================================================

fs/reiserfs/Makefile +1 -1
@@ -28,7 +28,7 @@ endif
 # will work around it. If any other architecture displays this behavior,
 # add it here.
 ifeq ($(CONFIG_PPC32),y)
-EXTRA_CFLAGS := -O1
+EXTRA_CFLAGS := $(shell set -x ; if [ $(call cc-version) -lt 0402 ] ; then echo $(call cc-option,-O1); fi ;)
 endif

cc-option is only available from main Makefile as of today. I can try to move them to Kbuild.include - that should fix this usecase.

Sam

#2 lore raw
Quoted 1 line · Sam Ravnborg

I can try to move them to Kbuild.include - that should fix this usecase.

Thanks.

Signature · 2 lines
short story of a lazy sysadmin:
 alias appserv=wotan
#3 lore raw
In reply to Olaf Hering
Quoted 3 lines · Olaf Hering

I want to add a gcc version check for reiserfs, on akpms request. This one doesnt work with 2.6.16rc1, havent checked if it ever worked.

I did the following:
- Moved definitions from Makefile to scripts/Kbuild.include
- Moved include of Kbuild.include up before include of kbuild file
- Documented the 'new' as-option
- Added new macro: cc-ifversion
- Added documentation for cc-ifversion

Let me know if this works for you.

Review

Quoted 3 lines

ifeq ($(CONFIG_PPC32),y)

(quoted diff) +1 -1
-EXTRA_CFLAGS := -O1
+EXTRA_CFLAGS := $(shell set -x ; if [ $(call cc-version) -lt 0402 ] ; then echo $(call cc-option,-O1); fi ;)

For -O1 I do not see the point in using $(call cc-option ...). I assume all gcc version does support -O1 - or?

Sam

Documentation/kbuild/makefiles.txt +29 -1
index 443230b..14f925a 100644
@@ -981,6 +981,20 @@ When kbuild executes the following steps
 	$(CC) is useally the gcc compiler, but other alternatives are
 	available.
 
+    as-option
+    	as-option is used to check if $(CC) when used to compile
+	assembler (*.S) files supports the given option. An optional
+	second option may be specified if first option are not supported.
+
+	Example:
+		#arch/sh/Makefile
+		cflags-y += $(call as-option,-Wa$(comma)-isa=$(isa-y),)
+
+	In the above example cflags-y will be assinged the the option
+	-Wa$(comma)-isa=$(isa-y) if it is supported by $(CC).
+	The second argument is optional, and if supplied will be used
+	if first argument is not supported.
+
     cc-option
 	cc-option is used to check if $(CC) support a given option, and not
 	supported to use an optional second option.
@@ -1039,7 +1053,21 @@ When kbuild executes the following steps
 
 	In the above example -mregparm=3 is only used for gcc version greater
 	than or equal to gcc 3.0.
-	
+
+    cc-ifversion
+	cc-ifversion test the version of $(CC) and equals last argument if
+	version expression is true.
+
+	Example:
+		#fs/reiserfs/Makefile
+		EXTRA_CFLAGS := $(call cc-ifversion, -lt, 0402, -O1)
+
+	In this example EXTRA_CFLAGS will be assigned the value -O1 if the
+	$(CC) version is less than 4.2.
+	cc-ifversion takes all the shell operators: 
+	-eq, -ne, -lt, -le, -gt, and -ge
+	The third parameter may be a text as in this example, but it may also
+	be an expanded variable or a macro.
 
 === 7 Kbuild Variables
 
Makefile +0 -32
index 31bbc6a..da3c528 100644
@@ -259,38 +259,6 @@ endif
 
 export quiet Q KBUILD_VERBOSE
 
-######
-# cc support functions to be used (only) in arch/$(ARCH)/Makefile
-# See documentation in Documentation/kbuild/makefiles.txt
-
-# as-option
-# Usage: cflags-y += $(call as-option, -Wa$(comma)-isa=foo,)
-
-as-option = $(shell if $(CC) $(CFLAGS) $(1) -Wa,-Z -c -o /dev/null \
-	     -xassembler /dev/null > /dev/null 2>&1; then echo "$(1)"; \
-	     else echo "$(2)"; fi ;)
-
-# cc-option
-# Usage: cflags-y += $(call cc-option, -march=winchip-c6, -march=i586)
-
-cc-option = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
-             > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
-
-# cc-option-yn
-# Usage: flag := $(call cc-option-yn, -march=winchip-c6)
-cc-option-yn = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
-                > /dev/null 2>&1; then echo "y"; else echo "n"; fi;)
-
-# cc-option-align
-# Prefix align with either -falign or -malign
-cc-option-align = $(subst -functions=0,,\
-	$(call cc-option,-falign-functions=0,-malign-functions=0))
-
-# cc-version
-# Usage gcc-ver := $(call cc-version $(CC))
-cc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh \
-              $(if $(1), $(1), $(CC)))
-
 
 # Look for make include files relative to root of kernel src
 MAKEFLAGS += --include-dir=$(srctree)
scripts/Kbuild.include +37 -0
index 0168d6c..92ce94b 100644
@@ -44,6 +44,43 @@ define filechk
 	fi
 endef
 
+######
+# cc support functions to be used (only) in arch/$(ARCH)/Makefile
+# See documentation in Documentation/kbuild/makefiles.txt
+
+# as-option
+# Usage: cflags-y += $(call as-option, -Wa$(comma)-isa=foo,)
+
+as-option = $(shell if $(CC) $(CFLAGS) $(1) -Wa,-Z -c -o /dev/null \
+	     -xassembler /dev/null > /dev/null 2>&1; then echo "$(1)"; \
+	     else echo "$(2)"; fi ;)
+
+# cc-option
+# Usage: cflags-y += $(call cc-option, -march=winchip-c6, -march=i586)
+
+cc-option = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
+             > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
+
+# cc-option-yn
+# Usage: flag := $(call cc-option-yn, -march=winchip-c6)
+cc-option-yn = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
+                > /dev/null 2>&1; then echo "y"; else echo "n"; fi;)
+
+# cc-option-align
+# Prefix align with either -falign or -malign
+cc-option-align = $(subst -functions=0,,\
+	$(call cc-option,-falign-functions=0,-malign-functions=0))
+
+# cc-version
+# Usage gcc-ver := $(call cc-version, $(CC))
+cc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh \
+              $(if $(1), $(1), $(CC)))
+
+# cc-ifversion
+# Usage:  EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1)
+cc-ifversion = $(shell if [ $(call cc-version, $(CC)) $(1) $(2) ]; then \
+                       echo $(3); fi;)
+
 ###
 # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj=
 # Usage:
scripts/Makefile.build +2 -1
index c33e62b..2737765 100644
@@ -10,11 +10,12 @@ __build:
 # Read .config if it exist, otherwise ignore
 -include .config
 
+include scripts/Kbuild.include
+
 # The filename Kbuild has precedence over Makefile
 kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
 include $(if $(wildcard $(kbuild-dir)/Kbuild), $(kbuild-dir)/Kbuild, $(kbuild-dir)/Makefile)
 
-include scripts/Kbuild.include
 include scripts/Makefile.lib
 
 ifdef host-progs
#4 lore raw
Quoted 1 line · Sam Ravnborg

Let me know if this works for you.

Works perfect, beside this minor glitch.

Warning: trailing whitespace in line 1067 of
Documentation/kbuild/makefiles.txt

Quoted 6 lines

Review

Quoted 3 lines

ifeq ($(CONFIG_PPC32),y)

(quoted diff) +1 -1
-EXTRA_CFLAGS := -O1
+EXTRA_CFLAGS := $(shell set -x ; if [ $(call cc-version) -lt 0402 ] ; then echo $(call cc-option,-O1); fi ;)

For -O1 I do not see the point in using $(call cc-option ...). I assume all gcc version does support -O1 - or?

this was just c&p during debug, from another file.

Documentation/kbuild/makefiles.txt When kbuild executes the following steps · line 1066

Quoted 6 lines
Documentation/kbuild/makefiles.txt +6 -0
+	Example:
+		#fs/reiserfs/Makefile
+		EXTRA_CFLAGS := $(call cc-ifversion, -lt, 0402, -O1)
+
+	In this example EXTRA_CFLAGS will be assigned the value -O1 if the
+	$(CC) version is less than 4.2.

I meant 4.0.2 as shipped with SuSE 10.0, but thats ok. I think the buggy version was 3.2, as we have not seen in with gcc 3.3-hammer in SLES9. Will you include the reiserfs change with a check for earlier then 4.0 or 4.1 or should I send a separate patch?

Signature · 2 lines
short story of a lazy sysadmin:
 alias appserv=wotan
#5 lore raw
Quoted 2 lines · Olaf Hering

Will you include the reiserfs change with a check for earlier then 4.0 or 4.1 or should I send a separate patch?

Please submit as a separate patch. I try to keep non-kbuild stuff out of the kbuild tree. This make is less confusing.

I will not commit this until sometime tomorrow - I have to set up something so I can track bugfixes and enhancements in parallel. This is 2.6.17 material IMO in kbuild land except if we want this in for reiserfs before 2.6.17.

I try to be rather strict about bug-fixes versus enhancements in kbuild. The latest unexpected breakage shows how easy it is to introduce unexpected errors in someones build :-(

Sam

#6 lore raw
Quoted 2 lines · Sam Ravnborg

This is 2.6.17 material IMO in kbuild land except if we want this in for reiserfs before 2.6.17.

Yes, thats ok.

Signature · 2 lines
short story of a lazy sysadmin:
 alias appserv=wotan
#7 lore raw
In reply to Sam Ravnborg
Quoted 11 lines · Sam Ravnborg

+++ b/Makefile

Makefile +1 -3
@@ -259,38 +259,6 @@ endif
 
 export quiet Q KBUILD_VERBOSE
 
-######
-# cc support functions to be used (only) in arch/$(ARCH)/Makefile
-# See documentation in Documentation/kbuild/makefiles.txt
 
+++ b/scripts/Kbuild.include

Makefile define filechk · line 49

Quoted 6 lines
Makefile +3 -0
@@ -44,6 +44,43 @@ define filechk
 	fi
 endef
 
+######
+# cc support functions to be used (only) in arch/$(ARCH)/Makefile
+# See documentation in Documentation/kbuild/makefiles.txt

The comment needs updating.

Signature · 2 lines
short story of a lazy sysadmin:
 alias appserv=wotan
#8 lore raw
Quoted 17 lines · Olaf Hering
Quoted 14 lines · Sam Ravnborg

+++ b/Makefile

Makefile +1 -3
@@ -259,38 +259,6 @@ endif
 
 export quiet Q KBUILD_VERBOSE
 
-######
-# cc support functions to be used (only) in arch/$(ARCH)/Makefile
-# See documentation in Documentation/kbuild/makefiles.txt
 
+++ b/scripts/Kbuild.include
@@ -44,6 +44,43 @@ define filechk
 	fi
 endef
 
Quoted 5 lines

scripts/Kbuild.include define filechk · line 49

Quoted 3 lines
scripts/Kbuild.include +3 -0
+######
+# cc support functions to be used (only) in arch/$(ARCH)/Makefile
+# See documentation in Documentation/kbuild/makefiles.txt

The comment needs updating.

Done - thanks.

Sam

#9 lore raw
In reply to Olaf Hering
Quoted 2 lines · Olaf Hering

I want to add a gcc version check for reiserfs, on akpms request.

This debug patch still doesnt work in 2.6.18-rc2:

make -kj 14 O=$O

scripts/gcc-version.sh: line 11: _c_flags: command not found scripts/gcc-version.sh: line 12: _c_flags: command not found
+ '[' 0000 -lt 0500 ']'
+ echo -O1

---
 fs/reiserfs/Makefile |    1 +
 1 file changed, 1 insertion(+)
fs/reiserfs/Makefile +1 -0
Index: linux-2.6.18-rc2/fs/reiserfs/Makefile
===================================================================
@@ -30,6 +30,7 @@ endif
 ifeq ($(CONFIG_PPC32),y)
 EXTRA_CFLAGS := -O1
 endif
+EXTRA_CFLAGS += $(shell set -x ; if [ $(call cc-version) -lt 0500 ] ; then echo -O1 ; fi ;)
 
 TAGS:
 	etags *.c
#10 lore raw
Quoted 8 lines · Olaf Hering
Quoted 2 lines · Olaf Hering

I want to add a gcc version check for reiserfs, on akpms request.

This debug patch still doesnt work in 2.6.18-rc2:

Quoted 6 lines

make -kj 14 O=$O

scripts/gcc-version.sh: line 11: _c_flags: command not found scripts/gcc-version.sh: line 12: _c_flags: command not found
+ '[' 0000 -lt 0500 ']'
+ echo -O1

Fixed by following patch. Please consider using: cc-ifversion (see Documentation/kbuild/makefiles.txt

Sam

commit 045cfddb5f89722259c90fb742e201d289d94092

Author: Sam Ravnborg <[email protected]>
Date:   Sun Jul 23 19:49:45 2006 +0200

kbuild: always use $(CC) for $(call cc-version)

The possibility to specify an optional parameter did not work out as expected and it was not used - so remove the possibility.

scripts/Kbuild.include +1 -2
index 7a18353..dbb20a6 100644
@@ -81,8 +81,7 @@ cc-option-align = $(subst -functions=0,,
 
 # cc-version
 # Usage gcc-ver := $(call cc-version, $(CC))
-cc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh \
-              $(if $(1), $(1), $(CC)))
+cc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh $(CC))
 
 # cc-ifversion
 # Usage:  EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1)