From 90655e4bc01ba8d00be3281d13cc771b53e75b43 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Tue, 28 Sep 2021 15:00:50 +0300 Subject: [PATCH] Make the build of source tarball produce *.eln files * lisp/emacs-lisp/comp.el (batch-native-compile): Accept an optional argument; if non-nil, place the .eln file as appropriate for building a source tarball. * doc/lispref/compile.texi (Native-Compilation Functions): Document the new optional argument of 'batch-native-compile'. * lisp/Makefile.in (.PHONY, $(THEFILE)n) [HAVE_NATIVE_COMP]: New targets. * src/Makefile.in (%.eln) [HAVE_NATIVE_COMP]: New recipe. (all) [HAVE_NATIVE_COMP]: Add ../native-lisp to prerequisites. (elnlisp) [HAVE_NATIVE_COMP]: New list of *.eln files. (../native-lisp) [HAVE_NATIVE_COMP]: New recipe. * src/verbose.mk.in (AM_V_ELN): New macro. --- doc/lispref/compile.texi | 11 +++++++++-- lisp/Makefile.in | 8 ++++++++ lisp/emacs-lisp/comp.el | 25 ++++++++++++++++--------- src/Makefile.in | 40 ++++++++++++++++++++++++++++++++++++++++ src/verbose.mk.in | 4 ++++ 5 files changed, 77 insertions(+), 11 deletions(-) diff --git a/doc/lispref/compile.texi b/doc/lispref/compile.texi index f48f4f47e8b..15d1f4ce53a 100644 --- a/doc/lispref/compile.texi +++ b/doc/lispref/compile.texi @@ -904,13 +904,20 @@ invokes the same Emacs executable as the process that called this function. @end defun -@defun batch-native-compile +@defun batch-native-compile &optional for-tarball This function runs native-compilation on files specified on the Emacs command line in batch mode. It must be used only in a batch execution of Emacs, as it kills Emacs upon completion of the compilation. If one or more of the files fail to compile, the Emacs process will attempt to compile all the other files, and will terminate with a -non-zero status code. +non-zero status code. The optional argument @var{for-tarball}, if +non-@code{nil}, tells the function to place the resulting @file{.eln} +files in the last directory mentioned in +@code{native-comp-eln-load-path} (@pxref{Library Search}); this is +meant to be used as part of building an Emacs source tarball for the +first time, when the natively-compiled files, which are absent from +the source tarball, should be generated in the build tree instead of +the user's cache directory. @end defun Native compilation can be run entirely asynchronously, in a subprocess diff --git a/lisp/Makefile.in b/lisp/Makefile.in index 431217a9dac..60d1d10e5b2 100644 --- a/lisp/Makefile.in +++ b/lisp/Makefile.in @@ -281,6 +281,14 @@ else -f batch-byte-compile $(THEFILE) endif +ifeq ($(HAVE_NATIVE_COMP),yes) +.PHONY: $(THEFILE)n +$(THEFILE)n: + $(AM_V_ELN)$(emacs) $(BYTE_COMPILE_FLAGS) \ + -l comp -f byte-compile-refresh-preloaded \ + --eval '(batch-native-compile t)' $(THEFILE) +endif + # Files MUST be compiled one by one. If we compile several files in a # row (i.e., in the same instance of Emacs) we can't make sure that # the compilation environment is clean. We also set the load-path of diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el index 7c93ebd6300..83605ca5a77 100644 --- a/lisp/emacs-lisp/comp.el +++ b/lisp/emacs-lisp/comp.el @@ -4191,20 +4191,27 @@ form, return the compiled function." (comp--native-compile function-or-file nil output)) ;;;###autoload -(defun batch-native-compile () +(defun batch-native-compile (&optional for-tarball) "Perform batch native compilation of remaining command-line arguments. Native compilation equivalent of `batch-byte-compile'. Use this from the command line, with ‘-batch’; it won’t work -in an interactive Emacs session." +in an interactive Emacs session. +Optional argument FOR-TARBALL non-nil means the file being compiled +as part of building the source tarball, in which case the .eln file +will be placed under the native-lisp/ directory (actually, in the +last directory in `native-comp-eln-load-path')." (comp-ensure-native-compiler) - (cl-loop for file in command-line-args-left - if (or (null byte+native-compile) - (cl-notany (lambda (re) (string-match re file)) - native-comp-bootstrap-deny-list)) - do (comp--native-compile file) - else - do (byte-compile-file file))) + (let ((native-compile-target-directory + (if for-tarball + (car (last native-comp-eln-load-path))))) + (cl-loop for file in command-line-args-left + if (or (null byte+native-compile) + (cl-notany (lambda (re) (string-match re file)) + native-comp-bootstrap-deny-list)) + do (comp--native-compile file) + else + do (byte-compile-file file)))) ;;;###autoload (defun batch-byte+native-compile () diff --git a/src/Makefile.in b/src/Makefile.in index c11d96d2c4e..34335cfa96d 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -448,7 +448,15 @@ FIRSTFILE_OBJ=@FIRSTFILE_OBJ@ ALLOBJS = $(FIRSTFILE_OBJ) $(VMLIMIT_OBJ) $(obj) $(otherobj) # Must be first, before dep inclusion! +ifeq ($(HAVE_NATIVE_COMP),yes) +ifeq ($(NATIVE_DISABLED),) +all: emacs$(EXEEXT) $(pdmp) $(OTHER_FILES) ../native-lisp +else +all: emacs$(EXEEXT) $(pdmp) $(OTHER_FILES) +endif +else all: emacs$(EXEEXT) $(pdmp) $(OTHER_FILES) +endif .PHONY: all dmpstruct_headers=$(srcdir)/lisp.h $(srcdir)/buffer.h \ @@ -775,6 +783,38 @@ tags: TAGS ../lisp/TAGS $(lwlibdir)/TAGS @$(MAKE) $(AM_V_NO_PD) -C ../lisp EMACS="$(bootstrap_exe)"\ THEFILE=$< $