1
1
Fork 0
linux-spica-e5-2600v4/PKGBUILD

557 lines
16 KiB
Bash

# 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' 'module-init-tools' 'mkinitcpio')
pkgver=4.13.rc1
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)
#source=($pkgname::git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.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.12.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=1
#######
# Skip the merge of Linus's kernel tree
#
# _skip_merge=1
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
#######
# The directory where the kernel should be built
#
# Can be useful, for example, if you want to compile on a
# tmpfs mount, which can speed up the compilation process
#
#_build_dir="${_build_dir:-$srcdir}"
#######
# Append the date to the localversion
#
# e.g. -ARCH -> -ARCH-20090422
#
#_date_localversion=0
#######
# Set the pkgver to the kernel version
# rather than the build date
#
# _kernel_pkgver=1
#######
# Save the .config file to package directory
# as config.saved.$CARCH
#
_save_config=1
#######
# Do not compress kernel modules
#
_no_modules_compression=0
#######
# 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)"
#(( 1 )) && _kernel_src="$_build_dir/$pkgname_$"
#######
# 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_kernel; }"
eval "package_$pkgbase-headers() { _generic_package_kernel-headers; }"
eval "package_$pkgbase-docs() { _generic_package_kernel-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 "$_kernel_src" "$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
#################
# 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
############
# CLEANUP
############
###################################
# Copy files from build directory
####################################
# if (( ! CLEANUP )) && [[ $_build_dir != $srcdir ]]; then
# msg "Saving $_kernel_src to $srcdir/${_kernel_src##*/}..."
# mv "$_kernel_src" "$srcdir"
# rm -rf "$_kernel_src"
# fi
}
_generic_package_initialization() {
cd "$_kernel_src"
_karch="x86"
######################
# Get kernel version
######################
_kernver=$(make kernelrelease)
_basekernel=${_kernver%%-*}
############################################################
# Use kernel version instead of the current date as pkgver
############################################################
if [[ -n $_kernel_pkgver ]]; then
pkgver=${_kernver//-/_}
msg "Setting pkgver to kernel version: $pkgver"
fi
}
_generic_package_kernel() {
pkgdesc="The Linux Kernel and modules from Linus' git tree"
depends=('coreutils' 'linux-firmware' 'module-init-tools' 'mkinitcpio')
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
##########################
if [[ -n $_make_modules ]]; then
msg "Installing kernel modules..."
make INSTALL_MOD_PATH="$pkgdir" modules_install
[[ -z $_no_modules_compression ]] && find "$pkgdir" -name "*.ko"
-exec gzip -9 {} +
##################################
# Create important symlinks
##################################
msg "Creating important symlinks..."
# Create generic modules symlink
if [[ $_kernver != ${_basekernel}${_pkgext} ]]; then
cd "$pkgdir/lib/modules"
ln -s "$_kernver" "${_basekernel}${_pkgext}"
cd "$OLDPWD"
# remove header symlinks
cd "$pkgdir/lib/modules/$_kernver"
rm -rf source build
cd "$OLDPWD"
fi
fi
############################
# Install mkinitcpio files
############################
install -d "$pkgdir/etc/mkinitcpio.d"
msg "Generating $pkgname.preset..."
cat > "$pkgdir/etc/mkinitcpio.d/$pkgname.preset" <<EOF
# mkinitcpio preset file for $pkgname
ALL_config="/etc/mkinitcpio.conf"
ALL_kver="/boot/vmlinuz-$pkgname"
PRESETS=('default')
#default_config="/etc/mkinitcpio.conf"
default_image="/boot/initramfs-$pkgname.img"
COMPRESSION="lz4" # since kernel 2.6.34
EOF
msg "Generating $pkgname.kver..."
echo -e "# DO NOT EDIT THIS FILE\nALL_kver='$_kernver'" \
> "$pkgdir/etc/mkinitcpio.d/$pkgname.kver"
#######################
# Update install file
#######################
msg "Updating install file..."
sed -ri "s/^(pkgname=).*$/\1$pkgname/" "$startdir/$pkgname.install"
sed -ri "s/^(kernver=).*$/\1$_kernver/" "$startdir/$pkgname.install"
#######################
# Remove the firmware
#######################
# remove the firmware
rm -rf "${pkgdir}/lib/firmware"
if [[ -n $_make_modules ]]; then
# Now we call depmod...
depmod -b "${pkgdir}" -F System.map "${_kernver}"
# move module tree /lib -> /usr/lib
mkdir -p "${pkgdir}/usr"
mv "${pkgdir}/lib" "${pkgdir}/usr/"
fi
}
_generic_package_kernel-headers() {
pkgdesc="Header files and scripts for building modules for $pkgbase"
depends=("$pkgbase")
# set required variables
_generic_package_initialization
#############################################################
# Provide linux-headers
# (probably someone wants to use this kernel exclusively?)
#############################################################
provides=("${provides[@]}" "linux-headers=${_kernver//-/_}")
##############################
# Install fake kernel source
##############################
install -Dm644 Module.symvers "$pkgdir/usr/src/linux-$_kernver/Module.symvers"
install -Dm644 Makefile "$pkgdir/usr/src/linux-$_kernver/Makefile"
install -Dm644 kernel/Makefile "$pkgdir/usr/src/linux-$_kernver/kernel/Makefile"
install -Dm644 .config "$pkgdir/usr/lib/modules/$_kernver/.config"
#######################################################
# Install scripts directory and fix permissions on it
#######################################################
cp -a scripts "$pkgdir/usr/src/linux-$_kernver"
##########################
# Install header files
##########################
msg "Installing header files..."
for i in net/ipv4/netfilter/ipt_CLUSTERIP.c \
$(find include/ net/mac80211/ drivers/{md,media/video/} -iname "*.h") \
$(find include/config/ -type f) \
$(find . -name "Kconfig*")
do
mkdir -p "$pkgdir/usr/src/linux-$_kernver/${i%/*}"
cp -af "$i" "$pkgdir/usr/src/linux-$_kernver/$i"
done
# required by virtualbox and probably others
ln -s "../generated/autoconf.h" "$pkgdir/usr/src/linux-$_kernver/include/linux/"
########################################
# Install architecture dependent files
########################################
msg "Installing architecture files..."
mkdir -p "$pkgdir/usr/src/linux-$_kernver/arch/$_karch/kernel"
cp -a arch/$_karch/kernel/asm-offsets.s "$pkgdir/usr/src/linux-$_kernver/arch/$_karch/kernel/"
cp -a arch/$_karch/Makefile* "$pkgdir/usr/src/linux-$_kernver/arch/$_karch/"
cp -a arch/$_karch/configs "$pkgdir/usr/src/linux-$_kernver/arch/$_karch/"
# copy arch includes for external modules and fix the nVidia issue
mkdir -p "$pkgdir/usr/src/linux-$_kernver/arch/$_karch"
cp -a "arch/$_karch/include" "$pkgdir/usr/src/linux-$_kernver/arch/$_karch/"
# create a necessary symlink to the arch folder
cd "$pkgdir/usr/src/linux-$_kernver/arch"
if [[ $CARCH = "x86_64" ]]; then
ln -s $_karch x86_64
else
ln -s $_karch i386
fi
cd "$OLDPWD"
################################
# Remove unneeded architecures
################################
msg "Removing unneeded architectures..."
for i in "$pkgdir/usr/src/linux-$_kernver/arch/"*; do
[[ ${i##*/} =~ ($_karch|Kconfig) ]] || rm -rf "$i"
done
############################
# Remove .gitignore files
############################
msg "Removing .gitignore files from kernel source..."
find "$pkgdir/usr/src/linux-$_kernver/" -name ".gitignore" -delete
##################################
# Create important symlinks
##################################
msg "Creating important symlinks..."
# the build symlink needs to be relative
if [[ -n $_make_modules ]]; then
cd "$pkgdir/usr/lib/modules/$_kernver"
rm -rf source build
ln -s "/usr/src/linux-$_kernver" build
cd "$OLDPWD"
fi
if [[ $_kernver != ${_basekernver}${_pkgext} ]]; then
cd "$pkgdir/usr/src"
ln -s "linux-$_kernver" "linux-${_basekernel}${_pkgext}"
cd "$OLDPWD"
fi
}
_generic_package_kernel-docs() {
pkgdesc="Kernel hackers manual - HTML documentation that comes with the Linux kernel."
depends=("$pkgbase")
# set required variables
_generic_package_initialization
mkdir -p "$pkgdir/usr/src/linux-$_kernver"
cp -a Documentation "$pkgdir/usr/src/linux-$_kernver/"
}
# vim: set fenc=utf-8 ts=2 sw=2 noet: