3 # Copyright 2012 Luis R. Rodriguez <mcgrof@frijolero.org>
4 # Copyright 2011 Hauke Mehrtens <hauke@hauke-m.de>
5 # Copyright 2011 John W. Linville <linville@tuxdriver.com>
7 # Use this to parse a small .config equivalent looking file to generate
8 # our own autoconf.h. This file has defines for each config option
9 # just like the kernels include/linux/autoconf.h
11 # XXX: consider using scripts/kconfig/confdata.c instead.
12 # On the downside this would require the user to have libc though.
14 # This indicates which is the oldest kernel we support
15 # Update this if you are adding support for older kernels.
16 OLDEST_KERNEL_SUPPORTED="2.6.24"
19 echo "Usage $0 config-file"
25 if [ ! -f $COMPAT_CONFIG ]; then
26 echo "File $1 is not a file"
30 # Defines a CONFIG_ option if not defined yet, this helps respect
32 function define_config {
36 n) # Try to undefine it
42 echo "#endif /* $VAR */"
47 echo "#endif /* $VAR */"
50 # XXX: add better checks to make sure what was on
51 # the right was indeed a string
53 echo "#define $VAR \"$VALUE\""
54 echo "#endif /* $VAR */"
59 function kernel_version_req {
60 VERSION=$(echo $1 | sed -e 's/\./,/g')
61 echo "#if (LINUX_VERSION_CODE < KERNEL_VERSION($VERSION))"
62 echo "#error compat requirement: Linux >= $VERSION"
63 echo "#endif /* (LINUX_VERSION_CODE < KERNEL_VERSION($VERSION) */"
67 #ifndef COMPAT_AUTOCONF_INCLUDED
68 #define COMPAT_AUTOCONF_INCLUDED
70 * Automatically generated C config: don't edit
74 # Checks user is compiling against a kernel we support
75 kernel_version_req $OLDEST_KERNEL_SUPPORTED
77 # For each CONFIG_FOO=x option
78 for i in $(egrep '^CONFIG_|^ifdef CONFIG_|^ifndef CONFIG_|^endif #CONFIG_|^else #CONFIG_' $COMPAT_CONFIG | sed 's/ /+/'); do
81 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)/'
85 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)/'
88 'else+#CONFIG_'* | 'endif+#CONFIG_'* )
89 echo "#$i */" |sed -e 's/+#/ \/* /g'
93 # Get the element on the left of the "="
94 VAR=$(echo $i | cut -d"=" -f 1)
95 # Get the element on the right of the "="
96 VALUE=$(echo $i | cut -d"=" -f 2)
98 # Any other module which can *definitely* be built as a module goes here
99 define_config $VAR $VALUE
105 echo "#endif /* COMPAT_AUTOCONF_INCLUDED */"