#!/bin/sh -e

./configure \
    --prefix=/usr \
    --with-modules \
    --with-xft \
    --with-x-toolkit=gtk2 \
    --with-toolkit-scroll-bars \
    --without-dbus \
    --without-gconf \
    --without-gsettings \
    --with-xpm=yes \
    --with-gnutls=yes \
    --with-json=yes

mkdir -p "$1/usr/share/emacs/site-lisp"
cat << EOF > "$1/usr/share/emacs/site-lisp/site-start.el"
;; Better security defaults
(with-eval-after-load 'gnutls
  (setq
   gnutls-verify-error t
   gnutls-min-prime-bits 2048
   gnutls-trustfiles '("/etc/ssl/cert.pem")))

;; Needed unless KISS Linux gains librsvg support
(setq-default shr-blocked-images ".*\.svg$")
EOF

make
make DESTDIR="$1" install

rm -rf "$1/usr/lib/systemd"

for packages in play progmodes/ruby-mode* org/ob-ruby* ../etc/schema/xhtml-ruby.rnc progmodes/*antlr* textmodes/*artist* progmodes/*cfengine* auth-source-path* erc mail obsolete eshell gnus images/gnus
do rm -r "/usr/share/emacs/27.2/lisp/${packages}"
done
