updated on Tue Jan 17 16:10:12 UTC 2012
[aur-mirror.git] / linux-git / PKGBUILD
blob9059efbfa5985a21c8a6edd5e93210250e42029e
1 # Maintainer: xduugu
2 _pkgext=-git
3 pkgbase=linux$_pkgext
4 pkgname=$pkgbase
6 # required by AUR
7 # comment the following line to build a single package containing the kernel and the headers
8 (( 1 )) && pkgname=("$pkgbase" "$pkgbase-headers" "$pkgbase-docs")
9 pkgdesc="The Linux Kernel and modules from Linus' git tree"
10 depends=('coreutils' 'linux-firmware-git' 'module-init-tools>=3.12-2' 'mkinitcpio>=0.6.8')
12 pkgver=20111105
13 pkgrel=1
14 url="http://www.kernel.org/"
15 arch=(i686 x86_64)
16 license=('GPL2')
17 makedepends=('git')
18 options=(!strip)
19 source=(config.{i686,x86_64})
20 md5sums=('e28ab5a2d0c57d72c7d5c35feca9cecd'
21          'd99008ddc04e9b9eb1ae92faf6686ca2')
22 sha256sums=('743fce863aae9c738fa0e5a66af908bdbfd196f0c39b31a9472b7bf11307f73c'
23             '2de35706b89e0a5eedf886a568199ab215f756a5ab9f7888ea210ac4b2f664fc')
25 _gitroot="git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git"
26 _gitname="linux.git"
28 # set _gitrev to a git revision (man gitrevisions) like a tag, a commit sha1
29 # hash or a branch name to build from this tree instead of master
31 # _gitrev=""
33 ####################################################################
34 # KERNEL CONFIG FILES
36 # This PKGBUILD searches for config files in the current directory
37 # and will use the first one it finds from the following
38 # list as base configuration:
39 #       config.local
40 #       config.saved.$CARCH
41 #       config.$CARCH
43 ####################################################################
46 #############################################################
47 # PATCHES
49 # This package builds the vanilla git kernel by default,
50 # but it is possible to patch the source without modifying
51 # this PKGBUILD.
53 # Simply create a directory 'patches' in your PKGBUILD
54 # directory and _any_ file (dotfiles excluded) in this
55 # folder will be applied to the kernel source.
57 # Prefixing the patch file names with dots will obviously
58 # excluded them from the patching process.
60 #############################################################
63 #############################
64 # CONFIGURATION
66 # Uncomment desired options
67 #############################
70 #######
71 # Set to e.g. menuconfig, xconfig or gconfig
73 # For a full list of supported commands, please have a look
74 # at "Configuration targets" section of `make help`'s output
75 # or the help target in scripts/kconfig/Makefile
76 # http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=scripts/kconfig/Makefile
78 # If unset or set to an empty or space-only string, the
79 # (manual) kernel configuration step will be skipped.
81 _config_cmd="${_config_cmd:-menuconfig}"
84 #######
85 # The directory where the kernel should be built
87 # Can be useful, for example, if you want to compile on a
88 # tmpfs mount, which can speed up the compilation process
90 _build_dir="${_build_dir:-$srcdir}"
93 #######
94 # Stop build process after kernel configuration
96 # This option enables _save_config implicitly.
98 # _configure_only=1
101 #######
102 # Append the date to the localversion
104 #       e.g. -ARCH -> -ARCH-20090422
106 # _date_localversion=1
109 #######
110 # Set the pkgver to the kernel version
111 # rather than the build date
113 # _kernel_pkgver=1
116 #######
117 # Save the .config file to package directory
118 # as config.saved.$CARCH
120 # _save_config=1
123 #######
124 # Do not compress kernel modules
126 # _no_modules_compression=1
129 #######
130 # Make the kernel build process verbose
132 # _verbose=1
135 # internal variables
136 if [[ -n $_gitname && -n $_gitroot ]]; then
137         (( 1 )) && _kernel_src="$_build_dir/$_gitname-build"
138 else
139         (( 1 )) && _kernel_src="$_build_dir/$(find . -maxdepth 1 -type d -name "linux-*" -printf "%f\n" | head -1)"
142 #######
143 # define required functions
145 # single package
146 package() {
147         eval package_$pkgbase-headers
148         eval package_$pkgbase
151 # split package functions
152 eval "package_$pkgbase() { _generic_package_linux; }"
153 eval "package_$pkgbase-headers() { _generic_package_linux-headers; }"
154 eval "package_$pkgbase-docs() { _generic_package_linux-docs; }"
157 ##############################
158 # where the magic happens...
159 ##############################
160 build() {
161         if [[ -n $_gitname && -n $_gitroot ]]; then
162                 #################################
163                 # Get the latest kernel sources
164                 #################################
165                 msg "Fetching sources..."
167                 cd "$startdir"
168                 if [[ -d $_gitname ]]; then
169                         msg2 "Updating sources..."
170                         cd "$_gitname"
171                         git fetch || true
172                         cd "$OLDPWD"
173                 else
174                         msg2 "Cloning the project..."
175                         warning "The initial clone will download approximately 450 mb"
176                         git clone --mirror "$_gitroot" "$_gitname"
177                 fi
179                 msg "Creating build branch..."
180                 rm -rf "$_kernel_src"
181                 git clone "$_gitname" "$_kernel_src"
183                 # reset to specified git revision
184                 cd "$_kernel_src"
185                 [[ -n $_gitrev ]] && git reset --hard "$_gitrev"
186         fi
188         cd "$_kernel_src"
190         #################
191         # Apply patches
192         #################
193         msg "Applying patches..."
194         local i patches
195         for i in "${source[@]}"; do
196                 i=${i##*/}
197                 [[ $i =~ .*\.patch$ ]] && patches=("${patches[@]}" "$srcdir/$i")
198                 [[ ${i%.*} =~ .*\.patch$ ]] && patches=("${patches[@]}" "$srcdir/${i%.*}")
199         done
201         shopt -s nullglob
202         for i in "${patches[@]}" "$startdir/patches/"*; do
203                 msg2 "Applying ${i##*/}..."
204                 patch -Np1 -i "$i" || (error "Applying ${i##*/} failed" && return 1)
205         done
206         shopt -u nullglob
209         #################
210         # CONFIGURATION
211         #################
213         #########################
214         # Loading configuration
215         #########################
216         msg "Loading configuration..."
217         for i in local "saved.$CARCH" "$CARCH"; do
218                 if [[ -e $startdir/config.$i ]]; then
219                         msg2 "Using kernel config file config.$i..."
220                         cp -f "$startdir/config.$i" .config
221                         break
222                 fi
223         done
225         [[ ! -e .config ]] &&
226                 warning "No suitable kernel config file was found. You'll have to configure the kernel from scratch."
229         ###########################
230         # Start the configuration
231         ###########################
232         msg "Updating configuration..."
233         yes "" | make config > /dev/null
235         # fix lsmod path
236         sed -ri "s@s(bin/lsmod)@\1@" scripts/kconfig/streamline_config.pl
238         if [[ -n ${_config_cmd// /} ]]; then
239                 msg2 "Running make $_config_cmd..."
240                 make $_config_cmd
241         else
242                 warning "Unknown config command: $_config_cmd"
243         fi
246         ##############################################
247         # Save the config file the package directory
248         ##############################################
249         if [[ -n $_save_config || -n $_configure_only ]]; then
250                 msg "Saving configuration..."
251                 msg2 "Saving $_kernel_src/.config as $startdir/config.saved.$CARCH"
252                 cp .config "$startdir/config.saved.$CARCH"
253         fi
256         #######################################
257         # Stop after configuration if desired
258         #######################################
259         if [[ -n $_configure_only ]]; then
260                 rm -rf "$_kernel_src" "$srcdir" "$pkgdir"
261                 return 1
262         fi
265         ###############################
266         # Append date to localversion
267         ###############################
268         if [[ -n $_date_localversion ]]; then
269                 local _localversion="$(sed -rn 's/^CONFIG_LOCALVERSION="([^"]*)"$/\1/p' .config)"
270                 [[ -n $_localversion ]] && msg2 "CONFIG_LOCALVERSION is set to: $_localversion"
272                 # since this is a git package, the $pkgver is equal to $(date +%Y%m%d)
273                 msg2 "Appending $pkgver to CONFIG_LOCALVERSION..."
274                 sed -ri "s/^(CONFIG_LOCALVERSION=).*$/\1\"$_localversion-$pkgver\"/" .config
275         fi
278         ####################################
279         # Append pkgrel to kernel version
280         ####################################
281         [[ -z $_gitname || -z $_gitroot ]] &&
282                 sed -ri "s/^(EXTRAVERSION =).*$/\1 -$pkgrel/" Makefile
285         #################
286         # BUILD PROCESS
287         #################
289         ################################
290         # Build the kernel and modules
291         ################################
292         msg "Building kernel and modules..."
293         make $MAKEFLAGS V="$_verbose" bzImage modules
296         ###################################
297         # Copy files from build directory
298         ####################################
299         if [[ $_build_dir != $srcdir ]]; then
300                 msg "Saving $_kernel_src to $srcdir/${_kernel_src##*/}..."
301                 mv "$_kernel_src" "$srcdir"
302                 rm -rf "$_kernel_src"
303         fi
307 _generic_package_initialization() {
308         cd "$srcdir/${_kernel_src##*/}"
310         _karch="x86"
312         ######################
313         # Get kernel version
314         ######################
315         _kernver=$(make kernelrelease)
316         _basekernver=${_kernver%%-*}
319         ############################################################
320         # Use kernel version instead of the current date as pkgver
321         ############################################################
322         if [[ -n $_kernel_pkgver ]]; then
323                 pkgver=${_kernver//-/_}
324                 msg "Setting pkgver to kernel version: $pkgver"
325         fi
328 _generic_package_linux() {
329         pkgdesc="The Linux Kernel and modules from Linus' git tree"
330         backup=(etc/mkinitcpio.d/$pkgname.preset)
331         install=$pkgname.install
332         changelog=$pkgname.changelog
334         # set required variables
335         _generic_package_initialization
338         #############################################################
339         # Provide linux
340         # (probably someone wants to use this kernel exclusively?)
341         #############################################################
342         provides=("${provides[@]}" "linux=${_kernver//-/_}")
345         ################
346         # INSTALLATION
347         ################
349         #####################
350         # Install the image
351         #####################
352         msg "Installing kernel image..."
353         install -Dm644 arch/$_karch/boot/bzImage "$pkgdir/boot/vmlinuz-$pkgname"
356         ##########################
357         # Install kernel modules
358         ##########################
359         msg "Installing kernel modules..."
360         # force -j1 to work around make 3.82 bug
361         make -j1 INSTALL_MOD_PATH="$pkgdir" modules_install
362         [[ -z $_no_modules_compression ]] && find "$pkgdir" -name "*.ko" -exec gzip -9 {} +
364         #########################################################
365         # Set up extramodules directory (for external modules)
366         #########################################################
367         local extramodules="$pkgdir/lib/modules/extramodules-$(cut -d. -f1,2 <<<$_basekernver)"
368         local modversion=$(grep '^CONFIG_LOCALVERSION=' .config | cut -d'"' -f2)
369         [[ -n $modversion ]] && extramodules+=$modversion
370         install -dm755 "${extramodules}${_pkgext}"
371         echo $_kernver > "${extramodules}${_pkgext}/version"
372         ln -s "../${extramodules##*/}${_pkgext}" "$pkgdir/lib/modules/$_kernver/extramodules"
375         ##################################
376         # Create important symlinks
377         ##################################
378         msg "Creating important symlinks..."
380         # Create generic modules symlink
381         if [[ $_kernver != ${_basekernver}${_pkgext} ]]; then
382                 cd "$pkgdir/lib/modules"
383                 ln -s "$_kernver" "${_basekernver}${_pkgext}"
384                 cd "$OLDPWD"
385         fi
387         # remove header symlinks
388         cd "$pkgdir/lib/modules/$_kernver"
389                 rm -rf source build
390                 cd "$OLDPWD"
393         ############################
394         # Install mkinitcpio files
395         ############################
396         install -d "$pkgdir/etc/mkinitcpio.d"
398         msg "Generating $pkgname.preset..."
399         cat > "$pkgdir/etc/mkinitcpio.d/$pkgname.preset" <<EOF
400 # mkinitcpio preset file for the '$pkgname' package
402 ALL_config="/etc/mkinitcpio.conf"
403 ALL_kver="/boot/vmlinuz-$pkgname"
405 PRESETS=('default')
407 #default_config="/etc/mkinitcpio.conf"
408 default_image="/boot/initramfs-$pkgname.img"
409 #default_options=""
413         #######################
414         # Update install file
415         #######################
416         msg "Updating install file..."
417         sed -ri "s/^(pkgname=).*$/\1$pkgname/" "$startdir/$pkgname.install"
418         sed -ri "s/^(kernver=).*$/\1$_kernver/" "$startdir/$pkgname.install"
421         #######################
422         # Remove the firmware
423         #######################
424         rm -rf "$pkgdir/lib/firmware"
429 _generic_package_linux-headers() {
430         pkgdesc="Header files and scripts for building modules for $pkgbase"
431         depends=("$pkgbase")
433         # set required variables
434         _generic_package_initialization
436         #############################################################
437         # Provide linux-headers
438         # (probably someone wants to use this kernel exclusively?)
439         #############################################################
440         provides=("${provides[@]}" "linux-headers=${_kernver//-/_}")
443         ##############################
444         # Install fake kernel source
445         ##############################
446         install -Dm644 Module.symvers  "$pkgdir/usr/src/linux-$_kernver/Module.symvers"
447         install -Dm644 Makefile        "$pkgdir/usr/src/linux-$_kernver/Makefile"
448         install -Dm644 kernel/Makefile "$pkgdir/usr/src/linux-$_kernver/kernel/Makefile"
449         install -Dm644 .config         "$pkgdir/usr/src/linux-$_kernver/.config"
450         install -Dm644 .config         "$pkgdir/lib/modules/$_kernver/.config"
453         #######################################################
454         # Install scripts directory and fix permissions on it
455         #######################################################
456         cp -a scripts "$pkgdir/usr/src/linux-$_kernver"
459         ##########################
460         # Install header files
461         ##########################
462         msg "Installing header files..."
464         for i in net/ipv4/netfilter/ipt_CLUSTERIP.c \
465                 $(find include/ net/mac80211/ drivers/{md,media/video/} -iname "*.h") \
466                 $(find include/config/ -type f) \
467                 $(find . -name "Kconfig*")
468         do
469                 mkdir -p "$pkgdir/usr/src/linux-$_kernver/${i%/*}"
470                 cp -af "$i" "$pkgdir/usr/src/linux-$_kernver/$i"
471         done
473         # required by virtualbox and probably others
474         ln -s "../generated/autoconf.h" "$pkgdir/usr/src/linux-$_kernver/include/linux/"
477         ########################################
478         # Install architecture dependent files
479         ########################################
480         msg "Installing architecture files..."
481         mkdir -p "$pkgdir/usr/src/linux-$_kernver/arch/$_karch/kernel"
482         cp -a arch/$_karch/kernel/asm-offsets.s "$pkgdir/usr/src/linux-$_kernver/arch/$_karch/kernel/"
484         cp -a arch/$_karch/Makefile* "$pkgdir/usr/src/linux-$_kernver/arch/$_karch/"
485         cp -a arch/$_karch/configs "$pkgdir/usr/src/linux-$_kernver/arch/$_karch/"
487         # copy arch includes for external modules and fix the nVidia issue
488         mkdir -p "$pkgdir/usr/src/linux-$_kernver/arch/$_karch"
489         cp -a "arch/$_karch/include" "$pkgdir/usr/src/linux-$_kernver/arch/$_karch/"
491         # create a necessary symlink to the arch folder
492         cd "$pkgdir/usr/src/linux-$_kernver/arch"
494         if [[ $CARCH = "x86_64" ]]; then
495                 ln -s $_karch x86_64
496         else
497                 ln -s $_karch i386
498         fi
500         cd "$OLDPWD"
503         ################################
504         # Remove unneeded architecures
505         ################################
506         msg "Removing unneeded architectures..."
507         for i in "$pkgdir/usr/src/linux-$_kernver/arch/"*; do
508                 [[ ${i##*/} =~ ($_karch|Kconfig) ]] || rm -rf "$i"
509         done
512         ############################
513         # Remove .gitignore files
514         ############################
515         msg "Removing .gitignore files from kernel source..."
516         find "$pkgdir/usr/src/linux-$_kernver/" -name ".gitignore" -delete
519         ##################################
520         # Create important symlinks
521         ##################################
522         msg "Creating important symlinks..."
524         # the build symlink needs to be relative
525         cd "$pkgdir/lib/modules/$_kernver"
526                 rm -rf source build
527                 ln -s "/usr/src/linux-$_kernver" build
528                 cd "$OLDPWD"
530         if [[ $_kernver != ${_basekernver}${_pkgext} ]]; then
531                 cd "$pkgdir/usr/src"
532                 ln -s "linux-$_kernver" "linux-${_basekernver}${_pkgext}"
533                 cd "$OLDPWD"
534         fi
537 _generic_package_linux-docs() {
538         pkgdesc="Kernel hackers manual - HTML documentation that comes with the Linux kernel."
539         depends=("$pkgbase")
541         # set required variables
542         _generic_package_initialization
544         mkdir -p "$pkgdir/usr/src/linux-$_kernver"
545         cp -aL Documentation "$pkgdir/usr/src/linux-$_kernver/"
548 # vim: set fenc=utf-8 ts=2 sw=2 noet: