2012-02-25 01:52:11

by Luis R. Rodriguez

[permalink] [raw]
Subject: [PATCH 0/5] compat / compat-wireless: merge autoconf generation

From: Luis R. Rodriguez <[email protected]>

While testing ckmake cross compiling compat through different kernels I
realized that compat was failing to build on some kernels but compat-wireless
was not. The reason for this turned out to be that compat did not have an
autoconf for the CONFIG_COMPAT_KERNEL_* variables. In order to make use
of a variable properly in code on kernel we need two things: a makefile
equivalent and a header file that defines it. The compat project had
only makefile variable generation while compat-wireless had makefile
variable generation with a *few* variables propagated to actual code.

To avoid issues with this any further I've decided to try merging the
autoconf effort for both projects and taking leads on what compat does
first.

compat then does the CONFIG_COMPAT_KERNEL_* trickery and generates a
clean .config for us. This in turn generates our compat's compat_autoconf.h.
The compat-wireless project leverages this work by dropping its own
Makefile hackery in favor of the same work and later also uses the same
.config to expand its own compat_autoconf.h.

John, I could use some extra help on reviewing the RHEL stuff. I'm going
to push this stuff out now to help with testing.

compat:

Luis R. Rodriguez (2):
compat: fix few compilations by adding compat_autoconf.h support
compat: add some initial RHEL support

.gitignore | 10 ++++
Makefile | 59 ++++++++++------------
include/linux/compat_autoconf.h | 37 --------------
scripts/gen-compat-autoconf.sh | 105 +++++++++++++++++++++++++++++++++++++++
scripts/gen-compat-config.sh | 60 ++++++++++++++++++++++
5 files changed, 201 insertions(+), 70 deletions(-)
delete mode 100644 include/linux/compat_autoconf.h
create mode 100755 scripts/gen-compat-autoconf.sh
create mode 100755 scripts/gen-compat-config.sh

compat-wireless:

Luis R. Rodriguez (3):
compat-wireless: fix old checks on KERNEL_SUBLEVEL
compat-wireless: start using CONFIG_COMPAT_KERNEL_ in code
compat-wireless: use compat's CONFIG_COMPAT_KERNEL_* variables
Makefile | 22 ++++++++++++++++------
config.mk | 24 ++++--------------------
scripts/check_config.sh | 9 +++++----
scripts/gen-compat-autoconf.sh | 13 +++++++------
4 files changed, 32 insertions(+), 36 deletions(-)

--
1.7.4.15.g7811d



2012-02-27 21:18:11

by Luis R. Rodriguez

[permalink] [raw]
Subject: Re: [PATCH 0/5] compat / compat-wireless: merge autoconf generation

On Sat, Feb 25, 2012 at 12:05:46PM +0100, Hauke Mehrtens wrote:
> On 02/25/2012 02:52 AM, Luis R. Rodriguez wrote:
> > From: Luis R. Rodriguez <[email protected]>
> >
> > While testing ckmake cross compiling compat through different kernels I
> > realized that compat was failing to build on some kernels but compat-wireless
> > was not. The reason for this turned out to be that compat did not have an
> > autoconf for the CONFIG_COMPAT_KERNEL_* variables. In order to make use
> > of a variable properly in code on kernel we need two things: a makefile
> > equivalent and a header file that defines it. The compat project had
> > only makefile variable generation while compat-wireless had makefile
> > variable generation with a *few* variables propagated to actual code.
> >
> > To avoid issues with this any further I've decided to try merging the
> > autoconf effort for both projects and taking leads on what compat does
> > first.
> >
> > compat then does the CONFIG_COMPAT_KERNEL_* trickery and generates a
> > clean .config for us. This in turn generates our compat's compat_autoconf.h.
> > The compat-wireless project leverages this work by dropping its own
> > Makefile hackery in favor of the same work and later also uses the same
> > .config to expand its own compat_autoconf.h.
> >
> > John, I could use some extra help on reviewing the RHEL stuff. I'm going
> > to push this stuff out now to help with testing.
> >
> > compat:
> >
> > Luis R. Rodriguez (2):
> > compat: fix few compilations by adding compat_autoconf.h support
> > compat: add some initial RHEL support
> >
> > .gitignore | 10 ++++
> > Makefile | 59 ++++++++++------------
> > include/linux/compat_autoconf.h | 37 --------------
> > scripts/gen-compat-autoconf.sh | 105 +++++++++++++++++++++++++++++++++++++++
> > scripts/gen-compat-config.sh | 60 ++++++++++++++++++++++
> > 5 files changed, 201 insertions(+), 70 deletions(-)
> > delete mode 100644 include/linux/compat_autoconf.h
> > create mode 100755 scripts/gen-compat-autoconf.sh
> > create mode 100755 scripts/gen-compat-config.sh
> >
> > compat-wireless:
> >
> > Luis R. Rodriguez (3):
> > compat-wireless: fix old checks on KERNEL_SUBLEVEL
> > compat-wireless: start using CONFIG_COMPAT_KERNEL_ in code
> > compat-wireless: use compat's CONFIG_COMPAT_KERNEL_* variables
> > Makefile | 22 ++++++++++++++++------
> > config.mk | 24 ++++--------------------
> > scripts/check_config.sh | 9 +++++----
> > scripts/gen-compat-autoconf.sh | 13 +++++++------
> > 4 files changed, 32 insertions(+), 36 deletions(-)
> >
>
> This patch series breaks parallel build.
> Before these patches where applied parallel build was no problem I just
> saw two error at the beginning, but after this patch series it does not
> work any more.
>
> These are the current error messages at the beginning and then it
> compiles sequential.
>
> Hauke
>
> hauke@hauke:~/compat-wireless/compat-wireless$ make -j5
> make[1]: warning: jobserver unavailable: using -j1. Add `+' to parent
> make rule.
> make[1]: warning: jobserver unavailable: using -j1. Add `+' to parent
> make rule.
> ./scripts/gen-compat-autoconf.sh .config config.mk >
> include/linux/compat_autoconf.h
> make[1]: warning: jobserver unavailable: using -j1. Add `+' to parent
> make rule.
> make[1]: warning: jobserver unavailable: using -j1. Add `+' to parent
> make rule.
> make -C /home/hauke/compat-wireless/compat-wireless modules
> make[1]: Entering directory `/home/hauke/compat-wireless/compat-wireless'
> make[1]: warning: jobserver unavailable: using -j1. Add `+' to parent
> make rule.
> make -C /lib/modules/3.0.0-16-generic/build
> M=/home/hauke/compat-wireless/compat-wireless modules
> make[2]: Entering directory `/usr/src/linux-headers-3.0.0-16-generic'
> LD /home/hauke/compat-wireless/compat-wireless/compat/built-in.o

I had at first the below cheasy fix, but now I have an even better one
that does not require recursion. I'll post and merge. Thanks for reporting
this.

diff --git a/Makefile b/Makefile
index d96d098..d11da17 100644
--- a/Makefile
+++ b/Makefile
@@ -62,8 +62,8 @@ install: modules
$(COMPAT_AUTOCONF): ;

$(COMPAT_CONFIG):
- @$(PWD)/scripts/gen-compat-config.sh > $(PWD)/$(COMPAT_CONFIG)
- @$(PWD)/scripts/gen-compat-autoconf.sh $(COMPAT_CONFIG) > $(PWD)/$(COMPAT_AUTOCONF)
+ +@$(PWD)/scripts/gen-compat-config.sh > $(PWD)/$(COMPAT_CONFIG)
+ +@$(PWD)/scripts/gen-compat-autoconf.sh $(COMPAT_CONFIG) > $(PWD)/$(COMPAT_AUTOCONF)
@$(MAKE) -C $(PWD) modules

kkinstall: modules

2012-02-25 11:06:03

by Hauke Mehrtens

[permalink] [raw]
Subject: Re: [PATCH 0/5] compat / compat-wireless: merge autoconf generation

On 02/25/2012 02:52 AM, Luis R. Rodriguez wrote:
> From: Luis R. Rodriguez <[email protected]>
>
> While testing ckmake cross compiling compat through different kernels I
> realized that compat was failing to build on some kernels but compat-wireless
> was not. The reason for this turned out to be that compat did not have an
> autoconf for the CONFIG_COMPAT_KERNEL_* variables. In order to make use
> of a variable properly in code on kernel we need two things: a makefile
> equivalent and a header file that defines it. The compat project had
> only makefile variable generation while compat-wireless had makefile
> variable generation with a *few* variables propagated to actual code.
>
> To avoid issues with this any further I've decided to try merging the
> autoconf effort for both projects and taking leads on what compat does
> first.
>
> compat then does the CONFIG_COMPAT_KERNEL_* trickery and generates a
> clean .config for us. This in turn generates our compat's compat_autoconf.h.
> The compat-wireless project leverages this work by dropping its own
> Makefile hackery in favor of the same work and later also uses the same
> .config to expand its own compat_autoconf.h.
>
> John, I could use some extra help on reviewing the RHEL stuff. I'm going
> to push this stuff out now to help with testing.
>
> compat:
>
> Luis R. Rodriguez (2):
> compat: fix few compilations by adding compat_autoconf.h support
> compat: add some initial RHEL support
>
> .gitignore | 10 ++++
> Makefile | 59 ++++++++++------------
> include/linux/compat_autoconf.h | 37 --------------
> scripts/gen-compat-autoconf.sh | 105 +++++++++++++++++++++++++++++++++++++++
> scripts/gen-compat-config.sh | 60 ++++++++++++++++++++++
> 5 files changed, 201 insertions(+), 70 deletions(-)
> delete mode 100644 include/linux/compat_autoconf.h
> create mode 100755 scripts/gen-compat-autoconf.sh
> create mode 100755 scripts/gen-compat-config.sh
>
> compat-wireless:
>
> Luis R. Rodriguez (3):
> compat-wireless: fix old checks on KERNEL_SUBLEVEL
> compat-wireless: start using CONFIG_COMPAT_KERNEL_ in code
> compat-wireless: use compat's CONFIG_COMPAT_KERNEL_* variables
> Makefile | 22 ++++++++++++++++------
> config.mk | 24 ++++--------------------
> scripts/check_config.sh | 9 +++++----
> scripts/gen-compat-autoconf.sh | 13 +++++++------
> 4 files changed, 32 insertions(+), 36 deletions(-)
>

This patch series breaks parallel build.
Before these patches where applied parallel build was no problem I just
saw two error at the beginning, but after this patch series it does not
work any more.

These are the current error messages at the beginning and then it
compiles sequential.

Hauke

hauke@hauke:~/compat-wireless/compat-wireless$ make -j5
make[1]: warning: jobserver unavailable: using -j1. Add `+' to parent
make rule.
make[1]: warning: jobserver unavailable: using -j1. Add `+' to parent
make rule.
./scripts/gen-compat-autoconf.sh .config config.mk >
include/linux/compat_autoconf.h
make[1]: warning: jobserver unavailable: using -j1. Add `+' to parent
make rule.
make[1]: warning: jobserver unavailable: using -j1. Add `+' to parent
make rule.
make -C /home/hauke/compat-wireless/compat-wireless modules
make[1]: Entering directory `/home/hauke/compat-wireless/compat-wireless'
make[1]: warning: jobserver unavailable: using -j1. Add `+' to parent
make rule.
make -C /lib/modules/3.0.0-16-generic/build
M=/home/hauke/compat-wireless/compat-wireless modules
make[2]: Entering directory `/usr/src/linux-headers-3.0.0-16-generic'
LD /home/hauke/compat-wireless/compat-wireless/compat/built-in.o


2012-02-25 01:52:23

by Luis R. Rodriguez

[permalink] [raw]
Subject: [PATCH 4/5] compat-wireless: start using CONFIG_COMPAT_KERNEL_ in code

From: Luis R. Rodriguez <[email protected]>

This lets use the defined CONFIG_COMPAT_KERNEL_* in C code and
header files. Next step is to remove the Makefile hackery to
defines CONFIG_COMPAT_KERNEL_* stuff as we have a generated
file for us now.

Signed-off-by: Luis R. Rodriguez <[email protected]>
---
Makefile | 14 +++++++++-----
scripts/check_config.sh | 9 +++++----
scripts/gen-compat-autoconf.sh | 13 +++++++------
3 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/Makefile b/Makefile
index 4149d8d..b5423ee 100644
--- a/Makefile
+++ b/Makefile
@@ -8,6 +8,7 @@ endif
export KLIB_BUILD ?= $(KLIB)/build
# Sometimes not available in the path
MODPROBE := /sbin/modprobe
+export MAKE

ifneq ($(wildcard $(MODPROBE)),)
MADWIFI=$(shell $(MODPROBE) -l ath_pci)
@@ -66,14 +67,16 @@ CFLAGS += \

# These exported as they are used by the scripts
# to check config and compat autoconf
-export COMPAT_CONFIG=config.mk
-export CONFIG_CHECK=.$(COMPAT_CONFIG)_md5sum.txt
+export COMPAT_CONFIG_CW=config.mk
+export COMPAT_CONFIG=.config
+export CONFIG_CHECK=.$(COMPAT_CONFIG_CW)_md5sum.txt
export COMPAT_AUTOCONF=include/linux/compat_autoconf.h
export CREL=$(shell cat $(PWD)/compat_version)
export CREL_PRE:=.compat_autoconf_
export CREL_CHECK:=$(CREL_PRE)$(CREL)

-include $(PWD)/$(COMPAT_CONFIG)
+include $(PWD)/$(COMPAT_CONFIG_CW)
+-include $(PWD)/$(COMPAT_CONFIG)

all: modules

@@ -92,10 +95,11 @@ bt: $(CREL_CHECK)
# $(COMPAT_CONFIG) file
$(CREL_CHECK):
@# Force to regenerate compat autoconf
+ @./compat/scripts/gen-compat-config.sh > $(PWD)/$(COMPAT_CONFIG)
@rm -f $(CONFIG_CHECK)
@./scripts/check_config.sh
@touch $@
- @md5sum $(COMPAT_CONFIG) > $(CONFIG_CHECK)
+ @md5sum $(COMPAT_CONFIG_CW) > $(CONFIG_CHECK)

btinstall: btuninstall bt-install-modules

@@ -234,4 +238,4 @@ wlunload:
endif

clean-files += Module.symvers Module.markers modules modules.order
-clean-files += $(CREL_CHECK) $(CONFIG_CHECK)
+clean-files += $(CREL_CHECK) $(CONFIG_CHECK) $(COMPAT_CONFIG)
diff --git a/scripts/check_config.sh b/scripts/check_config.sh
index 1ac9620..1804976 100755
--- a/scripts/check_config.sh
+++ b/scripts/check_config.sh
@@ -3,14 +3,15 @@
# regenerates the compat_autoconf header.

# These variables are expected to be exported:
-#COMPAT_CONFIG="config"
+#COMPAT_CONFIG=".config"
+#COMPAT_CONFIG_CW="config"
#CONFIG_CHECK=".${COMPAT_CONFIG}.md5"
#COMPAT_AUTOCONF="include/linux/compat_autoconf.h"

function gen_compat_autoconf {
- echo "./scripts/gen-compat-autoconf.sh $COMPAT_CONFIG > $COMPAT_AUTOCONF"
- ./scripts/gen-compat-autoconf.sh $COMPAT_CONFIG > $COMPAT_AUTOCONF
- md5sum $COMPAT_CONFIG > $CONFIG_CHECK
+ echo "./scripts/gen-compat-autoconf.sh $COMPAT_CONFIG $COMPAT_CONFIG_CW > $COMPAT_AUTOCONF"
+ ./scripts/gen-compat-autoconf.sh $COMPAT_CONFIG $COMPAT_CONFIG_CW > $COMPAT_AUTOCONF
+ md5sum $COMPAT_CONFIG $COMPAT_CONFIG_CW > $CONFIG_CHECK
}

which md5sum 2>&1 > /dev/null
diff --git a/scripts/gen-compat-autoconf.sh b/scripts/gen-compat-autoconf.sh
index 28ed25a..58a1c51 100755
--- a/scripts/gen-compat-autoconf.sh
+++ b/scripts/gen-compat-autoconf.sh
@@ -16,15 +16,16 @@ COMPAT_RELEASE="compat_version"
KERNEL_RELEASE="compat_base_tree_version"
MULT_DEP_FILE=".compat_pivot_dep"

-if [ $# -ne 1 ]; then
- echo "Usage $0 config-file"
+if [ $# -ne 2 ]; then
+ echo "Usage $0 <generic-compat-config-file> <compat-wireless-config-file>"
exit
fi

-COMPAT_CONFIG="$1"
+COMPAT_CONFIG_1="$1"
+COMPAT_CONFIG_2="$2"

-if [ ! -f $COMPAT_CONFIG ]; then
- echo "File $1 is not a file"
+if [[ ! -f $COMPAT_CONFIG_1 || ! -f $COMPAT_CONFIG_2 ]]; then
+ echo "File $COMPAT_CONFIG_1 and $COMPAT_CONFIG_2 files must be present"
exit
fi

@@ -145,7 +146,7 @@ EOF
kernel_version_req $OLDEST_KERNEL_SUPPORTED

# For each CONFIG_FOO=x option
-for i in $(egrep '^CONFIG_|^ifdef CONFIG_|^ifndef CONFIG_|^endif #CONFIG_|^else #CONFIG_' $COMPAT_CONFIG | sed 's/ /+/'); do
+for i in $(egrep -h '^CONFIG_|^ifdef CONFIG_|^ifndef CONFIG_|^endif #CONFIG_|^else #CONFIG_' $COMPAT_CONFIG_1 $COMPAT_CONFIG_2 | sed 's/ /+/'); do
case $i in
'ifdef+CONFIG_'* )
echo "#$i" | sed -e 's/+/ /' -e 's/\(ifdef CONFIG_COMPAT_KERNEL_3_\)\([0-9]*\)/if (LINUX_VERSION_CODE < KERNEL_VERSION(3,\2,0))/' -e 's/\(ifdef CONFIG_COMPAT_KERNEL_2_6_\)\([0-9]*\)/if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,\2))/' -e 's/\(ifdef CONFIG_COMPAT_RHEL_\)\([0-9]*\)_\([0-9]*\)/if (defined(RHEL_MAJOR) \&\& RHEL_MAJOR == \2 \&\& RHEL_MINOR >= \3)/' -e 's/\(#ifdef \)\(CONFIG_[^:space:]*\)/#if defined(\2) || defined(\2_MODULE)/'
--
1.7.4.15.g7811d


2012-02-25 01:52:17

by Luis R. Rodriguez

[permalink] [raw]
Subject: [PATCH 2/5] compat: add some initial RHEL support

From: Luis R. Rodriguez <[email protected]>

This adds a series of CONFIG_COMPAT_${RHEL_MAJOR}_${i} tags
for each known RHEL version that we supercede. I cannot
verify if this is correct but this is my translation of
this to script:

RHEL_MAJOR := $(shell grep ^RHEL_MAJOR $(KLIB_BUILD)/Makefile | sed -n 's/.*= *\(.*\)/\1/p')
ifneq ($(RHEL_MAJOR),)
RHEL_MINOR := $(shell grep ^RHEL_MINOR $(KLIB_BUILD)/Makefile | sed -n 's/.*= *\(.*\)/\1/p')
COMPAT_RHEL_VERSIONS := $(shell I=$(RHEL_MINOR); while [ "$$I" -ge 0 ]; do echo $$I; I=$$(($$I - 1)); done)
$(foreach ver,$(COMPAT_RHEL_VERSIONS),$(eval CONFIG_COMPAT_RHEL_$(RHEL_MAJOR)_$(ver)=y))

Cc: John W. Linville <[email protected]>
Signed-off-by: Luis R. Rodriguez <[email protected]>
---
scripts/gen-compat-config.sh | 10 ++++++++++
1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/scripts/gen-compat-config.sh b/scripts/gen-compat-config.sh
index 82b439c..656e8d3 100755
--- a/scripts/gen-compat-config.sh
+++ b/scripts/gen-compat-config.sh
@@ -41,6 +41,16 @@ for i in $(seq ${KERNEL_SUBLEVEL} ${COMPAT_LATEST_VERSION}); do
echo "CONFIG_COMPAT_KERNEL_3_${i}=y"
done

+# The purpose of these seem to be the inverse of the above other varibales.
+# The RHEL checks seem to annotate the existance of RHEL minor versions.
+RHEL_MAJOR=$(grep ^RHEL_MAJOR ${KLIB_BUILD}/Makefile | sed -n 's/.*= *\(.*\)/\1/p')
+if [[ ! -z ${RHEL_MAJOR} ]]; then
+ RHEL_MINOR=$(grep ^RHEL_MINOR $(KLIB_BUILD)/Makefile | sed -n 's/.*= *\(.*\)/\1/p')
+ for i in $(seq 0 ${RHEL_MINOR}); do
+ echo "CONFIG_COMPAT_${RHEL_MAJOR}_${i}=y"
+ done
+fi
+
if [[ ${CONFIG_COMPAT_KERNEL_2_6_33} -eq "y" ]]; then
echo "CONFIG_COMPAT_FIRMWARE_CLASS=m"
fi
--
1.7.4.15.g7811d


2012-02-25 01:52:46

by Luis R. Rodriguez

[permalink] [raw]
Subject: [PATCH 5/5] compat-wireless: use compat's CONFIG_COMPAT_KERNEL_* variables

From: Luis R. Rodriguez <[email protected]>

compat already deals with defining CONFIG_COMPAT_KERNEL_* variables
for us for both makefiles and C / header files. The C / header file
usage was fixed in the last commit, this removes internal usage we
had for the Makefiles in preference over the same mechanism.

Signed-off-by: Luis R. Rodriguez <[email protected]>
---
Makefile | 8 +++++++-
config.mk | 18 ------------------
2 files changed, 7 insertions(+), 19 deletions(-)

diff --git a/Makefile b/Makefile
index b5423ee..5393b40 100644
--- a/Makefile
+++ b/Makefile
@@ -76,9 +76,14 @@ export CREL_PRE:=.compat_autoconf_
export CREL_CHECK:=$(CREL_PRE)$(CREL)

include $(PWD)/$(COMPAT_CONFIG_CW)
+
+# Recursion lets us ensure we get this file included.
+# Trick is to run make -C $(PWD) modules later.
-include $(PWD)/$(COMPAT_CONFIG)

-all: modules
+all: $(CREL_CHECK)
+
+$COMPAT_CONFIG: ;

modules: $(CREL_CHECK)
@./scripts/check_config.sh
@@ -100,6 +105,7 @@ $(CREL_CHECK):
@./scripts/check_config.sh
@touch $@
@md5sum $(COMPAT_CONFIG_CW) > $(CONFIG_CHECK)
+ make -C $(PWD) modules

btinstall: btuninstall bt-install-modules

diff --git a/config.mk b/config.mk
index 4b47321..4bbbd88 100644
--- a/config.mk
+++ b/config.mk
@@ -16,29 +16,11 @@ endif

ifneq ($(wildcard $(KLIB_BUILD)/Makefile),)

-COMPAT_LATEST_VERSION = 3
-
KERNEL_VERSION := $(shell $(MAKE) -C $(KLIB_BUILD) kernelversion | sed -n 's/^\([0-9]\)\..*/\1/p')

ifneq ($(KERNEL_VERSION),2)
-KERNEL_SUBLEVEL := $(shell $(MAKE) -C $(KLIB_BUILD) kernelversion | sed -n 's/^3\.\([0-9]\+\).*/\1/p')
else
-COMPAT_26LATEST_VERSION = 39
KERNEL_26SUBLEVEL := $(shell $(MAKE) -C $(KLIB_BUILD) kernelversion | sed -n 's/^2\.6\.\([0-9]\+\).*/\1/p')
-COMPAT_26VERSIONS := $(shell I=$(COMPAT_26LATEST_VERSION); while [ "$$I" -gt $(KERNEL_26SUBLEVEL) ]; do echo $$I; I=$$(($$I - 1)); done)
-$(foreach ver,$(COMPAT_26VERSIONS),$(eval CONFIG_COMPAT_KERNEL_2_6_$(ver)=y))
-KERNEL_SUBLEVEL := -1
-endif
-
-COMPAT_VERSIONS := $(shell I=$(COMPAT_LATEST_VERSION); while [ "$$I" -gt $(KERNEL_SUBLEVEL) ]; do echo $$I; I=$$(($$I - 1)); done)
-$(foreach ver,$(COMPAT_VERSIONS),$(eval CONFIG_COMPAT_KERNEL_3_$(ver)=y))
-
-RHEL_MAJOR := $(shell grep ^RHEL_MAJOR $(KLIB_BUILD)/Makefile | sed -n 's/.*= *\(.*\)/\1/p')
-
-ifneq ($(RHEL_MAJOR),)
-RHEL_MINOR := $(shell grep ^RHEL_MINOR $(KLIB_BUILD)/Makefile | sed -n 's/.*= *\(.*\)/\1/p')
-COMPAT_RHEL_VERSIONS := $(shell I=$(RHEL_MINOR); while [ "$$I" -ge 0 ]; do echo $$I; I=$$(($$I - 1)); done)
-$(foreach ver,$(COMPAT_RHEL_VERSIONS),$(eval CONFIG_COMPAT_RHEL_$(RHEL_MAJOR)_$(ver)=y))
endif

ifdef CONFIG_COMPAT_KERNEL_2_6_24
--
1.7.4.15.g7811d


2012-02-25 01:52:20

by Luis R. Rodriguez

[permalink] [raw]
Subject: [PATCH 3/5] compat-wireless: fix old checks on KERNEL_SUBLEVEL

From: Luis R. Rodriguez <[email protected]>

KERNEL_SUBLEVEL used to be used on config.mk for th 2.6.x series
but after 3.x support was added the variable should have been
changed to KERNEL_26SUBLEVEL.

Signed-off-by: Luis R. Rodriguez <[email protected]>
---
config.mk | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/config.mk b/config.mk
index f8a4ca5..4b47321 100644
--- a/config.mk
+++ b/config.mk
@@ -53,7 +53,8 @@ endif
# 2.6.27 has FTRACE_DYNAMIC borked, so we will complain if
# you have it enabled, otherwise you will very likely run into
# a kernel panic.
-ifeq ($(shell test $(KERNEL_VERSION) -eq 2 -a $(KERNEL_SUBLEVEL) -eq 27 && echo yes),yes)
+# XXX: move this to compat_autoconf.h script generation
+ifeq ($(shell test $(KERNEL_VERSION) -eq 2 -a $(KERNEL_26SUBLEVEL) -eq 27 && echo yes),yes)
ifeq ($(CONFIG_DYNAMIC_FTRACE),y)
$(error "ERROR: Your 2.6.27 kernel has CONFIG_DYNAMIC_FTRACE, please upgrade your distribution kernel as newer ones should not have this enabled (and if so report a bug) or remove this warning if you know what you are doing")
endif
@@ -70,7 +71,8 @@ endif
#
# In kernel 2.6.32 both attributes were removed.
#
-ifeq ($(shell test $(KERNEL_VERSION) -eq 2 -a $(KERNEL_SUBLEVEL) -ge 27 -a $(KERNEL_SUBLEVEL) -le 31 && echo yes),yes)
+# XXX: move this to compat_autoconf.h script generation
+ifeq ($(shell test $(KERNEL_VERSION) -eq 2 -a $(KERNEL_26SUBLEVEL) -ge 27 -a $(KERNEL_26SUBLEVEL) -le 31 && echo yes),yes)
ifeq ($(CONFIG_MAC80211),)
$(error "ERROR: Your >=2.6.27 and <= 2.6.31 kernel has CONFIG_MAC80211 disabled, you should have it CONFIG_MAC80211=m if you want to use this thing.")
endif
--
1.7.4.15.g7811d


2012-02-25 01:52:15

by Luis R. Rodriguez

[permalink] [raw]
Subject: [PATCH 1/5] compat: fix few compilations by adding compat_autoconf.h support

From: Luis R. Rodriguez <[email protected]>

The Makefile was generating the appropriate CONFIG_COMPAT_KERNEL_*
variables for our Makefiles but this was being ignored by C files
as compat had no compat_autoconf.h being generated. This patch
addresses this but also puhes out the CONFIG_COMPAT_KERNEL_* variable
generation to scripts. We have now two scripts:

scripts/gen-compat-config.sh - generates .config for Makefile propagation
scripts/gen-compat-autoconf.sh - generates compat_autoconf.h for code propagation

This fixes running ckmake on older kernels. This issue was present
only on compat and not compat_wireless as compat_wireless was generating
its own compat_autoconf.h. This fixes compilation against some older
kernels of just the compat module alone. Some work is still required
for some newer and really ancient kernels:

mcgrof@tux ~/compat (git::master)$ ckmake
Trying kernel 3.3.0-030300rc2-generic [FAILED]
Trying kernel 3.2.2-030202-generic [FAILED]
Trying kernel 3.1.10-030110-generic [FAILED]
Trying kernel 3.0.18-030018-generic [FAILED]
Trying kernel 2.6.39-02063904-generic [FAILED]
Trying kernel 2.6.38-8-generic [OK]
Trying kernel 2.6.38-13-generic [OK]
Trying kernel 2.6.38-12-generic [OK]
Trying kernel 2.6.38-11-generic [OK]
Trying kernel 2.6.38-10-generic [OK]
Trying kernel 2.6.38-02063808-generic [OK]
Trying kernel 2.6.37-02063706-generic [OK]
Trying kernel 2.6.36-02063604-generic [OK]
Trying kernel 2.6.35-02063512-generic [OK]
Trying kernel 2.6.34-02063410-generic [OK]
Trying kernel 2.6.33-02063305-generic [OK]
Trying kernel 2.6.32-02063255-generic [OK]
Trying kernel 2.6.31-22-generic [OK]
Trying kernel 2.6.31-02063113-generic [OK]
Trying kernel 2.6.30-02063010-generic [OK]
Trying kernel 2.6.29-02062906-generic [OK]
Trying kernel 2.6.28-02062810-generic [OK]
Trying kernel 2.6.27-020627-generic [OK]
Trying kernel 2.6.26-020626-generic [OK]
Trying kernel 2.6.25-020625-generic [FAILED]
Trying kernel 2.6.24-020624-generic [FAILED]

Signed-off-by: Luis R. Rodriguez <[email protected]>
---
.gitignore | 10 ++++
Makefile | 59 ++++++++++------------
include/linux/compat_autoconf.h | 37 --------------
scripts/gen-compat-autoconf.sh | 105 +++++++++++++++++++++++++++++++++++++++
scripts/gen-compat-config.sh | 50 ++++++++++++++++++
5 files changed, 191 insertions(+), 70 deletions(-)
delete mode 100644 include/linux/compat_autoconf.h
create mode 100755 scripts/gen-compat-autoconf.sh
create mode 100755 scripts/gen-compat-config.sh

diff --git a/.gitignore b/.gitignore
index e27f6c2..498cb5a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,13 @@ Module.symvers
module.order
.pc
ckmake.log
+.config
+include/linux/compat_autoconf.h
+.tmp_versions/
+compat/*.cmd
+compat/*.o
+compat/*.mod.c
+compat/*.ko
+modules.order
+modules
+*.patch
diff --git a/Makefile b/Makefile
index 9215e6e..fdcff5c 100644
--- a/Makefile
+++ b/Makefile
@@ -20,37 +20,14 @@ export COMPAT_BASE_TREE_VERSION := "next-20100517"
export COMPAT_VERSION := $(shell git describe)
endif

-# This generates a bunch of CONFIG_COMPAT_KERNEL_2_6_22 CONFIG_COMPAT_KERNEL_3_0 .. etc for
-# each kernel release you need an object for.
-ifneq ($(wildcard $(KLIB_BUILD)/Makefile),)
+# to check config and compat autoconf
+export COMPAT_CONFIG=.config
+export COMPAT_AUTOCONF=include/linux/compat_autoconf.h
+export MAKE

-COMPAT_LATEST_VERSION = 3
-KERNEL_VERSION := $(shell $(MAKE) -C $(KLIB_BUILD) kernelversion | sed -n 's/^\([0-9]\)\..*/\1/p')
-
-ifneq ($(KERNEL_VERSION),2)
-KERNEL_SUBLEVEL := $(shell $(MAKE) -C $(KLIB_BUILD) kernelversion | sed -n 's/^3\.\([0-9]\+\).*/\1/p')
-else
-COMPAT_26LATEST_VERSION = 39
-KERNEL_26SUBLEVEL := $(shell $(MAKE) -C $(KLIB_BUILD) kernelversion | sed -n 's/^2\.6\.\([0-9]\+\).*/\1/p')
-COMPAT_26VERSIONS := $(shell I=$(COMPAT_26LATEST_VERSION); while [ "$$I" -gt $(KERNEL_26SUBLEVEL) ]; do echo $$I; I=$$(($$I - 1)); done)
-$(foreach ver,$(COMPAT_26VERSIONS),$(eval export CONFIG_COMPAT_KERNEL_2_6_$(ver)=y))
-KERNEL_SUBLEVEL := -1
-endif
-
-COMPAT_VERSIONS := $(shell I=$(COMPAT_LATEST_VERSION); while [ "$$I" -gt $(KERNEL_SUBLEVEL) ]; do echo $$I; I=$$(($$I - 1)); done)
-$(foreach ver,$(COMPAT_VERSIONS),$(eval export CONFIG_COMPAT_KERNEL_3_$(ver)=y))
-
-endif
-
-ifeq ($(CONFIG_COMPAT_KERNEL_2_6_33),y)
-ifneq ($(CONFIG_FW_LOADER),)
- export CONFIG_COMPAT_FIRMWARE_CLASS=m
-endif
-endif
-
-ifeq ($(CONFIG_COMPAT_KERNEL_2_6_36),y)
- export CONFIG_COMPAT_KFIFO=m
-endif #CONFIG_COMPAT_KERNEL_2_6_36
+# Recursion lets us ensure we get this file included.
+# Trick is to run make -C $(PWD) modules later.
+-include $(PWD)/$(COMPAT_CONFIG)

obj-y += compat/

@@ -65,15 +42,31 @@ NOSTDINC_FLAGS := -I$(M)/include/ \
-DCOMPAT_PROJECT="\"Generic kernel\"" \
-DCOMPAT_VERSION="\"$(COMPAT_VERSION)\""

-modules:
+all: $(COMPAT_CONFIG)
+
+modules: $(COMPAT_CONFIG) $(COMPAT_AUTOCONF)
$(MAKE) -C $(KLIB_BUILD) M=$(PWD) modules
+ @touch modules
+
install: modules
$(MAKE) -C $(KLIB_BUILD) M=$(PWD) $(KMODDIR_ARG) $(KMODPATH_ARG) \
modules_install
depmod -a
- @./scripts/compat_firmware_install
+ $(MAKE) -C $(KLIB_BUILD) M=$(PWD) clean
+
+$(COMPAT_AUTOCONF): ;
+
+$(COMPAT_CONFIG):
+ @$(PWD)/scripts/gen-compat-config.sh > $(PWD)/$(COMPAT_CONFIG)
+ @$(PWD)/scripts/gen-compat-autoconf.sh $(COMPAT_CONFIG) > $(PWD)/$(COMPAT_AUTOCONF)
+ @$(MAKE) -C $(PWD) modules
+
+install: modules
+
clean:
$(MAKE) -C $(KLIB_BUILD) M=$(PWD) clean
-all: modules

clean-files := Module.symvers modules.order Module.markers compat/modules.order
+clean-files += modules $(COMPAT_CONFIG) $(COMPAT_AUTOCONF)
+
+.PHONY: all install clean
diff --git a/include/linux/compat_autoconf.h b/include/linux/compat_autoconf.h
deleted file mode 100644
index 813755c..0000000
--- a/include/linux/compat_autoconf.h
+++ /dev/null
@@ -1,37 +0,0 @@
-#ifndef COMPAT_AUTOCONF_INCLUDED
-#define COMPAT_AUTOCONF_INCLUDED
-
-/*
- * This is an example of a compat autconf header file that gets
- * automatically generated by your projet. You will only need this
- * if you are working with a lot of config options.
- *
- * Your project will likely just override this, or leave this as-is.
- */
-
-/*
- * Example automatically generated C config: don't edit
- * Thu Dec 10 10:34:11 PST 2009
- * compat-wireless-2.6: master-2009-11-19-5-gb4fd4dd
- * linux-2.6: next-20091208
- */
-//#define COMPAT_PROJECT_FOO_RELEASE "master-2009-11-19-5-gb4fd4dd"
-//#define COMPAT_UPSTREAM_FOO_KERNEL_RELEASE "next-20091208"
-
-/* Example kernel version minimum requirement */
-//#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10))
-//#error Compat-wireless requirement: Linux >= 2,6,10
-//#endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10) */
-
-/* Example hard requirement */
-//#error Compat-wireless requirement: CONFIG_WIRELESS_EXT must be enabled in your kernel
-//#endif /* CONFIG_WIRELESS_EXT */
-
-/*
- * Example of how to match your external modules kconfig options into this.
- * You'll need something to generate this for you.
- */
-//#ifndef CONFIG_FOO_BAR
-//#define CONFIG_FOO_BAR 1
-
-#endif /* COMPAT_AUTOCONF_INCLUDED */
diff --git a/scripts/gen-compat-autoconf.sh b/scripts/gen-compat-autoconf.sh
new file mode 100755
index 0000000..e52cc5a
--- /dev/null
+++ b/scripts/gen-compat-autoconf.sh
@@ -0,0 +1,105 @@
+#!/bin/bash
+#
+# Copyright 2012 Luis R. Rodriguez <[email protected]>
+# Copyright 2011 Hauke Mehrtens <[email protected]>
+# Copyright 2011 John W. Linville <[email protected]>
+#
+# Use this to parse a small .config equivalent looking file to generate
+# our own autoconf.h. This file has defines for each config option
+# just like the kernels include/linux/autoconf.h
+#
+# XXX: consider using scripts/kconfig/confdata.c instead.
+# On the downside this would require the user to have libc though.
+
+# This indicates which is the oldest kernel we support
+# Update this if you are adding support for older kernels.
+OLDEST_KERNEL_SUPPORTED="2.6.24"
+
+if [ $# -ne 1 ]; then
+ echo "Usage $0 config-file"
+ exit
+fi
+
+COMPAT_CONFIG="$1"
+
+if [ ! -f $COMPAT_CONFIG ]; then
+ echo "File $1 is not a file"
+ exit
+fi
+
+# Defines a CONFIG_ option if not defined yet, this helps respect
+# linux/autoconf.h
+function define_config {
+ VAR=$1
+ VALUE=$2
+ case $VALUE in
+ n) # Try to undefine it
+ echo "#undef $VAR"
+ ;;
+ y)
+ echo "#ifndef $VAR"
+ echo "#define $VAR 1"
+ echo "#endif /* $VAR */"
+ ;;
+ m)
+ echo "#ifndef $VAR"
+ echo "#define $VAR 1"
+ echo "#endif /* $VAR */"
+ ;;
+ *) # Assume string
+ # XXX: add better checks to make sure what was on
+ # the right was indeed a string
+ echo "#ifndef $VAR"
+ echo "#define $VAR \"$VALUE\""
+ echo "#endif /* $VAR */"
+ ;;
+ esac
+}
+
+function kernel_version_req {
+ VERSION=$(echo $1 | sed -e 's/\./,/g')
+ echo "#if (LINUX_VERSION_CODE < KERNEL_VERSION($VERSION))"
+ echo "#error compat requirement: Linux >= $VERSION"
+ echo "#endif /* (LINUX_VERSION_CODE < KERNEL_VERSION($VERSION) */"
+}
+
+cat <<EOF
+#ifndef COMPAT_AUTOCONF_INCLUDED
+#define COMPAT_AUTOCONF_INCLUDED
+/*
+ * Automatically generated C config: don't edit
+ */
+EOF
+
+# Checks user is compiling against a kernel we support
+kernel_version_req $OLDEST_KERNEL_SUPPORTED
+
+# For each CONFIG_FOO=x option
+for i in $(egrep '^CONFIG_|^ifdef CONFIG_|^ifndef CONFIG_|^endif #CONFIG_|^else #CONFIG_' $COMPAT_CONFIG | sed 's/ /+/'); do
+ case $i in
+ 'ifdef+CONFIG_'* )
+ echo "#$i" | sed -e 's/+/ /' -e 's/\(ifdef CONFIG_COMPAT_KERNEL_3_\)\([0-9]*\)/if (LINUX_VERSION_CODE < KERNEL_VERSION(3,\2,0))/' -e 's/\(ifdef CONFIG_COMPAT_KERNEL_2_6_\)\([0-9]*\)/if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,\2))/' -e 's/\(ifdef CONFIG_COMPAT_RHEL_\)\([0-9]*\)_\([0-9]*\)/if (defined(RHEL_MAJOR) \&\& RHEL_MAJOR == \2 \&\& RHEL_MINOR >= \3)/' -e 's/\(#ifdef \)\(CONFIG_[^:space:]*\)/#if defined(\2) || defined(\2_MODULE)/'
+ continue
+ ;;
+ 'ifndef+CONFIG_'* )
+ echo "#$i" | sed -e 's/+/ /' -e 's/\(ifndef CONFIG_COMPAT_KERNEL_3_\)\([0-9]*\)/if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,\2,0))/' -e 's/\(ifndef CONFIG_COMPAT_KERNEL_2_6_\)\([0-9]*\)/if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,\2))/' -e 's/\(ifndef CONFIG_COMPAT_RHEL_\)\([0-9]*\)_\([0-9]*\)/if (!defined(RHEL_MAJOR) || RHEL_MAJOR != \2 || RHEL_MINOR < \3)/' -e 's/\(#ifndef \)\(CONFIG_[^:space:]*\)/#if !defined(\2) \&\& !defined(\2_MODULE)/'
+ continue
+ ;;
+ 'else+#CONFIG_'* | 'endif+#CONFIG_'* )
+ echo "#$i */" |sed -e 's/+#/ \/* /g'
+ continue
+ ;;
+ CONFIG_* )
+ # Get the element on the left of the "="
+ VAR=$(echo $i | cut -d"=" -f 1)
+ # Get the element on the right of the "="
+ VALUE=$(echo $i | cut -d"=" -f 2)
+
+ # Any other module which can *definitely* be built as a module goes here
+ define_config $VAR $VALUE
+ continue
+ ;;
+ esac
+done
+
+echo "#endif /* COMPAT_AUTOCONF_INCLUDED */"
diff --git a/scripts/gen-compat-config.sh b/scripts/gen-compat-config.sh
new file mode 100755
index 0000000..82b439c
--- /dev/null
+++ b/scripts/gen-compat-config.sh
@@ -0,0 +1,50 @@
+#!/bin/bash
+# Copyright 2012 Luis R. Rodriguez <[email protected]>
+# Copyright 2012 Hauke Mehrtens <[email protected]>
+#
+# This generates a bunch of CONFIG_COMPAT_KERNEL_2_6_22
+# CONFIG_COMPAT_KERNEL_3_0 .. etc for each kernel release you need an object
+# for.
+#
+# Note: this is part of the compat.git project, not compat-wireless.git,
+# send patches against compat.git.
+
+if [[ ! -f ${KLIB_BUILD}/Makefile ]]; then
+ exit
+fi
+
+# Actual kernel version
+KERNEL_VERSION=$(${MAKE} -C ${KLIB_BUILD} kernelversion | sed -n 's/^\([0-9]\)\..*/\1/p')
+
+# 3.0 kernel stuff
+COMPAT_LATEST_VERSION="3"
+KERNEL_SUBLEVEL="-1"
+
+# This allows all these variables to be propagated through
+# all of our Makefiles
+echo export
+
+if [[ ${KERNEL_VERSION} -eq "3" ]]; then
+ KERNEL_SUBLEVEL=$(${MAKE} -C ${KLIB_BUILD} kernelversion | sed -n 's/^3\.\([0-9]\+\).*/\1/p')
+else
+ COMPAT_26LATEST_VERSION="39"
+ KERNEL_26SUBLEVEL=$(${MAKE} -C ${KLIB_BUILD} kernelversion | sed -n 's/^2\.6\.\([0-9]\+\).*/\1/p')
+ let KERNEL_26SUBLEVEL=${KERNEL_26SUBLEVEL}+1
+
+ for i in $(seq ${KERNEL_26SUBLEVEL} ${COMPAT_26LATEST_VERSION}); do
+ echo "CONFIG_COMPAT_KERNEL_2_6_${i}=y"
+ done
+fi
+
+let KERNEL_SUBLEVEL=${KERNEL_SUBLEVEL}+1
+for i in $(seq ${KERNEL_SUBLEVEL} ${COMPAT_LATEST_VERSION}); do
+ echo "CONFIG_COMPAT_KERNEL_3_${i}=y"
+done
+
+if [[ ${CONFIG_COMPAT_KERNEL_2_6_33} -eq "y" ]]; then
+ echo "CONFIG_COMPAT_FIRMWARE_CLASS=m"
+fi
+
+if [[ ${CONFIG_COMPAT_KERNEL_2_6_36} -eq "y" ]]; then
+ echo "CONFIG_COMPAT_KFIFO=m"
+fi
--
1.7.4.15.g7811d