# RPM macro for GNU Emacs
# 
# $Id: rpm-build-emacs.macros,v 1.4 2005/11/06 23:27:57 eugene Exp $

# Standard dirs (in addition to _emacslispdir)
%_emacs_datadir        %_datadir/emacs
# System-wide site-start dir
%_emacs_sitestart_dir  %_sysconfdir/emacs/site-start.d
# Dir for etc (noarch non-lisp) files
%_emacs_etc_dir        %_emacs_datadir/etc

# Emacs binary
%__emacs               %_bindir/emacs

# load-path additions
%set_lisp_loadpath()   %global _lisppath "%1"
%add_lisp_loadpath()   %global _lisppath %{?_lisppath:%_lisppath "%1"}%{!?_lisppath:"%1"}

# Interface to elisp function byte-compile-file - without site-start
%byte_compile_file()   [ -f %1 ] || exit 0; [ -x %__emacs ] && \
%global _lisppath %{?_lisppath:%_lisppath}%{!?_lisppath:"."} \
%__emacs --batch --no-site-file --eval '(progn (setq load-path (append (list %_lisppath) load-path)) (byte-compile-file "'%1'"))' ||: \
%nil

# Interface to elisp function byte-compile-file - with site-start
%bc_file_with_site()   [ -f %1 ] || exit 0; [ -x %__emacs ] && \
%global _lisppath %{?_lisppath:%_lisppath}%{!?_lisppath:"."} \
%__emacs --batch --eval '(progn (setq load-path (append (list %_lisppath) load-path)) (byte-compile-file "'%1'"))' ||: \
%nil

# Byte compile all .el files in dir - without site-start
%byte_compile_dir()    [ -d %1 ] && \
(pushd %1 ; \
for el_file in *.el ; do \
  %byte_compile_file $el_file ; \
done ; \
popd) ||: %nil

# Byte compile all .el files in dir - with site-start
%bc_dir_with_site()    [ -d %1 ] && \
(pushd %1 ; \
for el_file in *.el ; do \
  %bc_file_with_site $el_file ; \
done ; \
popd) ||: %nil

# Interface to elisp function byte-recompile-directoty - without site-start
%byte_recompile_dir()   [ -d %1 ] || exit 0; [ -x %__emacs ] && \
%global _lisppath %{?_lisppath:%_lisppath}%{!?_lisppath:"%1"} \
%__emacs --batch --no-site-file --eval '(progn (setq load-path (append (list %_lisppath) load-path)) (byte-recompile-directory "'%1'" 0 t))' ||: \
%nil

# Interface to elisp function byte-recompile-directoty - with site-start
%brecomp_dir_with_site()   [ -d %1 ] || exit 0; [ -x %__emacs ] && \
%global _lisppath %{?_lisppath:%_lisppath}%{!?_lisppath:"%1"} \
%__emacs --batch --eval '(progn (setq load-path (append (list %_lisppath) load-path)) (byte-recompile-directory "'%1'" 0 t))' ||: \
%nil

# Recompile all files in _emacslispdir - without site-start
%byte_recompile_lispdir() %byte_recompile_dir %buildroot%_emacslispdir

# Recompile all files in _emacslispdir - with site-start
%brecomp_lispdir_with_site() %brecomp_dir_with_site %buildroot%_emacslispdir

# Local Variables:
# mode: rpm-spec
# fill-column: 80
# tab-width: 2
# End:
