Advertisement
Guest User

PKGBUILD

a guest
Dec 28th, 2012
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 15.71 KB | None | 0 0
  1. # Maintainer: xduugu
  2. _pkgext=-git
  3. pkgbase=linux$_pkgext
  4. pkgname=$pkgbase
  5.  
  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' 'mkinitcpio')
  11.  
  12. pkgver=20121225
  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=('1b7c79c377c52314489c62edfb18287f'
  21.          'ab11879c6b02054615ca3ea84a79b7c4')
  22. sha256sums=('ddcb6aa5811533adbb82f0bed7092bc4df04984952522d2ac0da6c2509414733'
  23.             '8a879350dfc29b716c16677cbb9500d367cc216ac2a6be391bf7f317942729c6')
  24.  
  25. _gitroot="git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git"
  26. _gitname="linux.git"
  27.  
  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
  30.  
  31. # _gitrev=""
  32.  
  33. ####################################################################
  34. # KERNEL CONFIG FILES
  35. #
  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
  42. #
  43. ####################################################################
  44.  
  45.  
  46. #############################################################
  47. # PATCHES
  48. #
  49. # This package builds the vanilla git kernel by default,
  50. # but it is possible to patch the source without modifying
  51. # this PKGBUILD.
  52. #
  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.
  56. #
  57. # Prefixing the patch file names with dots will obviously
  58. # excluded them from the patching process.
  59. #
  60. #############################################################
  61.  
  62.  
  63. #############################
  64. # CONFIGURATION
  65. #
  66. # Uncomment desired options
  67. #############################
  68.  
  69.  
  70. #######
  71. # Set to e.g. menuconfig, xconfig or gconfig
  72. #
  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
  77. #
  78. # If unset or set to an empty or space-only string, the
  79. # (manual) kernel configuration step will be skipped.
  80. #
  81. _config_cmd="${_config_cmd:-xconfig}"
  82.  
  83.  
  84. #######
  85. # The directory where the kernel should be built
  86. #
  87. # Can be useful, for example, if you want to compile on a
  88. # tmpfs mount, which can speed up the compilation process
  89. #
  90. _build_dir="${_build_dir:-$srcdir}"
  91.  
  92.  
  93. #######
  94. # Stop build process after kernel configuration
  95. #
  96. # This option enables _save_config implicitly.
  97. #
  98. # _configure_only=1
  99.  
  100.  
  101. #######
  102. # Append the date to the localversion
  103. #
  104. #   e.g. -ARCH -> -ARCH-20090422
  105. #
  106. # _date_localversion=1
  107.  
  108.  
  109. #######
  110. # Set the pkgver to the kernel version
  111. # rather than the build date
  112. #
  113. # _kernel_pkgver=1
  114.  
  115.  
  116. #######
  117. # Save the .config file to package directory
  118. # as config.saved.$CARCH
  119. #
  120. # _save_config=1
  121.  
  122.  
  123. #######
  124. # Do not compress kernel modules
  125. #
  126. # _no_modules_compression=1
  127.  
  128.  
  129. #######
  130. # Make the kernel build process verbose
  131. #
  132. # _verbose=1
  133.  
  134.  
  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)"
  140. fi
  141.  
  142. #######
  143. # define required functions
  144.  
  145. # single package
  146. package() {
  147.     eval package_$pkgbase-headers
  148.     eval package_$pkgbase
  149. }
  150.  
  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; }"
  155.  
  156.  
  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..."
  166.  
  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 500 mb"
  176.             git clone --mirror "$_gitroot" "$_gitname"
  177.         fi
  178.  
  179.         msg "Creating build branch..."
  180.         rm -rf "$_kernel_src"
  181.         git clone "$_gitname" "$_kernel_src"
  182.  
  183.         # reset to specified git revision
  184.         cd "$_kernel_src"
  185.         [[ -n $_gitrev ]] && git reset --hard "$_gitrev"
  186.     fi
  187.  
  188.     cd "$_kernel_src"
  189.  
  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
  200.  
  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
  207.  
  208.  
  209.     #################
  210.     # CONFIGURATION
  211.     #################
  212.  
  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
  224.  
  225.     [[ ! -e .config ]] &&
  226.         warning "No suitable kernel config file was found. You'll have to configure the kernel from scratch."
  227.  
  228.  
  229.     ###########################
  230.     # Start the configuration
  231.     ###########################
  232.     msg "Updating configuration..."
  233.     yes "" | make config > /dev/null
  234.  
  235.     if [[ -n ${_config_cmd// /} ]]; then
  236.         msg2 "Running make $_config_cmd..."
  237.         zcat /proc/config.gz > /home/steve/Desktop/config
  238.         make $_config_cmd
  239.     else
  240.         warning "Unknown config command: $_config_cmd"
  241.     fi
  242.  
  243.  
  244.     ##############################################
  245.     # Save the config file the package directory
  246.     ##############################################
  247.     if [[ -n $_save_config || -n $_configure_only ]]; then
  248.         msg "Saving configuration..."
  249.         msg2 "Saving $_kernel_src/.config as $startdir/config.saved.$CARCH"
  250.         cp .config "$startdir/config.saved.$CARCH"
  251.     fi
  252.  
  253.  
  254.     #######################################
  255.     # Stop after configuration if desired
  256.     #######################################
  257.     if [[ -n $_configure_only ]]; then
  258.         rm -rf "$_kernel_src" "$srcdir" "$pkgdir"
  259.         return 1
  260.     fi
  261.  
  262.  
  263.     if [[ -f /home/steve/Desktop/config ]]; then
  264.         rm /home/steve/Desktop/config
  265.     fi
  266.     ###############################
  267.     # Append date to localversion
  268.     ###############################
  269.     if [[ -n $_date_localversion ]]; then
  270.         local _localversion="$(sed -rn 's/^CONFIG_LOCALVERSION="([^"]*)"$/\1/p' .config)"
  271.         [[ -n $_localversion ]] && msg2 "CONFIG_LOCALVERSION is set to: $_localversion"
  272.  
  273.         # since this is a git package, the $pkgver is equal to $(date +%Y%m%d)
  274.         msg2 "Appending $pkgver to CONFIG_LOCALVERSION..."
  275.         sed -ri "s/^(CONFIG_LOCALVERSION=).*$/\1\"$_localversion-$pkgver\"/" .config
  276.     fi
  277.  
  278.  
  279.     ####################################
  280.     # Append pkgrel to kernel version
  281.     ####################################
  282.     [[ -z $_gitname || -z $_gitroot ]] &&
  283.         sed -ri "s/^(EXTRAVERSION =).*$/\1 -$pkgrel/" Makefile
  284.  
  285.  
  286.     ####################################
  287.     # don't run depmod on 'make install'
  288.     ####################################
  289.     sed -i '2iexit 0' scripts/depmod.sh
  290.     git update-index --assume-unchanged scripts/depmod.sh
  291.  
  292.  
  293.     #################
  294.     # BUILD PROCESS
  295.     #################
  296.  
  297.     ################################
  298.     # Build the kernel and modules
  299.     ################################
  300.     msg "Building kernel and modules..."
  301.     make $MAKEFLAGS V="$_verbose" bzImage modules
  302.  
  303.  
  304.     ###################################
  305.     # Copy files from build directory
  306.     ####################################
  307.     if [[ $_build_dir != $srcdir ]]; then
  308.         msg "Saving $_kernel_src to $srcdir/${_kernel_src##*/}..."
  309.         mv "$_kernel_src" "$srcdir"
  310.         rm -rf "$_kernel_src"
  311.     fi
  312. }
  313.  
  314.  
  315. _generic_package_initialization() {
  316.     cd "$srcdir/${_kernel_src##*/}"
  317.  
  318.     _karch="x86"
  319.  
  320.     ######################
  321.     # Get kernel version
  322.     ######################
  323.     _kernver=$(make kernelrelease)
  324.     _basekernver=${_kernver%%-*}
  325.  
  326.  
  327.     ############################################################
  328.     # Use kernel version instead of the current date as pkgver
  329.     ############################################################
  330.     if [[ -n $_kernel_pkgver ]]; then
  331.         pkgver=${_kernver//-/_}
  332.         msg "Setting pkgver to kernel version: $pkgver"
  333.     fi
  334. }
  335.  
  336. _generic_package_linux() {
  337.     pkgdesc="The Linux Kernel and modules from Linus' git tree"
  338.     backup=(etc/mkinitcpio.d/$pkgname.preset)
  339.     install=$pkgname.install
  340.     changelog=$pkgname.changelog
  341.  
  342.     # set required variables
  343.     _generic_package_initialization
  344.  
  345.  
  346.     #############################################################
  347.     # Provide linux
  348.     # (probably someone wants to use this kernel exclusively?)
  349.     #############################################################
  350.     provides=("${provides[@]}" "linux=${_kernver//-/_}")
  351.  
  352.  
  353.     ################
  354.     # INSTALLATION
  355.     ################
  356.  
  357.     #####################
  358.     # Install the image
  359.     #####################
  360.     msg "Installing kernel image..."
  361.     install -Dm644 arch/$_karch/boot/bzImage "$pkgdir/boot/vmlinuz-$pkgname"
  362.  
  363.  
  364.     ##########################
  365.     # Install kernel modules
  366.     ##########################
  367.     msg "Installing kernel modules..."
  368.     # force -j1 to work around make 3.82 bug
  369.     make -j1 INSTALL_MOD_PATH="$pkgdir/usr" modules_install
  370.     [[ -z $_no_modules_compression ]] && find "$pkgdir" -name "*.ko" -exec gzip -9 {} +
  371.  
  372.     #########################################################
  373.     # Set up extramodules directory (for external modules)
  374.     #########################################################
  375.     local extramodules="$pkgdir/usr/lib/modules/extramodules-$(cut -d. -f1,2 <<<$_basekernver)"
  376.     local modversion=$(grep '^CONFIG_LOCALVERSION=' .config | cut -d'"' -f2)
  377.     [[ -n $modversion ]] && extramodules+=$modversion
  378.     install -dm755 "${extramodules}${_pkgext}"
  379.     echo $_kernver > "${extramodules}${_pkgext}/version"
  380.     ln -s "../${extramodules##*/}${_pkgext}" "$pkgdir/usr/lib/modules/$_kernver/extramodules"
  381.  
  382.  
  383.     ##################################
  384.     # Create important symlinks
  385.     ##################################
  386.     msg "Creating important symlinks..."
  387.  
  388.     # Create generic modules symlink
  389.     if [[ $_kernver != ${_basekernver}${_pkgext} ]]; then
  390.         cd "$pkgdir/usr/lib/modules"
  391.         ln -s "$_kernver" "${_basekernver}${_pkgext}"
  392.         cd "$OLDPWD"
  393.     fi
  394.  
  395.     # remove header symlinks
  396.     cd "$pkgdir/usr/lib/modules/$_kernver"
  397.         rm -rf source build
  398.         cd "$OLDPWD"
  399.  
  400.  
  401.     ############################
  402.     # Install mkinitcpio files
  403.     ############################
  404.     install -d "$pkgdir/etc/mkinitcpio.d"
  405.  
  406.     msg "Generating $pkgname.preset..."
  407.     cat > "$pkgdir/etc/mkinitcpio.d/$pkgname.preset" <<EOF
  408. # mkinitcpio preset file for the '$pkgname' package
  409.  
  410. ALL_config="/etc/mkinitcpio.conf"
  411. ALL_kver="/boot/vmlinuz-$pkgname"
  412.  
  413. PRESETS=('default')
  414.  
  415. #default_config="/etc/mkinitcpio.conf"
  416. default_image="/boot/initramfs-$pkgname.img"
  417. #default_options=""
  418. EOF
  419.  
  420.  
  421.     #######################
  422.     # Update install file
  423.     #######################
  424.     msg "Updating install file..."
  425.     sed -ri "s/^(pkgname=).*$/\1$pkgname/" "$startdir/$pkgname.install"
  426.     sed -ri "s/^(kernver=).*$/\1$_kernver/" "$startdir/$pkgname.install"
  427.  
  428.  
  429.     #######################
  430.     # Remove the firmware
  431.     #######################
  432.     rm -rf "$pkgdir/usr/lib/firmware"
  433.  
  434.  
  435.     #######################
  436.     # Run depmod
  437.     #######################
  438.     depmod -b "$pkgdir/usr" -F System.map "$_kernver"
  439. }
  440.  
  441.  
  442.  
  443. _generic_package_linux-headers() {
  444.     pkgdesc="Header files and scripts for building modules for $pkgbase"
  445.     depends=("$pkgbase")
  446.  
  447.     # set required variables
  448.     _generic_package_initialization
  449.  
  450.     #############################################################
  451.     # Provide linux-headers
  452.     # (probably someone wants to use this kernel exclusively?)
  453.     #############################################################
  454.     provides=("${provides[@]}" "linux-headers=${_kernver//-/_}")
  455.  
  456.  
  457.     ##############################
  458.     # Install fake kernel source
  459.     ##############################
  460.     install -Dm644 Module.symvers  "$pkgdir/usr/src/linux-$_kernver/Module.symvers"
  461.     install -Dm644 Makefile        "$pkgdir/usr/src/linux-$_kernver/Makefile"
  462.     install -Dm644 kernel/Makefile "$pkgdir/usr/src/linux-$_kernver/kernel/Makefile"
  463.     install -Dm644 .config         "$pkgdir/usr/src/linux-$_kernver/.config"
  464.     install -Dm644 .config         "$pkgdir/usr/lib/modules/$_kernver/.config"
  465.  
  466.  
  467.     #######################################################
  468.     # Install scripts directory and fix permissions on it
  469.     #######################################################
  470.     cp -a scripts "$pkgdir/usr/src/linux-$_kernver"
  471.  
  472.  
  473.     ##########################
  474.     # Install header files
  475.     ##########################
  476.     msg "Installing header files..."
  477.  
  478.     for i in net/ipv4/netfilter/ipt_CLUSTERIP.c \
  479.         $(find include/ net/mac80211/ drivers/{md,media/video/} -iname "*.h") \
  480.         $(find include/config/ -type f) \
  481.         $(find . -name "Kconfig*")
  482.     do
  483.         mkdir -p "$pkgdir/usr/src/linux-$_kernver/${i%/*}"
  484.         cp -af "$i" "$pkgdir/usr/src/linux-$_kernver/$i"
  485.     done
  486.  
  487.     # required by virtualbox and probably others
  488.     ln -s "../generated/autoconf.h" "$pkgdir/usr/src/linux-$_kernver/include/linux/"
  489.  
  490.  
  491.     ########################################
  492.     # Install architecture dependent files
  493.     ########################################
  494.     msg "Installing architecture files..."
  495.     mkdir -p "$pkgdir/usr/src/linux-$_kernver/arch/$_karch/kernel"
  496.     cp -a arch/$_karch/kernel/asm-offsets.s "$pkgdir/usr/src/linux-$_kernver/arch/$_karch/kernel/"
  497.  
  498.     cp -a arch/$_karch/Makefile* "$pkgdir/usr/src/linux-$_kernver/arch/$_karch/"
  499.     cp -a arch/$_karch/configs "$pkgdir/usr/src/linux-$_kernver/arch/$_karch/"
  500.  
  501.     # copy arch includes for external modules and fix the nVidia issue
  502.     mkdir -p "$pkgdir/usr/src/linux-$_kernver/arch/$_karch"
  503.     cp -a "arch/$_karch/include" "$pkgdir/usr/src/linux-$_kernver/arch/$_karch/"
  504.  
  505.     # create a necessary symlink to the arch folder
  506.     cd "$pkgdir/usr/src/linux-$_kernver/arch"
  507.  
  508.     if [[ $CARCH = "x86_64" ]]; then
  509.         ln -s $_karch x86_64
  510.     else
  511.         ln -s $_karch i386
  512.     fi
  513.  
  514.     cd "$OLDPWD"
  515.  
  516.  
  517.     ################################
  518.     # Remove unneeded architecures
  519.     ################################
  520.     msg "Removing unneeded architectures..."
  521.     for i in "$pkgdir/usr/src/linux-$_kernver/arch/"*; do
  522.         [[ ${i##*/} =~ ($_karch|Kconfig) ]] || rm -rf "$i"
  523.     done
  524.  
  525.  
  526.     ############################
  527.     # Remove .gitignore files
  528.     ############################
  529.     msg "Removing .gitignore files from kernel source..."
  530.     find "$pkgdir/usr/src/linux-$_kernver/" -name ".gitignore" -delete
  531.  
  532.  
  533.     ##################################
  534.     # Create important symlinks
  535.     ##################################
  536.     msg "Creating important symlinks..."
  537.  
  538.     # the build symlink needs to be relative
  539.     cd "$pkgdir/usr/lib/modules/$_kernver"
  540.         rm -rf source build
  541.         ln -s "/usr/src/linux-$_kernver" build
  542.         cd "$OLDPWD"
  543.  
  544.     if [[ $_kernver != ${_basekernver}${_pkgext} ]]; then
  545.         cd "$pkgdir/usr/src"
  546.         ln -s "linux-$_kernver" "linux-${_basekernver}${_pkgext}"
  547.         cd "$OLDPWD"
  548.     fi
  549. }
  550.  
  551. _generic_package_linux-docs() {
  552.     pkgdesc="Kernel hackers manual - HTML documentation that comes with the Linux kernel."
  553.     depends=("$pkgbase")
  554.  
  555.     # set required variables
  556.     _generic_package_initialization
  557.  
  558.     mkdir -p "$pkgdir/usr/src/linux-$_kernver"
  559.     cp -aL Documentation "$pkgdir/usr/src/linux-$_kernver/"
  560. }
  561.  
  562. # vim: set fenc=utf-8 ts=2 sw=2 noet:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement