Use decimal notation in a debug message
[madwifi/.git] / patch-kernel / install.sh
1 #! /bin/sh
2 #
3 # Shell script to integrate madwifi sources into a Linux
4 # source tree so it can be built statically.  Typically this
5 # is done to simplify debugging with tools like kgdb.
6 #
7
8 set -e
9
10 die()
11 {
12         echo "FATAL ERROR: $1" >&2
13         exit 1
14 }
15
16 SRC=..
17 KERNEL_VERSION=$(uname -r)
18
19 if test -n "$1"; then
20         KERNEL_PATH="$1"
21 else if test -e /lib/modules/${KERNEL_VERSION}/source; then
22         KERNEL_PATH="/lib/modules/${KERNEL_VERSION}/source"
23 else if test -e /lib/modules/${KERNEL_VERSION}/build; then
24         KERNEL_PATH="/lib/modules/${KERNEL_VERSION}/build"
25 else
26         die "Cannot guess kernel source location"
27 fi
28 fi
29 fi
30
31 test -d ${KERNEL_PATH} || die "No kernel directory ${KERNEL_PATH}"
32
33 PATCH()
34 {
35         patch -N $1 < $2
36 }
37
38 #
39 # Location of various pieces.  These mimic what is in Makefile.inc
40 # and can be overridden from the environment.
41 #
42 SRC_HAL=${HAL:-${SRC}/ath_hal}
43 test -d ${SRC_HAL} || die "No ath_hal directory ${SRC_HAL}"
44 SRC_NET80211=${WLAN:-${SRC}/net80211}
45 test -d ${SRC_NET80211} || die "No net80211 directory ${SRC_NET80211}"
46 SRC_ATH=${ATH:-${SRC}/ath}
47 test -d ${SRC_ATH} || die "No ath directory ${SRC_ATH}"
48 SRC_ATH_RATE=${SRC}/ath_rate
49 test -d ${SRC_ATH_RATE} ||
50         die "No rate control algorithm directory ${SRC_ATH_RATE}"
51 SRC_COMPAT=${SRC}/include
52 test -d ${SRC_COMPAT} || die "No compat directory ${SRC_COMPAT}"
53
54 WIRELESS=${KERNEL_PATH}/drivers/net/wireless
55 test -d ${WIRELESS} || die "No wireless directory ${WIRELESS}"
56
57 if test -f ${WIRELESS}/Kconfig; then
58         kbuild=2.6
59         kbuildconf=Kconfig
60 else if test -f ${WIRELESS}/Config.in; then
61         kbuild=2.4
62         kbuildconf=Config.in
63 else
64         die "Kernel build system is not supported"
65 fi
66 fi
67
68 echo "Copying top-level files"
69 MADWIFI=${WIRELESS}/madwifi
70 rm -rf ${MADWIFI}
71 mkdir -p ${MADWIFI}
72 make -s -C ${SRC} svnversion.h
73 cp -f ${SRC}/BuildCaps.inc ${SRC}/svnversion.h ${SRC}/release.h ${MADWIFI}
74
75
76 echo "Copying source files"
77 FILES=$(cd ${SRC} && find ath ath_hal ath_rate include net80211 -name '*.[ch]')
78 FILES="$FILES $(cd ${SRC} && find ath_hal -name '*.ini')"
79 for f in $FILES; do
80         case $f in
81                 *.mod.c) continue;;
82         esac
83         mkdir -p $(dirname ${MADWIFI}/$f)
84         cp -f ${SRC}/$f ${MADWIFI}/$f
85 done
86
87 echo "Copying makefiles"
88 FILES=$(cd ${SRC} && find . -name Makefile.kernel)
89 for f in $FILES; do
90         cp -f ${SRC}/$f $(dirname ${MADWIFI}/$f)/Makefile
91 done
92
93
94 echo "Patching the build system"
95 if test "$kbuild" = 2.6; then
96 cp -f Kconfig ${MADWIFI}
97 sed -i '/madwifi/d;/^endmenu/i\
98 source "drivers/net/wireless/madwifi/Kconfig"' ${WIRELESS}/Kconfig
99 sed -i '$a\
100 obj-$(CONFIG_ATHEROS) += madwifi/
101 /madwifi/d;' ${WIRELESS}/Makefile
102 else
103 cp -f Config.in ${MADWIFI}
104 sed -i '$a\
105 source drivers/net/wireless/madwifi/Config.in
106 /madwifi/d' ${WIRELESS}/Config.in
107 sed -i '/madwifi/d;/include/i\
108 subdir-$(CONFIG_ATHEROS) += madwifi\
109 obj-$(CONFIG_ATHEROS) += madwifi/madwifi.o' ${WIRELESS}/Makefile
110 DST_DOC=${KERNEL_PATH}/Documentation
111 grep -q 'CONFIG_ATHEROS' ${DST_DOC}/Configure.help || \
112         PATCH ${DST_DOC}/Configure.help Configure.help.patch
113 fi
114
115
116 echo "Done"