Source

linux-pf / build_target_pkgs.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 [[ $1 != "USE_EXISTING"  ]]; then
  rm -fr linux-pf
  aurdownload linux-pf
fi
cd linux-pf
unalias cp mv 2>/dev/null
major=3
_minor=`grep --color=never ^_minor PKGBUILD`
minor=`sed -e "s/_minor=//" <<<$_minor`
kernver=$major.$minor

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

if [ $_arch = "x86_64" ]; then
  _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"
  targets="CORE2 ATOM K8 P4 P3 PM 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
# Generic cpu package first
echo "Building generic version: `date`" >| $_basedir/batch_building_linux-pf.log
if [ `whoami` = "root" ]; then
  args=$args" --asroot"
fi
if [[ $1 = "USE_EXISTING"  ]]; then
  cp config.GENERIC-$_arch src/linux-$kernver/.config
  nice -n 20 makepkg -ef $args
else
  nice -n 20 makepkg $args
fi

# 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_linux-pf.log
  cp -vf linux-pf*.xz $_builddir 2>/dev/null
  mv -vf linux-pf*.xz $dropbox/$_arch 2>/dev/null && cd $dropbox/$_arch && repo-add pfkernel.db.tar.gz *.xz

export _PKGOPT=y
# Optimized CPU packages
for cpu in $targets; do
  export CPU=$cpu
  _cpu=`tr '[:upper:]' '[:lower:]' <<< $cpu`



  cd $_builddir/linux-pf/src/linux-$kernver
  rm -f .config
  make -j4 clean
  cd $_builddir/linux-pf
  rm -fr pkg/*
  echo "Building linux-pf-$_cpu"
  cp config.$cpu-$_arch src/linux-$kernver/.config
  echo "Building $_cpu version: `date`" >> $_basedir/batch_building_linux-pf.log
  repeat="$(date +%s)"
  nice -n 20 makepkg -ef $args
# calculate report build time
  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_linux-pf.log
  cp -vf linux-pf*.xz $_builddir
  mv -vf linux-pf*.xz $dropbox/$_arch && 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`