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')
14 url="http://www.kernel.org/"
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"
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
33 ####################################################################
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:
43 ####################################################################
46 #############################################################
49 # This package builds the vanilla git kernel by default,
50 # but it is possible to patch the source without modifying
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 #############################
66 # Uncomment desired options
67 #############################
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}"
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}"
94 # Stop build process after kernel configuration
96 # This option enables _save_config implicitly.
102 # Append the date to the localversion
104 # e.g. -ARCH -> -ARCH-20090422
106 # _date_localversion=1
110 # Set the pkgver to the kernel version
111 # rather than the build date
117 # Save the .config file to package directory
118 # as config.saved.$CARCH
124 # Do not compress kernel modules
126 # _no_modules_compression=1
130 # Make the kernel build process verbose
136 if [[ -n $_gitname && -n $_gitroot ]]; then
137 (( 1 )) && _kernel_src="$_build_dir/$_gitname-build"
139 (( 1 )) && _kernel_src="$_build_dir/$(find . -maxdepth 1 -type d -name "linux-*" -printf "%f\n" | head -1)"
143 # define required functions
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 ##############################
161 if [[ -n $_gitname && -n $_gitroot ]]; then
162 #################################
163 # Get the latest kernel sources
164 #################################
165 msg "Fetching sources..."
168 if [[ -d $_gitname ]]; then
169 msg2 "Updating sources..."
174 msg2 "Cloning the project..."
175 warning "The initial clone will download approximately 450 mb"
176 git clone --mirror "$_gitroot" "$_gitname"
179 msg "Creating build branch..."
180 rm -rf "$_kernel_src"
181 git clone "$_gitname" "$_kernel_src"
183 # reset to specified git revision
185 [[ -n $_gitrev ]] && git reset --hard "$_gitrev"
193 msg "Applying patches..."
195 for i in "${source[@]}"; do
197 [[ $i =~ .*\.patch$ ]] && patches=("${patches[@]}" "$srcdir/$i")
198 [[ ${i%.*} =~ .*\.patch$ ]] && patches=("${patches[@]}" "$srcdir/${i%.*}")
202 for i in "${patches[@]}" "$startdir/patches/"*; do
203 msg2 "Applying ${i##*/}..."
204 patch -Np1 -i "$i" || (error "Applying ${i##*/} failed" && return 1)
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
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
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..."
242 warning "Unknown config command: $_config_cmd"
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"
256 #######################################
257 # Stop after configuration if desired
258 #######################################
259 if [[ -n $_configure_only ]]; then
260 rm -rf "$_kernel_src" "$srcdir" "$pkgdir"
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
278 ####################################
279 # Append pkgrel to kernel version
280 ####################################
281 [[ -z $_gitname || -z $_gitroot ]] &&
282 sed -ri "s/^(EXTRAVERSION =).*$/\1 -$pkgrel/" Makefile
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"
307 _generic_package_initialization() {
308 cd "$srcdir/${_kernel_src##*/}"
312 ######################
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"
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 #############################################################
340 # (probably someone wants to use this kernel exclusively?)
341 #############################################################
342 provides=("${provides[@]}" "linux=${_kernver//-/_}")
349 #####################
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}"
387 # remove header symlinks
388 cd "$pkgdir/lib/modules/$_kernver"
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"
407 #default_config="/etc/mkinitcpio.conf"
408 default_image="/boot/initramfs-$pkgname.img"
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"
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*")
469 mkdir -p "$pkgdir/usr/src/linux-$_kernver/${i%/*}"
470 cp -af "$i" "$pkgdir/usr/src/linux-$_kernver/$i"
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
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"
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"
527 ln -s "/usr/src/linux-$_kernver" build
530 if [[ $_kernver != ${_basekernver}${_pkgext} ]]; then
532 ln -s "linux-$_kernver" "linux-${_basekernver}${_pkgext}"
537 _generic_package_linux-docs() {
538 pkgdesc="Kernel hackers manual - HTML documentation that comes with the Linux kernel."
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: