self-contained portable emacs
Asked Answered
P

4

6

I'm trying to compile and statically link Emacs, because at work I'm forced to do JavaScript development over ssh on a production server running CentOS 5.1 with a broken package manager configuration and Emacs21, which doesn't have a js-mode and produces errors whenever I try to install and use js[23]-mode.el or javascript.el, which I don't have time at work to debug.

c-mode indents everything

$().ready(function() {
            like();
            $(this).andIOnlyHave1024Pixels(function () {
                                               etc ();
                                               etc ();

How would I go about making a portable copy of a more modern version of Emacs? Or alternatively alter c-mode? (Or anything to avoid having to use vi...)

Thanks


Pangenesis answered 5/7, 2013 at 0:16 Comment(2)
Do you ssh from a personal machine into the CentOS machine? Run emacs from the personal machine and use TRAMP! C-x C-f /ssh:... Though, even if that works for you, I'd still love to see someone post instructions for a 'portable' emacs.Inestimable
@Inestimable Thanks! Unfortunately I can't, but that will be really useful in future.Pangenesis
H
3

I think I have the beginnings of an answer here. First of all, you need to be able to build Emacs on some machine with the same architecture as the runtime machine. You could get around this with cross compiling, but that makes everything way more complicated.

tar xf emacs.tar.bz2
cd emacs
./autogen.sh
./configure --with-x=no --prefix=/usr/local
make
mkdir install
make DESTDIR=$PWD/install install

You can make prefix whatever you want, it just has to be where you're going to have Emacs installed on the runtime machine. X is disabled because it drastically reduces the number of libraries required and you're running over ssh anyway.

Now figure out what shared libs are needed to run Emacs. A quick look at all of the executables shipped with Emacs shows that this is a superset of the libs needed for the entire Emacs installation.

$ ldd install/usr/local/bin/emacs
linux-vdso.so.1 (0x00007fff427fe000)
libasound.so.2 => /usr/lib/libasound.so.2 (0x00007f66b25a0000)
librt.so.1 => /usr/lib/librt.so.1 (0x00007f66b2398000)
libdbus-1.so.3 => /usr/lib/libdbus-1.so.3 (0x00007f66b2151000)
libxml2.so.2 => /usr/lib/libxml2.so.2 (0x00007f66b1de9000)
libgpm.so.2 => /usr/lib/libgpm.so.2 (0x00007f66b1be2000)
libncursesw.so.5 => /usr/lib/libncursesw.so.5 (0x00007f66b1983000)
libgnutls.so.28 => /usr/lib/libgnutls.so.28 (0x00007f66b1673000)
libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007f66b1457000)
libm.so.6 => /usr/lib/libm.so.6 (0x00007f66b1159000)
libc.so.6 => /usr/lib/libc.so.6 (0x00007f66b0dac000)
libdl.so.2 => /usr/lib/libdl.so.2 (0x00007f66b0ba8000)
/lib64/ld-linux-x86-64.so.2 (0x00007f66b2897000)
libz.so.1 => /usr/lib/libz.so.1 (0x00007f66b0992000)
liblzma.so.5 => /usr/lib/liblzma.so.5 (0x00007f66b076f000)
libp11-kit.so.0 => /usr/lib/libp11-kit.so.0 (0x00007f66b054e000)
libtasn1.so.6 => /usr/lib/libtasn1.so.6 (0x00007f66b033a000)
libnettle.so.4 => /usr/lib/libnettle.so.4 (0x00007f66b010c000)
libhogweed.so.2 => /usr/lib/libhogweed.so.2 (0x00007f66afedd000)
libgmp.so.10 => /usr/lib/libgmp.so.10 (0x00007f66afc66000)

So copy all of these libs to some directory in your install tree. linux-vdso.so is virtual and can't/doesn't need to be copied.

mkdir install/usr/local/solib
cp /usr/lib/libasound.so.2 /usr/lib/librt.so.1 /usr/lib/libdbus-1.so.3 /usr/lib/libxml2.so.2 /usr/lib/libgpm.so.2 /usr/lib/libncursesw.so.5 /usr/lib/libgnutls.so.28 /usr/lib/libpthread.so.0 /usr/lib/libm.so.6 /usr/lib/libc.so.6 /usr/lib/libdl.so.2 /lib64/ld-linux-x86-64.so.2 /usr/lib/libz.so.1 /usr/lib/liblzma.so.5 /usr/lib/libp11-kit.so.0 /usr/lib/libtasn1.so.6 /usr/lib/libnettle.so.4 /usr/lib/libhogweed.so.2 /usr/lib/libgmp.so.10 install/usr/local/solib/

Archive it all. I've been liking squashfs lately, use tar if you prefer.

mksquashfs install/usr/local emacs.sfs -noappend

On the runtime machine, extract your files and copy them to the prefix. With squashfs, we can just mount it.

mount emacs.sfs /usr/local

Start emacs with the LD_LIBRARY_PATH set to use the libraries you copied earlier.

LD_LIBRARY_PATH=/usr/local/solib /usr/local/bin/emacs

Hopefully that will work. I tested in a VM with a fairly similar OS to the one I built on, so maybe something will go awry when they differ by a lot.

Herzel answered 10/7, 2013 at 21:9 Comment(3)
Nice approach. Does this solution needs sudo access for mounting the squash fs? (if OP had sudo access, he probably would be able to upgrade emacs). A FUSE-based approach would remove this issue?Morrell
Yes, it needs sudo for mounting (and probably writing to /usr/local). But if you don't have sudo, you can just set the prefix to something in $HOME, extract the squashsfs image like any other archive format, and copy the files to prefix.Herzel
Here unix.stackexchange.com/questions/472989/… also a way to build static executableGrissel
M
2

If you can compile emacs in a machine, you can run from there without installing it. Just execute the binary that the compilation creates for you (you may need to change your path, since a emacsclient from different versions may not work well together).

I know this is not what you were looking (since the emacs is not portable and you might lack a compilation environment in that machine), but the trick might work for you.

Of course the TRAMP over ssh approach that assem suggested is a better solution (and what I personally use)

Morrell answered 5/7, 2013 at 6:49 Comment(2)
Thank you, I didn't know it would work without installing it. (unfortunately autotools isn't installed and can't be installed owing to the broken package manager.)Pangenesis
@user234461: IIRC, you don't need autotools to compile emacs, just a compiler and make... and maybe some mandatory libraries.Aerostatics
A
1

I commonly use sshfs to mount remote file systems and edit files on them with Emacs. It works pretty reliably.

Another good alternative is the Emacs clone mg, as it is way smaller and simpler, compiling it into a static executable should be easier. Even if it lacks most of the features on the real Emacs, you will still feel at home.

Aerostatics answered 11/7, 2013 at 7:35 Comment(0)
A
0

There's a portable Lisp development environment called Portacle which can run from a USB stick.

Portacle includes an Emacs among other things.

It's available for MS Windows, Linux and MacOS.

https://portacle.github.io/

Amphi answered 13/8 at 11:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.