3 # Copyright 1999-2005 ATI Technologies Inc., Markham, Ontario, CANADA.
6 # Your use and or redistribution of this software in source and \ or
7 # binary form, with or without modification, is subject to: (i) your
8 # ongoing acceptance of and compliance with the terms and conditions of
9 # the ATI Technologies Inc. software End User License Agreement; and (ii)
10 # your inclusion of this notice in any version of this software that you
11 # use or redistribute. A copy of the ATI Technologies Inc. software End
12 # User License Agreement is included with this software and is also
13 # available by contacting ATI Technologies Inc. at http://www.ati.com
15 # ==============================================================
16 # External environment variables
19 # Set this variable to backup kernel module before stripping
20 # The nonstripped version will be names like fglrx_dbg.ko
22 # ==============================================================
23 # local variables and files
26 logfile
=$current_wd/make.sh.log
# DKMS uses name 'make.log', so that we need another name
31 # ==============================================================
32 # sets the GCC to use to the one required by the module (if available)
35 #identify GCC default version major number
36 GCC_MAJOR
="`gcc --version | grep -o -e ") .
" | head -1 | cut -d " " -f 2`"
38 #identify the GCC major version that compiled the kernel
39 KERNEL_GCC_MAJOR
="`cat /proc/version | grep -o -e "gcc version .
" | cut -d " " -f 3`"
41 #see if they don't match
42 if [ ${GCC_MAJOR} != ${KERNEL_GCC_MAJOR} ]; then
43 #use kernel GCC version hopefully
44 KERNEL_GCC
="`cat /proc/version | grep -o -e "gcc version
[0-9]\.
[0-9]" | cut -d " " -f 3`"
45 CC
="gcc-${KERNEL_GCC}"
47 # check if gcc version requested exists
48 GCC_AVAILABLE
="`${CC} --version | grep -e ")" | head -1 | cut -d " " -f 4 | cut -c-3`"
50 if [ ${GCC_AVAILABLE} != ${KERNEL_GCC} ]; then
51 echo "The GCC version that is required to compile this module is version ${KERNEL_GCC}."
52 echo "Please install this GCC or recompile your kernel with ${GCC_AVAILABLE}"
58 if [ -z "${CC}" ]; then
63 # ==============================================================
64 # system/kernel identification
72 # ==============================================================
75 while [ $# -gt 0 ]; do
86 if echo $1 |
grep '=' >/dev
/null
; then
87 uname_r
=`echo $1 | sed 's/^.*=//'`
95 if echo $1 |
grep '=' >/dev
/null
; then
96 uname_v
=`echo $1 | sed 's/^.*=//'`
104 if echo $1 |
grep '=' >/dev
/null
; then
105 uname_s
=`echo $1 | sed 's/^.*=//'`
113 if echo $1 |
grep '=' >/dev
/null
; then
114 uname_m
=`echo $1 | sed 's/^.*=//'`
122 if echo $1 |
grep '=' >/dev
/null
; then
123 uname_a
=`echo $1 | sed 's/^.*=//'`
133 # ==============================================================
134 # check if we are running as root with typical login shell paths
136 if [ $rootcheck -ne 0 -a `id -u` -ne 0 ]; then
137 echo "You must be logged in as root to run this script."
141 which depmod
>/dev
/null
2>&1
143 if [ $?
-ne 0 ]; then
144 PATH
=/usr
/local
/sbin
:/usr
/sbin
:/sbin
:${PATH}
145 which depmod
>/dev
/null
2>&1
147 if [ $?
-ne 0 ]; then
148 echo "You arent running in a 'login shell'."
149 echo "Please login directly from a console"
150 echo "or use 'su -l' to get the same result."
155 # ==============================================================
156 # assing default location of linux kernel headers
158 linuxbuild
=/usr
/src
/linux
159 linuxsources
=$linuxbuild
161 # in /lib/modules/<kernel-version> there is a symlink for latest kernel
162 # which calls "build" and points to the directory where modules were built.
163 # On some distros some configuration-independent kernel headers can't be
164 # found in "build" but in a different directory pointed to by a symlink
166 if [ -d /lib
/modules
/${uname_r}/build
/include
]; then
167 # just comment this line out if you already set an alternative location
168 linuxbuild
=/lib
/modules
/${uname_r}/build
169 linuxsources
=/lib
/modules
/${uname_r}/source
172 linuxincludes
=$linuxbuild/include
174 # ==============================================================
175 # print some statistics, helpful for analyzing any build failures
177 echo AMD kernel module generator version
2.1 |
tee $logfile
180 echo Active kernel
: >> $logfile
181 echo uname
-a = `uname -a` >> $logfile
182 echo uname
-s = `uname -s` >> $logfile
183 echo uname
-m = `uname -m` >> $logfile
184 echo uname
-r = `uname -r` >> $logfile
185 echo uname
-v = `uname -v` >> $logfile
188 echo Target kernel
: >> $logfile
189 echo uname
-a = ${uname_a} >> $logfile
190 echo uname
-s = ${uname_s} >> $logfile
191 echo uname
-m = ${uname_m} >> $logfile
192 echo uname
-r = ${uname_r} >> $logfile
193 echo uname
-v = ${uname_v} >> $logfile
196 # ==============================================================
199 # ==============================================================
200 # locate and verify contents of kernel include file path
202 # verify match with respective line in linux/version.h
203 # sample: #define UTS_RELEASE "2.4.0-test7"
205 src_file
=$linuxincludes/linux
/version.h
207 if [ ! -e $src_file ]; then
208 echo "kernel includes at $linuxincludes not found or incomplete" |
tee -a $logfile
209 echo "file: $src_file" |
tee -a $logfile
215 # Before 2.6.18 UTS-defines are in linux/version.h.
216 # For 2.6.18 to 2.6.32, UTS-defines are in linux/utsrelease.h.
217 # For 2.6.33 and later UTS-defines are in generated/utsrelease.h.
218 # Some old distributions used to define UTS-defines in external
219 # version-*.h files, e.g. linux-2.2.14-5.0-RedHat. Is this kludge still needed?
221 "$linuxincludes/linux/version.h" \
222 "$linuxincludes/linux/utsrelease.h" \
223 "$linuxincludes/generated/utsrelease.h" \
224 "$linuxincludes/linux/version-*.h";
226 UTS_REL_COUNT
=`cat $src_file 2>/dev/null | grep UTS_RELEASE -c`
227 if [ $UTS_REL_COUNT -gt 1 ]; then
228 kernel_release
=`cat $src_file | grep UTS_RELEASE | grep \"$OsRelease\" | cut -d'"' -f2`
230 elif [ $UTS_REL_COUNT -gt 0 ]; then
231 kernel_release
=`cat $src_file | grep UTS_RELEASE | cut -d'"' -f2`
236 # compare release string of running kernel with kernel name from headers
240 if [ "$OsRelease" = "$kernel_release" ]; then
243 # Red Hat 7.0 source and some newer 2.4.x might not have smp suffix in UTS_RELEASE text
244 if [ `echo $OsRelease | grep smp -c` -ne 0 ]; then
245 if [ "$OsRelease" = "${kernel_release}smp" ]; then
251 if [ $hit -eq 0 ]; then
252 echo "Error:" |
tee -a $logfile
253 echo "kernel includes at $linuxincludes do not match current kernel." |
tee -a $logfile
254 echo "they are versioned as \"$kernel_release\"" |
tee -a $logfile
255 echo "instead of \"$OsRelease\"." |
tee -a $logfile
256 echo "you might need to adjust your symlinks:" |
tee -a $logfile
257 echo "- /usr/include" |
tee -a $logfile
258 echo "- /usr/src/linux" |
tee -a $logfile
262 kernel_release_major
=${kernel_release%%.*}
263 kernel_release_rest
=${kernel_release#*.}
264 kernel_release_minor
=${kernel_release_rest%%.*}
266 if [ "$kernel_release_major" -lt 2 -o \
267 \
( "$kernel_release_major" -eq 2 -a "$kernel_release_minor" -lt 6 \
) ]; then
269 echo "Your kernel version $kernel_release is not supported by this driver release."
270 echo "Only 2.6.0 and newer kernels are supported."
274 # ==============================================================
275 # resolve if we are running a SMP enabled kernel
280 # grep in OsVersion string for SMP specific keywords
283 if [ `echo $OsVersion | grep [sS][mM][pP] -c` -ne 0 ]; then
285 echo "OsVersion says: SMP=$SMP" >> $logfile
289 # grep in /proc/ksyms for SMP specific kernel symbols
290 # use triggerlevel of 10 occurences
291 # (UP kernels might have 0-1, SMP kernels might have 32-45 or much more)
295 if [ -e $src_file ]; then
296 if [ `fgrep smp $src_file -c` -gt 10 ]; then
298 echo "file $src_file says: SMP=$SMP" >> $logfile
302 src_file
=/proc
/kallsyms
304 if [ -e $src_file ]; then
305 if [ `fgrep smp $src_file -c` -gt 10 ]; then
307 echo "file $src_file says: SMP=$SMP" >> $logfile
312 # linux/autoconf.h may contain this: #define CONFIG_SMP 1
314 # Before 2.6.33 autoconf.h is under linux/.
315 # For 2.6.33 and later autoconf.h is under generated/.
316 if [ -f $linuxincludes/generated
/autoconf.h
]; then
317 autoconf_h
=$linuxincludes/generated
/autoconf.h
319 autoconf_h
=$linuxincludes/linux
/autoconf.h
323 if [ ! -e $src_file ]; then
324 echo "Warning:" >> $logfile
325 echo "kernel includes at $linuxincludes not found or incomplete" >> $logfile
326 echo "file: $src_file" >> $logfile
329 if [ `cat $src_file | grep "#undef" | grep "CONFIG_SMP" -c` = 0 ]; then
330 SMP
=`cat $src_file | grep CONFIG_SMP | cut -d' ' -f3`
331 echo "file $src_file says: SMP=$SMP" >> $logfile
335 if [ "$SMP" = 0 ]; then
336 echo "assuming default: SMP=$SMP" >> $logfile
339 # act on final result
340 if [ ! "$SMP" = 0 ]; then
345 # ==============================================================
346 # resolve whether we need to set PAGE_ATTR_FIX
352 if [ -e $src_file ]; then
353 if [ `fgrep " change_page_attr\$" $src_file -c` -gt 0 ]; then
355 echo "file $src_file says: PAGE_ATTR_FIX=$PAGE_ATTR_FIX" >> $logfile
359 src_file
=/proc
/kallsyms
361 if [ -e $src_file ]; then
362 if [ `fgrep " change_page_attr\$" $src_file -c` -gt 0 ]; then
364 echo "file $src_file says: PAGE_ATTR_FIX=$PAGE_ATTR_FIX" >> $logfile
368 # ==============================================================
369 # resolve if we are running a MODVERSIONS enabled kernel
373 # autoconf.h may contain this: #define CONFIG_MODVERSIONS 1
375 if [ ! -e $src_file ];
377 echo "Warning:" >> $logfile
378 echo "kernel includes at $linuxincludes not found or incomplete" >> $logfile
379 echo "file: $src_file" >> $logfile
382 if [ `cat $src_file | grep "#undef" | grep "CONFIG_MODVERSIONS" -c` = 0 ]
384 MODVERSIONS
=`cat $src_file | grep CONFIG_MODVERSIONS | cut -d' ' -f3`
385 echo "file $src_file says: MODVERSIONS=$MODVERSIONS" >> $logfile
389 if [ $MODVERSIONS = 0 ]
391 echo "assuming default: MODVERSIONS=$MODVERSIONS" >> $logfile
394 # act on final result
395 if [ ! $MODVERSIONS = 0 ]
397 def_modversions
="-DMODVERSIONS"
400 # ==============================================================
401 # resolve if we are building for a kernel with a fix for CVE-2010-3081
402 # On kernels with the fix, use arch_compat_alloc_user_space instead
403 # of compat_alloc_user_space since the latter is GPL-only
405 COMPAT_ALLOC_USER_SPACE
=compat_alloc_user_space
408 $linuxbuild/arch
/x86
/include
/asm
/compat.h \
409 $linuxsources/arch
/x86
/include
/asm
/compat.h \
410 $linuxbuild/include
/asm-x86_64
/compat.h \
411 $linuxsources/include
/asm-x86_64
/compat.h
;
418 if [ ! -e $src_file ];
420 echo "Warning: x86 compat.h not found in kernel headers" >> $logfile
421 echo "neither arch/x86/include/asm/compat.h nor include/asm-x86_64/compat.h" >> $logfile
422 echo "could be found in $linuxbuild or $linuxsources" >> $logfile
425 if [ `cat $src_file | grep -c arch_compat_alloc_user_space` -gt 0 ]
427 COMPAT_ALLOC_USER_SPACE
=arch_compat_alloc_user_space
429 echo "file $src_file says: COMPAT_ALLOC_USER_SPACE=$COMPAT_ALLOC_USER_SPACE" >> $logfile
433 # ==============================================================
434 # break down OsRelease string into its components
436 major
=`echo $OsRelease | sed -n -e s/"^\([[:digit:]]*\)\.\([[:digit:]]*\)\.\([[:digit:]]*\)\(.*\)"/"\\1"/p`
437 minor
=`echo $OsRelease | sed -n -e s/"^\([[:digit:]]*\)\.\([[:digit:]]*\)\.\([[:digit:]]*\)\(.*\)"/"\\2"/p`
438 patch=`echo $OsRelease | sed -n -e s/"^\([[:digit:]]*\)\.\([[:digit:]]*\)\.\([[:digit:]]*\)\(.*\)"/"\\3"/p`
439 extra
=`echo $OsRelease | sed -n -e s/"^\([[:digit:]]*\)\.\([[:digit:]]*\)\.\([[:digit:]]*\)\(.*\)"/"\\4"/p`
441 if [ "$1" = "verbose" ]
443 echo OsRelease
=$OsRelease |
tee -a $logfile
444 echo major
=$major |
tee -a $logfile
445 echo minor
=$minor |
tee -a $logfile
446 echo patch=$patch |
tee -a $logfile
447 echo extra
=$extra |
tee -a $logfile
448 echo SMP
=$SMP |
tee -a $logfile
449 echo smp
=$smp |
tee -a $logfile
454 # ==============================================================
455 # make kernel module and check results
459 echo "doing Makefile based build for kernel 2.6.x and higher" |
tee -a $logfile
465 echo 'This is a dummy file created to suppress this warning: could not find /lib/modules/fglrx/build_mod/2.6.x/.libfglrx_ip.a.cmd for /lib/modules/fglrx/build_mod/2.6.x/libfglrx_ip.a' > .lib
${MODULE}_ip.a.cmd
467 CFLAGS_MODULE
="-DMODULE -DATI -DFGL -DPAGE_ATTR_FIX=$PAGE_ATTR_FIX -DCOMPAT_ALLOC_USER_SPACE=$COMPAT_ALLOC_USER_SPACE $def_smp $def_modversions"
469 LIBIP_PREFIX
=$
(echo "$LIBIP_PREFIX" |
sed -e 's|^\([^/]\)|../\1|') \
470 MODFLAGS
="$CFLAGS_MODULE" \
471 CFLAGS_MODULE
="$CFLAGS_MODULE" \
473 PAGE_ATTR_FIX
=$PAGE_ATTR_FIX \
478 tee -a $logfile < tlog
483 if [ $res -eq 0 ]; then
484 echo "build succeeded with return value $res" |
tee -a $logfile
486 echo "build failed with return value $res" |
tee -a $logfile
490 if [ -e ${MODULE}${kmod_extension} ]; then
491 rm -f ${MODULE}${kmod_extension}
494 ln -s 2.6.x
/${MODULE}${kmod_extension}
498 # ==============================================================
499 # install generated file at required location
503 if [ `pwd | grep "/lib/modules/${MODULE}/build_mod\$" -c` -gt 0 ]; then
504 echo duplicating results into driver repository... |
tee -a $logfile
507 target_dir
=`cd $target_dir;pwd`
509 echo "target location: $target_dir" >> $logfile
511 which strip
> /dev
/null
2>&1
514 if [ ! -z "${FGLRX_DEBUG}" ]; then
515 cp -f ${MODULE}${kmod_extension} ${MODULE}_dbg${kmod_extension}
518 strip
-g ${MODULE}${kmod_extension} > /dev
/null
2>&1
521 echo "the debug info stripped from the kernel module" >> $logfile
523 echo "could not strip the debug info of kernel module" >> $logfile
526 echo "could not find the strip utility on your system" >> $logfile
529 echo "copying ${MODULE}${kmod_extension}" >> $logfile
531 cp -f ${MODULE}${kmod_extension} $target_dir/${MODULE}.$OsRelease${kmod_extension} |
tee -a $logfile
533 echo "copying logfile of build" >> $logfile
534 echo "*** end of build log ***" >> $logfile
536 cp -f $logfile $target_dir/make.
$OsRelease.log
538 # terminal hint message
541 # the build was done from an external location - installation not intended
542 echo "duplication skipped - generator was not called from regular lib tree" |
tee -a $logfile
545 # ==============================================================
550 if [ $TERMINAL_HINT -eq 1 ]; then
551 echo "You must change your working directory to $target_dir"
552 echo "and then call ./make_install.sh in order to install the built module."