LinuxCNCKnowledgeBase | RecentChanges | PageIndex | Preferences | LinuxCNC.org

This page describe how to compile and install EMC2 on Gentoo using portage. This howto is targeted for experienced Linux user. User are expected to atleast be able to compile a kernel without much difficulty. For others, please see Installing EMC2.

Note: The provided ebuilds here is created with minimal efforts. It's only tested on x86 and with default package USE flags. Some dependencies might be missing, please update this page if you found any.


1. Preparation
2. RTAI Kernel
2.1. Installing RTAI kernel
2.2. Upgrading RTAI kernel
3. RTAI library
3.1. Installing RTAI library
3.2. Upgrading RTAI library
4. EMC2
4.1. Installing EMC2
4.2. Upgrading EMC2

1. Preparation

First, create a local overlay
 mkdir /usr/local/portage

Then, add overlay to /etc/make.conf

 PORTDIR_OVERLAY="${PORTDIR_OVERLAY} /usr/local/portage"

Next, create folder for EMC2 and RTAI ebuilds

 mkdir /usr/local/portage/sys-kernel/rtai-sources
 mkdir /usr/local/portage/sci-misc/rtai
 mkdir /usr/local/portage/sci-misc/emc

2. RTAI Kernel

Note: Skip RTAI kernel and library installation step if you only need EMC2 with simulation.

Save the following content to /usr/local/portage/sys-kernel/rtai-sources/rtai-sources-
inherit kernel-2

DESCRIPTION="Linux kernel with RTAI extension"
HOMEPAGE="http://www.kernel.org https://www.rtai.org"




Next, download RTAI kernel patches from RTAI CVS [1], and save it under /usr/local/portage/sys-kernel/rtai-sources/files

Then, create manifest files for rtai-sources ebuild.

 ebuild /usr/local/portage/sys-kernel/rtai-sources/rtai-sources- manifest

2.1. Installing RTAI kernel

Unmask the rtai-sources. Edit /etc/portage/package.keywords and add new line with:
 sys-kernel/rtai-sources **

Then, install the rtai kernel source

 emerge -av rtai-sources 

Select RTAI kernel as default then build the kernel with genkernel or make menuconfig

 eselect kernel list (this will show RTAI kernel index number>
 eselect kernel set <RTAI kernel index number>
 genkernel --menuconfig all

Update grub to point to new rtai kernel image

2.2. Upgrading RTAI kernel

To upgrade rtai kernel, you need to copy the rtai-sources ebuild and rename it to proper versioning scheme. You'll also need to edit the ebuild and change MY_PV value to correct patch version. The get latest patch version, visit RTAI CVS [1] , download the patch and save it under /usr/local/portage/sys-kernel/rtai-sources/files

For example, if the patches is named hal-linux-

New ebuild name: rtai-sources-<something>.ebuild
MY_PV value: 2.7-04
r<something> value: can be any number and useful if you want to bump package when new RTAI patch released but still using the same kernel version

Finally, you'll need to update manifest for the new ebuild.

 ebuild /usr/local/portage/sys-kernel/rtai-sources/rtai-sources- manifest

Then follow the Installing RTAI kernel Finally, rebuild all related modules with module-rebuild (Install with "emerge -av module-rebuild" if you haven't install it)

 module-rebuild rebuild
That will rebuild RTAI and EMC2 modules to match with new kernel

3. RTAI library

Before continuing, you must reboot the system with RTAI kernel. Next, save the following content to /usr/local/portage/sci-misc/rtai/rtai-9999.ebuild


inherit linux-mod python cvs flag-o-matic

DESCRIPTION="Real Time Application Interface for Linux"

IUSE="debug +fpu +testsuite doc compat +static-inline extern-inline +diag-tsc-sync +master-tsc-cpu +tune-tsc-sync sched-lock-isr +rtc-freq long-timed-lists +sched-8254-latency +sched-apic-latency +sched-lxrt-numslots +lxrt-use-linux-syscall  align-priority +cal-freq-fact +bits +fifos +netrpc netrpc-rtnet +shm +sem rt-poll rt-poll-on-stack +msg +mbx +tbx +tasklets +mq +math math-c99 +malloc malloc-tlsf +malloc-vmalloc +malloc-heap-size +kstack-heap-size task-switch-signal trace +usi +watchdog leds comedi-lxrt comedi-lock cplusplus +rtdm +rtdm-fd-max +rtdm-shirq +rtdm-select +serial +16550a rtailab ktasks-sched-lxrt"



src_unpack() {

src_configure () {
        econf \
                --with-module-dir="/lib/modules/${KV_FULL}/rtai" \
                --enable-cpus=3 \
                --prefix="/usr/realtime" \
                $(use_enable fpu) \
                $(use_enable testsuite) \
                $(use_enable doc dox-doc) \
                $(use_enable doc latex-doc) \
                $(use_enable doc verbose-latex) \
                $(use_enable doc dbx) \
                $(use_enable compat) \
                $(use static-inline && echo --with-lxrt-inline=static) \
                $(use extern-inline && echo --with-lxrt-inline=extern) \
                $(use_enable diag-tsc-sync) \
                $(use_enable master-tsc-cpu master-tsc-cpu 0) \
                $(use_enable tune-tsc-sync) \
                $(use_enable sched-lock-isr) \
                $(use_enable rtc-freq rtc-freq 0) \
                $(use_enable long-timed-lists) \
                $(use_enable sched-8254-latency sched-8254-latency 4700) \
                $(use_enable sched-apic-latency sched-apic-latency 3944) \
                $(use_enable sched-lxrt-numslots sched-lxrt-numslots 150) \
                $(use_enable lxrt-use-linux-syscall) \
                $(use_enable align-priority) \
                $(use_enable cal-freq-fact cal-freq-fact 0) \
                $(use_enable bits bits m) \
                $(use_enable fifos fifos m) \
                $(use_enable netrpc netrpc m) \
                $(use_enable netrpc-rtnet netrpc-rtnet m) \
                $(use_enable shm shm m) \
                $(use_enable sem sem m) \
                $(use_enable rt-poll rt-poll m) \
                $(use_enable rt-poll-on-stack rt-poll-on-stack m) \
                $(use_enable msg msg m) \
                $(use_enable mbx mbx m) \
                $(use_enable tbx tbx m) \
                $(use_enable tasklets tasklets m) \
                $(use_enable mq mq m) \
                $(use_enable math math m) \
                $(use_enable math-c99 math-c99 m) \
                $(use_enable malloc) \
                $(use_enable malloc-tlsf) \
                $(use_enable malloc-vmalloc) \
                $(use_enable malloc-heap-size malloc-heap-size 2048) \
                $(use_enable kstack-heap-size kstack-heap-size 512) \
                $(use_enable task-switch-signal) \
                $(use_enable trace) \
                $(use_enable usi usi m) \
                $(use_enable watchdog watchdog m) \
                $(use_enable leds leds m) \
                $(use_enable comedi-lxrt comedi-lxrt m) \
                $(use_enable comedi-lock comde-lock m) \
                $(use_enable cplusplus cplusplus m) \
                $(use_enable rtdm) \
                $(use_enable rtdm-fd-max rtdm-fd-max 128) \
                $(use_enable rtdm-shirq) \
                $(use_enable rtdm-select) \
                $(use_enable debug enable-debug-rtdm) \
                $(use_enable serial) \
                $(use_enable 16550a) \
                $(use 16550a && echo --with-16550a-ham=any) \
                $(use_enable rtailab) \
                $(use_enable debug module-debug) \
                $(use_enable debug user-debug) \
                $(use_enable ktasks-sched-lxrt)
        # remove invalid file delete
        find . -name 'GNUmakefile' -type f -print0 | xargs -0 sed -i 's:rm -f /usr/src/linux/.tmp_versions/rtai_\*.mod /usr/src/linux/.tmp_versions/\*_rt.mod;::g'

src_install () {
        emake  DESTDIR="${D}" install || die "install failed"
        rm "${D}/usr/realtime/include/asm"
        mv "${D}/usr/realtime/include/asm-i386" "${D}/usr/realtime/include/asm" || die "rename failed"
        dodoc README.* ChangeLog || die
Change the line
With the same amount of cpu core you have (in above case, it's 3 core CPU).

As usual, create the manifest for the new ebuild.

 ebuild /usr/local/portage/sci-misc/rtai/rtai-9999.ebuild manifest

Note: In theory, this ebuild will allow user to enable or disable any RTAI modules based on USE flag. But in practice, it's never tested so it might not work with certain USE flags combination.

3.1. Installing RTAI library

To install, unmask the rtai ebuild first. Edit /etc/portage/package.keywords and add the following line:
 sci-misc/rtai **

Since the rtai will get installed automatically by EMC2 dependencies, we'll skip manual install and go to EMC2 installation.

3.2. Upgrading RTAI library

As this is a live ebuild, simply rebuild the package and portage will fetch a source for the latest commit in RTAI CVS. Also, user can use ECVS_REVISION variable to build package to specific CVS commit revision.eg:
 ECVS_REVISION=1000 emerge -1 rtai (this will build rtai at commit 1000) 

4. EMC2

Save the following content to /usr/local/portage/sci-misc/emc/emc-9999.ebuild


inherit linux-mod autotools python git flag-o-matic

DESCRIPTION="G-Code interpreter for Linux based CNC"

IUSE="+X +gtk nls +python +doc-pdf doc-html simulator"

        !simulator? ( sci-misc/rtai )
        X? ( x11-libs/libXinerama 
            x11-libs/libICE )"


src_unpack() {

src_configure () {
        cd src
        econf \
                --with-module-dir="/lib/modules/${KV_FULL}/rtai/" \
                $(use_enable doc-pdf build-documentation build-documentation pdf) \
                $(use_enable doc-html build-documentation build-documentation html) \
                $(use_enable nls) \
                $(use_enable gtk) \
                $(use_enable python) \
                $(use_enable simulator) \
                $(use_with X x)
        # remove invalid ldconfig call
        sed -i -e 's:-ldconfig $(DESTDIR)$(libdir)::g' Makefile
        # replace pci_find_device to pci_get_device
        find . -type f -print0 | xargs -0 sed -i 's:pci_find_device:pci_get_device:g'

src_install () {
        cd src
        emake || die "compile failed"
        emake  DESTDIR="${D}" localedir="/usr/share/locale/" install || die "install failed"

Create the manifest.

 ebuild /usr/local/portage/sci-misc/emc/emc-9999.ebuild manifest

4.1. Installing EMC2

While the EMC2 main program itself doesn't need GNOME libraries, some tools bundle with EMC2 such as stepconf and ladder diagram printing do need GNOME libraries to work. If you want to use those tools, maybe it's better to install GNOME first. Skip this step if you don't need such function and prefer minimalistic setup.
 emerge -av gnome

To install EMC2, unmask the ebuild first. Edit /etc/portage/package.keywords and add the following line:

 sci-misc/emc **

Next, if you previously installed rtai manually these files should be removed.

Next, install EMC2

 emerge -av emc
RTAI library will automatically installed as a dependecies.

To enable simulation only, set USE flag to simulator. This will skip RTAI kernel and library installation. Edit /etc/portage/package.use, add new line

 sci-misc/emc simulator

4.2. Upgrading EMC2

As this is a live ebuild, simply rebuild the package and portage will fetch a source for the latest commit in EMC2 GIT. Also, user can use EGIT_COMMIT variable to build package to specific GIT commit revision. eg:
 EGIT_COMMIT=db9bfd3653de23693db67ec5a0534e4d4ac97f7d emerge -1 emc (this will build emc at commit db9bfd3653de23693db67ec5a0534e4d4ac97f7d)
There's also EGIT_BRANCH variable if user want to switch to another git branch

LinuxCNCKnowledgeBase | RecentChanges | PageIndex | Preferences | LinuxCNC.org
This page is read-only. Follow the BasicSteps to edit pages. | View other revisions
Last edited July 20, 2011 10:19 am by Johannesbauer (diff)
Published under a Creative Commons License