OSDN Git Service

fixed
[alterlinux/alterlinux-pkgbuilds.git] / alter-kernel / x86_64 / linux-lqx / PKGBUILD
1 # Maintainer: Piotr Gorski <lucjan.lucjanov@gmail.com> PGP-Key: BDB26C5A
2 # Contributor: shivik <> PGP-Key: 761E423C
3 # Contributor: Michael Duell <mail@akurei.me> PGP-Key: 6EE23EBE
4 # A special thanks to Steven Barrett for very important suggestions
5 # Contributor: Jan Alexander Steffens (heftig) <jan.steffens@gmail.com>
6 # Contributor: Tobias Powalowski <tpowa@archlinux.org>
7 # Contributor: Thomas Baechler <thomas@archlinux.org>
8
9 ### BUILD OPTIONS
10 # Set these variables to ANYTHING that is not null to enable them
11
12 ### Tweak kernel options prior to a build via nconfig
13 _makenconfig=
14
15 ### Tweak kernel options prior to a build via menuconfig
16 _makemenuconfig=
17
18 ### Tweak kernel options prior to a build via xconfig
19 _makexconfig=
20
21 ### Tweak kernel options prior to a build via gconfig
22 _makegconfig=
23
24 # NUMA is optimized for multi-socket motherboards.
25 # A single multi-core CPU actually runs slower with NUMA enabled.
26 # See, https://bugs.archlinux.org/task/31187
27 _NUMAdisable=y
28
29 # Compile ONLY used modules to VASTLYreduce the number of modules built
30 # and the build time.
31 #
32 # To keep track of which modules are needed for your specific system/hardware,
33 # give module_db script a try: https://aur.archlinux.org/packages/modprobed-db
34 # This PKGBUILD read the database kept if it exists
35 #
36 # More at this wiki page ---> https://wiki.archlinux.org/index.php/Modprobed-db
37 _localmodcfg=
38
39 # Use the current kernel's .config file
40 # Enabling this option will use the .config of the RUNNING kernel rather than
41 # the ARCH defaults. Useful when the package gets updated and you already went
42 # through the trouble of customizing your config options.  NOT recommended when
43 # a new kernel is released, but again, convenient for package bumps.
44 _use_current=
45
46 ### Disable MUQSS
47 _muqss_disable=
48
49 ### Enable htmldocs (increases compile time)
50 _htmldocs_enable=
51
52 ### Do not edit below this line unless you know what you're doing
53
54 # pkgname=('linux-lqx' 'linux-lqx-headers' 'linux-lqx-docs')
55 _major=5.9
56 _srcname=linux-${_major}
57 _lqxpatchname=liquorix-package
58 _lqxpatchrel=13
59 _lqxpatchver=${_lqxpatchname}-${_major}-${_lqxpatchrel}
60 pkgbase=linux-lqx
61 pkgver=5.9.13.lqx2
62 pkgrel=1
63 pkgdesc='Linux Liquorix'
64 url='https://liquorix.net/'
65 arch=(x86_64)
66 license=(GPL2)
67 makedepends=(bc kmod libelf cpio)
68 if [ -n "$_htmldocs_enable" ]; then
69     makedepends+=(xmlto python-sphinx python-sphinx_rtd_theme graphviz imagemagick)
70 fi
71 options=('!strip')
72 #_lucjanpath="https://raw.githubusercontent.com/sirlucjan/kernel-patches/master/${_major}"
73 _lucjanpath="https://gitlab.com/sirlucjan/kernel-patches/raw/master/${_major}"
74
75 source=("https://cdn.kernel.org/pub/linux/kernel/v5.x/${_srcname}.tar.xz"
76         "https://cdn.kernel.org/pub/linux/kernel/v5.x/${_srcname}.tar.sign"
77         "https://github.com/damentz/${_lqxpatchname}/archive/${_major}-${_lqxpatchrel}.tar.gz"
78         "${_lucjanpath}/docs-patches/0001-Documentation-Fix-sphinx-3.0-causes-compilation-erro.patch")
79 validpgpkeys=(
80     'ABAF11C65A2970B130ABE3C479BE3E4300411886' # Linus Torvalds
81     '647F28654894E3BD457199BE38DBBDC86092693E' # Greg Kroah-Hartman
82 )
83 sha512sums=('d3d92ce4246bad74c9a784212f160d98449b1e8793970c2c308276568d852b8effe0528686bdb87d55d691f09a826abf7938d69bdd4759ce65ddd5c05ffe4eca'
84             'SKIP'
85             '0bdd1249e3aed6a6e8e3ba3f016594cd7a2aebd035fed7e21a396d356be709c7b3d83523719fc6549e66de5b6d3359475f82c15a96d4e57fcd71c57a30d5ac59'
86             'b1abc4b21191c841326db341aeea6eac9918a4628f38e32f616a8eeeb9919395656fc4b805110dce93aa38188172fb672831fd76e848b3711fcd6ea9115118c6')
87
88
89
90 export KBUILD_BUILD_HOST=archlinux
91 export KBUILD_BUILD_USER=$pkgbase
92 export KBUILD_BUILD_TIMESTAMP="$(date -Ru${SOURCE_DATE_EPOCH:+d @$SOURCE_DATE_EPOCH})"
93
94 prepare() {
95     cd $_srcname
96
97     ### Set package version variables
98         _abiname="$(cat ${srcdir}/${_lqxpatchver}/linux-liquorix/debian/config/defines | grep 'abiname:' | sed -r 's/abiname:\s*//')"
99         _minor="$(echo "$_abiname" | cut -f1 -d .)"
100         _patchrel="$(echo "$_abiname" | cut -f2 -d .)"
101
102     ### Add Liquorix patches
103         local _patchrx='^zen/v\d+\.\d+\.\d+-lqx\d+.patch$'
104         local _patchfolder="${srcdir}/${_lqxpatchver}/linux-liquorix/debian/patches"
105         local _patchpath="$(grep -P "$_patchrx" "$_patchfolder/series")"
106         echo "Patching sources with ${_patchpath#*/}"
107         patch -Np1 -i "$_patchfolder/$_patchpath"
108
109     ### Setting version
110         echo "Setting version..."
111         scripts/setlocalversion --save-scmversion
112         echo "-$pkgrel" > localversion.10-pkgrel
113         echo "${pkgbase#linux}" > localversion.20-pkgname
114
115     ### Patching sources
116         local src
117         for src in "${source[@]}"; do
118             src="${src%%::*}"
119             src="${src##*/}"
120             [[ $src = *.patch ]] || continue
121         echo "Applying patch $src..."
122         patch -Np1 < "../$src"
123         done
124
125     ### Setting config
126         echo "Setting config..."
127         cat ${srcdir}/${_lqxpatchver}/linux-liquorix/debian/config/kernelarch-x86/config-arch-64 >./.config
128         make olddefconfig
129
130     ### Prepared version
131         make -s kernelrelease > version
132         echo "Prepared $pkgbase version $(<version)"
133
134     ### Optionally use running kernel's config
135         # code originally by nous; http://aur.archlinux.org/packages.php?ID=40191
136         if [ -n "$_use_current" ]; then
137                 if [[ -s /proc/config.gz ]]; then
138                         echo "Extracting config from /proc/config.gz..."
139                         # modprobe configs
140                         zcat /proc/config.gz > ./.config
141                 else
142                         warning "Your kernel was not compiled with IKCONFIG_PROC!"
143                         warning "You cannot read the current config!"
144                         warning "Aborting!"
145                         exit
146                 fi
147         fi
148
149     ### Disable MUQSS
150         if [ -n "$_muqss_disable" ]; then
151         echo "Disabling MUQSS..."
152             scripts/config --disable CONFIG_SCHED_MUQSS
153             scripts/config --disable CONFIG_RQ_NONE
154             scripts/config --disable CONFIG_RQ_SMT
155             scripts/config --disable CONFIG_RQ_MC
156             scripts/config --disable CONFIG_RQ_MC_LLC
157             scripts/config --disable CONFIG_RQ_SMP
158             scripts/config --disable CONFIG_RQ_ALL
159             scripts/config --undefine CONFIG_SHARERQ
160         fi
161
162     ### Optionally disable NUMA for 64-bit kernels only
163         # (x86 kernels do not support NUMA)
164         if [ -n "$_NUMAdisable" ]; then
165             echo "Disabling NUMA from kernel config..."
166             scripts/config --disable CONFIG_NUMA
167         fi
168
169     ### Optionally load needed modules for the make localmodconfig
170         # See https://aur.archlinux.org/packages/modprobed-db
171         if [ -n "$_localmodcfg" ]; then
172             if [ -f $HOME/.config/modprobed.db ]; then
173             echo "Running Steven Rostedt's make localmodconfig now"
174             make LSMOD=$HOME/.config/modprobed.db localmodconfig
175         else
176             echo "No modprobed.db data found"
177             exit
178             fi
179         fi
180
181     ### Running make nconfig
182         [[ -z "$_makenconfig" ]] ||  make nconfig
183
184     ### Running make menuconfig
185         [[ -z "$_makemenuconfig" ]] || make menuconfig
186
187     ### Running make xconfig
188         [[ -z "$_makexconfig" ]] || make xconfig
189
190     ### Running make gconfig
191         [[ -z "$_makegconfig" ]] || make gconfig
192
193     ### Save configuration for later reuse
194         cat .config > "${startdir}/config.last"
195 }
196
197 build() {
198   cd $_srcname
199
200   make all
201   if [ -n "$_htmldocs_enable" ]; then
202     make htmldocs
203   fi
204 }
205
206 _package() {
207     pkgdesc="The $pkgdesc kernel and modules"
208     depends=(coreutils kmod initramfs)
209     optdepends=('crda: to set the correct wireless channels of your country'
210                 'linux-firmware: firmware images needed for some devices'
211                 'sof-firmware: firmware images needed for Sound Open Firmware capable devices')
212     provides=(VIRTUALBOX-GUEST-MODULES WIREGUARD-MODULE)
213
214   cd $_srcname
215   local kernver="$(<version)"
216   local modulesdir="$pkgdir/usr/lib/modules/$kernver"
217
218   echo "Installing boot image..."
219   # systemd expects to find the kernel here to allow hibernation
220   # https://github.com/systemd/systemd/commit/edda44605f06a41fb86b7ab8128dcf99161d2344
221   install -Dm644 "$(make -s image_name)" "$modulesdir/vmlinuz"
222
223   # Used by mkinitcpio to name the kernel
224   echo "$pkgbase" | install -Dm644 /dev/stdin "$modulesdir/pkgbase"
225
226   echo "Installing modules..."
227   make INSTALL_MOD_PATH="$pkgdir/usr" modules_install
228
229   # remove build and source links
230   rm "$modulesdir"/{source,build}
231 }
232
233 _package-headers() {
234     pkgdesc="Headers and scripts for building modules for the $pkgdesc kernel"
235     depends=('linux-lqx')
236
237   cd $_srcname
238   local builddir="$pkgdir/usr/lib/modules/$(<version)/build"
239
240   echo "Installing build files..."
241   install -Dt "$builddir" -m644 .config Makefile Module.symvers System.map \
242     localversion.* version vmlinux
243   install -Dt "$builddir/kernel" -m644 kernel/Makefile
244   install -Dt "$builddir/arch/x86" -m644 arch/x86/Makefile
245   cp -t "$builddir" -a scripts
246
247   # add objtool for external module building and enabled VALIDATION_STACK option
248   install -Dt "$builddir/tools/objtool" tools/objtool/objtool
249
250   # add xfs and shmem for aufs building
251   mkdir -p "$builddir"/{fs/xfs,mm}
252
253   echo "Installing headers..."
254   cp -t "$builddir" -a include
255   cp -t "$builddir/arch/x86" -a arch/x86/include
256   install -Dt "$builddir/arch/x86/kernel" -m644 arch/x86/kernel/asm-offsets.s
257
258   install -Dt "$builddir/drivers/md" -m644 drivers/md/*.h
259   install -Dt "$builddir/net/mac80211" -m644 net/mac80211/*.h
260
261   # http://bugs.archlinux.org/task/13146
262   install -Dt "$builddir/drivers/media/i2c" -m644 drivers/media/i2c/msp3400-driver.h
263
264   # http://bugs.archlinux.org/task/20402
265   install -Dt "$builddir/drivers/media/usb/dvb-usb" -m644 drivers/media/usb/dvb-usb/*.h
266   install -Dt "$builddir/drivers/media/dvb-frontends" -m644 drivers/media/dvb-frontends/*.h
267   install -Dt "$builddir/drivers/media/tuners" -m644 drivers/media/tuners/*.h
268
269   echo "Installing KConfig files..."
270   find . -name 'Kconfig*' -exec install -Dm644 {} "$builddir/{}" \;
271
272   echo "Removing unneeded architectures..."
273   local arch
274   for arch in "$builddir"/arch/*/; do
275     [[ $arch = */x86/ ]] && continue
276     echo "Removing $(basename "$arch")"
277     rm -r "$arch"
278   done
279
280   echo "Removing documentation..."
281   rm -r "$builddir/Documentation"
282
283   echo "Removing broken symlinks..."
284   find -L "$builddir" -type l -printf 'Removing %P\n' -delete
285
286   echo "Removing loose objects..."
287   find "$builddir" -type f -name '*.o' -printf 'Removing %P\n' -delete
288
289   echo "Stripping build tools..."
290   local file
291   while read -rd '' file; do
292     case "$(file -bi "$file")" in
293       application/x-sharedlib\;*)      # Libraries (.so)
294         strip -v $STRIP_SHARED "$file" ;;
295       application/x-archive\;*)        # Libraries (.a)
296         strip -v $STRIP_STATIC "$file" ;;
297       application/x-executable\;*)     # Binaries
298         strip -v $STRIP_BINARIES "$file" ;;
299       application/x-pie-executable\;*) # Relocatable binaries
300         strip -v $STRIP_SHARED "$file" ;;
301     esac
302   done < <(find "$builddir" -type f -perm -u+x ! -name vmlinux -print0)
303
304   echo "Adding symlink..."
305   mkdir -p "$pkgdir/usr/src"
306   ln -sr "$builddir" "$pkgdir/usr/src/$pkgbase"
307 }
308
309 _package-docs() {
310     pkgdesc="Documentation for the $pkgdesc kernel"
311     depends=('linux-lqx')
312
313   cd $_srcname
314   local builddir="$pkgdir/usr/lib/modules/$(<version)/build"
315
316   echo "Installing documentation..."
317   local src dst
318   while read -rd '' src; do
319     dst="${src#Documentation/}"
320     dst="$builddir/Documentation/${dst#output/}"
321     install -Dm644 "$src" "$dst"
322   done < <(find Documentation -name '.*' -prune -o ! -type d -print0)
323
324   echo "Adding symlink..."
325   mkdir -p "$pkgdir/usr/share/doc"
326   ln -sr "$builddir/Documentation" "$pkgdir/usr/share/doc/$pkgbase"
327 }
328
329 pkgname=("$pkgbase" "$pkgbase-headers" "$pkgbase-docs")
330 for _p in "${pkgname[@]}"; do
331   eval "package_$_p() {
332     $(declare -f "_package${_p#$pkgbase}")
333     _package${_p#$pkgbase}
334   }"
335 done