Source

linux-pf / build_nvidia.sh

The default branch has multiple heads

#!/bin/bash

# The script I use to build the generic and optimized binaries of [pfkernel] repo

start="$(date +%s)"		# used for timer function
_builddir=/temp/pkgbuild	# temp space for building
_arch=$(uname -m)		# figure out which arch we are in and build with that
_basedir=/temp
dropbox=/temp/Dropbox/Public
args="-d --nosign"

mkdir -p $_builddir
cd $_builddir
if [[ "$USE_EXISTING" = 0 ||  $1 != "USE_EXISTING"  ]]; then
  rm -fr linux-pf nvidia-pf
  aurdownload linux-pf nvidia-pf
fi

cd linux-pf || exit 1
unalias cp mv 2>/dev/null
major=3
_minor=`grep --color=never ^_minor PKGBUILD`
minor=`sed -e "s/_minor=//" <<<$_minor`
kver=$major.$minor

# Try not to re-download the kernel tarball
if [[ -e $_basedir/linux-$kver.tar.xz ]]; then
  ln -sf $_basedir/linux-$kver.tar.xz
fi

if [ $_arch = "x86_64" ]; then
  cp config.$_arch config.GENERIC-$_arch
  _config="config.x86_64"
  targets="CORE2 K8 ATOM PSC"
  for cpu in $targets; do
   case $cpu in
    CORE2)
    sed -e 's/CONFIG_GENERIC_CPU=y/# CONFIG_GENERIC_CPU is not set/' \
    -e 's/# CONFIG_MCORE2 is not set/CONFIG_MCORE2=y/' \
    -e 's/CONFIG_X86_WP_WORKS_OK=y/CONFIG_X86_WP_WORKS_OK=y\nCONFIG_X86_INTEL_USERCOPY=y\
    \nCONFIG_X86_USE_PPRO_CHECKSUM=y\nCONFIG_X86_P6_NOP=y/' <$_config >|config.$cpu-$_arch
    ;;
    ATOM)
    sed -e 's/CONFIG_GENERIC_CPU=y/# CONFIG_GENERIC_CPU is not set/' \
    -e 's/# CONFIG_MATOM is not set/CONFIG_MATOM=y/' \
    -e 's/CONFIG_X86_WP_WORKS_OK=y/CONFIG_X86_WP_WORKS_OK=y\
    \nCONFIG_X86_USE_PPRO_CHECKSUM=y/' <$_config >|config.$cpu-$_arch
    ;;
    K8)
    sed -e 's/CONFIG_GENERIC_CPU=y/# CONFIG_GENERIC_CPU is not set/' \
    -e 's/# CONFIG_MK8 is not set/CONFIG_MK8=y/' \
    -e 's/CONFIG_X86_WP_WORKS_OK=y/CONFIG_X86_WP_WORKS_OK=y\
    \nCONFIG_X86_INTEL_USERCOPY=y\nCONFIG_X86_USE_PPRO_CHECKSUM=y/' <$_config >|config.$cpu-$_arch
    ;;
    PSC)
    sed -e 's/CONFIG_GENERIC_CPU=y/# CONFIG_GENERIC_CPU is not set/' \
    -e 's/CONFIG_X86_L1_CACHE_SHIFT=6/CONFIG_X86_L1_CACHE_SHIFT=7/' \
    -e 's/# CONFIG_MPSC is not set/CONFIG_MPSC=y/' \
    -e 's/CONFIG_X86_WP_WORKS_OK=y/CONFIG_X86_WP_WORKS_OK=y\nCONFIG_X86_P6_NOP=y/' \
    <$_config >|config.$cpu-$_arch
    ;;
   esac
 done
else
  _config="config"
  cp config config.GENERIC-$_arch
  targets="CORE2 P3 PM ATOM K8 P4 K7"
  for cpu in $targets; do
   case $cpu in
    ATOM)
    sed -e 's/CONFIG_M686=y/# CONFIG_M686 is not set/' \
    -e 's/# CONFIG_MATOM is not set/CONFIG_MATOM=y/' \
    -e '/CONFIG_X86_PPRO_FENCE/d' <$_config >|config.$cpu-$_arch
    ;;
    CORE2)
    sed -e 's/CONFIG_M686=y/# CONFIG_M686 is not set/' \
    -e 's/# CONFIG_MCORE2 is not set/CONFIG_MCORE2=y/' \
    -e '/CONFIG_X86_PPRO_FENCE/d' <$_config >|config.$cpu-$_arch
    ;;
    K8)
    sed -e 's/CONFIG_M686=y/# CONFIG_M686 is not set/' \
    -e 's/# CONFIG_MK8 is not set/CONFIG_MK8=y/' -e '/CONFIG_X86_PPRO_FENCE/d' \
    -e '/CONFIG_X86_CMPXCHG64/d' -e '/^CONFIG_X86_MINIMUM_CPU_FAMILY/ s,5,4,' \
    <$_config >|config.$cpu-$_arch
    ;;
    P4)
    sed -e 's/CONFIG_M686=y/# CONFIG_M686 is not set/' \
    -e 's/# CONFIG_MPENTIUM4 is not set/CONFIG_MPENTIUM4=y/' \
    -e '/CONFIG_X86_INTERNODE_CACHE_SHIFT/ s,=6,=7,' \
    -e '/CONFIG_X86_L1_CACHE_SHIFT/ s,=6,=7,' -e '/CONFIG_X86_PPRO_FENCE/d' \
    <$_config >|config.$cpu-$_arch
    ;;
    PM)
    sed -e 's/CONFIG_M686=y/# CONFIG_M686 is not set/' \
    -e 's/# CONFIG_MPENTIUMM is not set/CONFIG_MPENTIUMM=y/' \
    -e '/CONFIG_X86_PPRO_FENCE/d' <$_config >|config.$cpu-$_arch
    ;;
    P3)
    sed -e 's/CONFIG_M686=y/# CONFIG_M686 is not set/' \
    -e 's/# CONFIG_MPENTIUMIII is not set/CONFIG_MPENTIUMIII=y/' \
    -e '/CONFIG_X86_PPRO_FENCE/d' <$_config >|config.$cpu-$_arch
    ;;
    K7)
    sed -e 's/CONFIG_M686=y/# CONFIG_M686 is not set/' \
    -e 's/# CONFIG_MK7 is not set/CONFIG_MK7=y/' -e '/CONFIG_X86_PPRO_FENCE/d' \
    -e '/CONFIG_X86_CMPXCHG64/d' -e '/^CONFIG_X86_MINIMUM_CPU_FAMILY/ s,5,4,' \
    -e 's/CONFIG_X86_USE_PPRO_CHECKSUM=y/CONFIG_X86_USE_PPRO_CHECKSUM=y\
    \nCONFIG_X86_USE_3DNOW=y/' <$_config >|config.$cpu-$_arch
    ;;
   esac
 done
fi


# Use preset kernel configs
#cp -f $dropbox/$_arch/config.*-$_arch .

export _BATCH=y
export _NOBUILD=y
export _builddir

# Generic cpu package first
echo "Building generic version: `date`" >| $_basedir/batch_building_nvidia-pf.log
echo "Creating .config for linux-pf"
if [ `whoami` = "root" ]; then
  args=$args" --asroot"
fi

if [[ $1 = "USE_EXISTING"  ]]; then
  cp config.GENERIC-$_arch src/linux-$kver/.config
  nice -n 20 makepkg -ef $args
else
  nice -n 20 makepkg $args
fi

# Make sure our kernel is prepared
echo "Preparing kernel tree..."
cd src/linux-$kver || exit 1
make modules_prepare

# Try to use Module.symvers from installed package
if [[ ! -f src/linux-$kver/Module.symvers ]]; then
  echo "Using system Module.symvers"
  cp -f /usr/src/linux-$kver-pf/Module.symvers $_builddir/linux-pf/src/linux-$kver/
fi


cd $_builddir/nvidia-pf || exit 1

_nvpkgver=`grep pkgver= PKGBUILD`
_nvpkgver=`sed -e "s/pkgver=//" <<<$_nvpkgver`
# Try not to re-download the kernel tarball
if [[ -e $_basedir/NVIDIA-Linux-$_arch-$_nvpkgver-no-compat32.run ]]; then
  ln -sf $_basedir/NVIDIA-Linux-$_arch-$_nvpkgver-no-compat32.run
fi

# For GENERIC kernel, purge the cpu variable
sed -i 's/^_cpu\(.*\)/_cpu=/' PKGBUILD
sed -i "s|^_SYSSRC\(.*\)|_SYSSRC=$_builddir/linux-pf/src/linux-$kver/|" PKGBUILD

nice -n 20 makepkg $args

# calculate report build time
  now="$(date +%s)"
  elapsed="$(expr $now - $start)"
  remainder="$(expr $elapsed % 3600)"
  hours="$(expr $(expr $elapsed - $remainder) / 3600)"
  seconds="$(expr $remainder % 60)"
  minutes="$(expr $(expr $remainder - $seconds) / 60)"
  echo "Elapsed time: "`date -d $hours:$minutes:$seconds +%H:%M:%S` >> $_basedir/batch_building_nvidia-pf.log
  cp -f nvidia-pf*.xz $_builddir 2>/dev/null
  mv -f nvidia-pf*.xz $dropbox/$_arch 2>/dev/null && cd $dropbox/$_arch && repo-add pfkernel.db.tar.gz *.xz

export _PKGOPT=y
cd $_builddir/linux-pf || exit 1
# Optimized CPU packages
for cpu in $targets; do
  cd $_builddir/linux-pf || exit 1
  export CPU=$cpu
  _cpu=`tr '[:upper:]' '[:lower:]' <<< $cpu`
  echo "Creating .config for linux-pf-$_cpu"
  cp -v config.$cpu-$_arch src/linux-$kver/.config
  repeat="$(date +%s)"
  nice -n 20 makepkg -ef $args
  # linux-pf should exit gracefully

  cd $_builddir/nvidia-pf || exit 1
# Set the cpu variable
  sed -i "s/^_cpu\(.*\)/_cpu=-$_cpu/" PKGBUILD
  nice -n 20 makepkg -ef $args

  now="$(date +%s)"
  elapsed="$(expr $now - $repeat)"
  remainder="$(expr $elapsed % 3600)"
  hours="$(expr $(expr $elapsed - $remainder) / 3600)"
  seconds="$(expr $remainder % 60)"
  minutes="$(expr $(expr $remainder - $seconds) / 60)"
  echo "Elapsed time: "`date -d $hours:$minutes:$seconds +%H:%M:%S` >> $_basedir/batch_building_nvidia-pf.log
  cp -f nvidia-pf*.xz $_builddir 2>/dev/null
  mv -f nvidia-pf*.xz $dropbox/$_arch 2>/dev/null && cd $dropbox/$_arch && repo-add pfkernel.db.tar.gz *.xz
done

# calculate report build time
now="$(date +%s)"
elapsed="$(expr $now - $start)"
remainder="$(expr $elapsed % 3600)"
hours="$(expr $(expr $elapsed - $remainder) / 3600)"
seconds="$(expr $remainder % 60)"
minutes="$(expr $(expr $remainder - $seconds) / 60)"
echo "Total elapsed time: "`date -d $hours:$minutes:$seconds +%H:%M:%S`
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.