updated on Wed Jan 18 08:00:29 UTC 2012
[aur-mirror.git] / catalyst-hook / catalyst_build_module
blob6bd777432f22eec94aeaba45b3a580a5378de8ed
1 #!/bin/bash
3 kernver=${KERNVER:-$(uname -r)}
4 arch=${ARCH:-$(uname -m)}
5 arch=${arch/i686/i386}
6 LOG="/var/log/catalyst-install.log"
8 #patch_files(){
9 # file_patch="${kernver:0:6}.patch"
10 # if [[ -f "${file_patch}" ]]; then
11 # patch -Np6 -i ${file_patch} || return 1
12 # fi
16 install_module(){
17 echo ""
18 echo "--------"
19 date '+%Y-%m-%d %H:%M:%S'
20 echo "Building fglrx module for ${kernver} kernel ..."
21 echo "--------"
22 if [ ! -d "/lib/modules/${kernver}/build" ]; then
23 echo "Kernel header files are absent: directory /lib/modules/${kernver}/build doesn't exist! Game over"
24 return 1
26 workdir=$(mktemp -du /tmp/catalyst.XXXXXX)
27 # set -x
28 cp "/usr/share/ati/build_mod" "${workdir}" -R
29 cd "$workdir"
30 patch -Np7 -i makefile_compat.patch || return 1
32 # if [[ ${kernver:0:6} < "2.6.39" ]] && [[ `cat /lib/modules/${kernver}/build/.config | grep -c CONFIG_BKL=y` = 0 ]]; then
33 # patch -Np6 -i no_bkl.patch || return 1
34 # fi
36 # if [[ ${kernver:0:6} == "2.6.39" ]] || [[ ${kernver:0:6} > "2.6.39" ]]; then
37 # patch -Np6 -i no_bkl.patch || return 1
38 # patch -Np6 -i 2.6.39_bkl.patch || return 1
39 # fi
41 # patch_files
43 ## include ati_make.sh and use _ati_check function from it
44 . ati_make.sh
45 _ati_check
47 ## Compile module using _ati_check variables
48 make -C /lib/modules/${kernver}/build SUBDIRS="`pwd`" ARCH=${arch} \
49 MODFLAGS="-DMODULE -DATI -DFGL -DPAGE_ATTR_FIX=$PAGE_ATTR_FIX -DCOMPAT_ALLOC_USER_SPACE=$COMPAT_ALLOC_USER_SPACE $def_smp $def_modversions" \
50 PAGE_ATTR_FIX=$PAGE_ATTR_FIX COMPAT_ALLOC_USER_SPACE=$COMPAT_ALLOC_USER_SPACE modules || return 1
53 ## here we are checking kernel's extramodules dir
54 for r in /lib/modules/*; do
55 s=${r:13}
56 if [[ ${s:0:3} = "ext" ]]; then
57 if [[ `cat ${r}/version | grep -c ${kernver}` != 0 ]]; then
58 destidir=${s}
60 elif [[ ${s} = ${kernver} ]] && [[ ! -e ${r}/extramodules ]]; then
61 destidir=${kernver}/video
63 done
65 install -m755 -d "/lib/modules/${destidir}/" || return 1
66 install -m644 fglrx.ko "/lib/modules/${destidir}/" || return 1
68 depmod ${kernver}
69 rm -rf "${workdir}"
70 # set +x
71 echo "Ok."
74 build_all_modules(){
75 for p in /lib/modules/*; do
76 if [ ${p:13:3} != "ext" ] && [ -d $p/build ] && [ -d $p/kernel ]; then
77 /usr/bin/catalyst_build_module ${p##*/lib/modules/}
79 done
82 remove_module(){
83 for p in /lib/modules/*; do
84 if [[ ${p:13:3} != "ext" ]]; then
85 if [ ! -d $p/kernel ]; then #check if /lib/modules/p/kernel directory does NOT exist
86 if [[ -e $p/video/fglrx.ko ]] || [[ -e $p/extramodules/fglrx.ko ]]; then
87 echo "+ removing fglrx module from $p"
88 rm "$p/video/fglrx.ko" &>/dev/null
89 rm "$p/extramodules/fglrx.ko" &>/dev/null
90 rmdir -p "$p/video/" --ignore-fail-on-non-empty &>/dev/null
92 if [ -d $p ]; then #check if /lib/modules/p exist
93 if [ -z "$(ls $p)" ]; then #check if /lib/modules/p is empty
94 echo "+ removing empty directory: $p"
95 rm -rf $p
96 else echo "- $p looks like unused, maybe remove it manualy?"
101 done
104 remove_all_modules(){
105 for p in /lib/modules/*; do
106 if [[ ${p:13:3} != "ext" ]]; then
107 if [[ -e $p/video/fglrx.ko ]] || [[ -e $p/extramodules/fglrx.ko ]]; then
108 echo "+ removing fglrx module from $p"
109 rm "$p/video/fglrx.ko" &>/dev/null
110 rm "$p/extramodules/fglrx.ko" &>/dev/null
111 rmdir -p "$p/video/" --ignore-fail-on-non-empty &>/dev/null
112 depmod $(basename $p)
114 if [ -d $p ]; then #check if /lib/modules/p exist
115 if [ -z "$(ls $p)" ]; then #check if /lib/modules/p is empty
116 echo "+ removing empty directory: $p"
117 rm -rf $p
118 elif [ ! -d $p/kernel ]; then
119 echo "- $p looks like unused, maybe remove it manualy?"
123 done
126 auto_recompile(){
127 # add hook fglrx to mkiniticpio
128 hooks=$(grep ^HOOKS /etc/mkinitcpio.conf | grep fglrx)
129 if [ "$hooks" = "" ]; then
130 # add hook fglrx
131 sed 's/^HOOKS="\([^"]*\)"/HOOKS="\1 fglrx"/' -i /etc/mkinitcpio.conf
133 #add kernel26-headers to SyncFirst array of pacman.conf
134 heads=$(grep ^SyncFirst /etc/pacman.conf | grep kernel26-headers)
135 if [ "$heads" = "" ]; then
136 # add heads
137 sed '/^SyncFirst/s|$| kernel26-headers|' -i /etc/pacman.conf
139 echo "----------------------------------------------------------------"
140 echo "Answer 'Yes' whenever pacman ask you about updating"
141 echo "'kernel26-headers' in first place"
142 echo "----------------------------------------------------------------"
145 auto_recompile_off(){
146 # remove hook fglrx
147 sed '/^HOOKS/s/ *fglrx//' -i /etc/mkinitcpio.conf
148 # remove heads
149 sed '/^SyncFirst/s/ *kernel26-headers//' -i /etc/pacman.conf
150 echo "Auto re-compilation is Disabled."
153 case "$1" in
154 help|--help)
155 echo "usage: $0 {version|all|remove|remove_all|auto|autooff}"
156 echo "- with no specified kernel version it will use the current kernel version to build module"
157 echo "- all will try to build fglrx modules for all working system's kernels"
158 echo "- remove is removing unused fglrx modules and all empty /lib/modules/* directories"
159 echo "- remove_all is removing all fglrx modules and all empty /lib/modules/* directories"
160 echo "- auto will turn ON 'auto re-compilation of fglrx module with every kernel update'"
161 echo "- autooff will turn off auto re-compilation of fglrx module"
163 remove)
164 remove_module
166 remove_all)
167 remove_all_modules
169 auto)
170 auto_recompile
172 autooff)
173 auto_recompile_off
175 all)
176 build_all_modules
179 test "$1" != "" && kernver="$1"
180 echo "Building fglrx module for ${kernver} kernel ..."
181 install_module >> $LOG 2>&1 && echo "Ok." || echo "Failed!!! Check out log: $LOG"
183 esac