1
0
Fork 0
linux-spica-e3-1230v3/PKGBUILD

516 lines
14 KiB
Bash
Raw Normal View History

# 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" <<EOF
# mkinitcpio preset file for the '$pkgname' package
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
#######################
# 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
#######################
rm -rf "$pkgdir/usr/lib/firmware"
#######################
# Run depmod
#######################
if [[ -n $_make_modules ]]; then
depmod -a "$pkgdir/usr"
depmod -b "$pkgdir/usr" -F System.map "$_kernver"
fi
}
_generic_package_linux-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/src/linux-$_kernver/.config"
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 -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
cd "$pkgdir/usr/lib/modules/$_kernver"
rm -rf source build
ln -s "/usr/src/linux-$_kernver" build
cd "$OLDPWD"
if [[ $_kernver != ${_basekernver}${_pkgext} ]]; then
cd "$pkgdir/usr/src"
ln -s "linux-$_kernver" "linux-${_basekernver}${_pkgext}"
cd "$OLDPWD"
fi
}
_generic_package_linux-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 -aL Documentation "$pkgdir/usr/src/linux-$_kernver/"
}
# vim: set fenc=utf-8 ts=2 sw=2 noet: