# Rules for fetching and byte-compiling elisp libraries. -*- makefile-gmake -*-

ifeq ($(shell uname -s),Darwin)
    EMACS=/Applications/Emacs.app/Contents/MacOS/Emacs -q --no-site-file
else
    EMACS=emacs -q --no-site-file
endif

usage:
	@echo "usage: make [foo.el | foo.elc | autoloads | usage | all]"
	@echo "       make foo.el  will fetch foo.el from the Internet"
	@echo "       make foo.elc will byte-compile foo.el."
	@echo "                    (fetching foo.el first if necessary)."
	@echo "       make all will turn buil .elc for all .el in this dir."
	@echo "       make autoloads will update the autoloads file."
	@echo "       make usage displays this message."
	@echo

autoloads: install.el
	$(EMACS) -batch -L . -l install.el \
		-eval '(install-update-autoloads "autoloads")'


ELS = $(shell ls -1 *.el)
ELCS = $(ELS:.el=.elc)
all: $(ELCS)
	make $(ELCS)
.el.elc:
	$(EMACS) -batch -L . \
		-eval "(setq max-lisp-eval-depth 1500)" \
		-eval "(setq max-specpdl-size 3000)" \
		-eval "(mapc (lambda (dir) (add-to-list 'load-path dir)) \
			(parse-colon-path (getenv \"LOAD_PATH\")))" \
		-f batch-byte-compile $*.el



EMACSWIKI_DOWNLOAD=https://www.emacswiki.org/emacs/download/
GITHUB=https://raw.githubusercontent.com

# Where I most recently fetched various random elisp files written by
# other people.

applescript-mode.el:
	curl -O http://jaist.dl.sourceforge.jp/macemacsjp/9401/applescript-mode.el

boxquote.el:
	curl -O http://www.davep.org/emacs/boxquote.el
color-theme.el: color-theme.el.gz
	gzip -d -c color-theme.el.gz > color-theme.el
color-theme.el.gz:
	curl -O http://download.gna.org/color-theme/color-theme.el.gz

css-mode.el:
	curl -O http://www.garshol.priv.no/download/software/css-mode/css-mode.el
csv.el:
	curl -o csv.el http://ulf.epplejasper.de/downloads/csv.el

deft.el:
	curl -O http://jblevins.org/projects/deft/deft.el

dom.el:
	curl -O $(EMACSWIKI_DOWNLOAD)/dom.el

ecmascript-mode.el:
	curl -O $(EMACSWIKI_DOWNLOAD)/ecmascript-mode.el
erc-highlight-nicknames.el:
	curl -O $(EMACSWIKI_DOWNLOAD)/erc-highlight-nicknames.el
erc-hl-nicks.el:
	curl -O $(GITHUB)/leathekd/erc-hl-nicks/master/erc-hl-nicks.el

erc-robot.el:
	curl -O $(EMACSWIKI_DOWNLOAD)/erc-robot.el

espresso.el:
	curl -O http://download.savannah.gnu.org/releases-noredirect/espresso/espresso.el
fillcode.el:
	curl -O http://snarfed.org/space/fillcode/fillcode.el

haskell-mode-1.45/haskell-mode.el: haskell-mode-1.45.tar.gz
	tar xzvf haskell-mode-1.45.tar.gz
haskell-mode-1.45.tar.gz:
	curl -O http://www.haskell.org/haskell-mode/haskell-mode-1.45.tar.gz
SAVANNAH_VIEWVC=http://cvs.savannah.gnu.org/viewvc/*checkout*
http-cookies.el http-get.el http-post.el:
	curl -o $*.el $(SAVANNAH_VIEWVC)/http-emacs/$*.el?root=http-emacs

http-twiddle.el:
	curl -O http://fresh.homeunix.net/~luke/misc/emacs/http-twiddle.el

install.el:
	curl -O http://www.iro.umontreal.ca/~monnier/elisp/install.el
javascript.el: javascript.el.zip
	unzip -fo javascript.el.zip
javascript.el.zip:
	curl -O http://web.comhem.se/~u34308910/emacs/javascript.el.zip
mb-depth.el:
	curl -O $(EMACSWIKI_DOWNLOAD)/mb-depth.el

moz.el:
	curl -O http://github.com/bard/mozrepl/raw/master/chrome/content/moz.el
multi-region.el:
	curl -O http://purl.org/NET/wence/multi-region.el
mwe-log-commands.el:
	curl -O http://www.foldr.org/~michaelw/emacs/mwe-log-commands.el

oddmuse.el:
	curl -O $(EMACSWIKI_DOWNLOAD)/oddmuse.el

paredit.el:
	curl -O http://mumble.net/~campbell/emacs/paredit.el
parenface.el:
	curl -O http://www.davep.org/emacs/parenface.el
rpm-spec-mode.el:
	curl -O http://www.tihlde.org/~stigb/rpm-spec-mode.el
rails.el:
	curl -O https://opensvn.csie.org/mvision/emacs/.emacs.d/rails.el
ruby: misc.tar.gz
	tar xzvf misc.tar.gz
	mv misc ruby
RUBY_CVSWEB="http://www.ruby-lang.org/cgi-bin/cvsweb.cgi/ruby"
misc.tar.gz:
	curl -o misc.tar.gz "$(RUBY_CVSWEB)/misc/misc.tar.gz?tarball=1"
shavian-ucs.el:
	curl -O https://kovro.heliohost.org/emacs/shavian-ucs.el

swift-mode.el:
	curl -O https://raw.githubusercontent.com/apple/swift/master/utils/swift-mode.el
swift-project-settings.el:
	curl -O https://raw.githubusercontent.com/apple/swift/master/utils/swift-project-settings.el

tc.el:
	curl -O http://shasta.cs.uiuc.edu/~lrclause/tc.el
tidy.el:
	curl -O $(EMACSWIKI_DOWNLOAD)/tidy.el

tracking.el:
	curl -O $(EMACSWIKI_DOWNLOAD)/tracking.el
twit.el:
	curl -O $(EMACSWIKI_DOWNLOAD)/twit.el

two-mode-mode.el:
	curl -O http://www.welton.it/freesoftware/files/two-mode-mode.el

WIKIPEDIA_ROOT="http://cvs.gna.org/viewcvs/*checkout*/wikipedia-el"
WIKIPEDIA_PATH="wikipedia-el/wikipedia.el?rev=HEAD&content-type=text/plain"
wikipedia.el:
	curl -o wikipedia.el $(WIKIPEDIA_ROOT)/$(WIKIPEDIA_PATH)
wikipedia-mode.el:
	curl -O $(EMACSWIKI_DOWNLOAD)/wikipedia-mode.el
wdired.el:
	curl -O $(EMACSWIKI_DOWNLOAD)/wdired.el

xterm-frobs.el:
	curl -O ftp://ftp.splode.com/pub/users/friedman/emacs-lisp/xterm-frobs.el
yaml-mode.el:
	curl -O https://raw.githubusercontent.com/yoshiki/yaml-mode/master/yaml-mode.el

