Machinekit

Machinekit

Install packages required for building Debian packages with Docker

These instructions assume that you have sudo rights and that you can execute bash scripts on your machine. You can build the EMCApplication debian package this way which can be then installed on target machine by the apt utility. You will also need to have installed Git executable and for container specific instructions also Docker CLI and Docker daemon. Directions for both can be found in Set up common development environment for all Machinekit projects.

EMCApplication is tightly tracking https:github.com/linuxCNC/linuxcnc[LinuxCNC@master] branch with minimal set of additional patches to use the Machinekit-HAL project. You can try to follow LinuxCNC’d documentation, but be aware that any part pertaining RuntimeAPI (RTAPI), Hardware Abstraction Layer (HAL) and most HAL modules and Python code will not be accurate as these components come from Machinekit-HAL package.

The supported distributions for which you can build apt packages is the intersection of supported distribution of Machinekit-HAL and supported distributions for LinuxCNC.

Currently, Machinekit-HAL code stack is fully Python 3 ported, LinuxCNC code stack is made so both Python 2 and Python 3 are supported (with some parts [mainly GUI] requiring Python 2), however the Debian packaging recipes still support only Python 2 (this problem is being intensively worked on in PR#943). This means that for building of successful packages the input version of machinekit-hal and machinekit-hal-dev packages have to be 0.4.20868 maximum.

Following steps presume that you have cloned the EMCApplication repository to local folder and that you know the UID and GID of your user.

git clone https://github.com/machinekit/emcapplication.git
id

Starting from current version of Debian Buster image downloaded from DockerHUB (replace with version for which you want to build the packages), the following commands would be used for building:

docker run -it --rm -v "$(pwd):/machinekit/emca" debian:buster bash -i
apt update
apt upgrade
apt install build-essential fakeroot devscripts equivs sudo curl python lsb-release apt-cudf
addgroup machinekit --gid 1000
adduser machinekit --uid 1000 --gid 1000
echo "machinekit ALL = (ALL) NOPASSWD: ALL" >> /etc/sudoers
chown -R machinekit:machinekit /machinekit
su machinekit
curl -1sLf \
  'https://dl.cloudsmith.io/public/machinekit/machinekit/cfg/setup/bash.deb.sh' \
  | sudo -E bash
curl -1sLf \
  'https://dl.cloudsmith.io/public/machinekit/machinekit-hal/cfg/setup/bash.deb.sh' \
  | sudo -E bash
cd /machinekit/emca
./debian/configure machinekit-hal=0.4.20894-1.gitebe1344a0~$(lsb_release -cs) no-docs
mk-build-deps -irs sudo -t 'apt-cudf-get --solver aspcud -o Debug::pkgProblemResolver=0 -o APT::Install-Recommends=0'
dpkg-buildpackage -us -uc
cp ../*.deb .
exit
exit

At the end you will have several new .deb files in your folder.

You should replace --gid 1000 and --uid 1000 with numbers which you got from id command in previous step.

As EMCApplication packages are pinning the version of Machinekit-HAL packages dependency to one specific version, we need to pass this version string to debian/configure script as debian/configure machinekit-hal=${VERSION}. One can use either version available from one of accessible Debian repositories, or already installed version.

To determine which Machinekit-HAL packages are currently installed on the system, run:

apt list --installed | grep machinekit

As standard Debian mk-build-deps script with apt manager cannot resolve build dependencies fixed to one particular version, we need to install apt-cudf package to be able to choose different dependency solver.

LinuxCNC does not support cross-building of Debian packages, which is the reason why you will need to build the EMCApplication natively. Because of time needed to build the whole application on arm devices, the best course of action is to use QEMU-user-static binaries for running the foreign architecture code on amd64 machine. There are multiple ways how to reach functional system: First, use Multiarch/QEMU-user-static Docker image (please heed advice in this issue if you get sudo related problem), or Second, install the qemu-user-static Debian package (preferably the latest, Sid version).

Then run the Docker container with specific architecture (here arm32):

docker run -it --rm -v "$(pwd):/machinekit/emca" arm32v7/debian:buster bash -i
dpkg --print-architecture && uname -m
apt update
apt upgrade
apt install build-essential fakeroot devscripts equivs sudo curl python lsb-release apt-cudf
addgroup machinekit --gid 1000
adduser machinekit --uid 1000 --gid 1000
echo "machinekit ALL = (ALL) NOPASSWD: ALL" >> /etc/sudoers
chown -R machinekit:machinekit /machinekit
su machinekit
sudo apt install debian-keyring debian-archive-keyring apt-transport-https
curl -k 'https://dl.cloudsmith.io/public/machinekit/machinekit/cfg/gpg/gpg.A9B6D8B4BD8321F3.key' | sudo apt-key add -
curl -k https://dl.cloudsmith.io/public/machinekit/machinekit/cfg/setup/config.deb.txt?distro=$(lsb_release -is | tr "[:upper:]" "[:lower:]")\&codename=$(lsb_release -cs) | sudo tee -a /etc/apt/sources.list.d/machinekit-machinekit.list
curl -k 'https://dl.cloudsmith.io/public/machinekit/machinekit-hal/cfg/gpg/gpg.D35981AB4276AC36.key' | sudo apt-key add -
curl -k https://dl.cloudsmith.io/public/machinekit/machinekit-hal/cfg/setup/config.deb.txt?distro=$(lsb_release -is | tr "[:upper:]" "[:lower:]")\&codename=$(lsb_release -cs) | sudo tee -a /etc/apt/sources.list.d/machinekit-machinekit-hal.list
sudo apt update
cd /machinekit/emca
./debian/configure machinekit-hal=0.4.20894-1.gitebe1344a0~$(lsb_release -cs) no-docs
mk-build-deps -irs sudo -t 'apt-cudf-get --solver aspcud -o Debug::pkgProblemResolver=0 -o APT::Install-Recommends=0'
dpkg-buildpackage -us -uc
cp ../*.deb .
exit
exit

Running Docker containers has a problem with SLL/certificates/PGP (generally speaking there is some problem with encryption). This is why the previous example is using the manual installation of Debian registry instead of the automatic script like native build. (Here is the original procedure from Cloudsmith.) Information why is this happening and how to solve this issue are greatly appreciated.

All other notes mentioned with native build previously are also valid here.

Install packages required for building Run-In-Place

Building EMCApplication to run as separate and isolated software bundle (known as a RIP build from LinuxCNC world) is not possible. In all cases the Machinekit-HAL will need to be installed onto the system in the form of Debian packages. timeAPI to find them. (This condition could be circumvented with changing loader rules.)

All that would be compiled and ruI to find them. (This condition could be circumvented with changing loader rules.)

All that would be compiled and run from the given directory, will be the Enhanced Machine Controller and Graphical User Interfaces.

From root of the EMCApplication source directory run:

apt install build-essential fakeroot devscripts equivs python lsb-release apt-cudf
curl -1sLf \
  'https://dl.cloudsmith.io/public/machinekit/machinekit/cfg/setup/bash.deb.sh' \
  | sudo -E bash
curl -1sLf \
  'https://dl.cloudsmith.io/public/machinekit/machinekit-hal/cfg/setup/bash.deb.sh' \
  | sudo -E bash
debian/configure machinekit-hal=0.4.20894-1.gitebe1344a0~$(lsb_release -cs) no-docs
mk-build-deps -irs sudo -t 'apt-cudf-get --solver aspcud -o Debug::pkgProblemResolver=0 -o APT::Install-Recommends=0'
cd src
./autogen.sh
./configure --with-hal=machinekit-hal
make -j$(nproc)
sudo make install
source ../scripts/rip-environment
linuxcnc

Now you should have a functioning Machinekit-HAL + EMCApplication installation. You will need to rerun source ../scripts/rip-environment code in each new terminal to populate the environment with correct values.

It is also viable to disallow apt to upgrade the machinekit-hal package to higher version:

sudo apt-mark hold machinekit-hal

Why do I have to pass Machinekit-version when building Debian packages?

It is important to understand what Machinekit EMCApplication really is. From programming point of view it is just set of patches applied over LinuxCNC@master branch which it periodically tracks. (Meaning changes happening in the upstream LinuxCNC@master are from time to time merged into the EMCApplication@machinekit/master branch.) And all what these additional patches are doing is to allow parts of LinuxCNC CNC stack (historically called Enhanced Motion Controller) to use external HAL dependency.

Machinekit-HAL project and LinuxCNC project both have certain development vector independent of each other, i.e. Machinekit-HAL does not care about LinuxCNC and LinuxCNC does not care about Machinekit-HAL. This represents quite interesting problem when creating dpkg packages, because EMCApplication package has to depend on Machinekit-HAL package, but also specific version of EMCApplication has to depend on specific version of Machinekit-HAL (or specific range) as later or previous versions of Machinekit-HAL can include incompatible code. And the easiest way how to guarantee the compatibility is to require the same version of Machinekit-HAL package as install dependency of EMCApplication as was used in build stage.

This way the apt will make sure that the correct version of Machinekit-HAL is installed for the EMCApplication issue-less operation.

Using the mk-build-deps script from the devscripts package for creating environment capable of problem-less building of packages by invocating dpkg-buildpackage or compiling and linking the software during Run-In-Place build needs the debian/control file with correctly stated Build-Depends: machinekit-hal (= dependency. This is why we need to pass the machinekit-hal package version early in stage when calling the debian/configure machinekit-hal=${VERSION} script.