# -*- mode: makefile-gmake; mode: linkd; -*-
#
# Adjust the variables in (@> "Part I") to customize the build
# and install process. See the file (@file :file-name "./README" :display "README") for more details
# on customizing the intialization the .emacs file itself.
# Only change (@> "Part II") if you know what you are doing.
#
# Overview:
#
# To build and install a byte-compiled initialization file
# do the following:
#
#    make
#    make install
#    make clean  
#
# Be sure to verify successful compilation before proceeding to the
# second step. Emacs will give some compilation warnings which you can
# probably ignore. You can set INSTALL on the command line to
# change the final init file name and location;
# see (@> "INSTALL*") below for more options.
#
# To build and install an emacs lisp file, do the following:
#
#    make elisp
#    make install INSTALL_SUFX=.el
#    make fullclean  
#
# Again see (@> "INSTALL*") below for more options.
#
# By doing
#
#    make archive
#
# you can save a copy of these files in a compressed
# archive. The tag ARCHIVE allows you to specify the
# name and location of the archive file.
# See (@> "ARCHIVE*") below for more details.
#
# Note: This makefile follows GNU make conventions,
# particularly in the use of functions for the
# specification of the INSTALL tag.


################################# (@* "Part I")

# Set this to your emacs executable

EMACS=/Applications/Emacs.app/Contents/MacOS/Emacs  

# (@* "ARCHIVE*")
# Specifies name and location of archive file and the archiving method
# and options to be used in doing 'make archive'.
# Set ARCHIVE (e.g., on the command line) to specify an arbitrary name,
# or change individual options selectively.

ARCHIVE_DIR  = /tmp/#                          # directory in which put the archive file
ARCHIVE_APP  = tar#                            # executable name for archiving method  
ARCHIVE_OPT  = zcvf#                           # archiving options
ARCHIVE_NAME = crg-emacs-init.tgz
ARCHIVE      = $(ARCHIVE_DIR)$(ARCHIVE_NAME)

# (@* "INSTALL*")
# Specifies the name and location of the installed emacs initialization file.
# Set INSTALL (e.g., on the command line) to specify an arbitrary name.
# Or you can specify the directory, root name, and suffix selectively.
# Note that by default INSTALL is set to drop the suffix if INSTALL_SFX
# exactly equals ".el". In this case, the installed file will be .emacs
# in INSTALL_DIR by default.

INSTALL_DIR  = $(HOME)/
INSTALL_NAME = .emacs
INSTALL_SUFX = .elc   # if this is .el exactly, INSTALL_SUFX suppressed in INSTALL
INSTALL      = $(INSTALL_DIR)$(INSTALL_NAME)$(if $(subst .el,,$(INSTALL_SUFX)),$(INSTALL_SUFX),)


################################# (@* "Part II")

CONFIG    = Config
WHOAMI    = WhoAmI
CORENAME  = crg-emacs-init
MYMODULES = imports.el text-modes.el prog-modes.el shell-modes.el file-modes.el tex-modes.el ess.el keybindings.el settings.el system-settings.el faces.el init.el
COREFILES = header.el toc.el utility-funcs.el whoami.el $(MYMODULES)

compiled: $(CORENAME).elc

elisp: $(CORENAME).el

install: $(CORENAME)$(INSTALL_SUFX)
	cp $(CORENAME)$(INSTALL_SUFX) $(INSTALL)

archive:
	$(ARCHIVE_APP) $(ARCHIVE_OPT) $(ARCHIVE) --exclude './AuxInfo/*' --exclude './AuxInfo' --exclude './.*~' --wildcards .

clean:
	rm -i $(CORENAME).elc

fullclean:
	rm -i $(CORENAME).el*

$(CORENAME).el: $(COREFILES)
	cat $(COREFILES) > $@

whoami.el: $(WHOAMI) $(CONFIG)
	./makeconfig < $(CONFIG) > tmp-config-sub
	perl -p tmp-config-sub < $< > $@
	rm -f tmp-config-sub

toc.el: header.el utility-funcs.el whoami.el $(MYMODULES)
	./maketoc header.el utility-funcs.el whoami.el $(MYMODULES) > $@

.el.elc:
	$(EMACS) -q -batch -f batch-byte-compile $<

