app=file
version=5.39
build=3sml
homepage="https://www.darwinsys.com/file/"
download="http://astron.com/pub/file/file-$version.tar.gz"
desc="Utility to determine file types"
requires="bzip2 zlib"

build() {
  mkandenterbuilddir
  rm -rf $app-$version

  tar xf $srcdir/$app-$version.tar.?z*
  cd $app-$version
  fixbuilddirpermissions

  applypatch $srcdir/file.etc.file.diff
  applypatch $srcdir/file.short.diff

  # linking against libseccomp causes weird "Bad system call" issues
  CFLAGS="--std=c99" \
  ./configure \
    --prefix="" \
    --sysconfdir=/etc \
    --datadir=/etc \
    --enable-fsect-man5 \
    --disable-libseccomp

  # Install the flat files
  # We'll regenerate /etc/file/magic.mgc in the doinst.sh
  rm -rf $pkg/etc/file/magic.mgc
  mkdir -p $pkg/etc/file/magic
  cp -a magic/Magdir/* $pkg/etc/file/magic/
  chmod 0644 $pkg/etc/file/magic/* 

  install -Dm 755 $srcdir/recompile_magic.mgc.sh $pkg/etc/file/recompile_magic.mgc.sh

  ( cd $pkg/etc ; ln -sf file misc )

  make CFLAGS="--std=c99"
  make install DESTDIR=$pkg

  cp COPYING $pkgdocs/

  mkfinalpkg
}

sha512sums="
706f52abe8a4140983c03bc9403987153e3996a8bfbfd20d94f82fc7781c710a54e57b8967c8885e0ceec83f86ff0acca14b6d051b854f79df7aaa626d7068b8  file-5.39.tar.lz
3d5549ee9ec1357cd016b120c519c36b3f9fc1cd5f56a34ae5437ff0a9a536a0fa678dd151604e1d0b43c995fe766df5caf950e025c1ca1471f7bcc8715eca73  file.etc.file.diff
66c7ba2a0d963c12df85408cd07d26cc55ba8cefb117ea322091e63af5aabd6df6ca389139a8f8338ea0edd244dbe43e385799381de1b8c0d33137374b3d5734  file.short.diff
"
