From a4ad0c88f0508966014eb12c9bc2de8733161398 Mon Sep 17 00:00:00 2001 From: Hans Baier Date: Fri, 6 Nov 2026 17:03:00 +0700 Subject: [PATCH 1/3] build: export the NML client headers again Since #3837 the headers an out-of-tree NML client compiles against are not installed, so linuxcnc-nml and anything else written at that level cannot build against 2.10 (#4774). The headers a client needs are listed in NML_HEADERS and installed flat, next to the HAL and RTAPI headers, which is the layout an out-of-tree client has always compiled against. The includes inside the exported set are written as bare names again, as they were in 2.9: these headers are compiled from an installed directory, where "libnml/nml/nml_type.hh" does not resolve. The four directories they live in are on the in-tree include path, so the source build is unchanged. The set is exported for as long as NML exists. It is not an interface the NML replacement has to emulate; when NML goes, these headers go with it, and docs/src/code/nml-messages.adoc says so where a client author will read it. tests/build/nml-client-headers compiles and links a client against the installed set only. It runs in package builds and skips run-in-place ones, because there the installed headers are the ones a test can see. --- docs/src/code/nml-messages.adoc | 25 ++++++++++++++++ src/Makefile | 37 ++++++++++++++++++++++-- src/emc/nml_intf/emc.hh | 2 +- src/emc/nml_intf/emc_nml.hh | 4 +-- src/emc/rs274ngc/interp_base.hh | 4 +-- src/libnml/nml/nml.hh | 2 +- src/libnml/nml/nml_oi.hh | 2 +- src/libnml/nml/stat_msg.hh | 2 +- src/libnml/rcs/rcs.hh | 2 +- tests/build/nml-client-headers/client.cc | 37 ++++++++++++++++++++++++ tests/build/nml-client-headers/skip | 3 ++ tests/build/nml-client-headers/test.sh | 12 ++++++++ 12 files changed, 121 insertions(+), 11 deletions(-) create mode 100644 tests/build/nml-client-headers/client.cc create mode 100755 tests/build/nml-client-headers/skip create mode 100755 tests/build/nml-client-headers/test.sh diff --git a/docs/src/code/nml-messages.adoc b/docs/src/code/nml-messages.adoc index 307066ea39d..16f5bf383e1 100644 --- a/docs/src/code/nml-messages.adoc +++ b/docs/src/code/nml-messages.adoc @@ -7,6 +7,31 @@ List of NML messages. + For details see `src/emc/nml_intf/emc.hh`. +[[sec:nml-msg:client]] +== Writing a client outside the tree + +The headers a client compiles against are installed into +`$(includedir)/linuxcnc` (`/usr/include/linuxcnc` in a packaged build), +flat, so a client includes them by bare name: + +[source,c] +---- +#include "emc_nml.hh" +#include "nml.hh" +---- + +and links the same libraries the Python module uses: + +[source,sh] +---- +c++ -I/usr/include/linuxcnc client.cc -llinuxcnc -lnml -llinuxcncini +---- + +The exported set is the `NML_HEADERS` list in `src/Makefile`. It is +exported for as long as NML exists and is not a compatibility promise for the +NML replacement: when NML is removed these headers go with it, and clients +move to the interface the replacement publishes. + [[sec:nml-msg:operator]] == OPERATOR diff --git a/src/Makefile b/src/Makefile index 05715dd7985..e9f7ee04980 100644 --- a/src/Makefile +++ b/src/Makefile @@ -213,7 +213,8 @@ ULAPISRCS := rtapi/$(RTPREFIX)_ulapi.c # Each item in INCLUDES is transformed into a -I directive later on # The top directory is always included -INCLUDES := . +INCLUDES := . \ + emc/nml_intf libnml/nml libnml/rcs libnml/cms USERSRCS := PROGRAMS := @@ -387,6 +388,38 @@ build-software: $(INFILES) # where they are used from, not copies, which is why no rule builds them. HEADERS := $(wildcard ../include/*.h ../include/*.hh) +# The NML client headers. They are installed flat, next to the headers above, +# because that is the layout an out-of-tree client has always compiled +# against; their includes are written as bare names so they still resolve from +# an installed directory rather than only from the source tree. +# +# This set exists for as long as NML does. It is not an interface the NML +# replacement has to emulate: when NML goes, these headers go with it. Adding +# a header that a client needs is a one-line change here. +NML_HEADERS := \ + emc/rcs_status.hh \ + emc/nml_intf/canon.hh \ + emc/nml_intf/canon_position.hh \ + emc/nml_intf/debugflags.h \ + emc/nml_intf/emccfg.h \ + emc/nml_intf/emcglb.h \ + emc/nml_intf/emc.hh \ + emc/nml_intf/emc_nml.hh \ + emc/nml_intf/emctool.h \ + emc/nml_intf/interp_codes.h \ + emc/nml_intf/modal_state.hh \ + emc/nml_intf/state_tag.h \ + emc/rs274ngc/interp_base.hh \ + libnml/cms/cms.hh \ + libnml/cms/cms_user.hh \ + libnml/nml/cmd_msg.hh \ + libnml/nml/nml.hh \ + libnml/nml/nmlmsg.hh \ + libnml/nml/nml_oi.hh \ + libnml/nml/nml_type.hh \ + libnml/nml/stat_msg.hh \ + libnml/rcs/rcs.hh + # Add converting of %.po files TARGETS += $(patsubst po/%.po, ../share/locale/%/LC_MESSAGES/linuxcnc.mo, $(wildcard po/*.po)) TARGETS += $(patsubst po/gmoccapy/%.po, ../share/locale/%/LC_MESSAGES/gmoccapy.mo, $(wildcard po/gmoccapy/*.po)) @@ -677,7 +710,7 @@ endif cp --no-dereference $(wildcard ../lib/*.so) $(DESTDIR)$(libdir) -ldconfig $(DESTDIR)$(libdir) $(FILE) ../lib/linuxcnc/canterp.so $(DESTDIR)$(libdir)/linuxcnc/ - $(FILE) $(HEADERS) $(DESTDIR)$(includedir)/linuxcnc/ + $(FILE) $(HEADERS) $(NML_HEADERS) $(DESTDIR)$(includedir)/linuxcnc/ $(TREE) $(NC_FILES) $(DESTDIR)$(ncfilesdir) $(EXE) ../nc_files/M101 $(DESTDIR)$(ncfilesdir) $(FILE) Makefile.modinc $(DESTDIR)$(datadir)/linuxcnc diff --git a/src/emc/nml_intf/emc.hh b/src/emc/nml_intf/emc.hh index d251e08abc6..28dc82901ca 100644 --- a/src/emc/nml_intf/emc.hh +++ b/src/emc/nml_intf/emc.hh @@ -16,7 +16,7 @@ #define EMC_HH #include // EMC_JOINT_MAX, EMC_AXIS_MAX -#include "libnml/nml/nml_type.hh" +#include "nml_type.hh" #include #include #include "modal_state.hh" diff --git a/src/emc/nml_intf/emc_nml.hh b/src/emc/nml_intf/emc_nml.hh index f71030156bb..4f88067aa0e 100644 --- a/src/emc/nml_intf/emc_nml.hh +++ b/src/emc/nml_intf/emc_nml.hh @@ -18,8 +18,8 @@ #include #include // SWITCHKINS_MAX_TYPES #include "emc.hh" -#include "libnml/nml/cmd_msg.hh" -#include "libnml/nml/stat_msg.hh" +#include "cmd_msg.hh" +#include "stat_msg.hh" #include "modal_state.hh" #include "canon.hh" // CANON_TOOL_TABLE, CANON_UNITS #include "interp_codes.h" // ACTIVE_G_CODES, etc diff --git a/src/emc/rs274ngc/interp_base.hh b/src/emc/rs274ngc/interp_base.hh index 03d302a09c1..c0be1257885 100644 --- a/src/emc/rs274ngc/interp_base.hh +++ b/src/emc/rs274ngc/interp_base.hh @@ -23,8 +23,8 @@ #include #include #include -#include "../nml_intf/modal_state.hh" -#include "../nml_intf/interp_codes.h" +#include "modal_state.hh" +#include "interp_codes.h" class InterpBase : boost::noncopyable { public: diff --git a/src/libnml/nml/nml.hh b/src/libnml/nml/nml.hh index 7461ac46a17..e9b76b4bea5 100644 --- a/src/libnml/nml/nml.hh +++ b/src/libnml/nml/nml.hh @@ -18,7 +18,7 @@ #include /* size_t */ -#include "libnml/cms/cms_user.hh" /* class CMS_USER */ +#include "cms_user.hh" /* class CMS_USER */ class LinkedList; /* Generic NML Stuff */ #include "nml_type.hh" diff --git a/src/libnml/nml/nml_oi.hh b/src/libnml/nml/nml_oi.hh index ad56883b38d..33a6d5d31d5 100644 --- a/src/libnml/nml/nml_oi.hh +++ b/src/libnml/nml/nml_oi.hh @@ -17,7 +17,7 @@ #ifndef NML_OI_HH #define NML_OI_HH -#include "libnml/cms/cms.hh" // class CMS +#include "cms.hh" // class CMS #include "nml.hh" // class NML #include "nmlmsg.hh" // class NMLmsg diff --git a/src/libnml/nml/stat_msg.hh b/src/libnml/nml/stat_msg.hh index 77b81e144c0..4ef51546140 100644 --- a/src/libnml/nml/stat_msg.hh +++ b/src/libnml/nml/stat_msg.hh @@ -16,7 +16,7 @@ #include "nml.hh" #include "nmlmsg.hh" -#include "libnml/rcs/rcs.hh" +#include "rcs.hh" class RCS_STAT_MSG:public NMLmsg { public: diff --git a/src/libnml/rcs/rcs.hh b/src/libnml/rcs/rcs.hh index a3d48b70705..b16161cf41d 100644 --- a/src/libnml/rcs/rcs.hh +++ b/src/libnml/rcs/rcs.hh @@ -31,5 +31,5 @@ class RCS_STAT_MSG; // RCS_STATUS enum is int. See nml/stat_msg.hh for more details. #include "rcs_status.hh" // enum class RCS_STATUS -#include "libnml/nml/nml_type.hh" +#include "nml_type.hh" #endif /* !defined(RCS_HH) */ diff --git a/tests/build/nml-client-headers/client.cc b/tests/build/nml-client-headers/client.cc new file mode 100644 index 00000000000..9266405f7cf --- /dev/null +++ b/tests/build/nml-client-headers/client.cc @@ -0,0 +1,37 @@ +/* Copyright (c) 2026 All rights reserved. + * License: GPL Version 2 + * + * Compiles and links against the installed headers only, the way an + * out-of-tree NML client does: flat includes, no source tree, no + * generated files. + */ +#include "cmd_msg.hh" +#include "emc.hh" +#include "emc_nml.hh" +#include "emccfg.h" +#include "emcglb.h" +#include "interp_base.hh" +#include "nml.hh" +#include "nml_oi.hh" +#include "state_tag.h" +#include "stat_msg.hh" + +int main() +{ + EMC_STAT status; + EMC_TASK_SET_MODE set_mode; + EMC_TRAJ_STAT traj; + + set_mode.mode = EMC_TASK_MODE::MANUAL; + traj.mode = EMC_TRAJ_MODE::COORD; + (void)status; + (void)set_mode; + (void)traj; + + /* Addresses only: the link has to find the two format functions in + liblinuxcnc and libnml, which is what proves the libraries that go + with these headers are installed too. */ + int (*emc_format)(NMLTYPE, void *, CMS *) = &emcFormat; + int (*nml_error_format)(NMLTYPE, void *, CMS *) = &nmlErrorFormat; + return emc_format == nullptr || nml_error_format == nullptr; +} diff --git a/tests/build/nml-client-headers/skip b/tests/build/nml-client-headers/skip new file mode 100755 index 00000000000..1929fa7d3b2 --- /dev/null +++ b/tests/build/nml-client-headers/skip @@ -0,0 +1,3 @@ +#!/bin/sh +# Tests the installed header set, so it runs in package builds only. +[ -n "$SYSTEM_BUILD" ] diff --git a/tests/build/nml-client-headers/test.sh b/tests/build/nml-client-headers/test.sh new file mode 100755 index 00000000000..90e1fe84115 --- /dev/null +++ b/tests/build/nml-client-headers/test.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# The NML client headers are installed flat, together with the libraries they +# need. Compile and link a client against the installed set only; that is the +# build an out-of-tree UI of this kind has to be able to do. +set -e + +g++ -std=c++17 -Wall -Wextra -Werror -I"${HEADERS}" -c client.cc -o client.o +g++ -o client client.o -L"${LIBDIR}" -Wl,-rpath,"${LIBDIR}" \ + -llinuxcnc -lnml -llinuxcncini + +rm -f client client.o +exit 0 From 43f514c769dd97106b5d0397092fa483011ddf80 Mon Sep 17 00:00:00 2001 From: Hans Baier Date: Fri, 6 Nov 2026 17:32:06 +0700 Subject: [PATCH 2/3] build: install the libnml client headers under their own directory Review: adding libnml/nml, libnml/cms and libnml/rcs to the in-tree include path puts those -I flags on every compile, which #3837 removed on purpose, and rewriting the includes of exported headers to bare names changes headers that are otherwise untouched. Install the libnml headers under $(includedir)/linuxcnc/libnml/... instead, which is the layout their includes already expect, and leave both the headers and INCLUDES alone. A client still needs a single include path. interp_base.hh comes off the list: it pulls , which the development package does not depend on, and a client does not need it. --- docs/src/code/nml-messages.adoc | 12 ++++---- src/Makefile | 35 +++++++++++++++--------- src/emc/nml_intf/emc.hh | 2 +- src/emc/nml_intf/emc_nml.hh | 4 +-- src/emc/rs274ngc/interp_base.hh | 4 +-- src/libnml/nml/nml.hh | 2 +- src/libnml/nml/nml_oi.hh | 2 +- src/libnml/nml/stat_msg.hh | 2 +- src/libnml/rcs/rcs.hh | 2 +- tests/build/nml-client-headers/client.cc | 12 ++++---- 10 files changed, 44 insertions(+), 33 deletions(-) diff --git a/docs/src/code/nml-messages.adoc b/docs/src/code/nml-messages.adoc index 16f5bf383e1..219b3bda86f 100644 --- a/docs/src/code/nml-messages.adoc +++ b/docs/src/code/nml-messages.adoc @@ -10,14 +10,15 @@ For details see `src/emc/nml_intf/emc.hh`. [[sec:nml-msg:client]] == Writing a client outside the tree -The headers a client compiles against are installed into -`$(includedir)/linuxcnc` (`/usr/include/linuxcnc` in a packaged build), -flat, so a client includes them by bare name: +The emc headers a client compiles against are installed into +`$(includedir)/linuxcnc` (`/usr/include/linuxcnc` in a packaged build); the +libnml ones keep their directory under it, because that is how they include +each other. One include path is enough: [source,c] ---- #include "emc_nml.hh" -#include "nml.hh" +#include "libnml/nml/nml.hh" ---- and links the same libraries the Python module uses: @@ -27,7 +28,8 @@ and links the same libraries the Python module uses: c++ -I/usr/include/linuxcnc client.cc -llinuxcnc -lnml -llinuxcncini ---- -The exported set is the `NML_HEADERS` list in `src/Makefile`. It is +The exported set is the `NML_HEADERS`, `NML_HEADERS_NML`, `NML_HEADERS_CMS` +and `NML_HEADERS_RCS` lists in `src/Makefile`. It is exported for as long as NML exists and is not a compatibility promise for the NML replacement: when NML is removed these headers go with it, and clients move to the interface the replacement publishes. diff --git a/src/Makefile b/src/Makefile index e9f7ee04980..7656e568230 100644 --- a/src/Makefile +++ b/src/Makefile @@ -213,8 +213,7 @@ ULAPISRCS := rtapi/$(RTPREFIX)_ulapi.c # Each item in INCLUDES is transformed into a -I directive later on # The top directory is always included -INCLUDES := . \ - emc/nml_intf libnml/nml libnml/rcs libnml/cms +INCLUDES := . USERSRCS := PROGRAMS := @@ -388,14 +387,13 @@ build-software: $(INFILES) # where they are used from, not copies, which is why no rule builds them. HEADERS := $(wildcard ../include/*.h ../include/*.hh) -# The NML client headers. They are installed flat, next to the headers above, -# because that is the layout an out-of-tree client has always compiled -# against; their includes are written as bare names so they still resolve from -# an installed directory rather than only from the source tree. +# The NML client headers. The emc ones are installed flat, next to the +# headers above; the libnml ones keep their directory, because their includes +# are written as "libnml/nml/nml_type.hh" and a client only adds +# $(includedir)/linuxcnc to its include path. # # This set exists for as long as NML does. It is not an interface the NML -# replacement has to emulate: when NML goes, these headers go with it. Adding -# a header that a client needs is a one-line change here. +# replacement has to emulate: when NML goes, these headers go with it. NML_HEADERS := \ emc/rcs_status.hh \ emc/nml_intf/canon.hh \ @@ -408,16 +406,21 @@ NML_HEADERS := \ emc/nml_intf/emctool.h \ emc/nml_intf/interp_codes.h \ emc/nml_intf/modal_state.hh \ - emc/nml_intf/state_tag.h \ - emc/rs274ngc/interp_base.hh \ - libnml/cms/cms.hh \ - libnml/cms/cms_user.hh \ + emc/nml_intf/state_tag.h + +NML_HEADERS_NML := \ libnml/nml/cmd_msg.hh \ libnml/nml/nml.hh \ libnml/nml/nmlmsg.hh \ libnml/nml/nml_oi.hh \ libnml/nml/nml_type.hh \ - libnml/nml/stat_msg.hh \ + libnml/nml/stat_msg.hh + +NML_HEADERS_CMS := \ + libnml/cms/cms.hh \ + libnml/cms/cms_user.hh + +NML_HEADERS_RCS := \ libnml/rcs/rcs.hh # Add converting of %.po files @@ -711,6 +714,12 @@ endif -ldconfig $(DESTDIR)$(libdir) $(FILE) ../lib/linuxcnc/canterp.so $(DESTDIR)$(libdir)/linuxcnc/ $(FILE) $(HEADERS) $(NML_HEADERS) $(DESTDIR)$(includedir)/linuxcnc/ + $(DIR) $(DESTDIR)$(includedir)/linuxcnc/libnml/nml \ + $(DESTDIR)$(includedir)/linuxcnc/libnml/cms \ + $(DESTDIR)$(includedir)/linuxcnc/libnml/rcs + $(FILE) $(NML_HEADERS_NML) $(DESTDIR)$(includedir)/linuxcnc/libnml/nml/ + $(FILE) $(NML_HEADERS_CMS) $(DESTDIR)$(includedir)/linuxcnc/libnml/cms/ + $(FILE) $(NML_HEADERS_RCS) $(DESTDIR)$(includedir)/linuxcnc/libnml/rcs/ $(TREE) $(NC_FILES) $(DESTDIR)$(ncfilesdir) $(EXE) ../nc_files/M101 $(DESTDIR)$(ncfilesdir) $(FILE) Makefile.modinc $(DESTDIR)$(datadir)/linuxcnc diff --git a/src/emc/nml_intf/emc.hh b/src/emc/nml_intf/emc.hh index 28dc82901ca..d251e08abc6 100644 --- a/src/emc/nml_intf/emc.hh +++ b/src/emc/nml_intf/emc.hh @@ -16,7 +16,7 @@ #define EMC_HH #include // EMC_JOINT_MAX, EMC_AXIS_MAX -#include "nml_type.hh" +#include "libnml/nml/nml_type.hh" #include #include #include "modal_state.hh" diff --git a/src/emc/nml_intf/emc_nml.hh b/src/emc/nml_intf/emc_nml.hh index 4f88067aa0e..f71030156bb 100644 --- a/src/emc/nml_intf/emc_nml.hh +++ b/src/emc/nml_intf/emc_nml.hh @@ -18,8 +18,8 @@ #include #include // SWITCHKINS_MAX_TYPES #include "emc.hh" -#include "cmd_msg.hh" -#include "stat_msg.hh" +#include "libnml/nml/cmd_msg.hh" +#include "libnml/nml/stat_msg.hh" #include "modal_state.hh" #include "canon.hh" // CANON_TOOL_TABLE, CANON_UNITS #include "interp_codes.h" // ACTIVE_G_CODES, etc diff --git a/src/emc/rs274ngc/interp_base.hh b/src/emc/rs274ngc/interp_base.hh index c0be1257885..03d302a09c1 100644 --- a/src/emc/rs274ngc/interp_base.hh +++ b/src/emc/rs274ngc/interp_base.hh @@ -23,8 +23,8 @@ #include #include #include -#include "modal_state.hh" -#include "interp_codes.h" +#include "../nml_intf/modal_state.hh" +#include "../nml_intf/interp_codes.h" class InterpBase : boost::noncopyable { public: diff --git a/src/libnml/nml/nml.hh b/src/libnml/nml/nml.hh index e9b76b4bea5..7461ac46a17 100644 --- a/src/libnml/nml/nml.hh +++ b/src/libnml/nml/nml.hh @@ -18,7 +18,7 @@ #include /* size_t */ -#include "cms_user.hh" /* class CMS_USER */ +#include "libnml/cms/cms_user.hh" /* class CMS_USER */ class LinkedList; /* Generic NML Stuff */ #include "nml_type.hh" diff --git a/src/libnml/nml/nml_oi.hh b/src/libnml/nml/nml_oi.hh index 33a6d5d31d5..ad56883b38d 100644 --- a/src/libnml/nml/nml_oi.hh +++ b/src/libnml/nml/nml_oi.hh @@ -17,7 +17,7 @@ #ifndef NML_OI_HH #define NML_OI_HH -#include "cms.hh" // class CMS +#include "libnml/cms/cms.hh" // class CMS #include "nml.hh" // class NML #include "nmlmsg.hh" // class NMLmsg diff --git a/src/libnml/nml/stat_msg.hh b/src/libnml/nml/stat_msg.hh index 4ef51546140..77b81e144c0 100644 --- a/src/libnml/nml/stat_msg.hh +++ b/src/libnml/nml/stat_msg.hh @@ -16,7 +16,7 @@ #include "nml.hh" #include "nmlmsg.hh" -#include "rcs.hh" +#include "libnml/rcs/rcs.hh" class RCS_STAT_MSG:public NMLmsg { public: diff --git a/src/libnml/rcs/rcs.hh b/src/libnml/rcs/rcs.hh index b16161cf41d..a3d48b70705 100644 --- a/src/libnml/rcs/rcs.hh +++ b/src/libnml/rcs/rcs.hh @@ -31,5 +31,5 @@ class RCS_STAT_MSG; // RCS_STATUS enum is int. See nml/stat_msg.hh for more details. #include "rcs_status.hh" // enum class RCS_STATUS -#include "nml_type.hh" +#include "libnml/nml/nml_type.hh" #endif /* !defined(RCS_HH) */ diff --git a/tests/build/nml-client-headers/client.cc b/tests/build/nml-client-headers/client.cc index 9266405f7cf..6a1a636ae52 100644 --- a/tests/build/nml-client-headers/client.cc +++ b/tests/build/nml-client-headers/client.cc @@ -2,19 +2,19 @@ * License: GPL Version 2 * * Compiles and links against the installed headers only, the way an - * out-of-tree NML client does: flat includes, no source tree, no + * out-of-tree NML client does: one include path, no source tree, no * generated files. */ -#include "cmd_msg.hh" #include "emc.hh" #include "emc_nml.hh" #include "emccfg.h" #include "emcglb.h" -#include "interp_base.hh" -#include "nml.hh" -#include "nml_oi.hh" #include "state_tag.h" -#include "stat_msg.hh" + +/* The libnml headers keep their directory under $(includedir)/linuxcnc, + because that is how they include each other. */ +#include "libnml/nml/nml.hh" +#include "libnml/nml/nml_oi.hh" int main() { From 5f2fd2bdbad02f2f63c67582436b319c2e05a112 Mon Sep 17 00:00:00 2001 From: Hans Baier Date: Fri, 6 Nov 2026 18:25:15 +0700 Subject: [PATCH 3/3] tests: give nml-client-headers a checkresult The test harness requires either an expected file or a checkresult script; test.sh already reports failure through its exit status. --- tests/build/nml-client-headers/checkresult | 2 ++ 1 file changed, 2 insertions(+) create mode 100755 tests/build/nml-client-headers/checkresult diff --git a/tests/build/nml-client-headers/checkresult b/tests/build/nml-client-headers/checkresult new file mode 100755 index 00000000000..24dc9aa53e3 --- /dev/null +++ b/tests/build/nml-client-headers/checkresult @@ -0,0 +1,2 @@ +#!/bin/sh +exit 0 # test failure is indicated by test.sh exit value