1 #!/bin/bash
2 #
3 # Copyright 2007 Luis R. Rodriguez <mcgrof@winlab.rutgers.edu>
4 #
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
8 #
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.23"
15 COMPAT_RELEASE="compat_version"
16 KERNEL_RELEASE="compat_base_tree_version"
17 MULT_DEP_FILE=".compat_pivot_dep"
19 if [ $# -ne 1 ]; then
20 echo "Usage $0 config-file"
21 exit
22 fi
24 COMPAT_CONFIG="$1"
26 if [ ! -f $COMPAT_CONFIG ]; then
27 echo "File $1 is not a file"
28 exit
29 fi
31 if [ ! -f $COMPAT_RELEASE -o ! -f $KERNEL_RELEASE ]; then
32 echo "Error: $COMPAT_RELEASE or $KERNEL_RELEASE file is missing"
33 exit
34 fi
36 CREL=$(cat $COMPAT_RELEASE | tail -1)
37 KREL=$(cat $KERNEL_RELEASE | tail -1)
38 DATE=$(date)
40 # Defines a CONFIG_ option if not defined yet, this helps respect
41 # linux/autoconf.h
42 function define_config {
43 VAR=$1
44 VALUE=$2
45 case $VALUE in
46 n) # Try to undefine it
47 echo "#undef $VAR"
48 ;;
49 y)
50 echo "#ifndef $VAR"
51 echo "#define $VAR 1"
52 echo "#endif /* $VAR */ "
53 ;;
54 m)
55 echo "#ifndef $VAR"
56 echo "#define $VAR 1"
57 echo "#endif /* $VAR */ "
58 ;;
59 *) # Assume string
60 # XXX: add better checks to make sure what was on
61 # the right was indeed a string
62 echo "#ifndef $VAR"
63 echo "#define $VAR \"$VALUE\""
64 echo "#endif /* $VAR */ "
65 ;;
66 esac
67 }
69 # This deals with core compat-wireless kernel requirements.
70 function define_config_req {
71 VAR=$1
72 echo "#ifndef $VAR"
73 echo -n "#error Compat-wireless requirement: $VAR must be enabled "
74 echo "in your kernel"
75 echo "#endif /* $VAR */"
76 }
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 {
83 VAR=$1
84 VALUE=$2
85 DEP=$3
86 WARN_VAR="COMPAT_WARN_$VAR"
87 echo "#ifdef $DEP"
88 define_config $VAR $VALUE
89 echo "#else"
90 # XXX: figure out a way to warn only once
91 # define only once in case user tried to enable config option
92 # twice in config.mk
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 */"
100 }
102 # This handles options which have *multiple* dependencies from the kernel
103 function define_config_multiple_deps {
104 VAR=$1
105 VALUE=$2
106 DEP_ARRAY=$3
108 # First, put all ifdefs
109 for i in $(cat $MULT_DEP_FILE); do
110 echo "#ifdef $i"
111 done
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
119 echo "#endif"
120 done
122 }
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) */ "
129 }
131 cat <<EOF
132 #ifndef COMPAT_AUTOCONF_INCLUDED
133 #define COMPAT_AUTOCONF_INCLUDED
134 /*
135 * Automatically generated C config: don't edit
136 * $DATE
137 * compat-wireless-2.6: $CREL
138 * linux-2.6: $KREL
139 */
140 #define COMPAT_RELEASE "$CREL"
141 #define COMPAT_KERNEL_RELEASE "$KREL"
142 EOF
144 # Checks user is compiling against a kernel we support
145 kernel_version_req $OLDEST_KERNEL_SUPPORTED
147 # For each CONFIG_FOO=x option
148 for i in $(grep '^CONFIG_' $COMPAT_CONFIG); do
149 # Get the element on the left of the "="
150 VAR=$(echo $i | cut -d"=" -f 1)
151 # Get the element on the right of the "="
152 VALUE=$(echo $i | cut -d"=" -f 2)
154 # skip vars that weren't actually set due to dependencies
155 #if [ "${!VAR}" = "" ] ; then
156 # continue
157 #fi
159 # Handle core kernel module depenencies here.
160 case $VAR in
161 CONFIG_USB_NET_RNDIS_WLAN)
162 define_config_dep $VAR $VALUE CONFIG_USB_NET_CDCETHER
163 continue
164 ;;
165 CONFIG_USB_NET_RNDIS_HOST)
166 define_config_dep $VAR $VALUE CONFIG_USB_NET_CDCETHER
167 continue
168 ;;
169 # ignore this, we have a special hanlder for this at the botttom
170 # instead. We still need to keep this in config.mk to let Makefiles
171 # know its enabled so just ignore it here.
172 CONFIG_MAC80211_QOS)
173 continue
174 ;;
175 esac
176 # Any other module which can *definitely* be built as a module goes here
177 define_config $VAR $VALUE
178 done
180 # Deal with special cases. CONFIG_MAC80211_QOS is such a case.
181 # We handle this specially for different kernels we support.
182 if [ -f $KLIB_BUILD/Makefile ]; then
183 SUBLEVEL=$(make -C $KLIB_BUILD kernelversion | sed -n 's/^2\.6\.\([0-9]\+\).*/\1/p')
184 if [ $SUBLEVEL -le 22 ]; then
185 define_config CONFIG_MAC80211_QOS y
186 else # kernel >= 2.6.23
187 # CONFIG_MAC80211_QOS on these kernels requires
188 # CONFIG_NET_SCHED and CONFIG_NETDEVICES_MULTIQUEUE
189 rm -f $MULT_DEP_FILE
190 echo CONFIG_NET_SCHED >> $MULT_DEP_FILE
191 echo CONFIG_NETDEVICES_MULTIQUEUE >> $MULT_DEP_FILE
192 define_config_multiple_deps CONFIG_MAC80211_QOS y $ALL_DEPS
193 rm -f $MULT_DEP_FILE
194 # Kernels >= 2.6.32 can disable WEXT :D
195 if [ $SUBLEVEL -le 32 ]; then
196 define_config_dep CONFIG_CFG80211_WEXT 1 CONFIG_WIRELESS_EXT
197 fi
198 fi
199 fi
200 echo "#endif /* COMPAT_AUTOCONF_INCLUDED */"