unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* RFC: Cross compiling Emacs with qemu-user
@ 2017-12-12 17:32 Mario Lang
  2017-12-12 17:51 ` Andreas Schwab
  2017-12-12 20:34 ` Stefan Monnier
  0 siblings, 2 replies; 4+ messages in thread
From: Mario Lang @ 2017-12-12 17:32 UTC (permalink / raw)
  To: emacs-devel

Hi.

It appears cross compilation of Emacs (tested on ARM) can be done with
the help of qemu-user.  If you have binfmt support of qemu-user
installed properly, you can actually cross-compile Emacs without any
modifications at all.  However, this usually requires some tinkering
with the global state on the build host, which is undesireable.

To avoid going through binfmt support, I just whipped up a very crude
patch to prefix calling of built binaries.  I know this isn't ready for
inclusion, however, I'd like to post this here to solicit comments.

* In principle, would this be something Emacs would want to support?
* What would need to be done to make the patch below acceptable?

I needed to replace some of the relative executable paths since
qemu-user apparently has a problem with ./foo and ../foo alike paths.

I am using this patch in an experimental buildroot package for Emacs.

EMACS_CONF_OPTS += --with-emulator="$(QEMU_USER) -L $(TARGET_DIR)"

And voila!  I get a fully working Emacs for ARM built on x86_64.

diff --git a/admin/grammars/Makefile.in b/admin/grammars/Makefile.in
index 740168fc73..43fe11eaee 100644
--- a/admin/grammars/Makefile.in
+++ b/admin/grammars/Makefile.in
@@ -45,7 +45,7 @@ am__v_at_1 =
 unexport EMACSDATA EMACSDOC EMACSPATH
 
 EMACS = ${top_builddir}/src/emacs
-emacs = EMACSLOADPATH= "${EMACS}" -batch --no-site-file --no-site-lisp
+emacs = EMACSLOADPATH= ${EMACS} -batch --no-site-file --no-site-lisp
 
 make_bovine = ${emacs} -l semantic/bovine/grammar -f bovine-batch-make-parser
 make_wisent = ${emacs} -l semantic/wisent/grammar -f wisent-batch-make-parser
diff --git a/admin/unidata/Makefile.in b/admin/unidata/Makefile.in
index c389cb3f53..66d7587a58 100644
--- a/admin/unidata/Makefile.in
+++ b/admin/unidata/Makefile.in
@@ -31,7 +31,7 @@ top_builddir =
 
 EMACS = ${top_builddir}/src/emacs
 unidir = ${top_srcdir}/lisp/international
-emacs = "${EMACS}" -batch --no-site-file --no-site-lisp
+emacs = ${EMACS} -batch --no-site-file --no-site-lisp
 
 lparen = (
 unifiles = $(addprefix ${unidir}/,$(sort $(shell sed -n 's/^[ \t][ \t]*${lparen}"\(uni-[^"]*\)"$$/\1/p' ${srcdir}/unidata-gen.el)))
diff --git a/configure.ac b/configure.ac
index 562b19afe6..df2fc99836 100644
--- a/configure.ac
+++ b/configure.ac
@@ -298,6 +298,11 @@ AC_DEFUN
     [string giving default POP mail host])],
     AC_DEFINE_UNQUOTED(MAILHOST, ["$withval"], [String giving fallback POP mail host.]))
 
+AC_ARG_WITH([emulator],[AS_HELP_STRING([--with-emulator=EMULATOR],
+    [Emulator to use when executing target binaries])],
+    EMULATOR="$withval"
+    AC_SUBST(EMULATOR))
+
 AC_ARG_WITH([sound],[AS_HELP_STRING([--with-sound=VALUE],
   [compile with sound support (VALUE one of: yes, alsa, oss, bsd-ossaudio, no;
 default yes).  Only for GNU/Linux, FreeBSD, NetBSD, MinGW, Cygwin.])],
diff --git a/leim/Makefile.in b/leim/Makefile.in
index f18010af60..af55e3fc4b 100644
--- a/leim/Makefile.in
+++ b/leim/Makefile.in
@@ -53,7 +53,7 @@ EMACS =
 
 # How to run Emacs.
 # Prevent any setting of EMACSLOADPATH in user environment causing problems.
-RUN_EMACS = EMACSLOADPATH= '$(EMACS)' -batch --no-site-file --no-site-lisp
+RUN_EMACS = EMACSLOADPATH= $(EMACS) -batch --no-site-file --no-site-lisp
 
 MKDIR_P = @MKDIR_P@
 
diff --git a/lisp/Makefile.in b/lisp/Makefile.in
index de3dc18617..884417d3c1 100644
--- a/lisp/Makefile.in
+++ b/lisp/Makefile.in
@@ -56,7 +56,7 @@ FIND_DELETE =
 # 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.
-EMACS = ../src/emacs${EXEEXT}
+EMACS = @EMULATOR@ $(CURDIR)/../src/emacs${EXEEXT}
 
 # Command line flags for Emacs.
 
@@ -106,7 +106,7 @@ COMPILE_FIRST =
 
 # The actual Emacs command run in the targets below.
 # Prevent any setting of EMACSLOADPATH in user environment causing problems.
-emacs = EMACSLOADPATH= '$(EMACS)' $(EMACSOPT)
+emacs = EMACSLOADPATH= $(EMACS) $(EMACSOPT)
 
 ## Subdirectories, relative to builddir.
 SUBDIRS = $(sort $(shell find ${srcdir} -type d -print))
diff --git a/src/Makefile.in b/src/Makefile.in
index b395627893..d397dc4080 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -54,7 +54,7 @@ lwlibdir =
 # Configuration files for .o files to depend on.
 config_h = config.h $(srcdir)/conf_post.h
 
-bootstrap_exe = ../src/bootstrap-emacs$(EXEEXT)
+bootstrap_exe = $(CURDIR)/bootstrap-emacs$(EXEEXT)
 
 ## ns-app if HAVE_NS, else empty.
 OTHER_FILES = @OTHER_FILES@
@@ -320,7 +320,9 @@ INTERVALS_H =
 
 GETLOADAVG_LIBS = @GETLOADAVG_LIBS@
 
-RUN_TEMACS = ./temacs
+RUN_TEMACS = temacs
+
+EMULATOR = @EMULATOR@
 
 # Whether builds should contain details. '--no-build-details' or empty.
 BUILD_DETAILS = @BUILD_DETAILS@
@@ -506,7 +508,7 @@ LIBES =
 ## in practice this rule was always run anyway.
 $(srcdir)/macuvs.h $(lispsource)/international/charprop.el: \
   bootstrap-emacs$(EXEEXT) FORCE
-	$(MAKE) -C ../admin/unidata all EMACS="../$(bootstrap_exe)"
+	$(MAKE) -C ../admin/unidata all EMACS="$(EMULATOR) $(bootstrap_exe)"
 
 ## We require charprop.el to exist before ucs-normalize.el is
 ## byte-compiled, because ucs-normalize.el needs to load 2 uni-*.el files.
@@ -539,7 +541,7 @@ emacs$(EXEEXT):
 ifeq ($(CANNOT_DUMP),yes)
 	ln -f temacs$(EXEEXT) $@
 else
-	LC_ALL=C $(RUN_TEMACS) -batch $(BUILD_DETAILS) -l loadup dump
+	LC_ALL=C $(EMULATOR) $(RUN_TEMACS) -batch $(BUILD_DETAILS) -l loadup dump
   ifneq ($(PAXCTL_dumped),)
 	$(PAXCTL_dumped) $@
   endif
@@ -560,9 +562,9 @@ emacs$(EXEEXT):
 $(etc)/DOC: lisp.mk $(libsrc)/make-docfile$(EXEEXT) $(obj) $(lisp)
 	$(AM_V_GEN)$(MKDIR_P) $(etc)
 	-$(AM_V_at)rm -f $(etc)/DOC
-	$(AM_V_at)$(libsrc)/make-docfile -d $(srcdir) \
+	$(AM_V_at)$(EMULATOR) $(libsrc)/make-docfile -d $(srcdir) \
 	  $(SOME_MACHINE_OBJECTS) $(obj) > $(etc)/DOC
-	$(AM_V_at)$(libsrc)/make-docfile -a $(etc)/DOC -d $(lispsource) \
+	$(AM_V_at)$(EMULATOR) $(libsrc)/make-docfile -a $(etc)/DOC -d $(lispsource) \
 	  $(shortlisp)
 
 $(libsrc)/make-docfile$(EXEEXT): $(lib)/libgnu.a
@@ -583,7 +585,7 @@ am__v_GLOBALS_0 =
 am__v_GLOBALS_1 =
 
 gl-stamp: $(libsrc)/make-docfile$(EXEEXT) $(GLOBAL_SOURCES)
-	$(AM_V_GLOBALS)$(libsrc)/make-docfile -d $(srcdir) -g $(obj) > globals.tmp
+	$(AM_V_GLOBALS)$(EMULATOR) $(libsrc)/make-docfile -d $(srcdir) -g $(obj) > globals.tmp
 	$(AM_V_at)$(top_srcdir)/build-aux/move-if-change globals.tmp globals.h
 	$(AM_V_at)echo timestamp > $@
 
@@ -726,7 +728,7 @@ .PHONY:
 ## bootstrap-emacs$(EXEEXT) as an order-only prerequisite.
 
 %.elc: %.el | bootstrap-emacs$(EXEEXT)
-	@$(MAKE) -C ../lisp EMACS="$(bootstrap_exe)" THEFILE=$< $<c
+	@$(MAKE) -C ../lisp EMACS="$(EMULATOR) $(bootstrap_exe)" THEFILE=$< $<c
 
 ## VCSWITNESS points to the file that holds info about the current checkout.
 ## We use it as a heuristic to decide when to rebuild loaddefs.el.
@@ -734,7 +736,7 @@ .PHONY:
 VCSWITNESS =
 
 $(lispsource)/loaddefs.el: $(VCSWITNESS) | bootstrap-emacs$(EXEEXT)
-	$(MAKE) -C ../lisp autoloads EMACS="$(bootstrap_exe)"
+	$(MAKE) -C ../lisp autoloads EMACS="$(EMULATOR) $(bootstrap_exe)"
 
 ## Dump an Emacs executable named bootstrap-emacs containing the
 ## files from loadup.el in source form.
@@ -743,11 +745,11 @@ bootstrap-emacs$(EXEEXT):
 ifeq ($(CANNOT_DUMP),yes)
 	ln -f temacs$(EXEEXT) $@
 else
-	$(RUN_TEMACS) --batch $(BUILD_DETAILS) --load loadup bootstrap
+	$(EMULATOR) $(RUN_TEMACS) --batch $(BUILD_DETAILS) --load loadup bootstrap
   ifneq ($(PAXCTL_dumped),)
 	$(PAXCTL_dumped) emacs$(EXEEXT)
   endif
 	mv -f emacs$(EXEEXT) $@
 endif
 	@: Compile some files earlier to speed up further compilation.
-	$(MAKE) -C ../lisp compile-first EMACS="$(bootstrap_exe)"
+	$(MAKE) -C ../lisp compile-first EMACS="$(EMULATOR) $(bootstrap_exe)"


-- 
CYa,
  ⡍⠁⠗⠊⠕



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: RFC: Cross compiling Emacs with qemu-user
  2017-12-12 17:32 RFC: Cross compiling Emacs with qemu-user Mario Lang
@ 2017-12-12 17:51 ` Andreas Schwab
  2017-12-12 20:34 ` Stefan Monnier
  1 sibling, 0 replies; 4+ messages in thread
From: Andreas Schwab @ 2017-12-12 17:51 UTC (permalink / raw)
  To: Mario Lang; +Cc: emacs-devel

On Dez 12 2017, Mario Lang <mlang@delysid.org> wrote:

> @@ -320,7 +320,9 @@ INTERVALS_H =
>  
>  GETLOADAVG_LIBS = @GETLOADAVG_LIBS@
>  
> -RUN_TEMACS = ./temacs
> +RUN_TEMACS = temacs
> +
> +EMULATOR = @EMULATOR@
>  
>  # Whether builds should contain details. '--no-build-details' or empty.
>  BUILD_DETAILS = @BUILD_DETAILS@

> @@ -743,11 +745,11 @@ bootstrap-emacs$(EXEEXT):
>  ifeq ($(CANNOT_DUMP),yes)
>  	ln -f temacs$(EXEEXT) $@
>  else
> -	$(RUN_TEMACS) --batch $(BUILD_DETAILS) --load loadup bootstrap
> +	$(EMULATOR) $(RUN_TEMACS) --batch $(BUILD_DETAILS) --load loadup bootstrap

That cannot work, when $(EMULATOR) is empty temacs can no longer be
found.

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: RFC: Cross compiling Emacs with qemu-user
  2017-12-12 17:32 RFC: Cross compiling Emacs with qemu-user Mario Lang
  2017-12-12 17:51 ` Andreas Schwab
@ 2017-12-12 20:34 ` Stefan Monnier
  2017-12-12 21:03   ` Mario Lang
  1 sibling, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2017-12-12 20:34 UTC (permalink / raw)
  To: emacs-devel

> * In principle, would this be something Emacs would want to support?

I';ll let Eli and John chime in, but I don't see any reason why not.

> * What would need to be done to make the patch below acceptable?

Good question.  Some comments below.

>  EMACS = ${top_builddir}/src/emacs
> -emacs = EMACSLOADPATH= "${EMACS}" -batch --no-site-file --no-site-lisp
> +emacs = EMACSLOADPATH= ${EMACS} -batch --no-site-file --no-site-lisp

I'm not sure if Emacs can be built currently in a directory whose full
name includes spaces, but it's something that *should* work.  The above
would break it AFAICT, so we need some other solution.

> +AC_ARG_WITH([emulator],[AS_HELP_STRING([--with-emulator=EMULATOR],
> +    [Emulator to use when executing target binaries])],
> +    EMULATOR="$withval"
> +    AC_SUBST(EMULATOR))

It'd be good to make the doc slightly more precise (i.e. clarify that
it specifies an actual *command* rather than just which kind of
emulator we want to use).

> -RUN_TEMACS = ./temacs
> +RUN_TEMACS = temacs

Why did you need to get rid of the "./"?  It's needed to tell the shell
not to search through $PATH but in the cwd instead.

> -	$(MAKE) -C ../admin/unidata all EMACS="../$(bootstrap_exe)"
> +	$(MAKE) -C ../admin/unidata all EMACS="$(EMULATOR) $(bootstrap_exe)"

Hmm... how will $(EMULATOR) know to look in ../ ?


        Stefan




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: RFC: Cross compiling Emacs with qemu-user
  2017-12-12 20:34 ` Stefan Monnier
@ 2017-12-12 21:03   ` Mario Lang
  0 siblings, 0 replies; 4+ messages in thread
From: Mario Lang @ 2017-12-12 21:03 UTC (permalink / raw)
  To: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>>  EMACS = ${top_builddir}/src/emacs
>> -emacs = EMACSLOADPATH= "${EMACS}" -batch --no-site-file --no-site-lisp
>> +emacs = EMACSLOADPATH= ${EMACS} -batch --no-site-file --no-site-lisp
>
> I'm not sure if Emacs can be built currently in a directory whose full
> name includes spaces, but it's something that *should* work.  The above
> would break it AFAICT, so we need some other solution.

Yeah, I am unhappy with this as well.  It just was the easiest way to
get what I needed.

>> +AC_ARG_WITH([emulator],[AS_HELP_STRING([--with-emulator=EMULATOR],
>> +    [Emulator to use when executing target binaries])],
>> +    EMULATOR="$withval"
>> +    AC_SUBST(EMULATOR))
>
> It'd be good to make the doc slightly more precise (i.e. clarify that
> it specifies an actual *command* rather than just which kind of
> emulator we want to use).

Sure.

>> -RUN_TEMACS = ./temacs
>> +RUN_TEMACS = temacs
>
> Why did you need to get rid of the "./"?  It's needed to tell the shell
> not to search through $PATH but in the cwd instead.

As mentioned in my original mail, qemu-user seems to have issues with
executable paths starting with ./ and ../. In particular, in these
cases, it doesn't find the elf loader for some reason.  Specifying a
relative path without leading ./ works.  I have not investigated further
so far.

>> -	$(MAKE) -C ../admin/unidata all EMACS="../$(bootstrap_exe)"
>> +	$(MAKE) -C ../admin/unidata all EMACS="$(EMULATOR) $(bootstrap_exe)"
>
> Hmm... how will $(EMULATOR) know to look in ../ ?

bootstrap_exe has been modified to use $(CURDIR) a little further up...

-- 
CYa,
  ⡍⠁⠗⠊⠕



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-12-12 21:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-12 17:32 RFC: Cross compiling Emacs with qemu-user Mario Lang
2017-12-12 17:51 ` Andreas Schwab
2017-12-12 20:34 ` Stefan Monnier
2017-12-12 21:03   ` Mario Lang

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).