Magellan Linux

Annotation of /trunk/ati-drivers/ati-module.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 475 - (hide annotations) (download) (as text)
Mon Feb 11 13:14:04 2008 UTC (16 years, 8 months ago) by niro
File MIME type: application/x-sh
File size: 2766 byte(s)
-fixed several typos

1 niro 474 #!/bin/bash
2 niro 475 # $Header: /root/magellan-cvs/src/ati-drivers/ati-module.sh,v 1.2 2008-02-11 13:14:04 niro Exp $
3 niro 474 # Compiles nvidia-drivers for given kernel
4    
5     die() { echo -e "${COLRED}$@${COLDEFAULT}"; exit 1; }
6     mecho() { echo -e "${COLGREEN}$@${COLDEFAULT}"; }
7    
8     kernel_major_version()
9     {
10     local ksrc="$@"
11     local kv
12    
13     if [[ -z ${ksrc} ]]
14     then
15     kv="$(uname -r|cut -d. -f1-2)"
16     else
17     local version
18     local patchlevel
19    
20     # get version from makefile
21     version=$(grep "^VERSION[[:space:]]*=[[:space:]]*[[:digit:]]" ${ksrc}/Makefile | sed "s/^.*=[[:space:]]*\([[:digit:]]\+\)/\1/g")
22     # get patchlevel from makefile
23     patchlevel=$(grep "^PATCHLEVEL[[:space:]]*=[[:space:]]*[[:digit:]]" ${ksrc}/Makefile | sed "s/^.*=[[:space:]]*\([[:digit:]]\+\)/\1/g")
24     # kernelversion
25     kv="${version}.${patchlevel}"
26     fi
27    
28     echo "${kv}"
29     }
30    
31     mod_suffix()
32     {
33     local ksrc="$@"
34     local mod_suffix
35    
36     if [[ $(kernel_major_version ${ksrc}) = 2.6 ]]
37     then
38     mod_suffix="ko"
39     else
40     mod_suffix="o"
41     fi
42    
43     echo "${mod_suffix}"
44     }
45    
46     PVER="@@PVER@@"
47     BUILDROOT="$(mktemp -d)"
48     SRCTARBALL="/usr/src/ati-drivers/ati-drivers-${PVER}.tar.bz2"
49     SRCDIR="${BUILDROOT}/ati-drivers"
50     KERNEL_MODULE="fglrx"
51    
52     COLRED="\033[1;6m\033[31m"
53     COLGREEN="\033[1;6m\033[32m"
54     COLDEFAULT="\033[0m"
55    
56     if [[ ${NOCOLORS} = true ]]
57     then
58     COLRED=""
59     COLGREEN=""
60     COLDEFAULT=""
61     fi
62    
63     # must be root
64     [[ $(id -u) != 0 ]] && die "You must be r00t!"
65    
66     # check for given argvs
67     for i in $*
68     do
69     case $1 in
70     --kernel-version) shift; KERNEL_VERSION="$1" ;;
71     --kernel-sources) shift; KERNEL_SOURCES="$1" ;;
72     esac
73     shift
74     done
75    
76     # some sane defaults
77     [[ -z ${KERNEL_VERSION} ]] && KERNEL_VERSION="$(uname -r)"
78     [[ -z ${KERNEL_SOURCES} ]] && KERNEL_SOURCES="/lib/modules/${KERNEL_VERSION}/source"
79 niro 475 KERNEL_MODULE_DEST="/lib/modules/${KERNEL_VERSION}/video"
80     KERNEL_MODULE_SUFFIX="$(mod_suffix ${KERNEL_SOURCES})"
81 niro 474
82     if [[ -f ${KERNEL_MODULE_DEST}/${KERNEL_MODULE}.${KERNEL_MODULE_SUFFIX} ]]
83     then
84     mecho "Removing old ${KERNEL_MODULE}-module ..."
85     rm -f ${KERNEL_MODULE_DEST}/${KERNEL_MODULE}.${KERNEL_MODULE_SUFFIX}
86     fi
87    
88     # unpack src-tarball
89     mecho "Uncompressing src-tarball ..."
90     tar xjpf ${SRCTARBALL} -C ${BUILDROOT} || die
91     cd ${SRCDIR}
92    
93     mecho "Compiling ${KERNEL_MODULE}-module for kernel ${KERNEL_VERSION} ..."
94 niro 475 gcc_major="$(gcc --version | grep gcc | cut -d' ' -f3|cut -d. -f1)"
95 niro 474 export _POSIX2_VERSION="199209"
96     [[ $(kernel_major_version ${KERNEL_SOURCES}) = 2.6 ]] && cp 2.6.x/Makefile ${SRCDIR}
97 niro 475 make -C ${KERNEL_SOURCES} V=0 M="$(pwd)" GCC_VER_MAJ="${gcc_major}" modules || die
98 niro 474
99     mecho "Installing ${KERNEL_MODULE}-module into ${KERNEL_MODULE_DEST} ..."
100     install -d ${KERNEL_MODULE_DEST} || die
101     install -m0644 ${KERNEL_MODULE}.${KERNEL_MODULE_SUFFIX} ${KERNEL_MODULE_DEST} || die
102    
103     mecho "Calculating module dependencies ..."
104     depmod -ae ${KERNEL_VERSION}
105    
106     exit 0