practicalli / blog-cryogen

Cryogen powered blog with all the content used to generate the static website.
https://practical.li/blog-cryogen/
3 stars 2 forks source link

Article: Building Emacs on Ubuntu #129

Closed practicalli-johnny closed 2 years ago

practicalli-johnny commented 2 years ago

Building Emacs 28 on Ubuntu Linux

Emacs Wiki - Building Emacs https://www.emacswiki.org/emacs/BuildingEmacs

Emacs 28.1 whats new https://www.masteringemacs.org/article/whats-new-in-emacs-28-1

To avoid certificate issues, ensure gnutls-bin is installed

sudo apt-get install gnutls-bin

Visit a nearby GNU mirror https://www.gnu.org/software/emacs/download.html#gnu-linux

I was directed to http://ftp.snt.utwente.nl/pub/software/gnu/emacs/

Download Emacs 28.1 source code, either tar.gz or tar.xz Extract the source code (I used the archive tool)

Change into the emacs28.1 directory

cd emacs28-1

Inform the Emacs configuration script as to the location of gcc-10, otherwise it fails to find libgccjit

Error message:

configure: error: ELisp native compiler was requested, but libgccjit was not found.
Please try installing libgccjit or a similar package.

Set these environment variables to define the location of gcc-10

export CC=/usr/bin/gcc-10
export CXX=/usr/bin/gcc-10

Run the autogeneration script

./autogen.sh

Run the configuration script with the native compilation flag

./configure --with-native-compilation --with-harfbuzz

./configure --help to see the flags available

The Optional Features: section of the configure file contains a list of options to use with configure along with brief descriptions

For many features, if the library is found when running ./configure then that feature is enabled

Use the --without-all flag to disable all features and specifically add a list of optional features required. This approach can reduce the footprint of Emacs but requires that you know which features are needed.

Are there other useful configuration flags to include? Some configuration options to review are:

--without-all ;; remove all optional extras --with-cairo --with-gif --with-jpeg --with-png --with-rsvg --with-xml2 --with-zlib --with-threads --with-json ;; json parsing --with-file-notification=inotify ;; file watching - inotify gfilenotify, kqueue - https://www.gnu.org/software/emacs/manual/html_node/elisp/File-Notifications.html --with-gnutls ;; GnuTLS for SSL, TSL & DTLS connectivity e.g. https links --with-modules ;; modules extend Emacs with naively compiled code --with-xft ;; FreeType font support --with-libotf ;; OpenType font support --with-native-compilation ;; turbo boost for Emacs --with-harfbuzz ;; support for ligatures

GUI --without-toolkit-scroll-bar ;; no scrollbars

Improved X11 experience (recommended) --with-cairo --with-xwidgets --with-x-toolkit=gtk3

requires the dependencies for Ubuntu 20.04 libgtk-3-dev libwebkit2gtk-4.0-dev

TODO: can I compile without Emacs tabs

--prefix=/usr --with-cairo --with-modules --without-compress-install --with-x-toolkit=no --with-gnutls --without-gconf --without-xwidgets --without-xaw3d ;; 3D appearance and support for XPM images --without-gsettings --with-mailutils --with-json --with-harfbuzz --with-imagemagick --with-jpeg --with-png --with-rsvg --with-tiff --with-wide-int --with-xft --with-xml2 --with-xpm CFLAGS="-O3 -mtune=native -march=native -fomit-frame-pointer" --without-makeinfo Optomise make ? make -j$(nproc)

Check the output of ./configure was successful (ignore the warnings about movemail if not using Emacs for local email management)

Build emacs (and go do something else for a while)

make

Run Emacs to check it is working without loading your own `~/.emacs.d/ configuration, to see if it works as vanilla Emacs.

./src/emacs -Q

C-x C-c to quit Emacs.

Install Emacs using the Makefile.

If all looks good then install Emacs and emacsclient using the Makefile (it does quite a bit of work, so its not just copying a few files onto the execution path)

The Makefile installs emacs in /usr/local/bin by default. Edit the makefile and update the PREFIX to install Emacs in a different location (there is probably a way to pass that as an argument to make install)

make install

Include prefix=/path/to/install/directory install in a location other than /usr/local

Running Emacs

If the default /usr/local path was used to install Emacs, then the emacs and emacsclient binary files are already on the executable path

In a terminal, run the emacs command

emacs

If using Spacemacs and you have not run any version of Emacs 28 before, all the Spacemacs packages in your Spacemacs configuration will be downloaded and compiled. This may take 5-10 minutes and Emacs may make full use of your CPU (spawning several emacs processes on multi-core computers)

Leave Emacs for a few minutes running until the CPU activity has subsided and then consider restarting Emacs to ensure the packages have been loaded in the correct order.

Desktop configuration

Add a configuration to launch /usr/local/emacs from an application launcher, e.g pressing Super key in Ubuntu or Super+Space in Regolith Linux

The Exec value is the executable, either just the Emacs executable name or the full path to the executable

[Desktop Entry]
Name=Spacemacs
GenericName=Text Editor
Comment=Digitize your life
MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;
Exec=emacs %F
Icon=/home/practicalli/.emacs.d/core/banners/img/spacemacs.png
Type=Application
Terminal=false
Categories=Development;TextEditor;
StartupWMClass=Emacs

Removing Emacs

In the Emacs source code directory where Emacs was built, use the make file to remove emacs

sudo make uninstall

Reference

Configure output

Typical output of ./configure --with-native-compilation

Configured for 'x86_64-pc-linux-gnu'.

Where should the build process find the source code? . What compiler should emacs be built with? /usr/bin/gcc-10 -g3 -O2 Should Emacs use the GNU version of malloc? no (The GNU allocators don't work with this system configuration.) Should Emacs use a relocating allocator for buffers? no (use operating system allocator) Should Emacs use mmap(2) for buffer allocation? no (use operating system mmap) What window system should Emacs use? x11 What toolkit should Emacs use? GTK3 Where do we find X Windows header files? Standard dirs Where do we find X Windows libraries? Standard dirs Does Emacs use -lXaw3d? no (superseded by gtk) Does Emacs use -lXpm? yes Does Emacs use -ljpeg? yes Does Emacs use -ltiff? yes Does Emacs use a gif library? yes -lgif Does Emacs use a png library? yes -lpng16 -lz Does Emacs use -lrsvg-2? yes Does Emacs use cairo? yes Does Emacs use -llcms2? yes Does Emacs use imagemagick? no (deprecated Emacs 27.1 - security issues) Does Emacs use native APIs for images? no (only for MS-Windows) Does Emacs support sound? yes Does Emacs use -lgpm? yes Does Emacs use -ldbus? yes Does Emacs use -lgconf? no Does Emacs use GSettings? yes Does Emacs use a file notification library? yes -lglibc (inotify) Does Emacs use access control lists? yes -lacl Does Emacs use -lselinux? yes Does Emacs use -lgnutls? yes Does Emacs use -lxml2? yes Does Emacs use -lfreetype? yes Does Emacs use HarfBuzz? yes Does Emacs use -lm17n-flt? yes Does Emacs use -lotf? yes Does Emacs use -lxft? no Does Emacs use -lsystemd? yes Does Emacs use -ljansson? yes Does Emacs use the GMP library? yes Does Emacs directly use zlib? yes Does Emacs have dynamic modules support? yes Does Emacs use toolkit scroll bars? yes Does Emacs support Xwidgets? no (deprecated) Does Emacs have threading support in lisp? yes Does Emacs support the portable dumper? yes Does Emacs support legacy unexec dumping? no Which dumping strategy does Emacs use? pdumper Does Emacs have native lisp compiler? yes

Ubuntu dependencies

TODO: review build dependency ubuntu packages and descriptions

** Dependencies needed for compiling emacs28 from source

Below are the dependencies needed to compile emacs from source:

** Optional dependencies for running my emacs configuration

These are /optional/, but will definitely improve the experience for using emacs. I recommend installing all the below tools:

Flags for building Emacs

--disable-option-checking ignore unrecognized --enable/--with options --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) --enable-FEATURE[=ARG] include FEATURE [ARG=yes] --disable-ns-self-contained disable self contained build under NeXTstep --enable-locallisppath=PATH directories Emacs should search for lisp files specific to this site --enable-checking[=LIST] enable expensive checks. With LIST, enable only specific categories of checks. Categories are: all,yes,no. Flags are: stringbytes, stringoverrun, stringfreelist, structs, glyphs --enable-profiling build emacs with low-level, gprof profiling support. Mainly useful for debugging Emacs itself. May not work on all platforms. Stops profiler.el working. --enable-autodepend automatically generate dependencies to .h-files. Requires gcc, enabled if found. --enable-gtk-deprecation-warnings Show Gtk+/Gdk deprecation warnings for Gtk+ >= 3.0 --disable-build-details Make the build more deterministic by omitting host names, time stamps, etc. from the output. --disable-largefile omit support for large files --disable-year2038 omit support for timestamps past the year 2038 --enable-gcc-warnings[=TYPE] control generation of GCC warnings. The TYPE 'yes' means to fail if any warnings are issued; 'warn-only' means issue warnings without failing (default for developer builds); 'no' means disable warnings (default for non-developer builds). --enable-check-lisp-object-type Enable compile time checks for the Lisp_Object data type, which can catch some bugs during development. --enable-link-time-optimization build with link-time optimization (experimental; see INSTALL) --disable-silent-rules verbose build output (undo: "make V=0") --enable-cross-guesses={conservative|risky} specify policy for cross-compilation guesses --disable-acl do not support ACLs

Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --without-all omit almost all features and build small executable with minimal dependencies --with-mailutils rely on GNU Mailutils, so that the --without-pop through --with-mailhost options are irrelevant; this is the default if GNU Mailutils is installed --with-pop Support POP mail retrieval if Emacs movemail is used (not recommended, as Emacs movemail POP is insecure). This is the default only on native MS-Windows. --with-kerberos support Kerberos-authenticated POP --with-kerberos5 support Kerberos version 5 authenticated POP --with-hesiod support Hesiod to get the POP server host --with-mail-unlink unlink, rather than empty, mail spool after reading --with-mailhost=HOSTNAME string giving default POP mail host --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. --with-pdumper=VALUE enable pdumper support unconditionally ('yes', 'no', or 'auto': default 'auto') --with-unexec=VALUE enable unexec support unconditionally ('yes', 'no', or 'auto': default 'auto') --with-dumping=VALUE kind of dumping to use for initial Emacs build (VALUE one of: pdumper, unexec, none; default pdumper) --with-x-toolkit=KIT use an X toolkit (KIT one of: yes or gtk, gtk2, gtk3, lucid or athena, motif, no) --with-wide-int prefer wide Emacs integers (typically 62-bit); on 32-bit hosts, this allows buffer and string size up to 2GB, at the cost of 10% to 30% slowdown of Lisp interpreter and larger memory footprint --without-xpm don't compile with XPM image support --without-jpeg don't compile with JPEG image support --without-tiff don't compile with TIFF image support --without-gif don't compile with GIF image support --without-png don't compile with PNG image support --without-rsvg don't compile with SVG image support --without-lcms2 don't compile with Little CMS support --without-libsystemd don't compile with libsystemd support --without-cairo don't compile with Cairo drawing --without-xml2 don't compile with XML parsing support --with-imagemagick compile with ImageMagick image support --without-native-image-api don't use native image APIs (GDI+ on Windows) --with-json compile with native JSON support --without-xft don't use XFT for anti aliased fonts --without-harfbuzz don't use HarfBuzz for text shaping --without-libotf don't use libotf for OpenType font support --without-m17n-flt don't use m17n-flt for text shaping --without-toolkit-scroll-bars don't use Motif/Xaw3d/GTK toolkit scroll bars --without-xaw3d don't use Xaw3d --without-xim at runtime, default X11 XIM to off --without-xdbe don't use X11 double buffering support --with-ns use Nextstep (macOS Cocoa or GNUstep) windowing system. On by default on macOS. --with-w32 use native MS Windows GUI in a Cygwin build --without-gpm don't use -lgpm for mouse support on a GNU/Linux console --without-dbus don't compile with D-Bus support --with-gconf compile with Gconf support (Gsettings replaces this) --without-gsettings don't compile with GSettings support --without-selinux don't compile with SELinux support --without-gnutls don't use -lgnutls for SSL/TLS support --without-zlib don't compile with zlib decompression support --without-modules don't compile with dynamic modules support --without-threads don't compile with elisp threading support --with-native-compilation compile with Emacs Lisp native compiler support --with-cygwin32-native-compilation use native compilation on 32-bit Cygwin --with-file-notification=LIB use a file notification library (LIB one of: yes, inotify, kqueue, gfile, w32, no) --with-xwidgets enable use of xwidgets in Emacs buffers (requires gtk3 or macOS Cocoa) --without-compress-install don't compress some files (.el, .info, etc.) when installing. Equivalent to: make GZIP_PROG= install --with-gameuser=USER_OR_GROUP user for shared game score files. An argument prefixed by ':' specifies a group instead. --with-gnustep-conf=FILENAME name of GNUstep configuration file to use on systems where the command 'gnustep-config' does not work; default $GNUSTEP_CONFIG_FILE, or /etc/GNUstep/GNUstep.conf --with-x use the X Window System --without-libgmp do not use the GNU Multiple Precision (GMP) library; this is the default on systems lacking libgmp. --without-included-regex don't compile regex; this is the default on systems with recent-enough versions of the GNU C Library (use with caution on other systems).

Some influential environment variables: CC C compiler command CFLAGS C compiler flags LDFLAGS linker flags, e.g. -L if you have libraries in a nonstandard directory LIBS libraries to pass to the linker, e.g. -l CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I if you have headers in a nonstandard directory CPP C preprocessor PKG_CONFIG path to pkg-config utility PKG_CONFIG_PATH directories to add to pkg-config's search path PKG_CONFIG_LIBDIR path overriding pkg-config's built-in search path ALSA_CFLAGS C compiler flags for ALSA, overriding pkg-config ALSA_LIBS linker flags for ALSA, overriding pkg-config XMKMF Path to xmkmf, Makefile generator for X Window System OBJC Objective C compiler command OBJCFLAGS Objective C compiler flags RSVG_CFLAGS C compiler flags for RSVG, overriding pkg-config RSVG_LIBS linker flags for RSVG, overriding pkg-config IMAGEMAGICK_CFLAGS C compiler flags for IMAGEMAGICK, overriding pkg-config IMAGEMAGICK_LIBS linker flags for IMAGEMAGICK, overriding pkg-config GTK_CFLAGS C compiler flags for GTK, overriding pkg-config GTK_LIBS linker flags for GTK, overriding pkg-config WEBKIT_CFLAGS C compiler flags for WEBKIT, overriding pkg-config WEBKIT_LIBS linker flags for WEBKIT, overriding pkg-config DBUS_CFLAGS C compiler flags for DBUS, overriding pkg-config DBUS_LIBS linker flags for DBUS, overriding pkg-config GSETTINGS_CFLAGS C compiler flags for GSETTINGS, overriding pkg-config GSETTINGS_LIBS linker flags for GSETTINGS, overriding pkg-config GCONF_CFLAGS C compiler flags for GCONF, overriding pkg-config GCONF_LIBS linker flags for GCONF, overriding pkg-config GOBJECT_CFLAGS C compiler flags for GOBJECT, overriding pkg-config GOBJECT_LIBS linker flags for GOBJECT, overriding pkg-config LIBGNUTLS_CFLAGS C compiler flags for LIBGNUTLS, overriding pkg-config LIBGNUTLS_LIBS linker flags for LIBGNUTLS, overriding pkg-config LIBSYSTEMD_CFLAGS C compiler flags for LIBSYSTEMD, overriding pkg-config LIBSYSTEMD_LIBS linker flags for LIBSYSTEMD, overriding pkg-config JSON_CFLAGS C compiler flags for JSON, overriding pkg-config JSON_LIBS linker flags for JSON, overriding pkg-config KQUEUE_CFLAGS C compiler flags for KQUEUE, overriding pkg-config KQUEUE_LIBS linker flags for KQUEUE, overriding pkg-config GFILENOTIFY_CFLAGS C compiler flags for GFILENOTIFY, overriding pkg-config GFILENOTIFY_LIBS linker flags for GFILENOTIFY, overriding pkg-config CAIRO_CFLAGS C compiler flags for CAIRO, overriding pkg-config CAIRO_LIBS linker flags for CAIRO, overriding pkg-config FREETYPE_CFLAGS C compiler flags for FREETYPE, overriding pkg-config FREETYPE_LIBS linker flags for FREETYPE, overriding pkg-config FONTCONFIG_CFLAGS C compiler flags for FONTCONFIG, overriding pkg-config FONTCONFIG_LIBS linker flags for FONTCONFIG, overriding pkg-config XFT_CFLAGS C compiler flags for XFT, overriding pkg-config XFT_LIBS linker flags for XFT, overriding pkg-config LIBOTF_CFLAGS C compiler flags for LIBOTF, overriding pkg-config LIBOTF_LIBS linker flags for LIBOTF, overriding pkg-config M17N_FLT_CFLAGS C compiler flags for M17N_FLT, overriding pkg-config M17N_FLT_LIBS linker flags for M17N_FLT, overriding pkg-config HARFBUZZ_CFLAGS C compiler flags for HARFBUZZ, overriding pkg-config HARFBUZZ_LIBS linker flags for HARFBUZZ, overriding pkg-config LCMS2_CFLAGS C compiler flags for LCMS2, overriding pkg-config LCMS2_LIBS linker flags for LCMS2, overriding pkg-config PNG_CFLAGS C compiler flags for PNG, overriding pkg-config PNG_LIBS linker flags for PNG, overriding pkg-config XRANDR_CFLAGS C compiler flags for XRANDR, overriding pkg-config XRANDR_LIBS linker flags for XRANDR, overriding pkg-config XINERAMA_CFLAGS C compiler flags for XINERAMA, overriding pkg-config XINERAMA_LIBS linker flags for XINERAMA, overriding pkg-config XFIXES_CFLAGS C compiler flags for XFIXES, overriding pkg-config XFIXES_LIBS linker flags for XFIXES, overriding pkg-config LIBXML2_CFLAGS C compiler flags for LIBXML2, overriding pkg-config LIBXML2_LIBS linker flags for LIBXML2, overriding pkg-config LIBSECCOMP_CFLAGS C compiler flags for LIBSECCOMP, overriding pkg-config LIBSECCOMP_LIBS linker flags for LIBSECCOMP, overriding pkg-config

Use these variables to override the choices made by `configure' or to help it to find libraries and programs with nonstandard names/locations.

Report bugs to bug-gnu-emacs@gnu.org. GNU Emacs home page: https://www.gnu.org/software/emacs/. General help using GNU software: http://www.gnu.org/gethelp/.

practicalli-johnny commented 2 years ago

Published at https://practical.li/blog/posts/build-emacs-28-on-ubuntu/