# Maintainer: cygSimple <cygsimple@users.sourceforge.net>

# Cross build requires specifying --host, --build and sometimes --target.
# The --build is always $CHOST as specified in /etc/makepkg.conf
# The --host will be $CHOST if --target is also specified otherwise $THOST
# The --target is specified if the binary runs as a cross tool
if [ -z "${THOST}" ]; then
  THOST=${CHOST}
fi

# The pkgbase is the controller of the templated actions
pkgbase=filesystem

# The `eval'uated parts below require srcdir and pkgdir be set; but PKGBUILD
# is sourced before these are set so we must do it explicitly here.
srcdir=`pwd`/src
pkgdir=`pwd`/pkg

# Then pkgname becomes an array of the concantenation of the pkgbase and the
# individual pkgtypes.
pkgname=('filesystem')

# The pkgver comes from the upstream source distribution.
eval pkgver=$(date +%Y%m%d)

# The pkgrel is the count of number of issues of the same pkgver.
pkgrel=1

# cygSimple is only providing x86_64
arch=('any')

# The pkgdesc here comes from an upstream description of the package source.
pkgdesc="Base filesystem"

# The license comes from the upstream package source.
license=('BSD')

# The URL describing the package.
url='https://sourceforge.net/projects/cygsimple/'

# Backup existing files
backup=(
	'etc/fstab'
	'etc/shells'
	'etc/profile'
	'etc/bash.bashrc'
	'etc/bash.bash_logout'
	'etc/skel/.bashrc'
	'etc/skel/.bash_profile'
	'etc/skel/.bash_logout'
	'etc/nsswitch.conf'
)

# The source files both virtual and physical
source=(
	'cmd'
	'dep-search'
	'regen-info.sh'
	'start'
	'Cygwin.ico'
	'Cygwin-Terminal.ico'
	'bash.bash_logout'
	'bash.bashrc'
	'fstab'
	'nsswitch.conf'
	'01-devices.post'
	'03-mtab.post'
	'05-home-dir.post'
	'07-pacman-key.post'
	'08-xml-catalog.post'
	'profile'
	'lang.csh'
	'lang.sh'
	'tzset.csh'
	'tzset.sh'
	'shells'
	'.bash_logout'
	'.bash_profile'
	'.bashrc'
	'.inputrc'
	'.profile'
	'cygwin.ldif'
)

# The extra binaries should be declared here.
pkgexealsoprovides=(
	#@PKGEXEALSOPROVIDES@
)

# The extra libraries should be declared here.
pkglibalsoprovides=(
	#@PKGLIBALSOPROVIDES@
)

# The pkgconfigure is used to identify the name of the configure script.
# Not everyone uses autoconf tools.
pkgconfigure="${srcdir}/${pkgbase}-${pkgver}/configure"

# The pkgconfigoptions is used to add configure options that aren't standard.
# When specifying --target --host must be $CHOST.
pkgconfigoptions=(
	'--prefix=/usr'
	"--host=${THOST}"
	#"--host=${CHOST}"
	"--build=${CHOST}"
	#"--target=${THOST}"
	'--sysconfdir=/etc'
	'--sharedstatedir=/var'
	'--localstatedir=/var'
	'--disable-shared'
	'--enable-static'
)

# The pkgmake is used to identify the make program to use
# Not everyone likes GNU make
pkgmake=/usr/bin/make

# The pkgdestdir identifies deposition directory for creating packages.
pkgdestdir="${srcdir}/dest"

# The pkgsrcdir identifies the source directory of the package.
pkgsrcdir="${srcdir}/${pkgbase}-${pkgver}"

# The pkgblddir identifies the build directory for the source.
pkgblddir="${srcdir}/${pkgbase}-${pkgver}"

# The pkgmakeinstall is used to identify the method to use for installing
pkgmakeinstall="/usr/bin/make DESTDIR=${pkgdestdir} install"

# The pkgmakecheck is used to identify the method for testing the package.
pkgmakecheck='make check'

# The sha256sums array is in the same order as the source array, use 'SKIP'
# if the source file doesn't or shouldn't have one.
sha256sums=(
	'ccc55312dfbae5faaa110bad7de0a331db52e5bfe157f860b4716deb3710927e'  #bin-cmd
	'39bf05ea0bd01bc5de9da5badb928d2e0bd65f1bf8d7d67a3ab35207ec9a4775'  #bin-dep-search
	'756df34c5b28478a81331785de0f56438bb652cf5f29029a9db2d83281361340'  #bin-regen-info.sh
	'8622710b8b37d31b1e8f3dfb2b38a09cd9d064c84784aa36c328a7f96c35c83f'  #bin-start
	'a09c1f959655eb98b460f2ede1be33b51b3f35711e14f10d3c2b521746a9e72d'  #Cygwin.ico
	'56325ba711d10e3bdd86a562eb1264c640ff65b9e10be031093abecaa5e4117e'  #Cygwin-Terminal.ico
	'3d2adfcba79b9a0f54bfd194c80745cee32b550e39759d3da92e095f6f611df8'  #etc-bash.bash_logout
	'71c665f1009c395668b64973ad8a710f27b55e42bc35eb37d363790b83356b10'  #etc-bash.bashrc
	'4079185fa60e16f190d63a1a68abf5a636f1d1f16b998fa2e2af419f6d965022'  #etc-fstab
	'3da7478840c73bcb44ec9b74f9ec5d7870757426ab1e0720741376fdc9a60a0b'  #etc-nsswitch.conf
	'95105051d31ecbe4ace262a4496ec1055bdd14d61b7d475a771b56fe15f8ccd9'  #etc-postinstall-01-devices.post
	'd7b7eb4cd9e1f9bc227b009cdcacf700f5523ccc109fbd3c1c0331726d314c9e'  #etc-postinstall-03-mtab.post
	'218094b121426c35d1f9d821f71d3e174136f0c04a65de9779ec05786f19e288'  #etc-postinstall-05-home-dir.post
	'54aeb0f47542bbaa66e34bfe9794b0cbc15e5c1f4929606922fbfe82703c4772'  #etc-postinstall-07-pacman-key.post
	'ad8533809ea2b1bce0a41b3a0a24dbc7a9f58b992ceb40cc9f862b1978032790'  #etc-postinstall-08-xml-catalog.post
	'72f00f3e884fd80c63ccbe47f8da7b5ac62e7149334e9ee0b96f14c1847f9f3f'  #etc-profile
	'4dc37ad18435ec9208213c2005fc2602bf29ad58720d04012fa004554843afc7'  #etc-profile.d-lang.csh
	'24085cd235392724b2c44163f595044319dab68d01d1b4a69c99e7d16665828f'  #etc-profile.d-lang.sh
	'05f2eff08911b3b7896f563aa7700e00d6332fa996d873de696d0cb7380b53c7'  #etc-profile.d-tzset.csh
	'54dba659b5483df246029ce01a66ab6089aea84951930d068f256697f95af48e'  #etc-profile.d-tzset.sh
	'6147b60501e87b42cd0de79e8b5490655b700b3da795675c646b7c97c084ad6b'  #etc-shells
	'4330edf340394d0dae50afb04ac2a621f106fe67fb634ec81c4bfb98be2a1eb5'  #etc-skel-.bash_logout
	'c0fb060ef28ad7f587de8efcef5274ef891ead639f33712aaef3ebecb0f0fafc'  #etc-skel-.bash_profile
	'518b9054fee646c9315a4bd1206f05197c694fd1e599d51a657971de4b02ede0'  #etc-skel-.bashrc
	'da1d6e0ab64e1c2a9cd1f9be996e200f3012ec48b46e17e2620ba77a4484d5c3'  #etc-skel-.inputrc
	'4b2627fe2645f08fa28e3d73f0927da91c75007fa47c44f789bf24471487fa0c'  #etc-skel-.profile
	'b9af554432605fe4027fbc231170e01edb5bcbb958bfd0922609f1901a2dd555'  #usr-share-cygwin-cygwin.ldif
)

# The pdir variable is used because of the timing of the eval.
pdir=${pkgdir}/${pkgbase}

eval "package() {
  pkgdesc='${pkgbase^^} Base System Files'
  options=('!strip')

  mkdir -p ${pdir}/bin
  mkdir -p ${pdir}/usr/share/cygwin
  mkdir -p ${pdir}/etc/{profile.d,postinstall,skel}

  for F in cmd dep-search regen-info.sh start; do
    cp \${F} ${pdir}/bin/
  done

  for F in *.post; do
    cp \${F} ${pdir}/etc/postinstall/
  done

  for F in lang.{csh,sh} tzset.{csh,sh}; do
    cp \${F} ${pdir}/etc/profile.d/
  done

  for F in .bash* .inputrc .profile; do
    cp \${F} ${pdir}/etc/skel/
  done

  for F in bash.bash* fstab nsswitch.conf profile shells; do
    cp \${F} ${pdir}/etc/
  done

  for F in cygwin.ldif; do
    cp \${F} ${pdir}/usr/share/cygwin/
  done

  cp Cygwin.ico Cygwin-Terminal.ico ${pdir}/
}"
