LLVM can be used as an alternative to GNU's compiler, GCC. The main benefit of using LLVM compilers instead of GCC is their lower memory usage, faster compile time and better diagnostics. There are some Benchmarks on the [http://clang.llvm.org/features.html#performance Clang] and [http://www.phoronix.com/scan.php?page=article&item=llvm3_gcc_open64 Phoronix] homepages.

+

−

It may happen that some programs do not compile (like glibc) because they depend on GCC-specific language extensions [http://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html] (this is why the whole BSD code can be compiled with LLVM but some GNU code cannot) or segfault after successful compilation with LLVM (like xorg-server) but after following this guide, the system will still be able to compile packages with gcc. So if something goes wrong, it can be switched back to gcc for the particular package by uncommenting lines in /etc/make.conf and the bug should be reported.

+

Emacs is a famous text editor, famous by its flexibility and extensibility. One manual describes it as "the extensible, customizable, self-documenting, real-time display editor".

This page is designed to give users a good place to share their config and settings for a nice emacs setup.

−

Further, using LLVM 3.0 and up, there is a third way to compile with LLVM: the dragonegg package creates a gcc-plugin, that uses LLVM's optimizers but parses the code and creates binaries with gcc, which means that everything that compiles and works with gcc should work with dragonegg also. This plugin can be enabled by using a single CFLAG. Since LLVM 3.0 the old llvm-gcc package is deprecated and replaced by dragonegg, so it will disappear from portage with llvm version 2.9.

+

== Installing emacs ==

+

To install {{Package|app-editors/emacs}}, run the following command:

+

<console>

+

###i## emerge -av emacs

+

</console>

+

for the standard gnu emacs {{Package|app-editors/xemacs}} and

+

<console>

+

###i## emerge -av xemacs

+

</console>

−

==LLVM Frontends==

+

for the 1980 created fork of emacs, both should handle the same, while emacs on its own stands here for both. If you install additional extensions for both you might need to add <tt>app-emacs</tt> or <tt>app-xemacs</tt> to the package as there are two different versions for both.

−

To be able to compile some sourcecode of a specific language, LLVM needs an appropriate frontend. There are clang, llvm-gcc and dragonegg in portage.

+

−

The goal of the Clang project is to create a new C, C++, Objective C and Objective C++ front-end for the LLVM compiler.

+

== What emacs is and what it is not ==

−

llvm-gcc is a modified version of gcc that compiles C/ObjC programs into native objects, LLVM bitcode or LLVM assembly language, depending upon the options. As written in the previous section, dragonegg replaced llvm-gcc in version 3.0.

+

# Emacs is primarily a text editor and not a word processor, it concentrates on manipulating any kind of text, rather than manipulating the font and look. It is client and GUI based, so can be used on local box in graphical environments with a GUI and remote on a server in a client mode.

+

# Emacs provides commands for manipulate every kind of text and syntax highlighting.

−

So after installing llvm, clang and dragonegg, you will be able to choose between gcc and llvm whenever you like or use them both at the same time.

+

=== Customizability ===

−

== Install LLVM and its Frontends ==

+

'''Emacs is highly customizable:'''

−

Simply emerge the packages on ~arch systems. On arch systems you have to unmask some packages first. dragonegg requires gcc's ''lto'' USE-flag to be set and works with gcc 4.5 and gcc 4.6.

+

−

<console>

+

−

###i## emerge llvm clang dragonegg

+

−

</console>

+

−

Note, that for clang++ the C++ headers search path is hardcoded to the active gcc profile.

+

−

If you change the active gcc profile, or update gcc to a new version, you will have to remerge clang to update the search path.

+

−

To use dragonegg, run gcc as usual, with an extra command line argument <tt>-fplugin=/usr/lib/llvm/dragonegg.so</tt>

+

* the <tt>customize</tt> extension, which allows settings of customized variables, such as color themes, graphical interface, etc. This part is intended for emacs beginners, who do not want to work with Emacs lisp code.

−

If you change the active gcc profile, or update gcc to a new version, you will have to remerge dragonegg to update the plugin.

+

* combine keystrokes to execute complex makros.

+

* using Emacs Lisp. Designed for the emacs professional.

−

After the installation, check which CPUs are supported by using the command

+

=== Extensibility ===

−

<console>

+

−

###i## llvm-as < /dev/null | llc -mcpu=help

+

−

</console>

+

−

and then add the following lines to <code>/etc/make.conf</code> (uncommenting the lines you need) to enable compilation via LLVM, adapting the march-option according to the previous command:

+

−

in <code>/etc/portage/make.conf</code>:

+

As a result of the above points, Emacs behaviour can be easily definied to all text behavings without limit. Like some of the examples below show you:

−

{{File

+

−

|/etc/portage/make.conf|<pre>

+

−

# LLVM

+

−

#CC="/usr/bin/clang"

+

−

#CXX="/usr/bin/clang++"

+

−

# llvm-gcc for C++ code and fortran

+

* AUCTeX, A suite for LaTeX and other TeX versions,

−

# llvm-gcc is deprecated and only used with LLVM 2.9

+

* ERC, A Emacs IRC client,

−

#CC="/usr/bin/llvm-gcc"

+

* ORG-mode, A Emacs PIM and Orga tool

−

#CXX="/usr/bin/llvm-g++"

+

* Wanderlust, A highly flexible Mail tool for Emacs

−

#CPP="/usr/bin/llvm-cpp"

+

−

#F77="/usr/bin/llvm-gfortran"

+

−

# Flags for clang: Insert your arch here instead of k8 and have a look at the manpage of clang for flag descriptions.

+

== User Configs ==

−

# Some gcc flags like -pipe and -pthread also work, though they might be ignored by clang.

+

=== golodhrim's config ===

−

#CFLAGS="-march=k8 -O2"

+

==== .emacs ====

+

Edit the file <tt>~/.emacs</tt>:

−

# Flags for dragonegg; just use all the gcc flags you like and append -fplugin=/path/to/dragonegg.so

+

<pre>

−

#CFLAGS="-march=k8 -O2 -fplugin=/usr/lib64/llvm/dragonegg.so"

+

;;;;;;;;;;;;;;;;;;;;;;

−

</pre>}}

+

;; General Settings ;;

+

;;;;;;;;;;;;;;;;;;;;;;

−

{{Note}} Have a look at clang's manpages for additional information. If you get errors that your compiler cannot produce code, you should check your flags, e.g. don't use <tt>-O4 -flto -S</tt> or stuff like that; the examples above will work.

+

(setq emacs-root-dir (concat (getenv "HOME") "/em/"))

−

== Using clang with portage ==

+

(setq inhibit-startup-message t) ;; Suppress the startup message

+

(setq standard-indent 4) ;; Default indent level is 3 chars

+

(setq-default indent-tabs-mode nil) ;; Indent with spaces, not tabs

−

Although Gentoo package tree is not designed to be used with compiler other than GCC, clang can be enforced on most of the packages through ''CC'' and ''CXX'' variables.

Please note, however, that many of Gentoo packages still don't build with clang and a few don't work correctly after being built. That's why we suggest using <tt>/etc/portage/env</tt> file to enable the use of clang per-package.

+

(line-number-mode 1) ;; Show line-number in the mode line

+

(column-number-mode 1) ;; Show column-number in the mode line

−

In order to do that, first create a new environment override to use in <code>/etc/portage/env/clang</code>:

+

(setq auto-fill-mode 1) ;; Line wrap

−

{{File

+

−

|/etc/portage/env/clang|<pre>

+

−

CC=clang

+

−

CXX=clang++

+

−

</pre>}}

+

−

Then you can enable use of clang for packages using the [[:/etc/portage/env|/etc/portage/package.env]] file:

+

(set-default-font "Inconsolata-12")

−

{{File

+

−

|/etc/portage/package.env|<pre>

+

−

app-foo/bar clang

+

−

app-bar/baz clang

+

−

</pre>}}

+

−

If you want to use clang by default you can and need to specify some core packages. Here is small list of core packages that are currently failing on clang, but not that could be outdated:

+

(setq browse-url-browser-function 'browse-url-generic

−

{{File

+

browse-url-generic-program "google-chrome")

−

|/etc/portage/env/gcc|<pre>

+

−

CC=gcc

+

−

CXX=g++

+

−

</pre>}}

+

−

in addition, it is recommend to add compiler flags there:

+

(global-set-key (kbd "C-<prior>") 'previous-buffer)

−

{{File

+

(global-set-key (kbd "C-<next>" ) 'next-buffer )

−

|/etc/portage/env/gcc|<pre>

+

−

CFLAGS="-O2 -march=native -mtune=native -pipe"

+

−

CXXFLAGS="-O2 -march=native -mtune=native -pipe"

+

−

LDFLAGS="-Wl,--as-needed"

+

−

#You can disable gold link here

+

−

#EXTRA_ECONF="--enable-gold=default"

+

−

</pre>}}

+

−

And in <code>/etc/portage/package.env</code>:

−

{{File

−

|/etc/portage/package.env|<pre>

−

#---------------CORE PACKAGES TO BUILD WITH GCC:

−

sys-apps/which gcc

−

sys-fs/reiserfsprogs gcc

−

sys-libs/ncurses gcc

−

sys-libs/zlib gcc

−

sys-apps/busybox gcc

−

sys-fs/e2fsprogs gcc

−

sys-devel/binutils gcc

−

sys-libs/glibc gcc

−

sys-devel/dragonegg gcc

−

dev-libs/openssl gcc

−

sys-boot/grub gcc

−

#---------------USER PACKAGES TO BUILD WITH GCC:

−

sys-apps/pacman gcc

−

www-client/firefox gcc

−

x11-libs/cairo gcc

−

media-libs/mesa gcc

−

</pre>}}

−

If you have {{Package|app-portage/flaggie}} installed, you can modify <code>/etc/portage/package.env</code> by running the following:

+

(setq load-path (cons "~/.emacs.d/plugins" load-path))

−

<console>

+

−

###i## flaggie app-foo/bar app-bar/baz +clang

+

−

</console>

+

−

== Enabling link-time optimizations ==

+

(setq global-font-lock-mode 1)

−

The ''link-time optimization'' feature defers optimizing the resulting executables to linking phase. This can result in better optimization of packages but is unsupported in Gentoo, and many packages simply fail to build.

+

(show-paren-mode 1)

−

When using LTO, clang compiles units into LLVM byte-code rather than machine code. In order to support linking such object files, the [[gold]] linker must be installed and set as the default linker, as it does support plugins.

Similarly, ''ar'' needs plugin support as well. Sadly, binutils ar doesn't support passing '--plugin'' option before the actual command. Thus, we need to create a wrapper for it in <code>/usr/local/bin/clang-ar</code>:

If that's done, you can create a new environment override profile for LTO-enabled clang in <code>/etc/portage/env/clang-lt</code>:

+

;;;;;;;;;;;;;;;;;;;;

−

{{File

+

;; Org-mode stuff ;;

−

|/etc/portage/env/clang-lt|<pre>

+

;;;;;;;;;;;;;;;;;;;;

−

CC='clang'

+

−

CXX='clang++'

+

−

CFLAGS="${CFLAGS} -O4"

+

−

CXXFLAGS="${CXXFLAGS} -O4"

+

−

LDFLAGS="${LDFLAGS} -O4 -Wl,-plugin,/usr/lib/llvm/LLVMgold.so"

+

−

AR='/usr/local/bin/clang-ar'

+

−

RANLIB=':'

+

−

NM='nm --plugin /usr/lib64/llvm/LLVMgold.so'

+

−

</pre>}}

+

−

Note that the link-time optimizations were indirectly enabled here via ''-O4''. If you don't want to enable other optimizations enforced by ''-O3'', please use ''-flto'' instead. You need to also pass optimization flags when linking because that's where clang needs them.

Revision as of 17:35, February 22, 2014

Emacs is a famous text editor, famous by its flexibility and extensibility. One manual describes it as "the extensible, customizable, self-documenting, real-time display editor".

This page is designed to give users a good place to share their config and settings for a nice emacs setup.

Installing emacs

To install app-editors/emacs (package not on wiki - please add), run the following command:

# emerge -av emacs

for the standard gnu emacs app-editors/xemacs (package not on wiki - please add) and

# emerge -av xemacs

for the 1980 created fork of emacs, both should handle the same, while emacs on its own stands here for both. If you install additional extensions for both you might need to add app-emacs or app-xemacs to the package as there are two different versions for both.

What emacs is and what it is not

Emacs is primarily a text editor and not a word processor, it concentrates on manipulating any kind of text, rather than manipulating the font and look. It is client and GUI based, so can be used on local box in graphical environments with a GUI and remote on a server in a client mode.

Emacs provides commands for manipulate every kind of text and syntax highlighting.

Customizability

Emacs is highly customizable:

the customize extension, which allows settings of customized variables, such as color themes, graphical interface, etc. This part is intended for emacs beginners, who do not want to work with Emacs lisp code.

combine keystrokes to execute complex makros.

using Emacs Lisp. Designed for the emacs professional.

Extensibility

As a result of the above points, Emacs behaviour can be easily definied to all text behavings without limit. Like some of the examples below show you: