# Maintainer: Markus M. May <triplem@tu.archserver.org>

# Contributor: Juergen Hoetzel <juergen@archlinux.org>
# Contributor: Renchi Raju <renchi@green.tam.uiuc.edu>

pkgname=emacs
pkgver=23.3
pkgrel=1
pkgdesc="The Emacs Editor"
arch=(i686 x86_64)
url="http://www.gnu.org/software/emacs/emacs.html"
license=('GPL')
options=(docs)
replaces=(cedet)
depends=('gpm' 'texinfo')
source=(ftp://ftp.gnu.org/gnu/emacs/$pkgname-$pkgver.tar.gz)
md5sums=('bf07c01ef473d8540c9c39f94506b1e6')
install=emacs.install

_mandir='usr/share/man'

build() {
  cd "$srcdir/$pkgname-$pkgver"
  
  # gcc 4.5 Workaround: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43904
  CFLAGS="${CFLAGS} -fno-optimize-sibling-calls"\
    ./configure --prefix=/usr --sysconfdir=/etc --libexecdir=/usr/lib \
    --localstatedir=/var --mandir=/${_mandir} --without-sound --without-dbus \
    --with-x-toolkit=no --without-gconf --without-xpm --without-gif \
    --without-rsvg --without-jpeg --without-tiff

  make 
}

package() {
  cd "$srcdir/$pkgname-$pkgver"
  
  make DESTDIR=$pkgdir install 

  # remove conflict with ctags package
  mv $pkgdir/usr/bin/{ctags,ctags.emacs} 
  mv $pkgdir/usr/bin/{etags,etags.emacs} 
  mv $pkgdir/$_mandir/man1/{etags.1,etags.emacs.1} 
  mv $pkgdir/$_mandir/man1/{ctags.1,ctags.emacs.1} 

  # fix all the 777 perms on directories
  find $pkgdir/usr/share/emacs/$pkgver -type d -exec chmod 755 {} \;

  # fix user/root permissions on usr/share files
  find $pkgdir/usr/share/emacs/$pkgver -exec chown root.root {} \;

  # fix perms on /var/games
  chmod 775 $pkgdir/var/games
  chmod 775 $pkgdir/var/games/emacs
  chmod 664 $pkgdir/var/games/emacs/*
  chown -R root:50 $pkgdir/var/games
}
