PKGBUILD 7.18 KB
Newer Older
1

2
pkgbase=linux
Ram-Z's avatar
Ram-Z committed
3
pkgname=('linux' 'linux-headers' 'linux-docs')
Luca Giambonini's avatar
Luca Giambonini committed
4
pkgver=4.18.5
Luca Giambonini's avatar
Luca Giambonini committed
5
_srcname=linux-$pkgver
Luca Giambonini's avatar
Luca Giambonini committed
6
pkgrel=2
7
arch=('x86_64')
Xuetian Weng's avatar
Xuetian Weng committed
8
url="https://www.kernel.org/"
philm's avatar
philm committed
9
license=('GPL2')
Xuetian Weng's avatar
Xuetian Weng committed
10
makedepends=('xmlto' 'kmod' 'inetutils' 'bc' 'libelf')
11
options=('!strip')
Luca Giambonini's avatar
Luca Giambonini committed
12 13 14 15 16 17 18
source=(
  https://www.kernel.org/pub/linux/kernel/v4.x/${_srcname}.tar.{xz,sign}
  config.x86_64  # the main kernel config file
  60-linux.hook  # pacman hook for depmod
  90-linux.hook  # pacman hook for initramfs regeneration
  linux.preset   # standard config files for mkinitcpio ramdisk
)
Xuetian Weng's avatar
Xuetian Weng committed
19 20 21
validpgpkeys=(
  'ABAF11C65A2970B130ABE3C479BE3E4300411886'  # Linus Torvalds
  '647F28654894E3BD457199BE38DBBDC86092693E'  # Greg Kroah-Hartman
Luca Giambonini's avatar
Luca Giambonini committed
22
  '8218F88849AAC522E94CF470A5E9288C4FA415FA'  # Jan Alexander Steffens (heftig)
Xuetian Weng's avatar
Xuetian Weng committed
23
)
Luca Giambonini's avatar
Luca Giambonini committed
24
sha256sums=('fb090a3680eddf6f10bf895bc3075bd3f830e3d2429ce469982db5a28df647bd'
Ram-Z's avatar
Ram-Z committed
25
            'SKIP'
Luca Giambonini's avatar
Luca Giambonini committed
26
            'a7036446f02aab501936933d453f3a99c84904b9ad88ea662eb9618972abebf3'
Luca Giambonini's avatar
Luca Giambonini committed
27
            '287b43e83535d0aba2797b8fe4c1527788995cbfd858097be37214345e781a25'
Luca Giambonini's avatar
Luca Giambonini committed
28
            '75f99f5239e03238f88d1a834c50043ec32b1dc568f2cc291b07d04718483919'
Luca Giambonini's avatar
Luca Giambonini committed
29
            'ad6344badc91ad0630caacde83f7f9b97276f80d26a20619a87952be65492c65')
Luca Giambonini's avatar
Luca Giambonini committed
30 31

_kernelname=-CHAKRA
philm's avatar
philm committed
32

Samir's avatar
Samir committed
33
prepare() {
Ram-Z's avatar
Ram-Z committed
34
  cd ${_srcname}
35

36 37 38
  # add latest fixes from stable queue, if needed
  # http://git.kernel.org/?p=linux/kernel/git/stable/stable-queue.git

Xuetian Weng's avatar
Xuetian Weng committed
39 40 41 42
  cat ../config.x86_64 - >.config <<END
CONFIG_LOCALVERSION="${_kernelname}"
CONFIG_LOCALVERSION_AUTO=n
END
Phil's avatar
Phil committed
43

Luca Giambonini's avatar
Luca Giambonini committed
44 45 46 47
  # set extraversion to pkgrel and empty localversion
  sed -e "/^EXTRAVERSION =/s/=.*/= -${pkgrel}/" \
      -e "/^EXTRAVERSION =/aLOCALVERSION =" \
      -i Makefile
48

Samir's avatar
Samir committed
49 50 51
  # don't run depmod on 'make install'. We'll do this ourselves in packaging
  sed -i '2iexit 0' scripts/depmod.sh

Phil's avatar
Phil committed
52
  # get kernel version
philm's avatar
philm committed
53
  make prepare
Luca Giambonini's avatar
Luca Giambonini committed
54
  make -s kernelrelease > ../version
Phil's avatar
Phil committed
55

philm's avatar
philm committed
56 57
  # load configuration
  # Configure the kernel. Replace the line below with one of your choice.
Luca Giambonini's avatar
Luca Giambonini committed
58
  #make menuconfig # CLI menu for configuration
Fabian Kosmale's avatar
Fabian Kosmale committed
59
  #make nconfig # new CLI menu for configuration
philm's avatar
philm committed
60 61 62
  #make xconfig # X-based configuration
  #make oldconfig # using old config from previous kernel version
  # ... or manually edit .config
Ram-Z's avatar
Ram-Z committed
63

64 65
  # rewrite configuration
  yes "" | make config >/dev/null
Phil's avatar
Phil committed
66

Samir's avatar
Samir committed
67 68
  # save configuration for later reuse
  cat .config > "${startdir}/config.x86_64.last"
Luca Giambonini's avatar
Luca Giambonini committed
69
}
Phil's avatar
Phil committed
70

Luca Giambonini's avatar
Luca Giambonini committed
71
build() {
Xuetian Weng's avatar
Xuetian Weng committed
72
  cd ${_srcname}
Luca Giambonini's avatar
Luca Giambonini committed
73

Luca Giambonini's avatar
Luca Giambonini committed
74
  make ${MAKEFLAGS} bzImage modules
philm's avatar
philm committed
75 76 77 78 79
}

package_linux() {
  pkgdesc="The Linux Kernel and modules"
  groups=('base')
80
  depends=('coreutils' 'linux-firmware' 'kmod' 'mkinitcpio>=0.7')
philm's avatar
philm committed
81
  optdepends=('crda: to set the correct wireless channels of your country')
Xuetian Weng's avatar
Xuetian Weng committed
82
  backup=("etc/mkinitcpio.d/${pkgbase}.preset")
83
  install=linux.install
philm's avatar
philm committed
84

Luca Giambonini's avatar
Luca Giambonini committed
85 86
  local kernver="$(<version)"
  
Ram-Z's avatar
Ram-Z committed
87
  cd ${_srcname}
Xuetian Weng's avatar
Xuetian Weng committed
88

Luca Giambonini's avatar
Luca Giambonini committed
89 90
  msg2 "Installing boot image..."
  install -Dm644 "$(make -s image_name)" "$pkgdir/boot/vmlinuz-$pkgbase"
philm's avatar
philm committed
91

Luca Giambonini's avatar
Luca Giambonini committed
92 93 94 95
  msg2 "Installing modules..."
  local modulesdir="$pkgdir/usr/lib/modules/$kernver"
  mkdir -p "$modulesdir"
  make INSTALL_MOD_PATH="$pkgdir/usr" DEPMOD=/doesnt/exist modules_install
Luca Giambonini's avatar
Luca Giambonini committed
96

Luca Giambonini's avatar
Luca Giambonini committed
97 98 99 100 101 102
  # a place for external modules,
  # with version file for building modules and running depmod from hook
  local extramodules="extramodules$_kernelname"
  local extradir="$pkgdir/usr/lib/modules/$extramodules"
  install -Dt "$extradir" -m644 ../version
  ln -sr "$extradir" "$modulesdir/extramodules"
philm's avatar
philm committed
103 104

  # remove build and source links
Luca Giambonini's avatar
Luca Giambonini committed
105
  rm "$modulesdir"/{source,build}
Samir's avatar
Samir committed
106

Luca Giambonini's avatar
Luca Giambonini committed
107 108
  msg2 "Running depmod..."
  depmod -b "$pkgdir/usr" -E Module.symvers -e "$kernver"
Ram-Z's avatar
Ram-Z committed
109

Luca Giambonini's avatar
Luca Giambonini committed
110
  msg2 "Installing hooks..."
Xuetian Weng's avatar
Xuetian Weng committed
111

Luca Giambonini's avatar
Luca Giambonini committed
112
  # sed expression for following substitutions
Luca Giambonini's avatar
Luca Giambonini committed
113 114 115 116
  local subst="
    s|%PKGBASE%|$pkgbase|g
    s|%KERNVER%|$kernver|g
    s|%EXTRAMODULES%|$extramodules|g
BrLi's avatar
BrLi committed
117
  "
Luca Giambonini's avatar
Luca Giambonini committed
118 119

  # hack to allow specifying an initially nonexisting install file
120 121 122 123 124 125 126 127 128 129 130 131 132
  sed "$subst" "$startdir/$install" > "$startdir/$install.pkg"
  true && install=$install.pkg

  # fill in mkinitcpio preset and pacman hooks
  sed "$subst" ../linux.preset | install -Dm644 /dev/stdin \
    "$pkgdir/etc/mkinitcpio.d/$pkgbase.preset"
  sed "$subst" ../60-linux.hook | install -Dm644 /dev/stdin \
    "$pkgdir/usr/share/libalpm/hooks/60-$pkgbase.hook"
  sed "$subst" ../90-linux.hook | install -Dm644 /dev/stdin \
    "$pkgdir/usr/share/libalpm/hooks/90-$pkgbase.hook"

  msg2 "Fixing permissions..."
  chmod -Rc u=rwX,go=rX "$pkgdir"
philm's avatar
philm committed
133 134 135
}

package_linux-headers() {
Luca Giambonini's avatar
Luca Giambonini committed
136
  pkgdesc="Header files and scripts for building modules for ${pkgbase/linux/Linux} kernel"
philm's avatar
philm committed
137

Luca Giambonini's avatar
Luca Giambonini committed
138
  local builddir="$pkgdir/usr/lib/modules/$(<version)/build"
philm's avatar
philm committed
139

Luca Giambonini's avatar
Luca Giambonini committed
140
  cd $_srcname
philm's avatar
philm committed
141

Luca Giambonini's avatar
Luca Giambonini committed
142 143 144 145 146
  msg2 "Installing build files..."
  install -Dt "$builddir" -m644 Makefile .config Module.symvers System.map vmlinux
  install -Dt "$builddir/kernel" -m644 kernel/Makefile
  install -Dt "$builddir/arch/x86" -m644 arch/x86/Makefile
  cp -t "$builddir" -a scripts
philm's avatar
philm committed
147

Luca Giambonini's avatar
Luca Giambonini committed
148 149
  # add objtool for external module building and enabled VALIDATION_STACK option
  install -Dt "$builddir/tools/objtool" tools/objtool/objtool
philm's avatar
philm committed
150

Luca Giambonini's avatar
Luca Giambonini committed
151 152
  # add xfs and shmem for aufs building
  mkdir -p "$builddir"/{fs/xfs,mm}
Ram-Z's avatar
Ram-Z committed
153

Luca Giambonini's avatar
Luca Giambonini committed
154 155
  # ???
  mkdir "$builddir/.tmp_versions"
philm's avatar
philm committed
156

Luca Giambonini's avatar
Luca Giambonini committed
157 158 159 160 161 162 163
  msg2 "Installing headers..."
  cp -t "$builddir" -a include
  cp -t "$builddir/arch/x86" -a arch/x86/include
  install -Dt "$builddir/arch/x86/kernel" -m644 arch/x86/kernel/asm-offsets.s

  install -Dt "$builddir/drivers/md" -m644 drivers/md/*.h
  install -Dt "$builddir/net/mac80211" -m644 net/mac80211/*.h
philm's avatar
philm committed
164

Luca Giambonini's avatar
Luca Giambonini committed
165
  # http://bugs.archlinux.org/task/13146
Luca Giambonini's avatar
Luca Giambonini committed
166
  install -Dt "$builddir/drivers/media/i2c" -m644 drivers/media/i2c/msp3400-driver.h
philm's avatar
philm committed
167

Luca Giambonini's avatar
Luca Giambonini committed
168
  # http://bugs.archlinux.org/task/20402
Luca Giambonini's avatar
Luca Giambonini committed
169 170 171 172 173 174 175 176 177 178 179 180 181
  install -Dt "$builddir/drivers/media/usb/dvb-usb" -m644 drivers/media/usb/dvb-usb/*.h
  install -Dt "$builddir/drivers/media/dvb-frontends" -m644 drivers/media/dvb-frontends/*.h
  install -Dt "$builddir/drivers/media/tuners" -m644 drivers/media/tuners/*.h

  msg2 "Installing KConfig files..."
  find . -name 'Kconfig*' -exec install -Dm644 {} "$builddir/{}" \;

  msg2 "Removing unneeded architectures..."
  local arch
  for arch in "$builddir"/arch/*/; do
    [[ $arch = */x86/ ]] && continue
    echo "Removing $(basename "$arch")"
    rm -r "$arch"
philm's avatar
philm committed
182 183
  done

Luca Giambonini's avatar
Luca Giambonini committed
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
  msg2 "Removing documentation..."
  rm -r "$builddir/Documentation"

  msg2 "Removing broken symlinks..."
  find -L "$builddir" -type l -printf 'Removing %P\n' -delete

  msg2 "Removing loose objects..."
  find "$builddir" -type f -name '*.o' -printf 'Removing %P\n' -delete

  msg2 "Stripping build tools..."
  local file
  while read -rd '' file; do
    case "$(file -bi "$file")" in
      application/x-sharedlib\;*)      # Libraries (.so)
        strip -v $STRIP_SHARED "$file" ;;
      application/x-archive\;*)        # Libraries (.a)
        strip -v $STRIP_STATIC "$file" ;;
      application/x-executable\;*)     # Binaries
        strip -v $STRIP_BINARIES "$file" ;;
      application/x-pie-executable\;*) # Relocatable binaries
        strip -v $STRIP_SHARED "$file" ;;
Luca Giambonini's avatar
Luca Giambonini committed
205
    esac
Luca Giambonini's avatar
Luca Giambonini committed
206 207 208 209
  done < <(find "$builddir" -type f -perm -u+x ! -name vmlinux -print0)

  msg2 "Fixing permissions..."
  chmod -Rc u=rwX,go=rX "$pkgdir"
philm's avatar
philm committed
210 211 212
}

package_linux-docs() {
Luca Giambonini's avatar
Luca Giambonini committed
213
  pkgdesc="Kernel hackers manual - HTML documentation that comes with the ${pkgbase/linux/Linux} kernel"
philm's avatar
philm committed
214

Luca Giambonini's avatar
Luca Giambonini committed
215 216 217
  local builddir="$pkgdir/usr/lib/modules/$(<version)/build"

  cd $_srcname
philm's avatar
philm committed
218

Luca Giambonini's avatar
Luca Giambonini committed
219 220 221
  msg2 "Installing documentation..."
  mkdir -p "$builddir"
  cp -t "$builddir" -a Documentation
Xuetian Weng's avatar
Xuetian Weng committed
222

Luca Giambonini's avatar
Luca Giambonini committed
223 224
  msg2 "Fixing permissions..."
  chmod -Rc u=rwX,go=rX "$pkgdir"
Manuel's avatar
Manuel committed
225
}