wl1251: update hw/fw version info in wiphy struct
[pandora-wifi.git] / scripts / gen-compat-autoconf.sh
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.
11
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"
18
19 if [ $# -ne 1 ]; then
20         echo "Usage $0 config-file"
21         exit
22 fi
23
24 COMPAT_CONFIG="$1"
25
26 if [ ! -f $COMPAT_CONFIG ]; then
27         echo "File $1 is not a file"
28         exit
29 fi
30
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
35
36 CREL=$(cat $COMPAT_RELEASE | tail -1)
37 KREL=$(cat $KERNEL_RELEASE | tail -1)
38 DATE=$(date)
39
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 }
68
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 }
77
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 }
101
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
107
108         # First, put all ifdefs
109         for i in $(cat $MULT_DEP_FILE); do
110                 echo "#ifdef $i"
111         done
112
113         # Now put our option in the middle
114         define_config $VAR $VALUE
115
116         # Now close all ifdefs
117         # First, put all ifdefs
118         for i in $(cat $MULT_DEP_FILE); do
119                 echo "#endif"
120         done
121
122 }
123
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 }
130
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
143
144 # Checks user is compiling against a kernel we support
145 kernel_version_req $OLDEST_KERNEL_SUPPORTED
146
147 # Handle core kernel wireless depenencies here
148 define_config_req CONFIG_WIRELESS_EXT
149
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)
156
157         # skip vars that weren't actually set due to dependencies
158         #if [ "${!VAR}" = "" ] ; then
159         #       continue
160         #fi
161
162         # Handle core kernel module depenencies here.
163         case $VAR in
164         CONFIG_USB_NET_RNDIS_WLAN)
165                 define_config_dep $VAR $VALUE CONFIG_USB_NET_CDCETHER
166                 continue
167                 ;;
168         CONFIG_USB_NET_RNDIS_HOST)
169                 define_config_dep $VAR $VALUE CONFIG_USB_NET_CDCETHER
170                 continue
171                 ;;
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.
175         CONFIG_MAC80211_QOS)
176                 continue
177                 ;;
178         esac
179         # Any other module which can *definitely* be built as a module goes here
180         define_config $VAR $VALUE
181 done
182
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
192                 rm -f $MULT_DEP_FILE
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
196                 rm -f $MULT_DEP_FILE
197         fi
198 fi
199 echo "#endif /* COMPAT_AUTOCONF_INCLUDED */"