3 # Copyright 2007 Luis R. Rodriguez <mcgrof@winlab.rutgers.edu>
5 # Use this to parse a small .config equivalent looking file to generate
6 # our own autoconf.h. This file has defines for each config option
7 # just like the kernels include/linux/autoconf.h
9 # XXX: consider using scripts/kconfig/confdata.c instead.
10 # On the downside this would require the user to have libc though.
12 # This indicates which is the oldest kernel we support
13 # Update this if you are adding support for older kernels.
14 OLDEST_KERNEL_SUPPORTED="2.6.25"
15 COMPAT_RELEASE="compat-release"
16 KERNEL_RELEASE="git-describe"
17 MULT_DEP_FILE=".compat_pivot_dep"
20 echo "Usage $0 config-file"
26 if [ ! -f $COMPAT_CONFIG ]; then
27 echo "File $1 is not a file"
31 if [ ! -f $COMPAT_RELEASE -o ! -f $KERNEL_RELEASE ]; then
32 echo "Error: $COMPAT_RELEASE or $KERNEL_RELEASE file is missing"
36 CREL=$(cat $COMPAT_RELEASE | tail -1)
37 KREL=$(cat $KERNEL_RELEASE | tail -1)
40 # Defines a CONFIG_ option if not defined yet, this helps respect
42 function define_config {
46 n) # Try to undefine it
52 echo "#endif /* $VAR */ "
57 echo "#endif /* $VAR */ "
60 # XXX: add better checks to make sure what was on
61 # the right was indeed a string
63 echo "#define $VAR \"$VALUE\""
64 echo "#endif /* $VAR */ "
69 # This deals with core compat-wireless kernel requirements.
70 function define_config_req {
73 echo -n "#error Compat-wireless requirement: $VAR must be enabled "
75 echo "#endif /* $VAR */"
78 # This handles modules which have dependencies from the kernel
79 # which compat-wireless isn't providing yet either because
80 # the dependency is not available as kernel module or
81 # the module simply isn't provided by compat-wireless.
82 function define_config_dep {
86 WARN_VAR="COMPAT_WARN_$VAR"
88 define_config $VAR $VALUE
90 # XXX: figure out a way to warn only once
91 # define only once in case user tried to enable config option
93 echo "#ifndef $WARN_VAR"
94 # Lets skip these for now.. they might be too annoying
95 #echo "#warning Skipping $VAR as $DEP was needed... "
96 #echo "#warning This just means $VAR won't be built and is not fatal."
97 echo "#define $WARN_VAR"
98 echo "#endif /* $VAR */"
99 echo "#endif /* $WARN_VAR */"
102 # This handles options which have *multiple* dependencies from the kernel
103 function define_config_multiple_deps {
108 # First, put all ifdefs
109 for i in $(cat $MULT_DEP_FILE); do
113 # Now put our option in the middle
114 define_config $VAR $VALUE
116 # Now close all ifdefs
117 # First, put all ifdefs
118 for i in $(cat $MULT_DEP_FILE); do
124 function kernel_version_req {
125 VERSION=$(echo $1 | sed -e 's/\./,/g')
126 echo "#if (LINUX_VERSION_CODE < KERNEL_VERSION($VERSION))"
127 echo "#error Compat-wireless requirement: Linux >= $VERSION"
128 echo "#endif /* (LINUX_VERSION_CODE < KERNEL_VERSION($VERSION) */ "
132 #ifndef COMPAT_AUTOCONF_INCLUDED
133 #define COMPAT_AUTOCONF_INCLUDED
135 * Automatically generated C config: don't edit
137 * compat-wireless-2.6: $CREL
140 #define COMPAT_RELEASE "$CREL"
141 #define COMPAT_KERNEL_RELEASE "$KREL"
144 # Checks user is compiling against a kernel we support
145 kernel_version_req $OLDEST_KERNEL_SUPPORTED
147 # Handle core kernel wireless depenencies here
148 define_config_req CONFIG_WIRELESS_EXT
150 # For each CONFIG_FOO=x option
151 for i in $(grep '^CONFIG_' $COMPAT_CONFIG); do
152 # Get the element on the left of the "="
153 VAR=$(echo $i | cut -d"=" -f 1)
154 # Get the element on the right of the "="
155 VALUE=$(echo $i | cut -d"=" -f 2)
157 # skip vars that weren't actually set due to dependencies
158 #if [ "${!VAR}" = "" ] ; then
162 # Handle core kernel module depenencies here.
164 CONFIG_USB_NET_RNDIS_WLAN)
165 define_config_dep $VAR $VALUE CONFIG_USB_NET_CDCETHER
168 CONFIG_USB_NET_RNDIS_HOST)
169 define_config_dep $VAR $VALUE CONFIG_USB_NET_CDCETHER
172 # ignore this, we have a special hanlder for this at the botttom
173 # instead. We still need to keep this in config.mk to let Makefiles
174 # know its enabled so just ignore it here.
179 # Any other module which can *definitely* be built as a module goes here
180 define_config $VAR $VALUE
183 # Deal with special cases. CONFIG_MAC80211_QOS is such a case.
184 # We handle this specially for different kernels we support.
185 if [ -f $KLIB_BUILD/Makefile ]; then
186 SUBLEVEL=$(make -C $KLIB_BUILD kernelversion | sed -n 's/^2\.6\.\([0-9]\+\).*/\1/p')
187 if [ $SUBLEVEL -le 22 ]; then
188 define_config CONFIG_MAC80211_QOS y
189 else # kernel >= 2.6.23
190 # CONFIG_MAC80211_QOS on these kernels requires
191 # CONFIG_NET_SCHED and CONFIG_NETDEVICES_MULTIQUEUE
193 echo CONFIG_NET_SCHED >> $MULT_DEP_FILE
194 echo CONFIG_NETDEVICES_MULTIQUEUE >> $MULT_DEP_FILE
195 define_config_multiple_deps CONFIG_MAC80211_QOS y $ALL_DEPS
199 echo "#endif /* COMPAT_AUTOCONF_INCLUDED */"