Makefile.in 7.29 KB
Newer Older
1 2
### @configure_input@

Paul Eggert's avatar
Paul Eggert committed
3
# Copyright (C) 2010-2017 Free Software Foundation, Inc.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

# This file is part of GNU Emacs.

# GNU Emacs is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# GNU Emacs is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.

20 21 22
### Commentary:

## Some targets:
23
## check: re-run all tests, writing to .log files.
24 25
## check-maybe: run all tests which are outdated with their .log file
## or the source files they are testing.
26
## filename.log: run tests from filename.el(c) if .log file needs updating
27
## filename: re-run tests from filename.el(c), with no logging
28 29 30

### Code:

31
SHELL = @SHELL@
32 33 34 35

srcdir = @srcdir@
VPATH = $(srcdir)

Paul Eggert's avatar
Paul Eggert committed
36
FIND_DELETE = @FIND_DELETE@
37 38
MKDIR_P = @MKDIR_P@

39
SEPCHAR = @SEPCHAR@
40

41 42 43
# We never change directory before running Emacs, so a relative file
# name is fine, and makes life easier.  If we need to change
# directory, we can use emacs --chdir.
44
EMACS = ../src/emacs
45

46 47
EMACS_EXTRAOPT=

48
# Command line flags for Emacs.
49 50
# Apparently MSYS bash would convert "-L :" to "-L ;" anyway,
# but we might as well be explicit.
51
EMACSOPT = -batch --no-site-file --no-site-lisp -L "$(SEPCHAR)$(srcdir)" $(EMACS_EXTRAOPT)
52

53
# Prevent any settings in the user environment causing problems.
54
unexport EMACSDATA EMACSDOC EMACSPATH GREP_OPTIONS
55

56 57 58
## To run tests under a debugger, set this to eg: "gdb --args".
GDB =

59 60 61 62 63
# The locale to run tests under.  Tests should work if this is set to
# any supported locale.  Use the C locale by default, as it should be
# supported everywhere.
TEST_LOCALE = C

64
# The actual Emacs command run in the targets below.
65
# Prevent any setting of EMACSLOADPATH in user environment causing problems.
66 67
emacs = EMACSLOADPATH= LC_ALL=$(TEST_LOCALE) \
 EMACS_TEST_DIRECTORY=$(abspath $(srcdir)) \
68
 $(GDB) "$(EMACS)" $(EMACSOPT)
69

70
.PHONY: all check
71

72
all: check
73

74
%.elc: %.el
75
	@echo Compiling $<
76 77 78 79
	@$(emacs) -f batch-byte-compile $<

## Ignore any test errors so we can continue to test other files.
## But compilation errors are always fatal.
Wolfgang Jenkner's avatar
Wolfgang Jenkner committed
80
WRITE_LOG = > $@ 2>&1 || { stat=ERROR; cat $@; }; echo $$stat: $@
81

82 83 84 85 86 87 88 89 90 91
## I'd prefer to use -emacs -f ert-run-tests-batch-and-exit rather
## than || true, since the former makes problems more obvious.
## I'd also prefer to @-hide the grep part and not the
## ert-run-tests-batch-and-exit part.
##
## We need to use $loadfile because:
## i) -L :$srcdir -l basename does not work, because we have files whose
## basename duplicates a file in lisp/ (eg eshell.el).
## ii) Although -l basename will automatically load .el or .elc,
## -l ./basename treats basename as a literal file (it would be nice
92
## to change this; bug#17848 - if that gets done, this can be simplified).
93
##
94
## Beware: it approximates 'no-byte-compile', so watch out for false-positives!
95 96
SELECTOR_DEFAULT = (quote (not (tag :expensive-test)))
SELECTOR_EXPENSIVE = nil
Michael Albinus's avatar
Michael Albinus committed
97 98
ifdef SELECTOR
SELECTOR_ACTUAL=$(SELECTOR)
99 100 101 102
else ifndef MAKECMDGOALS
SELECTOR_ACTUAL=$(SELECTOR_DEFAULT)
else ifeq ($(MAKECMDGOALS),all)
SELECTOR_ACTUAL=$(SELECTOR_DEFAULT)
Michael Albinus's avatar
Michael Albinus committed
103 104 105
else ifeq ($(MAKECMDGOALS),check)
SELECTOR_ACTUAL=$(SELECTOR_DEFAULT)
else ifeq ($(MAKECMDGOALS),check-maybe)
106 107
SELECTOR_ACTUAL=$(SELECTOR_DEFAULT)
else
Michael Albinus's avatar
Michael Albinus committed
108
SELECTOR_ACTUAL=$(SELECTOR_EXPENSIVE)
109 110
endif

111 112 113
## Byte-compile all test files to test for errors (unless explicitly
## told not to), but then evaluate the un-byte-compiled files, because
## they give cleaner stacktraces.
114

115
## Beware: it approximates 'no-byte-compile', so watch out for false-positives!
116
%.log: %.el
117 118 119
	elc=$<c; \
	if ! grep '^;.*no-byte-compile: t' $< > /dev/null; then \
	  ${MAKE} $$elc; \
120
	fi; \
121
	loadfile=$<; \
122 123
	echo Testing $$loadfile; \
	stat=OK ; \
124
	${MKDIR_P} $(dir $@) ; \
125
	HOME=/nonexistent $(emacs) -l ert -l $$loadfile \
126
	  --eval "(ert-run-tests-batch-and-exit ${SELECTOR_ACTUAL})" ${WRITE_LOG}
127

128 129 130 131 132 133
ifeq (@HAVE_MODULES@, yes)
maybe_exclude_module_tests :=
else
maybe_exclude_module_tests := -name emacs-module-tests.el -prune -o
endif

134
ELFILES := $(shell find ${srcdir} -path "${srcdir}/manual" -prune -o \
Glenn Morris's avatar
Glenn Morris committed
135
		-path "${srcdir}/data" -prune -o \
136 137
		-name "*resources" -prune -o \
		${maybe_exclude_module_tests} \
138
		-name "*.el" ! -name ".*" -print)
Paul Eggert's avatar
Paul Eggert committed
139
## .log files may be in a different directory for out of source builds
140
LOGFILES := $(patsubst %.el,%.log, \
141 142
		$(patsubst $(srcdir)/%,%,$(ELFILES)))
TESTS := $(LOGFILES:.log=)
143 144 145 146 147

## If we have to interrupt a hanging test, preserve the log so we can
## see what the problem was.
.PRECIOUS: %.log

148 149 150
.PHONY: ${TESTS}

define test_template
151 152 153 154 155 156 157 158
  ## A test FOO-tests depends on the source file with the similar
  ## name, unless FOO itself contains the string '-tests/'.
  ## The similar name is FOO.c if FOO begins with 'src/', FOO.el
  ## otherwise.  Although this heuristic does not identify all the
  ## dependencies, it is better than nothing.
  ifeq (,$(patsubst %-tests,,$(1))$(findstring -tests/,$(1)))
    $(1).log: $(patsubst %-tests,$(srcdir)/../%,$(1))$(if \
					$(patsubst src/%,,$(1)),.el,.c)
159
  endif
160

161 162 163 164 165 166 167
  ## Short aliases that always re-run the tests, with no logging.
  ## Define both with and without the directory name for ease of use.
  .PHONY: $(1) $(notdir $(1))
  $(1):
	@test ! -f $(1).log || mv $(1).log $(1).log~
	@$(MAKE) $(1).log WRITE_LOG=
  $(notdir $(1)): $(1)
168 169 170 171
endef

$(foreach test,${TESTS},$(eval $(call test_template,${test})))

172 173 174 175 176 177 178 179 180
ifeq (@HAVE_MODULES@, yes)
test_module_dir := $(srcdir)/data/emacs-module
test_module_name := mod-test@MODULES_SUFFIX@
test_module := $(test_module_dir)/$(test_module_name)
$(srcdir)/src/emacs-module-tests.log: $(test_module)
$(test_module): $(srcdir)/../src/emacs-module.[ch]
	$(MAKE) -C $(test_module_dir) $(test_module_name) SO=@MODULES_SUFFIX@
endif

Paul Eggert's avatar
Paul Eggert committed
181 182 183 184 185 186 187
## Check that there is no 'automated' subdirectory, which would
## indicate an incomplete merge from an older version of Emacs where
## the tests were arranged differently.
.PHONY: check-no-automated-subdir
check-no-automated-subdir:
	test ! -d $(srcdir)/automated

188
## Rerun all default tests.
Paul Eggert's avatar
Paul Eggert committed
189
check: mostlyclean check-no-automated-subdir
190
	@${MAKE} check-doit SELECTOR="${SELECTOR_ACTUAL}"
191

192
## Rerun all default and expensive tests.
193
.PHONY: check-expensive
Paul Eggert's avatar
Paul Eggert committed
194
check-expensive: mostlyclean check-no-automated-subdir
195 196
	@${MAKE} check-doit SELECTOR="${SELECTOR_EXPENSIVE}"

197 198
## Re-run all tests which are outdated. A test is outdated if its
## logfile is out-of-date with either the test file, or the source
199
## files that the tests depend on.  See test_template.
200
.PHONY: check-maybe
Paul Eggert's avatar
Paul Eggert committed
201
check-maybe: check-no-automated-subdir
202
	@${MAKE} check-doit SELECTOR="${SELECTOR_ACTUAL}"
203 204 205 206

## Run the tests.
.PHONY: check-doit
check-doit: ${LOGFILES}
207
	@$(emacs) -l ert -f ert-summarize-tests-batch-and-exit $^
208 209 210

.PHONY: mostlyclean clean bootstrap-clean distclean maintainer-clean

211
mostlyclean:
212
	-@for f in ${LOGFILES}; do test ! -f $$f || mv $$f $$f~; done
213
	rm -f *.tmp
214 215

clean:
Paul Eggert's avatar
Paul Eggert committed
216
	find . '(' -name '*.log' -o -name '*.log~' ')' $(FIND_DELETE)
217 218

bootstrap-clean: clean
Paul Eggert's avatar
Paul Eggert committed
219
	find $(srcdir) -name '*.elc' $(FIND_DELETE)
220 221

distclean: clean
222
	rm -f Makefile
223 224

maintainer-clean: distclean bootstrap-clean