Makefile 7.83 KB
Newer Older
Roland Walker's avatar
Roland Walker committed
1 2 3 4 5 6 7 8
EMACS=emacs
# EMACS=/Applications/Emacs.app/Contents/MacOS/Emacs
# EMACS=/Applications/Emacs23.app/Contents/MacOS/Emacs
# EMACS=/Applications/Aquamacs.app/Contents/MacOS/Aquamacs
# EMACS=/Applications/Macmacs.app/Contents/MacOS/Emacs
# EMACS=/usr/local/bin/emacs
# EMACS=/opt/local/bin/emacs
# EMACS=/usr/bin/emacs
9 10 11 12 13 14 15

INTERACTIVE_EMACS=/usr/local/bin/emacs
# can't find an OS X variant that works correctly for interactive tests:
# INTERACTIVE_EMACS=open -a Emacs.app --new --args
# INTERACTIVE_EMACS=/Applications/Emacs.app/Contents/MacOS/Emacs
# INTERACTIVE_EMACS=/Applications/Emacs.app/Contents/MacOS/bin/emacs

16 17 18
RESOLVED_EMACS=$(shell readlink `which $(EMACS)` || echo "$(EMACS)")
RESOLVED_INTERACTIVE_EMACS=$(shell readlink `which "$(INTERACTIVE_EMACS)"` || echo "$(INTERACTIVE_EMACS)")

19 20
EMACS_CLEAN=-Q
EMACS_BATCH=$(EMACS_CLEAN) --batch
Roland Walker's avatar
Roland Walker committed
21
# TESTS can be overridden to specify a subset of tests
22
TESTS=
23
WIKI_USERNAME=roland.walker
Roland Walker's avatar
Roland Walker committed
24

25
CURL=curl --location --silent
26
EDITOR=runemacs -no_wait
27
WORK_DIR=$(shell pwd)
Roland Walker's avatar
Roland Walker committed
28
# overriding PACKAGE_NAME can be useful for run-pristine, run-pristine-local, upload-wiki
29
PACKAGE_NAME=$(shell basename $(WORK_DIR))
30
PACKAGE_VERSION=$(shell perl -ne 'print "$$1\n" if m{^;+ *Version: *(\S+)}' $(PACKAGE_NAME).el)
31
AUTOLOADS_FILE=$(PACKAGE_NAME)-autoloads.el
Roland Walker's avatar
Roland Walker committed
32
TRAVIS_FILE=.travis.yml
33 34
TEST_DIR=ert-tests
TEST_DEP_1=ert
Roland Walker's avatar
Roland Walker committed
35 36
TEST_DEP_1_STABLE_URL=http://git.savannah.gnu.org/cgit/emacs.git/plain/lisp/emacs-lisp/ert.el?h=emacs-24.3
TEST_DEP_1_LATEST_URL=http://git.savannah.gnu.org/cgit/emacs.git/plain/lisp/emacs-lisp/ert.el?h=master
37

38 39 40 41 42
.PHONY : build dist not-dirty pkg-version downloads downloads-latest autoloads \
 test-autoloads test-travis test test-prep test-batch test-interactive         \
 test-tests clean edit run-pristine run-pristine-local upload-github           \
 upload-wiki upload-marmalade test-dep-1 test-dep-2 test-dep-3 test-dep-4      \
 test-dep-5 test-dep-6 test-dep-7 test-dep-8 test-dep-9
43

Roland Walker's avatar
Roland Walker committed
44
build :
45
	$(RESOLVED_EMACS) $(EMACS_BATCH) --eval    \
46 47 48
	    "(progn                                \
	      (setq byte-compile-error-on-warn t)  \
	      (batch-byte-compile))" *.el
Roland Walker's avatar
Roland Walker committed
49

50
not-dirty :
Roland Walker's avatar
Roland Walker committed
51 52 53
	@git diff --quiet '$(PACKAGE_NAME).el'     || \
	 ( git --no-pager diff '$(PACKAGE_NAME).el';  \
	   echo "Uncommitted edits - do a git stash"; \
54 55 56 57 58 59
	   false )

pkg-version :
	@test -n '$(PACKAGE_VERSION)'    || \
	 ( echo "No package version"; false )

60
test-dep-1 :
Roland Walker's avatar
Roland Walker committed
61 62
	@cd '$(TEST_DIR)'                                               && \
	$(RESOLVED_EMACS) $(EMACS_BATCH)  -L . -L .. -l '$(TEST_DEP_1)' || \
63 64 65
	(echo "Can't load test dependency $(TEST_DEP_1).el, run 'make downloads' to fetch it" ; exit 1)

downloads :
Roland Walker's avatar
Roland Walker committed
66
	$(CURL) '$(TEST_DEP_1_STABLE_URL)' > '$(TEST_DIR)/$(TEST_DEP_1).el'
67 68

downloads-latest :
Roland Walker's avatar
Roland Walker committed
69
	$(CURL) '$(TEST_DEP_1_LATEST_URL)' > '$(TEST_DIR)/$(TEST_DEP_1).el'
Roland Walker's avatar
Roland Walker committed
70

71
autoloads :
72
	$(RESOLVED_EMACS) $(EMACS_BATCH) --eval              \
73 74 75 76 77
	    "(progn                                          \
	      (setq generated-autoload-file \"$(WORK_DIR)/$(AUTOLOADS_FILE)\") \
	      (update-directory-autoloads \"$(WORK_DIR)\"))"

test-autoloads : autoloads
Roland Walker's avatar
Roland Walker committed
78
	@$(RESOLVED_EMACS) $(EMACS_BATCH) -L . -l './$(AUTOLOADS_FILE)' || \
79
	 ( echo "failed to load autoloads: $(AUTOLOADS_FILE)" && false )
80

Roland Walker's avatar
Roland Walker committed
81
test-travis :
Roland Walker's avatar
Roland Walker committed
82
	@if test -z "$$TRAVIS" && test -e '$(TRAVIS_FILE)'; then travis-lint '$(TRAVIS_FILE)'; fi
Roland Walker's avatar
Roland Walker committed
83

84
test-tests :
Roland Walker's avatar
Roland Walker committed
85
	@perl -ne 'if (m/^\s*\(\s*ert-deftest\s*(\S+)/) {die "$$1 test name duplicated in $$ARGV\n" if $$dupes{$$1}++}' '$(TEST_DIR)/'*-test.el
86 87

test-prep : build test-dep-1 test-autoloads test-travis test-tests
88 89

test-batch :
Roland Walker's avatar
Roland Walker committed
90
	@cd '$(TEST_DIR)'                                 && \
91
	(for test_lib in *-test.el; do                       \
92
	   $(RESOLVED_EMACS) $(EMACS_BATCH) -L . -L .. -l cl \
Roland Walker's avatar
Roland Walker committed
93
	   -l '$(TEST_DEP_1)' -l "$$test_lib" --eval         \
94 95 96
	    "(progn                                          \
	      (fset 'ert--print-backtrace 'ignore)           \
	      (ert-run-tests-batch-and-exit '(and \"$(TESTS)\" (not (tag :interactive)))))" || exit 1; \
97
	done)
98

99
test-interactive : test-prep
Roland Walker's avatar
Roland Walker committed
100
	@cd '$(TEST_DIR)'                                             && \
101
	(for test_lib in *-test.el; do                                   \
102
	    $(RESOLVED_INTERACTIVE_EMACS) $(EMACS_CLEAN) --eval          \
103 104 105
	    "(progn                                                      \
	      (cd \"$(WORK_DIR)/$(TEST_DIR)\")                           \
	      (setq dired-use-ls-dired nil)                              \
106
	      (setq frame-title-format \"TEST SESSION $$test_lib\")      \
107
	      (setq enable-local-variables :safe))"                      \
Roland Walker's avatar
Roland Walker committed
108 109
	    -L . -L .. -l cl -l '$(TEST_DEP_1)' -l "$$test_lib"          \
	    --visit "$$test_lib" --eval                                  \
110 111 112 113 114 115 116 117 118 119 120 121 122
	    "(progn                                                      \
	      (when (> (length \"$(TESTS)\") 0)                          \
	       (push \"\\\"$(TESTS)\\\"\" ert--selector-history))        \
	      (setq buffer-read-only t)                                  \
	      (setq cursor-in-echo-area t)                               \
	      (call-interactively 'ert-run-tests-interactively)          \
	      (ding)                                                     \
	      (when (y-or-n-p \"PRESS Y TO QUIT THIS TEST SESSION\")     \
	       (with-current-buffer \"*ert*\"                            \
	        (kill-emacs                                              \
	         (if (re-search-forward \"^Failed:[^\\n]+unexpected\" 500 t) 1 0)))))" || exit 1; \
	done)

123 124
test : test-prep test-batch

125
run-pristine :
Roland Walker's avatar
Roland Walker committed
126
	@cd '$(TEST_DIR)'                                              && \
127 128 129 130 131 132 133 134 135 136
	$(RESOLVED_EMACS) $(EMACS_CLEAN) --eval                           \
	 "(progn                                                          \
	   (setq package-enable-at-startup nil)                           \
	   (setq package-load-list nil)                                   \
	   (when (fboundp 'package-initialize)                            \
	    (package-initialize))                                         \
	   (cd \"$(WORK_DIR)/$(TEST_DIR)\")                               \
	   (setq dired-use-ls-dired nil)                                  \
	   (setq frame-title-format \"PRISTINE SESSION $(PACKAGE_NAME)\") \
	   (setq enable-local-variables :safe))"                          \
Roland Walker's avatar
Roland Walker committed
137
	 -L .. -l '$(PACKAGE_NAME)' .
138 139

run-pristine-local :
Roland Walker's avatar
Roland Walker committed
140
	@cd '$(TEST_DIR)'                                              && \
141 142 143 144 145 146
	$(RESOLVED_EMACS) $(EMACS_CLEAN) --eval                           \
	 "(progn                                                          \
	   (cd \"$(WORK_DIR)/$(TEST_DIR)\")                               \
	   (setq dired-use-ls-dired nil)                                  \
	   (setq frame-title-format \"PRISTINE-LOCAL SESSION $(PACKAGE_NAME)\") \
	   (setq enable-local-variables :safe))"                          \
Roland Walker's avatar
Roland Walker committed
147
	 -L . -L .. -l '$(PACKAGE_NAME)' .
148

Roland Walker's avatar
Roland Walker committed
149
clean :
Roland Walker's avatar
Roland Walker committed
150 151
	@rm -f '$(AUTOLOADS_FILE)' *.elc *~ */*.elc */*~ .DS_Store */.DS_Store *.bak */*.bak && \
	cd '$(TEST_DIR)'                                                                     && \
152
	rm -f './$(TEST_DEP_1).el' './$(TEST_DEP_2).el' './$(TEST_DEP_3).el' './$(TEST_DEP_4).el' './$(TEST_DEP_5a).el' \
Roland Walker's avatar
Roland Walker committed
153
	      './$(TEST_DEP_5).el' './$(TEST_DEP_6).el' './$(TEST_DEP_7).el' './$(TEST_DEP_8).el' './$(TEST_DEP_9).el'
154 155 156

edit :
	@$(EDITOR) `git ls-files`
157 158 159 160

upload-github :
	@git push origin master

161
upload-wiki : not-dirty
162 163 164 165 166 167 168 169 170 171 172 173 174
	@$(RESOLVED_EMACS) $(EMACS_BATCH) --eval          \
	 "(progn                                          \
	   (setq package-load-list '((yaoddmuse t)))      \
	   (when (fboundp 'package-initialize)            \
	    (package-initialize))                         \
	   (require 'yaoddmuse)                           \
	   (setq yaoddmuse-username \"$(WIKI_USERNAME)\") \
	   (yaoddmuse-post-file                           \
	    \"$(PACKAGE_NAME).el\"                        \
	    yaoddmuse-default-wiki                        \
	    \"$(PACKAGE_NAME).el\"                        \
	    \"updated version\") \
	   (sleep-for 5))"