Skip to content

Commit d32027c

Browse files
committed
switchkins: install the implementation as source for out-of-tree modules
A realtime module cannot link a library, so an out-of-tree kinematics module has to compile the switchkins implementation itself. Asking it for the path to a source tree, as the template did, leaves anybody on a deb install with nothing to point at. Install switchkins.c and kins_util.c into share/linuxcnc, the way mesa_modbus.c.tmpl already is, and put that directory on the realtime include path. The template then reads #include <switchkins.c> #include <kins_util.c> and builds as it stands.
1 parent 1c8dcc5 commit d32027c

7 files changed

Lines changed: 40 additions & 33 deletions

File tree

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ share/desktop-directories/linuxcnc-cnc.directory
2121
share/desktop-directories/linuxcnc-ref.directory
2222
share/desktop-directories/linuxcnc-doc.directory
2323
share/linuxcnc/mesa_modbus.c.tmpl
24+
share/linuxcnc/switchkins.c
25+
share/linuxcnc/kins_util.c
2426
src/modules.order
2527
/configs/*/emc.nml
2628
!/configs/common/emc.nml

‎debian/linuxcnc-uspace-dev.install‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ usr/lib/liblinuxcnc.a
55
usr/lib/*.so
66
usr/share/linuxcnc/Makefile.modinc
77
usr/share/linuxcnc/mesa_modbus.c.tmpl
8+
usr/share/linuxcnc/switchkins.c
9+
usr/share/linuxcnc/kins_util.c

‎docs/src/motion/switchkins.adoc‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -438,18 +438,21 @@ it gets the kinematics switching, the 'kinstype.is-N' pins, the
438438
without reimplementing any of them.
439439

440440
The template is src/hal/components/switchkinscomp.comp. Copy and
441-
rename it (both the file and the component name), point its TOPDIR
442-
at a LinuxCNC source tree, and replace the example kinstype with the
443-
real kinematics:
441+
rename it (both the file and the component name) and replace the
442+
example kinstype with the real kinematics. The implementation itself
443+
is included:
444444

445445
[source,c]
446446
----
447-
#define TOPDIR /home/myname/linuxcnc-dev
448-
// ...
449-
#include USE_TOPDIR(src/emc/kinematics/switchkins.c)
450-
#include USE_TOPDIR(src/emc/kinematics/kins_util.c)
447+
#include <switchkins.c>
448+
#include <kins_util.c>
451449
----
452450

451+
A realtime module cannot link a library, so the implementation arrives
452+
as source: switchkins.c and kins_util.c are installed beside the
453+
headers, in share/linuxcnc, and halcompile already looks there. With
454+
a deb install they come from the linuxcnc-dev package.
455+
453456
The module registers each of its kinstypes and calls switchkinsInit()
454457
from EXTRA_SETUP(), which halcompile runs after hal_init() and before
455458
hal_ready(). See <<sec:switchkins-code-notes,Code Notes>> for both

‎src/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,7 @@ ifeq ($(BUILD_GUI),yes)
774774
endif
775775

776776
$(FILE) ../src/hal/drivers/mesa-hostmot2/modbus/*.tmpl $(DESTDIR)$(prefix)/share/linuxcnc/
777+
$(FILE) ../src/emc/kinematics/switchkins.c ../src/emc/kinematics/kins_util.c $(DESTDIR)$(prefix)/share/linuxcnc/
777778

778779
install-kernel-indep: install-python
779780
install-python: install-dirs

‎src/Makefile.modinc.in‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ EXTRA_CFLAGS += -fno-builtin-sin -fno-builtin-cos -fno-builtin-sincos
7676
EMC2_HOME=@EMC2_HOME@
7777
RUN_IN_PLACE=@RUN_IN_PLACE@
7878
ifeq ($(RUN_IN_PLACE),yes)
79-
EXTRA_CFLAGS := $(RTFLAGS) -D__MODULE__ -I$(EMC2_HOME)/include
79+
EXTRA_CFLAGS := $(RTFLAGS) -D__MODULE__ -I$(EMC2_HOME)/include -I$(EMC2_HOME)/share/linuxcnc
8080
RTLIBDIR := @EMC2_HOME@/rtlib
8181
LIBDIR := @EMC2_HOME@/lib
8282
else
8383
prefix := @prefix@
84-
EXTRA_CFLAGS := $(RTFLAGS) -D__MODULE__ -I@includedir@/linuxcnc
84+
EXTRA_CFLAGS := $(RTFLAGS) -D__MODULE__ -I@includedir@/linuxcnc -I${prefix}/share/linuxcnc
8585
RTLIBDIR := @EMC2_RTLIB_DIR@
8686
LIBDIR := @libdir@
8787
endif

‎src/emc/kinematics/Submakefile‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,16 @@ EMCKINEMATICSINCS = \
4040

4141
$(patsubst ./emc/kinematics/%,../include/%,$(EMCKINEMATICSINCS)): ../include/%.h: ./emc/kinematics/%.h
4242
cp $^ $@
43+
44+
# The switchkins implementation is shipped as source, since a realtime module
45+
# cannot link a library, so a module built out of tree includes it the way the
46+
# in-tree ones link it.
47+
EMCKINEMATICSSRCS = \
48+
../share/linuxcnc/switchkins.c \
49+
../share/linuxcnc/kins_util.c
50+
51+
$(EMCKINEMATICSSRCS): ../share/linuxcnc/%.c: ./emc/kinematics/%.c
52+
$(ECHO) Copying switchkins source $(notdir $@)
53+
$(Q)cp -f $< $@
54+
55+
TARGETS += $(EMCKINEMATICSSRCS)

‎src/hal/components/switchkinscomp.comp‎

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ the same 'kinstype.is-N' pins, the same 'coordinates=' identity
1212
mapping, and the same G-code and HAL controls, without reimplementing
1313
any of it.
1414

15-
The example switchkinscomp.comp is not usable until modified for the
16-
user environment. To create a runnable switchkinscomp module, the
17-
file must be edited to supply a valid '#define TOPDIR' pointing at a
18-
LinuxCNC source tree.
15+
The example builds as it stands, its type 1 being an X offset to
16+
replace with the kinematics wanted. The switchkins implementation is
17+
installed as source alongside the headers, so nothing needs a path to
18+
a LinuxCNC source tree.
1919

2020
To avoid updates that overwrite switchkinscomp.comp, best practice is
2121
to rename the file and its component name (example:
@@ -33,7 +33,8 @@ JOINTS = 3
3333

3434
*Note:* If using a deb install:
3535

36-
1. halcompile is provided by the deb package linuxcnc-dev
36+
1. halcompile and the switchkins source are provided by the deb
37+
package linuxcnc-dev
3738
2. This source file for BRANCHNAME (master, 2.9, etc) is downloadable from github:
3839

3940
https://github.com/LinuxCNC/linuxcnc/blob/BRANCHNAME/src/hal/components/switchkinscomp.comp
@@ -49,30 +50,15 @@ option extra_setup;
4950
;;
5051

5152
//=====================================================================
52-
/* To use the switchkins implementation from a local git src tree:
53-
** set TOPDIR to the git tree top directory
54-
** (Edit 'myname' as required)
55-
*/
56-
57-
//#define TOPDIR /home/myname/linuxcnc-dev
58-
59-
#ifdef TOPDIR // {
60-
61-
#define STR(s) #s
62-
#define XSTR(s) STR(s)
63-
#define USE_TOPDIR(b) XSTR(TOPDIR/b)
64-
6553
// switchkins.c provides kinematicsForward(), kinematicsInverse(),
6654
// kinematicsSwitch() and the rest of the kinematics interface, and
6755
// dispatches each call to the currently selected switchkins-type.
6856
// kins_util.c provides the identity kinematics and the coordinates
69-
// letters-to-joints mapping they use.
70-
#include USE_TOPDIR(src/emc/kinematics/switchkins.c)
71-
#include USE_TOPDIR(src/emc/kinematics/kins_util.c)
57+
// letters-to-joints mapping they use. Both are installed with the
58+
// headers, so halcompile finds them with no path of your own.
7259

73-
#else
74-
#error No TOPDIR defined, skeleton component provides no kinematics functions.
75-
#endif // }
60+
#include <switchkins.c>
61+
#include <kins_util.c>
7662
//=====================================================================
7763

7864
// module parameter naming the joint order for the identity type

0 commit comments

Comments
 (0)