# Maintainer: xduugu _pkgext=-spica pkgbase=linux$_pkgext pkgname=$pkgbase # required by AUR # comment the following line to build a single package containing the kernel and the headers (( 1 )) && pkgname=("$pkgbase" "$pkgbase-headers" "$pkgbase-docs") pkgdesc="The Linux Kernel and modules from Linus' git tree" depends=('coreutils' 'linux-firmware-git' 'mkinitcpio') pkgver=4.5.rc6 pkgrel=1 url="http://www.kernel.org/" arch=(i686 x86_64) license=('GPL2') makedepends=(git bc) options=(!strip) source=($pkgname::git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git) md5sums=('SKIP') sha256sums=('SKIP') # set _gitrev to a git revision (man gitrevisions) like a tag, a commit sha1 # hash or a branch name to build from this tree instead of master _gitrev="v4.4.4" #################################################################### # KERNEL CONFIG FILES # # This PKGBUILD searches for config files in the current directory # and will use the first one it finds from the following # list as base configuration: # config.local # config.saved.$CARCH # config.$CARCH # #################################################################### ############################################################# # PATCHES # # This package builds the vanilla git kernel by default, # but it is possible to patch the source without modifying # this PKGBUILD. # # Simply create a directory 'patches' in your PKGBUILD # directory and _any_ file (dotfiles excluded) in this # folder will be applied to the kernel source. # # Prefixing the patch file names with dots will obviously # excluded them from the patching process. # ############################################################# ############################# # CONFIGURATION # # Uncomment desired options ############################# #_make_modules=0 MAKEFLAGS="-j $(expr $(cat /proc/cpuinfo |grep processor |wc -l) \* 2)" ####### # Set to e.g. menuconfig, xconfig or gconfig # # For a full list of supported commands, please have a look # at "Configuration targets" section of `make help`'s output # or the help target in scripts/kconfig/Makefile # http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=scripts/kconfig/Makefile # # If unset or set to an empty or space-only string, the # (manual) kernel configuration step will be skipped. # _config_cmd="${_config_cmd:-menuconfig}" #_config_cmd="${_config_cmd:-oldconfig}" ####### # Stop build process after kernel configuration # # This option enables _save_config implicitly. # # _configure_only=1 ####### # Append the date to the localversion # # e.g. -ARCH -> -ARCH-20090422 # # _date_localversion=1 ####### # Save the .config file to package directory # as config.saved.$CARCH # _save_config=1 ####### # Do not compress kernel modules # # _no_modules_compression=1 ####### # Make the kernel build process verbose # # _verbose=1 # internal variables (( 1 )) && _kernel_src="$pkgname" #(( 1 )) && _kernel_src="$BUILDDIR/$(find . -maxdepth 1 -type d -name "linux-*" -printf "%f\n" | head -1)" ####### # define required functions pkgver() { cd "$_kernel_src" git describe --always | sed 's/^v//;s/-/./g' } # single package package() { eval package_$pkgbase-headers eval package_$pkgbase } # split package functions eval "package_$pkgbase() { _generic_package_linux; }" eval "package_$pkgbase-headers() { _generic_package_linux-headers; }" eval "package_$pkgbase-docs() { _generic_package_linux-docs; }" ############################## # where the magic happens... ############################## build() { cd "$_kernel_src" msg "Sanitizing source tree.." [[ -n $_gitrev ]] && git reset --hard "$_gitrev" # cleaning source trees git clean -f ################# # Apply patches ################# msg "Applying patches..." local i patches for i in "${source[@]}"; do i=${i##*/} [[ $i =~ .*\.patch$ ]] && patches=("${patches[@]}" "$srcdir/$i") [[ ${i%.*} =~ .*\.patch$ ]] && patches=("${patches[@]}" "$srcdir/${i%.*}") done shopt -s nullglob for i in "${patches[@]}" "$startdir/patches/"*; do msg2 "Applying ${i##*/}..." patch -Np1 -i "$i" || (error "Applying ${i##*/} failed" && return 1) done shopt -u nullglob ################# # CONFIGURATION ################# ######################### # Loading configuration ######################### msg "Loading configuration..." for i in local "saved.$CARCH" "$CARCH"; do if [[ -e $startdir/config.$i ]]; then msg2 "Using kernel config file config.$i..." cp -f "$startdir/config.$i" .config break fi done [[ ! -e .config ]] && warning "No suitable kernel config file was found. You'll have to configure the kernel from scratch." ########################### # Start the configuration ########################### msg "Updating configuration..." yes "" | make config > /dev/null if [[ -f "$startdir/config.saved.$CARCH" ]]; then msg2 "migrating previous config..." cp "$startdir/config.saved.$CARCH" .config make oldconfig else msg2 "migrating default config..." cp "$startdir/config.$CARCH" .config make oldconfig fi if [[ -n ${_config_cmd// /} ]]; then msg2 "Running make $_config_cmd..." make $_config_cmd else warning "Unknown config command: $_config_cmd" fi ############################################## # Save the config file the package directory ############################################## if [[ -n $_save_config || -n $_configure_only ]]; then msg "Saving configuration..." msg2 "Saving $_kernel_src/.config as $startdir/config.saved.$CARCH" cp .config "$startdir/config.saved.$CARCH" fi ####################################### # Stop after configuration if desired ####################################### if [[ -n $_configure_only ]]; then rm -rf "$srcdir" "$pkgdir" return 1 fi ############################### # Append date to localversion ############################### if [[ -n $_date_localversion ]]; then local _localversion="$(sed -rn 's/^CONFIG_LOCALVERSION="([^"]*)"$/\1/p' .config)" [[ -n $_localversion ]] && msg2 "CONFIG_LOCALVERSION is set to: $_localversion" # since this is a git package, the $pkgver is equal to $(date +%Y%m%d) msg2 "Appending $pkgver to CONFIG_LOCALVERSION..." sed -ri "s/^(CONFIG_LOCALVERSION=).*$/\1\"$_localversion-$pkgver\"/" .config fi #################################### # Append pkgrel to kernel version #################################### sed -ri "s/^(EXTRAVERSION =).*$/\1 -$pkgrel/" Makefile #################################### # don't run depmod on 'make install' #################################### sed -i '2iexit 0' scripts/depmod.sh git update-index --assume-unchanged scripts/depmod.sh ################# # BUILD PROCESS ################# ################################ # Build the kernel and modules ################################ msg "Building kernel and modules..." if [[ -n $_make_modules ]]; then make $MAKEFLAGS V="$_verbose" bzImage modules else make $MAKEFLAGS V="$_verbose" bzImage fi } _generic_package_initialization() { cd "$srcdir/${_kernel_src##*/}" _karch="x86" ###################### # Get kernel version ###################### _kernver=$(make kernelrelease) _basekernver=${_kernver%%-*} } _generic_package_linux() { pkgdesc="The Linux Kernel and modules from Linus' git tree" backup=(etc/mkinitcpio.d/$pkgname.preset) install=$pkgname.install changelog=$pkgname.changelog # set required variables _generic_package_initialization ############################################################# # Provide linux # (probably someone wants to use this kernel exclusively?) ############################################################# provides=("${provides[@]}" "linux=${_kernver//-/_}") ################ # INSTALLATION ################ ##################### # Install the image ##################### msg "Installing kernel image..." install -Dm644 arch/$_karch/boot/bzImage "$pkgdir/boot/vmlinuz-$pkgname" ########################## # Install kernel modules ########################## msg "Installing kernel modules..." if [[ -n $_make_modules ]]; then # force -j1 to work around make 3.82 bug make -j1 INSTALL_MOD_PATH="$pkgdir/usr" modules_install [[ -z $_no_modules_compression ]] && find "$pkgdir" -name "*.ko" -exec gzip -9 {} + ######################################################### # Set up extramodules directory (for external modules) ######################################################### local extramodules="$pkgdir/usr/lib/modules/extramodules-$(cut -d. -f1,2 <<<$_basekernver)" local modversion=$(grep '^CONFIG_LOCALVERSION=' .config | cut -d'"' -f2) [[ -n $modversion ]] && extramodules+=$modversion install -dm755 "${extramodules}${_pkgext}" echo $_kernver > "${extramodules}${_pkgext}/version" ln -s "../${extramodules##*/}${_pkgext}" "$pkgdir/usr/lib/modules/$_kernver/extramodules" ################################## # Create important symlinks ################################## msg "Creating important symlinks..." # Create generic modules symlink if [[ $_kernver != ${_basekernver}${_pkgext} ]]; then cd "$pkgdir/usr/lib/modules" ln -s "$_kernver" "${_basekernver}${_pkgext}" cd "$OLDPWD" fi # remove header symlinks cd "$pkgdir/usr/lib/modules/$_kernver" rm -rf source build cd "$OLDPWD" fi ############################ # Install mkinitcpio files ############################ install -d "$pkgdir/etc/mkinitcpio.d" msg "Generating $pkgname.preset..." cat > "$pkgdir/etc/mkinitcpio.d/$pkgname.preset" <