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

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

# 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
18
# along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
19 20 21 22 23 24 25 26 27 28 29 30 31 32

### Commentary:

# make all	to compile and build Emacs.
# make install	to install it.
# make TAGS	to update tags tables.
#
# make clean  or  make mostlyclean
#      Delete all files from the current directory that are normally
#      created by building the program.	 Don't delete the files that
#      record the configuration.  Also preserve files that could be made
#      by building, but normally aren't because the distribution comes
#      with them.
#
33
#      Delete '.dvi' files here if they are not part of the distribution.
34 35 36 37 38
#
# make distclean
#      Delete all files from the current directory that are created by
#      configuring or building the program.  If you have unpacked the
#      source and built the program without creating any other files,
39
#      'make distclean' should leave only the files that were in the
40 41 42 43 44 45 46 47 48 49 50
#      distribution.
#
# make maintainer-clean
#      Delete everything from the current directory that can be
#      reconstructed with this Makefile.  This typically includes
#      everything deleted by distclean, plus more: .elc files,
#      C source files produced by Bison, tags tables, info files,
#      and so on.
#
# make extraclean
#      Still more severe - delete backup and autosave files, too.
51 52
#      Also generated files that do not normally change and can be slow
#      to rebuild (eg leim/ja-dic).
53 54 55 56
#
# make bootstrap
#      Removes all the compiled files to force a new bootstrap from a
#      clean slate, and then build in the normal way.
57 58 59
#
# make docs
#      Make Emacs documentation files from their sources; requires makeinfo.
60
#
61 62 63 64 65
# make check (or check-expensive or check-all)
#      Run the Emacs test suite.
#      check-expensive includes additional tests that can be slow.
#      check-all runs all tests, including ones that can be slow, or
#        fail unpredictably
66

67
SHELL = @SHELL@
68

Daniel Colascione's avatar
Daniel Colascione committed
69 70
DUMPING=@DUMPING@

Glenn Morris's avatar
Glenn Morris committed
71 72
# This only matters when inheriting a CDPATH not starting with the
# current directory.
73 74
CDPATH=

75
# ==================== Things 'configure' Might Edit ====================
76

77
cache_file = @cache_file@
78
CONFIGURE_FLAGS = --cache-file=$(cache_file)
79

80
AWK = @AWK@
81

82 83 84 85 86 87
EXEEXT=@EXEEXT@

### These help us choose version- and architecture-specific directories
### to install files in.

### This should be the number of the Emacs version we're building,
88
### like '24.5' or '25.0.50'.
89 90 91
version=@version@

### This should be the name of the configuration we're building Emacs
92
### for, like 'x86_64-unknown-linux-gnu' or 'powerpc-ibm-aix7.1.2.0'.
93 94
configuration=@configuration@

95 96 97
### The nt/ subdirectory gets built only for MinGW
NTDIR=@NTDIR@

Paul Eggert's avatar
Paul Eggert committed
98 99 100 101 102 103 104 105 106 107 108 109 110
# 'make' verbosity.
AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@

AM_V_GEN = $(am__v_GEN_@AM_V@)
am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
am__v_GEN_0 = @echo "  GEN     " $@;
am__v_GEN_1 =

AM_V_at = $(am__v_at_@AM_V@)
am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
am__v_at_0 = @
am__v_at_1 =

111 112
# ==================== Where To Install Things ====================

113
# Location to install Emacs.app under GNUstep / macOS.
114 115 116
# Later values may use these.
ns_appbindir=@ns_appbindir@
ns_appresdir=@ns_appresdir@
117 118
# Either yes or no depending on whether this is a relocatable Emacs.app.
ns_self_contained=@ns_self_contained@
119

120 121 122 123 124 125
# The default location for installation.  Everything is placed in
# subdirectories of this directory.  The default values for many of
# the variables below are expressed in terms of this one, so you may
# not need to change them.  This defaults to /usr/local.
prefix=@prefix@

126
# Like 'prefix', but used for architecture-specific files.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
exec_prefix=@exec_prefix@

# Where to install Emacs and other binaries that people will want to
# run directly (like etags).
bindir=@bindir@

# The root of the directory tree for read-only architecture-independent
# data files.  ${datadir}, ${infodir} and ${mandir} are based on this.
datarootdir=@datarootdir@

# Where to install architecture-independent data files.	 ${lispdir}
# and ${etcdir} are subdirectories of this.
datadir=@datadir@

# Where to install and expect the files that Emacs modifies as it
# runs.  These files are all architecture-independent.
# Right now, this is not used.
sharedstatedir=@sharedstatedir@

# Where to install and expect executable files to be run by Emacs
147 148 149 150
# rather than directly by users (and other architecture-dependent
# data, although Emacs does not have any).  The executables
# are actually installed in ${archlibdir}, which is (normally)
# a subdirectory of this.
151 152
libexecdir=@libexecdir@

153 154 155
# Currently only used for the systemd service file.
libdir=@libdir@

156 157 158
# Where to install emacs-module.h.
includedir=@includedir@

159
# Where to install Emacs's man pages.
160
# Note they contain cross-references that expect them to be in section 1.
161 162 163
mandir=@mandir@
man1dir=$(mandir)/man1

164
# Where to install and expect the info files describing Emacs.
165
infodir=@infodir@
166
# Info files not in the doc/misc directory (we get those via make echo-info).
167
INFO_NONMISC=emacs.info eintr.info elisp.info
168

169 170 171
# If no makeinfo was found and configured --without-makeinfo, "no"; else "yes".
HAVE_MAKEINFO=@HAVE_MAKEINFO@

172 173 174 175 176 177 178 179 180
# Directory for local state files for all programs.
localstatedir=@localstatedir@

# Where to look for bitmap files.
bitmapdir=@bitmapdir@

# Where to find the source code.  The source code for Emacs's C kernel is
# expected to be in ${srcdir}/src, and the source code for Emacs's
# utility programs is expected to be in ${srcdir}/lib-src.  This is
181
# set by the configure script's '--srcdir' option.
182 183 184

# We use $(srcdir) explicitly in dependencies so as not to depend on VPATH.
srcdir=@srcdir@
185
abs_srcdir=@abs_srcdir@
186 187 188 189 190 191 192 193 194 195 196 197 198

# Where the manpage source files are kept.
mansrcdir=$(srcdir)/doc/man

# Tell make where to find source files; this is needed for the makefiles.
VPATH=@srcdir@

# Where to find the application default.
x_default_search_path=@x_default_search_path@

# Where the etc/emacs.desktop file is to be installed.
desktopdir=$(datarootdir)/applications

199
# Where the etc/emacs.appdata.xml file is to be installed.
200
appdatadir=$(datarootdir)/metainfo
201

202 203 204 205 206 207 208 209 210 211 212
# Where the etc/emacs.service file is to be installed.
# The system value (typically /usr/lib/systemd/user) can be
# obtained with: pkg-config --variable=systemduserunitdir systemd
# but that does not respect configure's prefix.
# It is not clear where we should install this file when
# prefix != /usr (or /usr/local?) (eg for non-root installs).
# Other options include ~/.config/systemd/user/,
# $XDG_RUNTIME_DIR/systemd/user/
# It seems the user may end up having to make a manual link...
systemdunitdir=$(libdir)/systemd/user

213 214 215 216 217 218 219 220 221 222 223
# Where the etc/images/icons/hicolor directory is to be installed.
icondir=$(datarootdir)/icons

# The source directory for the icon files.
iconsrcdir=$(srcdir)/etc/images/icons

# ==================== Emacs-specific directories ====================

# These variables hold the values Emacs will actually use.  They are
# based on the values of the standard Make variables above.

224 225 226
# Where to install the lisp files distributed with Emacs.
# This includes the Emacs version, so that the lisp files for different
# versions of Emacs will install themselves in separate directories.
227 228
lispdir=@lispdir@

229
# Directories Emacs should search for standard lisp files.
230
# The default is ${lispdir}.
231 232 233 234 235
standardlisppath=@standardlisppath@

# Directories Emacs should search for lisp files specific to this
# site (i.e. customizations), before consulting ${standardlisppath}.
# This should be a colon-separated list of directories.
236 237 238 239 240 241
locallisppath=@locallisppath@

# Where Emacs will search to find its lisp files.  Before
# changing this, check to see if your purpose wouldn't
# better be served by changing locallisppath.  This
# should be a colon-separated list of directories.
242
# The default is ${locallisppath}:${standardlisppath}.
243 244
lisppath=@lisppath@

Glenn Morris's avatar
Glenn Morris committed
245 246 247 248
# Where Emacs will search for its lisp files while building.
# This is only used during the process of compiling Emacs,
# to help Emacs find its lisp files before they've been installed
# in their final location.
249
# This should be a colon-separated list of directories.
250
# Normally it points to the lisp/ directory in the sources.
Glenn Morris's avatar
Glenn Morris committed
251
# NB lread.c relies on lisp/ being first here.
252
buildlisppath=${abs_srcdir}/lisp
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268

# Where to install the other architecture-independent
# data files distributed with Emacs (like the tutorial,
# the cookie recipes and the Zippy database). This path
# usually contains the Emacs version number, so the data
# files for multiple versions of Emacs may be installed
# at once.
etcdir=@etcdir@

# Where to put executables to be run by Emacs rather than
# the user.  This path usually includes the Emacs version
# and configuration name, so that multiple configurations
# for multiple versions of Emacs may be installed at
# once.
archlibdir=@archlibdir@

269 270
# Where to put the etc/DOC file.
etcdocdir=@etcdocdir@
271

272 273 274 275 276 277
# User or group of the auxiliary program update-game-score, which is
# installed on platforms with a game directory shared by multiple users.
# On other platforms Emacs can update the score files itself.
gameuser=@gameuser@
gamegroup=@gamegroup@
# Where to install game score files, if gameuser or gamegroup is nonempty.
278
gamedir=@gamedir@
279 280
# Nonempty if and only if a shared gamedir is used.
use_gamedir=$(gameuser)$(gamegroup)
281 282 283 284

# ==================== Utility Programs for the Build ====================

# Allow the user to specify the install program.
285 286 287
# Note that if the system does not provide a suitable install,
# configure will use build-aux/install-sh.  Annoyingly, it does
# not use an absolute path.  So we must take care to always run
288
# INSTALL-type commands from the directory containing the Makefile.
289
# This explains (I think) the cd thisdir seen in several install rules.
290 291 292 293 294 295
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_INFO = @INSTALL_INFO@
# By default, we uphold the dignity of our programs.
INSTALL_STRIP =
296
MKDIR_P = @MKDIR_P@
297 298
# Create a link to a file in the same directory as the target.
LN_S_FILEONLY = @LN_S_FILEONLY@
299

300
# We use gzip to compress installed .el and some .txt files.
301 302 303 304 305 306 307 308
GZIP_PROG = @GZIP_PROG@

# ============================= Targets ==============================

# Program name transformation.
TRANSFORM = @program_transform_name@

# What emacs should be called when installed.
309 310
EMACS_NAME = `echo emacs | sed '$(TRANSFORM)'`
EMACS = ${EMACS_NAME}${EXEEXT}
311
EMACSFULL = `echo emacs-${version} | sed '$(TRANSFORM)'`${EXEEXT}
312

313
# Subdirectories to make recursively.
314
SUBDIR = $(NTDIR) lib lib-src src lisp
315 316

# The subdir makefiles created by config.status.
317
SUBDIR_MAKEFILES_IN = @SUBDIR_MAKEFILES_IN@
318
SUBDIR_MAKEFILES = $(patsubst ${srcdir}/%,%,${SUBDIR_MAKEFILES_IN:.in=})
319

320 321 322 323 324
# Non-makefile files created by config.status.
CONFIG_STATUS_FILES_IN = \
 ${srcdir}/nt/emacs.rc.in ${srcdir}/nt/emacsclient.rc.in \
 ${srcdir}/doc/man/emacs.1.in

325 326 327
# Subdirectories to install, and where they'll go.  lib-src's and nt's
# makefiles know how to install them, so we don't do that here.
# Directories that cannot simply be copied, eg info, are treated
328 329 330
# separately.
COPYDIR = ${srcdir}/etc ${srcdir}/lisp
COPYDESTS = "$(DESTDIR)${etcdir}" "$(DESTDIR)${lispdir}"
331

332
all: ${SUBDIR} info
333

334 335 336 337 338 339 340 341 342 343 344 345
.PHONY: all ${SUBDIR} blessmail epaths-force epaths-force-w32 etc-emacsver

# If configure were to just generate emacsver.tex from emacsver.tex.in
# in the normal way, the timestamp of emacsver.tex would always be
# newer than that of the pdf files, which are prebuilt in release tarfiles.
# So we use this rule, and move-if-change, to avoid that.
etc-emacsver:
	majorversion=`echo ${version} | sed 's/\..*//'`; \
	sed "s/[@]majorversion@/$${majorversion}/" \
	  ${srcdir}/etc/refcards/emacsver.tex.in > emacsver.tex.$$$$ && \
	  ${srcdir}/build-aux/move-if-change emacsver.tex.$$$$ \
	  ${srcdir}/etc/refcards/emacsver.tex
346

347 348 349
# The shared gamedir name as a C string literal, or a null ptr if not in use.
PATH_GAME = $(if $(use_gamedir),"$(gamedir)",((char const *) 0))

350
# Generate epaths.h from epaths.in.  This target is invoked by 'configure'.
351
# See comments in configure.ac for why it is done this way, as opposed
352 353
# to just letting configure generate epaths.h from epaths.in in a
# similar way to how Makefile is made from Makefile.in.
Paul Eggert's avatar
Paul Eggert committed
354
epaths-force:
355 356 357
	@for dir in '$(abs_srcdir)' '$(lispdir)' '$(archlibdir)'; do \
	  case $$dir in \
	    *:*) \
358
	      printf >&2 "Build or installation directory '%s'\\n" "$$dir"; \
359 360 361 362
	      echo >&2 "cannot contain ':'."; \
	      exit 1;; \
	  esac; \
	done
363
	@(gamedir='${gamedir}'; \
364
	  sed < ${srcdir}/src/epaths.in > epaths.h.$$$$		\
365 366 367 368 369
	  -e 's;\(#.*PATH_LOADSEARCH\).*$$;\1 "${standardlisppath}";' \
	  -e 's;\(#.*PATH_SITELOADSEARCH\).*$$;\1 "${locallisppath}";' \
	  -e 's;\(#.*PATH_DUMPLOADSEARCH\).*$$;\1 "${buildlisppath}";' \
	  -e '/^#define PATH_[^ ]*SEARCH /s/\([":]\):*/\1/g'		\
	  -e '/^#define PATH_[^ ]*SEARCH /s/:"/"/'			\
370 371 372 373 374
	  -e 's;\(#.*PATH_EXEC\).*$$;\1 "${archlibdir}";'		\
	  -e 's;\(#.*PATH_INFO\).*$$;\1 "${infodir}";'			\
	  -e 's;\(#.*PATH_DATA\).*$$;\1 "${etcdir}";'			\
	  -e 's;\(#.*PATH_BITMAPS\).*$$;\1 "${bitmapdir}";'		\
	  -e 's;\(#.*PATH_X_DEFAULTS\).*$$;\1 "${x_default_search_path}";' \
375
	  -e 's;\(#.*PATH_GAME\).*$$;\1 $(PATH_GAME);'			\
376
	  -e 's;\(#.*PATH_DOC\).*$$;\1 "${etcdocdir}";') &&		\
377
	${srcdir}/build-aux/move-if-change epaths.h.$$$$ src/epaths.h
378

379 380
# The w32 build needs a slightly different editing, and it uses
# nt/epaths.nt as the template.
381
#
382
# Use the value of ${locallisppath} supplied by 'configure',
383
# to support the --enable-locallisppath argument.
384
#
385 386 387 388
# In this case, the paths written to 'src/epaths.h' must be in native
# MS-Windows format (e.g. 'c:/foo/bar'), because temacs is a MinGW
# program that doesn't support MSYS-style paths (e.g. '/c/foo/bar' or
# '/foo/bar').
Paul Eggert's avatar
Paul Eggert committed
389
epaths-force-w32:
390
	@(w32srcdir=`${srcdir}/build-aux/msys-to-w32 "${abs_srcdir}"`; \
391
	  w32prefix=`${srcdir}/build-aux/msys-to-w32 "${prefix}"`; \
392 393
	  w32locallisppath=`${srcdir}/build-aux/msys-to-w32 "${locallisppath}"` ; \
	  w32locallisppath=$${w32locallisppath//$${w32prefix}/"%emacs_dir%"} ; \
394
	  sed < ${srcdir}/nt/epaths.nt > epaths.h.$$$$		\
395
	  -e 's;\(#.*PATH_SITELOADSEARCH\).*$$;\1 "'"$${w32locallisppath//;/\\;}"'";' \
396 397 398 399 400
	  -e '/^.*#/s/@VER@/${version}/g' 			\
	  -e '/^.*#/s/@CFG@/${configuration}/g' 		\
	  -e "/^.*#/s|@SRC@|$${w32srcdir}|g") &&		\
	${srcdir}/build-aux/move-if-change epaths.h.$$$$ src/epaths.h

401
lib-src src: $(NTDIR) lib
Paul Eggert's avatar
Paul Eggert committed
402

Paul Eggert's avatar
Paul Eggert committed
403
src: lib-src
404

405
# We need to build 'emacs' in 'src' to compile the *.elc files in 'lisp'.
406
lisp: src
407

408
# These targets should be "${SUBDIR} without 'src'".
Paul Eggert's avatar
Paul Eggert committed
409
lib lib-src lisp nt: Makefile
410
	$(MAKE) -C $@ all
411

Eric S. Raymond's avatar
Eric S. Raymond committed
412 413 414 415 416
# Ideally, VCSWITNESS should be a file that is modified whenever the
# repository registers a commit from either a local checkin or a
# repository pull. In git there is no single file that guarantees
# this, but the local log for the current head should be close enough.
#
417
# Pass an unexpanded $srcdir to src's Makefile, which then
Glenn Morris's avatar
Glenn Morris committed
418 419
# expands it using its own value of srcdir (which points to the
# source directory of src/).
420 421
dirstate = .git/logs/HEAD
VCSWITNESS = $(if $(wildcard $(srcdir)/$(dirstate)),$$(srcdir)/../$(dirstate))
Paul Eggert's avatar
Paul Eggert committed
422
src: Makefile
423
	$(MAKE) -C $@ VCSWITNESS='$(VCSWITNESS)' all
424

Paul Eggert's avatar
Paul Eggert committed
425
blessmail: Makefile src
426
	$(MAKE) -C lib-src maybe-blessmail
427 428

# We used to have one rule per */Makefile.in, but that leads to race
Paul Eggert's avatar
Paul Eggert committed
429 430 431 432
# conditions with parallel makes, so assume that the timestamp on
# ./Makefile represents the timestamp on all the other Makefiles.
# Similarly, assume the timestamp on ./configure represents the
# timestamp on src/config.in.
433 434 435 436
#
# config.status overrides MAKEFILE_NAME with a bogus name when creating
# src/epaths.h, so that 'make epaths-force' does not recursively invoke
# config.status and overwrite config.status while executing it (Bug#11214).
437 438 439 440
#
# 'make bootstrap' overrides MAKEFILE_NAME to a nonexistent file but
# then attempts to build that file.  This forces 'Makefile', 'lib/Makefile',
# etc. to be built without running into similar recursion problems.
441
MAKEFILE_NAME = Makefile
Paul Eggert's avatar
Paul Eggert committed
442
$(MAKEFILE_NAME): config.status $(srcdir)/configure \
Paul Eggert's avatar
Paul Eggert committed
443
	 $(srcdir)/lib/gnulib.mk.in \
444
         $(srcdir)/Makefile.in $(SUBDIR_MAKEFILES_IN) $(CONFIG_STATUS_FILES_IN)
445
	MAKE='$(MAKE)' ./config.status
446

447 448
# Don't erase these files if make is interrupted while refreshing them.
.PRECIOUS: Makefile config.status
449

450
config.status: ${srcdir}/configure
451
	if [ -x ./config.status ]; then	\
452
	    $(CFG) ./config.status --recheck;	\
453
	else				\
454
	    $(CFG) $(srcdir)/configure $(CONFIGURE_FLAGS); \
455
	fi
456

Paul Eggert's avatar
Paul Eggert committed
457
$(srcdir)/configure: $(srcdir)/configure.ac $(srcdir)/m4/*.m4
458
	cd $(srcdir) && ./autogen.sh autoconf
459 460 461

# ==================== Installation ====================

462
.PHONY: install install-arch-dep install-arch-indep install-etcdoc install-info
463 464
.PHONY: install-man install-etc install-strip install-$(NTDIR)
.PHONY: uninstall uninstall-$(NTDIR)
465

466 467 468 469
## If we let lib-src do its own installation, that means we
## don't have to duplicate the list of utilities to install in
## this Makefile as well.

470
install: all install-arch-indep install-etcdoc install-arch-dep install-$(NTDIR) blessmail
471 472
	@true

473
## Ensure that $subdir contains a subdirs.el file.
474 475 476 477
## Here and elsewhere, we set the umask so that any created files are
## world-readable.
## TODO it might be good to warn about non-standard permissions of
## pre-existing directories, but that does not seem easy.
478
write_subdir=if [ -f "$${subdir}/subdirs.el" ]; \
479 480
	then true; \
	else \
481
	  umask 022; \
482
	  ${MKDIR_P} "$${subdir}"; \
483 484
	  (echo "(if (fboundp 'normal-top-level-add-subdirs-to-load-path)"; \
	   echo "    (normal-top-level-add-subdirs-to-load-path))") \
485
	    > "$${subdir}/subdirs.el"; \
486
	fi
487

488
### Install the executables that were compiled specifically for this machine.
489 490
### We do install-arch-indep first because the executable needs the
### Lisp files and DOC file to work properly.
491
install-arch-dep: src install-arch-indep install-etcdoc install-$(NTDIR)
492
	umask 022; ${MKDIR_P} "$(DESTDIR)${bindir}"
493
	$(MAKE) -C lib-src install
494 495
ifeq (${ns_self_contained},no)
	${INSTALL_PROGRAM} $(INSTALL_STRIP) src/emacs${EXEEXT} "$(DESTDIR)${bindir}/$(EMACSFULL)"
Daniel Colascione's avatar
Daniel Colascione committed
496 497 498
ifeq (${DUMPING},pdumper)
	${INSTALL_DATA} src/emacs.pdmp "$(DESTDIR)${libexecdir}/emacs/${version}/${configuration}"/emacs.pdmp
endif
499
	-chmod 755 "$(DESTDIR)${bindir}/$(EMACSFULL)"
500 501
ifndef NO_BIN_LINK
	rm -f "$(DESTDIR)${bindir}/$(EMACS)"
502
	cd "$(DESTDIR)${bindir}" && $(LN_S_FILEONLY) "$(EMACSFULL)" "$(EMACS)"
503 504 505 506 507
endif
else
	subdir=${ns_appresdir}/site-lisp && ${write_subdir}
	rm -rf ${ns_appresdir}/share
endif
508 509 510 511 512

### Windows-specific install target for installing programs produced
### in nt/, and its Posix do-nothing shadow.
install-:
install-nt:
513
	$(MAKE) -C $(NTDIR) install
514

515
## In the share directory, we are deleting:
516 517
## applications (with emacs.desktop, also found in etc/)
## emacs (basically empty except for unneeded site-lisp directories)
518 519
## icons (duplicates etc/images/icons/hicolor)

Glenn Morris's avatar
Glenn Morris committed
520 521 522 523
## This is install-etc for everything except self-contained-ns builds.
## For them, it is empty.
INSTALL_ARCH_INDEP_EXTRA = @INSTALL_ARCH_INDEP_EXTRA@

524
## https://lists.gnu.org/r/emacs-devel/2007-10/msg01672.html
525 526
## Needs to be the user running install, so configure can't set it.
set_installuser=for installuser in $${LOGNAME} $${USERNAME} $${USER} \
Paul Eggert's avatar
Paul Eggert committed
527
	  `(id -u) 2> /dev/null`; do \
528
	  [ -n "$${installuser}" ] && break ; \
Paul Eggert's avatar
Paul Eggert committed
529 530 531
	done; \
	installgroup=`(id -g) 2>/dev/null` && [ -n "$$installgroup" ] && \
	  installuser=$$installuser:$$installgroup
532 533

### Install the files that are machine-independent.
534 535
### Most of them come straight from the distribution; the exception is
### the DOC file, which is copied from the build directory.
536

537 538 539 540 541
## We delete each directory in ${COPYDESTS} before we copy into it;
## that way, we can reinstall over directories that have been put in
## place with their files read-only (perhaps because they are checked
## into RCS).  In order to make this safe, we make sure that the
## source exists and is distinct from the destination.
542

543 544 545
## We delete etc/DOC* because there may be irrelevant DOC files from
## other builds in the source directory.  This is ok because we just
## deleted the entire installed etc/ directory and recreated it.
546
## install-etcdoc installs the relevant DOC.
547

548 549 550 551 552
## Note that we install etc/refcards/*.ps if present.
## TODO we should compress these if GZIP_PROG is set.
## It would be simpler to have a separate install rule for etc/refcards
## (maybe move it to doc/refcards?).

553 554 555
## Note that the Makefiles in the etc directory are potentially useful
## in an installed Emacs, so should not be excluded.

Glenn Morris's avatar
Glenn Morris committed
556 557 558 559 560 561
## We always create the _default_ locallisppath directories, and
## ensure that they contain a subdirs.el file (via write_subdir).
## This is true even if locallisppath has a non-default value.
## In case of non-default value, we used to create the specified directories,
## but not add subdirs.el to them.  This was a strange halfway house.
## Nowadays we do not create non-default directories.
Glenn Morris's avatar
Glenn Morris committed
562 563 564

## Note that we use tar instead of plain old cp -R/-r because the latter
## is apparently not portable (even in 2012!).
565
## https://lists.gnu.org/r/emacs-devel/2012-05/msg00278.html
Glenn Morris's avatar
Glenn Morris committed
566 567
## I have no idea which platforms Emacs supports where cp -R does not
## work correctly, and therefore no idea when tar can be replaced.
Glenn Morris's avatar
Glenn Morris committed
568
## See also these comments from 2004 about cp -r working fine:
569
## https://lists.gnu.org/r/autoconf-patches/2004-11/msg00005.html
570
install-arch-indep: lisp install-info install-man ${INSTALL_ARCH_INDEP_EXTRA}
571 572
	umask 022 && $(MKDIR_P) "$(DESTDIR)$(includedir)"
	$(INSTALL_DATA) src/emacs-module.h "$(DESTDIR)$(includedir)/emacs-module.h"
573 574 575 576
	-set ${COPYDESTS} ; \
	unset CDPATH; \
	$(set_installuser); \
	for dir in ${COPYDIR} ; do \
577
	  [ -d $${dir} ] || exit 1 ; \
578
	  dest="$$1" ; shift ; \
579 580 581 582 583
	  if [ -d "$${dest}" ]; then \
	    exp_dest=`cd "$${dest}" && /bin/pwd`; \
	    [ "$$exp_dest" = "`cd $${dir} && /bin/pwd`" ] && continue ; \
	  else true; \
	  fi; \
584 585
	  rm -rf "$${dest}" ; \
	  umask 022; ${MKDIR_P} "$${dest}" ; \
586
	  printf 'Copying %s to %s...\n' "$$dir" "$$dest" ; \
587
	  (cd $${dir}; tar -chf - . ) \
588
	    | (cd "$${dest}"; umask 022; \
589
	       tar -xvf - && cat > /dev/null) || exit 1; \
590
	  if [ "$${dir}" = "${srcdir}/etc" ]; then \
591 592
	      rm -f "$${dest}/DOC"* ; \
	      rm -f "$${dest}/refcards"/*.aux "$${dest}/refcards"/*.dvi; \
593
	      rm -f "$${dest}/refcards"/*.log "$${dest}/refcards"/*.in; \
594 595
	  else true; \
	  fi; \
596 597 598 599 600 601
	  (cd "$${dest}" || exit 1; \
	    for subdir in `find . -type d -print` ; do \
	      chmod a+rx $${subdir} ; \
	      rm -f $${subdir}/.gitignore ; \
	      rm -f $${subdir}/.arch-inventory ; \
	      rm -f $${subdir}/.DS_Store ; \
602 603
	      rm -f $${subdir}/#* ; \
	      rm -f $${subdir}/.#* ; \
604 605 606 607 608 609 610
	      rm -f $${subdir}/*~ ; \
	      rm -f $${subdir}/*.orig ; \
	      rm -f $${subdir}/ChangeLog* ; \
	      [ "$${dir}" != "${srcdir}/etc" ] && \
	        rm -f $${subdir}/[mM]akefile*[.-]in $${subdir}/[mM]akefile ; \
	    done ); \
	  find "$${dest}" -exec chown $${installuser} {} ';' ;\
611
	done
612 613 614
	-rm -f "$(DESTDIR)${lispdir}/subdirs.el"
	umask 022; $(srcdir)/build-aux/update-subdirs "$(DESTDIR)${lispdir}"
	subdir="$(DESTDIR)${datadir}/emacs/${version}/site-lisp" ; \
615
	  ${write_subdir}
616
	subdir="$(DESTDIR)${datadir}/emacs/site-lisp" ; \
617
	  ${write_subdir} || true
618
	[ -z "${GZIP_PROG}" ] || { \
619
	  echo "Compressing *.el etc. ..." && \
620
	  cd "$(DESTDIR)${lispdir}" && \
621 622 623
	  for f in `find . -name "*.elc" -print | sed 's/.elc$$/.el/'`; do \
	    ${GZIP_PROG} -9n "$$f"; \
	  done; \
624
	  ${GZIP_PROG} -9n "../etc/publicsuffix.txt"; \
625
	}
626
	-chmod -R a+r "$(DESTDIR)${datadir}/emacs/${version}" ${COPYDESTS}
627

628 629 630
## The above chmods are needed because "umask 022; tar ..." is not
## guaranteed to do the right thing; eg if we are root and tar is
## preserving source permissions.
631

632 633
## Note that install-arch-indep deletes and recreates the entire
## installed etc/ directory, so we need it to run before this does.
634
install-etcdoc: src install-arch-indep
635
	-unset CDPATH; \
636
	umask 022; ${MKDIR_P} "$(DESTDIR)${etcdocdir}" ; \
637 638
	exp_etcdocdir=`cd "$(DESTDIR)${etcdocdir}"; /bin/pwd`; \
	if [ "`cd ./etc; /bin/pwd`" != "$$exp_etcdocdir" ]; \
639
	then \
640
	   docfile="DOC"; \
641 642
	   printf 'Copying %s to %s ...\n' "etc/$$docfile" \
	     "$(DESTDIR)${etcdocdir}"; \
643
	   ${INSTALL_DATA} etc/$${docfile} "$(DESTDIR)${etcdocdir}/$${docfile}"; \
644
	   $(set_installuser); \
645
	     chown $${installuser} "$(DESTDIR)${etcdocdir}/$${docfile}" || true ; \
646
	else true; fi
647

648 649 650 651
## FIXME:
## If info/dir is missing, but we have install-info, we should let
## that handle it.  If info/dir is present and we do not have install-info,
## we should check for missing entries and add them by hand.
652 653 654
##
## FIXME:
## If HAVE_MAKEINFO = no and there are no info files, do not install info/dir.
655
install-info: info
656
	umask 022; ${MKDIR_P} "$(DESTDIR)${infodir}"
657 658
	-unset CDPATH; \
	thisdir=`/bin/pwd`; \
659 660
	exp_infodir=`cd "$(DESTDIR)${infodir}" && /bin/pwd`; \
	if [ "`cd ${srcdir}/info && /bin/pwd`" = "$$exp_infodir" ]; then \
661 662
	  true; \
	else \
663
	   [ -f "$(DESTDIR)${infodir}/dir" ] || \
664
	      [ ! -f ${srcdir}/info/dir ] || \
665
	      ${INSTALL_DATA} ${srcdir}/info/dir "$(DESTDIR)${infodir}/dir"; \
666
	   info_misc=`$(MAKE) --no-print-directory -s -C doc/misc echo-info`; \
667
	   cd ${srcdir}/info ; \
668
	   for elt in ${INFO_NONMISC} $${info_misc}; do \
669
	      test "$(HAVE_MAKEINFO)" = "no" && test ! -f $$elt && continue; \
670
	      for f in `ls $$elt $$elt-[1-9] $$elt-[1-9][0-9] 2>/dev/null`; do \
671
	       (cd "$${thisdir}"; \
672
	        ${INSTALL_DATA} ${srcdir}/info/$$f "$(DESTDIR)${infodir}/$$f"); \
673
	        [ -n "${GZIP_PROG}" ] || continue ; \
674 675
	        rm -f "$(DESTDIR)${infodir}/$$f.gz"; \
	        ${GZIP_PROG} -9n "$(DESTDIR)${infodir}/$$f"; \
676
	      done; \
677
	     (cd "$${thisdir}"; \
678
	      ${INSTALL_INFO} --info-dir="$(DESTDIR)${infodir}" "$(DESTDIR)${infodir}/$$elt"); \
679 680
	   done; \
	fi
681

682 683 684 685 686 687
## "gzip || true" is because some gzips exit with non-zero status
## if compression would not reduce the file size.  Eg, the gzip in
## OpenBSD 4.9 seems to do this (2013/03).  In Emacs, this can
## only happen with the tiny ctags.1 manpage.  We don't really care if
## ctags.1 is compressed or not.  "gzip -f" is another option here,
## but not sure if portable.
688
install-man:
689
	umask 022; ${MKDIR_P} "$(DESTDIR)${man1dir}"
690 691
	thisdir=`/bin/pwd`; \
	cd ${mansrcdir}; \
692
	for page in *.1; do \
693
	  test "$$page" = ChangeLog.1 && continue; \
694
	  dest=`echo "$${page}" | sed -e 's/\.1$$//' -e '$(TRANSFORM)'`.1; \
695
	  (cd "$${thisdir}"; \
696
	   ${INSTALL_DATA} ${mansrcdir}/$${page} "$(DESTDIR)${man1dir}/$${dest}"); \
697
	  [ -n "${GZIP_PROG}" ] || continue ; \
698 699
	  rm -f "$(DESTDIR)${man1dir}/$${dest}.gz"; \
	  ${GZIP_PROG} -9n "$(DESTDIR)${man1dir}/$${dest}" || true; \
700 701 702
	done

## Install those items from etc/ that need to end up elsewhere.
703 704 705 706 707

## If you prefer, choose "emacs22" at installation time.
## Note: emacs22 does not have all the resolutions.
EMACS_ICON=emacs

Glenn Morris's avatar
Glenn Morris committed
708
install-etc:
709
	umask 022; ${MKDIR_P} "$(DESTDIR)${desktopdir}"
710
	tmp=etc/emacs.tmpdesktop; rm -f $${tmp}; \
711 712
	sed -e "/^Exec=emacs/ s/emacs/${EMACS_NAME}/" \
	  -e "/^Icon=emacs/ s/emacs/${EMACS_NAME}/" \
713
	  ${srcdir}/etc/emacs.desktop > $${tmp}; \
714
	${INSTALL_DATA} $${tmp} "$(DESTDIR)${desktopdir}/${EMACS_NAME}.desktop"; \
715
	rm -f $${tmp}
716 717 718 719 720 721
	umask 022; ${MKDIR_P} "$(DESTDIR)${appdatadir}"
	tmp=etc/emacs.tmpappdata; rm -f $${tmp}; \
	sed -e "s/emacs\.desktop/${EMACS_NAME}.desktop/" \
	  ${srcdir}/etc/emacs.appdata.xml > $${tmp}; \
	${INSTALL_DATA} $${tmp} "$(DESTDIR)${appdatadir}/${EMACS_NAME}.appdata.xml"; \
	rm -f $${tmp}
722 723 724 725
	umask 022; $(MKDIR_P) "$(DESTDIR)$(systemdunitdir)"
	tmp=etc/emacs.tmpservice; rm -f $${tmp}; \
	client_name=`echo emacsclient | sed '$(TRANSFORM)'`${EXEEXT}; \
	sed -e '/^##/d' \
726 727
	  -e "/^Documentation/ s/emacs(1)/${EMACS_NAME}(1)/" \
	  -e "/^ExecStart/ s|emacs|${bindir}/${EMACS}|" \
728
	  -e "/^ExecStop/ s|emacsclient|${bindir}/$${client_name}|" \
729 730 731
	  ${srcdir}/etc/emacs.service > $${tmp}; \
	$(INSTALL_DATA) $${tmp} "$(DESTDIR)$(systemdunitdir)/${EMACS_NAME}.service"; \
	rm -f $${tmp}
732
	thisdir=`/bin/pwd`; \
Glenn Morris's avatar
Glenn Morris committed
733 734 735
	cd ${iconsrcdir} || exit 1; umask 022 ; \
	for dir in */*/apps */*/mimetypes; do \
	  [ -d $${dir} ] || continue ; \
736
	  ( cd "$${thisdir}"; ${MKDIR_P} "$(DESTDIR)${icondir}/$${dir}" ) ; \
737
	  for icon in $${dir}/${EMACS_ICON}[.-]*; do \
Glenn Morris's avatar
Glenn Morris committed
738
	    [ -r $${icon} ] || continue ; \
739
	    ext=`echo "$${icon}" | sed -e 's|.*\.||'`; \
740
	    dest=`echo "$${icon}" | sed -e 's|.*/||' -e "s|\\.$${ext}\$$||" -e 's/$(EMACS_ICON)/emacs/' -e '$(TRANSFORM)'`.$${ext} ; \
741
	    ( cd "$${thisdir}"; \
742
	      ${INSTALL_DATA} ${iconsrcdir}/$${icon} "$(DESTDIR)${icondir}/$${dir}/$${dest}" ) \
743
	    || exit 1; \
Glenn Morris's avatar
Glenn Morris committed
744
	  done ; \
745 746 747 748
	done

### Build Emacs and install it, stripping binaries while installing them.
install-strip:
749
	$(MAKE) INSTALL_STRIP=-s install
750

751 752
### Delete all the installed files that the 'install' target would
### create (but not the noninstalled files such as 'make all' would create).
753 754
###
### Don't delete the lisp and etc directories if they're in the source tree.
755
uninstall: uninstall-$(NTDIR) uninstall-doc
756
	rm -f "$(DESTDIR)$(includedir)/emacs-module.h"
757
	$(MAKE) -C lib-src uninstall
758
	-unset CDPATH; \
759 760
	for dir in "$(DESTDIR)${lispdir}" "$(DESTDIR)${etcdir}" ; do 	\
	  if [ -d "$${dir}" ]; then			\
761 762
	    case `cd "$${dir}" ; /bin/pwd` in		\
	      "`cd ${srcdir} ; /bin/pwd`"* ) ;;		\
763
	      * ) rm -rf "$${dir}" ;;			\
764
	    esac ;					\
765 766 767
	    case "$${dir}" in				\
	      "$(DESTDIR)${datadir}/emacs/${version}"/* )		\
	        rm -rf "$(DESTDIR)${datadir}/emacs/${version}"	\
768 769 770 771
	      ;;					\
	    esac ;					\
	  fi ;						\
	done
772
	-rm -rf "$(DESTDIR)${libexecdir}/emacs/${version}"
773
	thisdir=`/bin/pwd`; \
774
	(info_misc=`$(MAKE) --no-print-directory -s -C doc/misc echo-info`; \
775
	 if cd "$(DESTDIR)${infodir}"; then \
Glenn Morris's avatar
Glenn Morris committed
776
	   for elt in ${INFO_NONMISC} $${info_misc}; do \
777
	     (cd "$${thisdir}"; \
778
	      $(INSTALL_INFO) --remove --info-dir="$(DESTDIR)${infodir}" "$(DESTDIR)${infodir}/$$elt"); \
779
	     if [ -n "${GZIP_PROG}" ]; then \
Glenn Morris's avatar
Glenn Morris committed
780 781 782 783
	        ext=.gz; else ext=; fi; \
	     rm -f $$elt$$ext $$elt-[1-9]$$ext $$elt-[1-9][0-9]$$ext; \
	   done; \
	 fi)
784
	(if [ -n "${GZIP_PROG}" ]; then \
785
	    ext=.gz; else ext=; fi; \
Glenn Morris's avatar
Glenn Morris committed
786 787
	 if cd ${mansrcdir}; then \
	   for page in *.1; do \
788
	     rm -f "$(DESTDIR)${man1dir}"/`echo "$${page}" | sed -e 's/\.1$$//' -e '$(TRANSFORM)'`.1$$ext; done; \
Glenn Morris's avatar
Glenn Morris committed
789
	 fi)
790
	rm -f "$(DESTDIR)${bindir}/$(EMACS)" "$(DESTDIR)${bindir}/$(EMACSFULL)"
791
	(if cd "$(DESTDIR)${icondir}"; then \
792 793
	   rm -f hicolor/*x*/apps/"${EMACS_NAME}.png" \
	     "hicolor/scalable/apps/${EMACS_NAME}.svg" \
794 795 796
	     "hicolor/scalable/apps/${EMACS_NAME}.ico" \
	     "hicolor/scalable/mimetypes/${EMACS_NAME}-document.svg" \
	     "hicolor/scalable/mimetypes/${EMACS_NAME}-document23.svg"; \
Glenn Morris's avatar
Glenn Morris committed
797
	fi)
798
	-rm -f "$(DESTDIR)${desktopdir}/${EMACS_NAME}.desktop"
799
	-rm -f "$(DESTDIR)${appdatadir}/${EMACS_NAME}.appdata.xml"
800
	-rm -f "$(DESTDIR)$(systemdunitdir)/${EMACS_NAME}.service"
801
  ifneq (,$(use_gamedir))
802
	for file in snake-scores tetris-scores; do \
803 804
	  file="$(DESTDIR)${gamedir}/$${file}"; \
	  [ -s "$${file}" ] || rm -f "$$file"; \
805
	done
806
  endif
807

808 809 810 811
### Windows-specific uninstall target for removing programs produced
### in nt/, and its Posix do-nothing shadow.
uninstall-:
uninstall-nt:
812
	$(MAKE) -C $(NTDIR) uninstall
813

814 815
# ==================== Cleaning up and miscellanea ====================

816
.PHONY: mostlyclean clean distclean bootstrap-clean maintainer-clean extraclean
817

818 819 820 821 822 823 824 825 826
## Eg:
## src_clean:
##     make -C src clean
define submake_template
.PHONY: $(1)_$(2)
$(1)_$(2):
	$$(MAKE) -C $(1) $(2)
endef

827 828 829 830
### 'mostlyclean'
###      Like 'clean', but may refrain from deleting a few files that people
###      normally don't want to recompile.  For example, the 'mostlyclean'
###      target for GCC does not delete 'libgcc.a', because recompiling it
831
###      is rarely necessary and takes a lot of time.
832 833 834 835 836 837
mostlyclean_dirs = src oldXMenu lwlib lib lib-src nt doc/emacs doc/misc \
  doc/lispref doc/lispintro

$(foreach dir,$(mostlyclean_dirs),$(eval $(call submake_template,$(dir),mostlyclean)))

mostlyclean: $(mostlyclean_dirs:=_mostlyclean)
838
	[ ! -d test ] || $(MAKE) -C test $@
839

840
### 'clean'
841 842 843 844 845 846
###      Delete all files from the current directory that are normally
###      created by building the program.  Don't delete the files that
###      record the configuration.  Also preserve files that could be made
###      by building, but normally aren't because the distribution comes
###      with them.
###
847
###      Delete '.dvi' files here if they are not part of the distribution.
848 849 850 851 852
clean_dirs = $(mostlyclean_dirs) nextstep

$(foreach dir,$(clean_dirs),$(eval $(call submake_template,$(dir),clean)))

clean: $(clean_dirs:=_clean)
853 854
	$(MAKE) -C admin/charsets $@
	[ ! -d test ] || $(MAKE) -C test $@
855
	-rm -f ./*.tmp etc/*.tmp*
856
	-rm -rf info-dir.*
857

858
### 'bootclean'
859 860
###      Delete all files that need to be remade for a clean bootstrap.
top_bootclean=\
861
	rm -f config.cache config.log ${srcdir}/doc/man/emacs.1
862

863
### 'distclean'
864 865 866
###      Delete all files from the current directory that are created by
###      configuring or building the program.  If you have unpacked the
###      source and built the program without creating any other files,
867
###      'make distclean' should leave only the files that were in the
868 869 870
###      distribution.
top_distclean=\
	${top_bootclean}; \
Paul Eggert's avatar
Paul Eggert committed
871
	rm -f config.status config.log~ \
Paul Eggert's avatar
Paul Eggert committed
872
	  Makefile lib/gnulib.mk ${SUBDIR_MAKEFILES}
873 874 875 876 877

distclean_dirs = $(clean_dirs) leim lisp

$(foreach dir,$(distclean_dirs),$(eval $(call submake_template,$(dir),distclean)))

878
maybeclean_dirs = test admin/grammars admin/unidata admin/charsets
879

880
distclean: $(distclean_dirs:=_distclean)
881 882
	for dir in $(filter-out test,$(maybeclean_dirs)); do \
	  $(MAKE) -C $$dir $@ || exit; \
883
	done
884
	[ ! -d test ] || $(MAKE) -C test $@
885 886
	${top_distclean}

887 888
### 'bootstrap-clean'
###      Delete everything that can be reconstructed by 'make' and that
889
###      needs to be deleted in order to force a bootstrap from a clean state.
890 891 892
$(foreach dir,$(distclean_dirs),$(eval $(call submake_template,$(dir),bootstrap-clean)))

bootstrap-clean: $(distclean_dirs:=_bootstrap-clean)
893 894
	for dir in $(filter-out test,$(maybeclean_dirs)); do \
	  $(MAKE) -C $$dir $@ || exit; \
895
	done
896
	[ ! -d test ] || $(MAKE) -C test $@
897
	[ ! -f config.log ] || mv -f config.log config.log~
898
	rm -rf ${srcdir}/info
899
	rm -f ${srcdir}/etc/refcards/emacsver.tex
900 901
	${top_bootclean}

902
### 'maintainer-clean'
903 904 905 906 907
###      Delete everything from the current directory that can be
###      reconstructed with this Makefile.  This typically includes
###      everything deleted by distclean, plus more: C source files
###      produced by Bison, tags tables, info files, and so on.
###
908 909 910 911
###      One exception, however: 'make maintainer-clean' should not delete
###      'configure' even if 'configure' can be remade using a rule in the
###      Makefile.  More generally, 'make maintainer-clean' should not delete
###      anything that needs to exist in order to run 'configure' and then
912
###      begin to build the program.