SHELL = bash

# Keep this synchronized with src/Makefile, but split them up to prevent
#  problems spawning make-docfile.
# Make sure that you load all packages that are loaded by loadup.el (and only 
#  those).

SOME_MACHINE_LISP := ../lisp/facemenu.elc ../lisp/float-sup.elc ../lisp/frame.elc ../lisp/menu-bar.elc ../lisp/mouse.elc ../lisp/select.elc ../lisp/scroll-bar.elc ../lisp/vmsproc.elc ../lisp/vms-patch.elc ../lisp/ls-lisp.elc ../lisp/dos-fns.elc ../lisp/w32-fns.elc ../lisp/dos-w32.elc
lisp1 := ../lisp/abbrev.elc ../lisp/buff-menu.elc ../lisp/byte-run.elc ../lisp/cus-start.el ../lisp/custom.elc ../lisp/emacs-lisp/lisp-mode.elc ../lisp/emacs-lisp/lisp.elc ../lisp/faces.elc ../lisp/files.elc ../lisp/format.elc ../lisp/help.elc ../lisp/indent.elc ../lisp/isearch.elc ../lisp/loadup.el ../lisp/loaddefs.el
lisp2 := ../lisp/bindings.el ../lisp/map-ynp.elc ../lisp/international/mule.elc ../lisp/international/mule-conf.el ../lisp/international/mule-cmds.elc ../lisp/international/characters.elc ../lisp/case-table.elc ../lisp/language/chinese.elc ../lisp/language/cyrillic.elc ../lisp/language/indian.elc ../lisp/language/devanagari.elc
lisp3 := ../lisp/language/english.elc ../lisp/language/ethiopic.elc ../lisp/language/european.elc ../lisp/language/czech.elc ../lisp/language/slovak.elc ../lisp/language/romanian.elc ../lisp/language/greek.elc ../lisp/language/hebrew.elc ../lisp/language/japanese.elc ../lisp/language/korean.elc ../lisp/language/lao.elc ../lisp/language/thai.elc ../lisp/language/tibetan.elc ../lisp/language/vietnamese.elc
lisp4 := ../lisp/language/misc-lang.elc ../lisp/paths.el ../lisp/register.elc ../lisp/replace.elc ../lisp/simple.elc ../lisp/startup.elc ../lisp/subr.elc ../lisp/textmodes/fill.elc ../lisp/textmodes/page.elc ../lisp/textmodes/paragraphs.elc ../lisp/textmodes/text-mode.elc ../lisp/vc-hooks.elc ../lisp/ediff-hook.elc ../lisp/widget.elc ../lisp/window.elc ../lisp/version.el
lisp  := ${lisp1} ${lisp2} ${lisp3} ${lisp4} ${SOME_MACHINE_LISP}

.PHONY: all djp upx1 upx upxbest
all: emacs.exe
# BaseDoc is the part of the DOC file that is generated from the object files
../etc/DOC: BaseDoc ${lisp}
	-cp -f $@ ../etc/DOC.old 2>/dev/null
	cp -f BaseDoc $@
	${libsrc}make-docfile -a $@ -d . ${lisp1}
	${libsrc}make-docfile -a $@ -d . ${lisp2}
	${libsrc}make-docfile -a $@ -d . ${lisp3}
	${libsrc}make-docfile -a $@ -d . ${lisp4}
	${libsrc}make-docfile -a $@ -d . ${SOME_MACHINE_LISP}
emacs: ../etc/DOC
	go32 temacs -batch -l loadup dump
	strip emacs
emacs.exe: emacs
	stubify emacs
# Be generous. Emacs needs it.
	stubedit emacs.exe minstack=3m bufsize=60k
	./emacs.exe -q -batch -f list-load-path-shadows

djp: emacs.exe
	@echo "Compressing with DJP..."
	@djp $<
	@echo "Consider getting UPX for better compression."

upx1: emacs.exe
	@echo "Fast-Compressing with UPX..."
	@upx -1 $<

upx: emacs.exe
	@echo "Compressing with UPX..."
	@upx $<

upxbest: emacs.exe
	@echo "Slow-Compressing with UPX... This takes at least 15 minutes!"
	upx --best $<
