Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions debian/copyright
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ Files:
src/hal/drivers/hal_vti.c
src/hal/drivers/hal_vti.h
src/hal/drivers/motenc.h
src/hal/hal.h
src/hal/user_comps/gs2_vfd.c
src/hal/user_comps/hy_gt_vfd.c
src/hal/user_comps/pi500_vfd/pi500_vfd.comp
Expand Down Expand Up @@ -286,6 +285,7 @@ Files:
src/hal/utils/scope_vert.c
src/hal/utils/upci.c
src/hal/utils/upci.h
include/hal.h
Copyright: same flock of LinuxCNC devs as above
License: GPL-2

Expand Down Expand Up @@ -341,7 +341,7 @@ Files: src/hal/hal_lib.c
Copyright: 2003 John Kasunich
License: LGPL-2

Files: src/emc/linuxcnc.h
Files: include/linuxcnc.h
Copyright: 2021 Petter Reinholdtsen
License: LGPL-2

Expand Down
2 changes: 1 addition & 1 deletion docs/src/code/code-notes.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ of the HAL, and uses terms like HAL pins, HAL signals, etc, without
explaining them. For more information about the HAL, see the
HAL Manual. Another chapter of this document will
eventually go into the internals of the HAL itself, but in this
chapter, we only use the HAL API as defined in src/hal/hal.h.
chapter, we only use the HAL API as defined in include/hal.h.

=== Motion Controller Modules

Expand Down
2 changes: 1 addition & 1 deletion docs/src/config/core-components.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ These pins, parameters, and functions are created by the realtime 'motmod' modul
This will be delayed during spindle synch moves till the end of the move.
* 'motion.in-position' - (bit, out) TRUE if the machine is in position.
* 'motion.motion-enabled' - (bit, out) TRUE when in 'machine on' state.
* 'motion.motion-type' - (s32, out) These values are from src/emc/nml_intf/motion_types.h
* 'motion.motion-type' - (s32, out) These values are from include/motion_types.h
- 0: Idle (no motion)
- 1: Traverse
- 2: Linear feed
Expand Down
2 changes: 1 addition & 1 deletion docs/src/hal/tutorial.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ does things a little differently.
To address these differences, the LinuxCNC team came up with RTAPI, which
provides a consistent way for programs to talk to the RTOS. If you are
a programmer who wants to work on the internals of LinuxCNC, you may want to
study 'linuxcnc/src/rtapi/rtapi.h' to understand the API.
study 'linuxcnc/include/rtapi.h' to understand the API.
But if you are a normal person, all you need to
know about RTAPI is that it (and the RTOS) needs to be loaded into the
memory of your computer before you do anything with HAL.
Expand Down
2 changes: 1 addition & 1 deletion docs/src/man/man9/motion.9.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ Note: feed-inhibit applies to G-code commands -- not jogs.
*motion.motion-enabled* OUT BIT::
+
*motion.motion-type* OUT S32::
These values are from src/emc/nml_intf/motion_types.h:
These values are from include/motion_types.h:

0: Idle (no motion)

Expand Down
2 changes: 0 additions & 2 deletions include/.gitignore

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/python/mtc/kinematics.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
}

# Human-readable name for LinuxCNC's KINEMATICS_TYPE enum
# (src/emc/kinematics/kinematics.h).
# (include/kinematics.h).
KINEMATICS_TYPE_NAMES = {
1: "IDENTITY",
2: "FORWARD_ONLY",
Expand Down
64 changes: 32 additions & 32 deletions scripts/include-dep-report.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

Resolves every #include the way the compiler does, aggregates the result to the
directory that builds each file, finds the strongly connected components, and
writes a markdown report. The exported-header list is read out of SRCHEADERS in
src/Makefile, so the report follows what the build actually installs.
writes a markdown report. The exported headers are the contents of the include/
directory beside src, which is the set an out-of-tree component may use.

./scripts/include-dep-report.py [src] > report.md
"""
Expand All @@ -15,6 +15,7 @@
from collections import defaultdict

SRC = os.path.abspath(sys.argv[1] if len(sys.argv) > 1 else "src")
INC = os.path.join(os.path.dirname(SRC), "include")
SKIP_DIRS = {"objects", "autom4te.cache", "m4", "depends"}
EXTS = (".c", ".cc", ".cpp", ".h", ".hh", ".hpp", ".comp", ".icomp")
INC_RE = re.compile(r'^\s*#\s*include\s*([<"])([^>"]+)[>"]')
Expand All @@ -29,20 +30,10 @@
SEARCH = {"user": ["", "emc"], "rt": [""], "comp": [""]}


def read_srcheaders():
out, collecting = [], False
for line in open(os.path.join(SRC, "Makefile"), encoding="utf-8", errors="replace"):
if not collecting:
if re.match(r'^\s*SRCHEADERS\s*:?=', line):
collecting = True
line = line.split("=", 1)[1]
else:
continue
cont = line.rstrip("\n").endswith("\\")
out += [t for t in line.replace("\\", " ").split() if t.endswith((".h", ".hh"))]
if not cont:
break
return out
def read_exported():
"""The headers an out-of-tree component may use. They are the whole content
of the include/ directory beside src, so the directory is the list."""
return sorted(fn for fn in os.listdir(INC) if fn.endswith((".h", ".hh")))


def walk_sources():
Expand All @@ -51,6 +42,8 @@ def walk_sources():
for fn in filenames:
if fn.endswith(EXTS):
yield os.path.join(dirpath, fn)
for fn in read_exported():
yield os.path.join(INC, fn)


def read_rt_sources():
Expand Down Expand Up @@ -135,8 +128,16 @@ def folded_dirs():
FOLD = folded_dirs()


def show(rel):
"""A path relative to the tree root. Everything the walk finds is relative
to src, except the exported headers, which sit beside it."""
return os.path.normpath(os.path.join("src", rel))


def module_of(rel):
parts = rel.split("/")
if parts[0] == "..":
return "include"
if len(parts) == 1:
return "src"
if parts[0] in ("emc", "hal", "libnml", "rtapi") and len(parts) > 2:
Expand Down Expand Up @@ -182,7 +183,7 @@ def sccs(adj, nodes):


def analyse():
exported = {os.path.basename(h): h for h in read_srcheaders()}
exported = {h: os.path.join("..", "include", h) for h in read_exported()}
relfiles = {os.path.relpath(f, SRC): f for f in walk_sources()}
by_name = defaultdict(list)
for rel in relfiles:
Expand Down Expand Up @@ -302,7 +303,7 @@ def main():
"compile it actually goes through, taken from the `-objs` lists in `src/Makefile`; "
"`.comp` sources are scanned below their `;;` line and resolved the way "
"halcompile does, with the component's own directory ahead of the rest. The "
"exported-header set is read out of `SRCHEADERS`, so it follows what the build "
"exported-header set is the content of the include/ directory, so it follows what the build "
"installs rather than a list of its own. Includes that resolve outside the tree "
"are dropped.\n\n")

Expand Down Expand Up @@ -337,8 +338,8 @@ def main():
for (a, b), v in sorted(thin.items()):
rel, ln, tgt, style = sorted(v)[0]
close = '"' if style == '"' else '>'
w(f"| `{a}` -> `{b}` | `src/{rel}:{ln}` | "
f"`{style}{os.path.basename(tgt)}{close}` = `src/{tgt}` |\n")
w(f"| `{a}` -> `{b}` | `{show(rel)}:{ln}` | "
f"`{style}{os.path.basename(tgt)}{close}` = `{show(tgt)}` |\n")
w("\n")

heavy = [(k, v) for k, v in intra.items() if len(v) > 1]
Expand All @@ -363,7 +364,7 @@ def main():
else:
w("| file | line | include | resolved in userspace by |\n|---|---|---|---|\n")
for rel, ln, name, via in sorted(rtbad):
w(f"| `src/{rel}` | {ln} | `{name}` | {via} |\n")
w(f"| `{show(rel)}` | {ln} | `{name}` | {via} |\n")
w("\n")

both = sorted(h for h in data["rt_reach"] & data["user_reach"]
Expand All @@ -385,19 +386,18 @@ def main():
w(f"| `{d}` | {len(bydir[d])} | {names} |\n")
w("\n")

w("## Exported headers with no in-tree user outside their own directory\n\n")
w("A header reached only from its own directory is a candidate for coming off "
"`SRCHEADERS`, but not automatically: a header included by its umbrella beside "
"it, or by code in a subdirectory that falls in the same bucket, shows up here "
"too.\n\n")
w("| header | users elsewhere |\n|---|---|\n")
w("## Exported headers with at most two in-tree users\n\n")
w("An exported header is there for code outside the tree, so a thin in-tree "
"user list says nothing on its own. It does say where to look: a header with "
"no in-tree user at all is either an interface only out-of-tree code needs, "
"or a leftover nobody has taken off the list.\n\n")
w("| header | in-tree users |\n|---|---|\n")
for h in sorted(exported.values()):
own = module_of(h)
outside = sorted({u for u in exported_users.get(h, set()) if module_of(u) != own})
if len(outside) > 2:
users = sorted(exported_users.get(h, set()))
if len(users) > 2:
continue
cell = ", ".join(f"`src/{u}`" for u in outside) or "none"
w(f"| `{h}` | {cell} |\n")
cell = ", ".join(f"`{show(u)}`" for u in users) or "none"
w(f"| `include/{os.path.basename(h)}` | {cell} |\n")
w("\n")

w("<details><summary>Full directory edge list</summary>\n\n")
Expand Down
83 changes: 7 additions & 76 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ cxx-option = $(shell if $(CXX) $(CXXFLAGS) $(1) -S -o /dev/null -xc++ /dev/null
ifeq ($(origin KERNELRELEASE),undefined)
# When KERNELRELEASE is not defined, this is the userspace build.
# The "modules" target is the gateway to the kernel module build.
build-software: headers userspace modules
build-software: userspace modules
ifeq ($(RUN_IN_PLACE),yes)
ifneq ($(BUILD_SYS),uspace)
@if [ -f ../bin/linuxcnc_module_helper ]; then if ! [ `id -u` = 0 -a -O ../bin/linuxcnc_module_helper -a -u ../bin/linuxcnc_module_helper ]; then $(VECHO) "You now need to run 'sudo make setuid' in order to run in place."; fi; fi
Expand Down Expand Up @@ -379,77 +379,12 @@ INFILES = \
$(INFILES): %: %.in config.status
@./config.status --file=$@

build-software: headers $(INFILES)
build-software: $(INFILES)

# For each file to be copied to ../include, its location in the source tree
# is listed here.
# Note that due to $(INCLUDE), defined above, the include files in the source
# tree are normally the ones used or not found at all when building linuxcnc if
# you are not aware of the differences between "" and <> includes.
#
# All sources should #include <> (like in #include <rtapi.h>) for these special
# headers in the ../include directory to ensure they are used.
# The *only* exception is those sources that use the include and reside in the
# /same/ source directory as the include. That means that the local version
# should have precedence over the global one.
#
# If you add to these headers, then you must make absolutely sure that they are
# required for out-of-tree components and that the proper #include type is
# used.
#
SRCHEADERS := \
hal/hal.h \
hal/drivers/mesa-hostmot2/hostmot2-serial.h \
emc/linuxcnc.h \
emc/kinematics/kinematics.h \
emc/nml_intf/emcmotcfg.h \
emc/ini/inifile.hh \
emc/ini/inifile.h \
emc/nml_intf/emcpos.h \
emc/nml_intf/motion_types.h \
libposemath/emcpose.h \
libposemath/posemath.h \
libposemath/posemath.hh \
libposemath/posemath_types.h \
rtapi/rtapi.h \
rtapi/rtapi_app.h \
rtapi/rtapi_atomic.h \
rtapi/rtapi_bitops.h \
rtapi/rtapi_bool.h \
rtapi/rtapi_byteorder.h \
rtapi/rtapi_ctype.h \
rtapi/rtapi_device.h \
rtapi/rtapi_errno.h \
rtapi/rtapi_firmware.h \
rtapi/rtapi_gfp.h \
rtapi/rtapi_io.h \
rtapi/rtapi_limits.h \
rtapi/rtapi_list.h \
rtapi/rtapi_math.h \
rtapi/rtapi_math_i386.h \
rtapi/rtapi_math64.h \
rtapi/rtapi_mutex.h \
rtapi/rtapi_parport.h \
rtapi/rtapi_pci.h \
rtapi/rtapi_slab.h \
rtapi/rtapi_stdint.h \
rtapi/rtapi_string.h \
rtapi/rtapi_vsnprintf.h

# the "headers" target installs all the header files in ../include. One rule
# does the copying for every entry in SRCHEADERS, so a directory that exports a
# header does not carry a recipe of its own. Two headers sharing a basename
# would collide here, and make says so rather than letting one cp win.
.PHONY: headers
HEADERS := $(patsubst %,../include/%,$(notdir $(SRCHEADERS)))
$(foreach h,$(SRCHEADERS),$(eval ../include/$(notdir $(h)): $(h)))
$(HEADERS):
$(ECHO) Exporting $(notdir $@)
$(Q)cp $< $@
headers: $(HEADERS)

# install header files as part of the build
TARGETS += headers
# ../include holds the headers an out-of-tree component may use and nothing
# else, so the whole directory is what gets installed. They are sources kept
# where they are used from, not copies, which is why no rule builds them.
HEADERS := $(wildcard ../include/*.h ../include/*.hh)

# Add converting of %.po files
TARGETS += $(patsubst po/%.po, ../share/locale/%/LC_MESSAGES/linuxcnc.mo, $(wildcard po/*.po))
Expand Down Expand Up @@ -513,11 +448,7 @@ python: $(PYTARGETS)
userspace: python
inclean:
$(RM) $(INFILES)
# Not just $(HEADERS): a header that has been dropped from SRCHEADERS still has
# a copy sitting in ../include, and that copy is what an angled include finds.
headersclean:
$(RM) ../include/*.h ../include/*.hh
clean: docclean pythonclean cscopeclean headersclean
clean: docclean pythonclean cscopeclean
distclean: clean inclean

# This is the gateway into the crazy world of "kbuild", the linux 2.6 system
Expand Down
3 changes: 1 addition & 2 deletions src/Submakefile.skel
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ $(call TOOBJSDEPS, $(FOOSRCS)) : EXTRAFLAGS = -Dfoo
$(CXX) -o $@ $^
userspace: ../bin/foo

# See emc/rs274ngc/Submakefile for an example of creating a shared library
# or allowing headers to be copied to ../include.
# See emc/rs274ngc/Submakefile for an example of creating a shared library.

# See rtapi/Submakefile for an example of how to make some other kind of
# file (in this case, ../scripts/rtapi.conf)
2 changes: 1 addition & 1 deletion src/emc/ini/inifile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

#include "nml_intf/emc.hh"

#include "inifile.hh"
#include <inifile.hh>

using namespace linuxcnc;

Expand Down
2 changes: 1 addition & 1 deletion src/emc/nml_intf/emc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "canon.hh"
#include "emc.hh"
#include "emc_nml.hh"
#include "emcpos.h"
#include <emcpos.h>
#include "libnml/cms/cms.hh"

//
Expand Down
2 changes: 1 addition & 1 deletion src/emc/nml_intf/emc.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include <emcmotcfg.h> // EMC_JOINT_MAX, EMC_AXIS_MAX
#include "libnml/nml/nml_type.hh"
#include "motion_types.h"
#include <motion_types.h>
#include <stdint.h>
#include "modal_state.hh"

Expand Down
2 changes: 1 addition & 1 deletion src/hal/drivers/mesa-hostmot2/pktuart.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <rtapi_string.h>
#include <hal.h>
#include "hostmot2.h"
#include "hostmot2-serial.h"
#include <hostmot2-serial.h>

Comment on lines +23 to 24

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This header should not really be exposed, at all.

The reason for doing it are hal/components/mesa_pktgyro_test.comp and the hal/drivers/mesa-hostmot2/modbus/mesa_modbus.c.tmpl. The first is a test and should probably be retired. The second is the old modbus driver via hostmot2, which has been deprecated.

@grandixximo grandixximo Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed on the principle, and it is unchanged here. One correction to the plan though: those two are not the whole list.

src/hal/drivers/mesa_7i65.comp:49              include <hostmot2-serial.h>;
src/hal/drivers/mesa_uart.comp:42              include <hostmot2-serial.h>;
src/hal/components/mesa_pktgyro_test.comp:50   include <hostmot2-serial.h>;
src/hal/drivers/mesa-hostmot2/modbus/mesa_modbus.c.tmpl:26  #include <hostmot2-serial.h>

pktuart.c and hm2_modbus.c are beside the header, so they cost nothing. mesa_7i65.comp and mesa_uart.comp sit one directory up in hal/drivers/ and take it angled, so they reach it only through the export. Retiring the test and the old modbus driver leaves those two still needing it, unless they take a relative include or move down beside the driver. So it is a four-part job, not two...


#define MAX_TX_FRAMES (16) // Send counts are written to 16 deep FIFO, burst mode
Expand Down
2 changes: 1 addition & 1 deletion src/hal/hal_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
#endif

#include <rtapi.h> /* RTAPI realtime OS API */
#include "hal.h" /* HAL public API decls */
#include <hal.h> /* HAL public API decls */
#define __HAL_LIBRARY_INTERNAL_ONLY 1
#include "hal_priv.h" /* HAL private decls */

Expand Down
2 changes: 1 addition & 1 deletion src/hal/hal_lib_extra.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

#include "hal.h"
#include <hal.h>
#define __HAL_LIBRARY_INTERNAL_ONLY 1
#include "hal_priv.h"

Expand Down
2 changes: 1 addition & 1 deletion src/hal/hal_lib_query.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

#include "hal.h"
#include <hal.h>
#define __HAL_LIBRARY_INTERNAL_ONLY 1
#include "hal_priv.h"

Expand Down
2 changes: 1 addition & 1 deletion src/libposemath/_posemath.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <stdio.h>
#include <stdarg.h>
#endif
#include "posemath.h"
#include <posemath.h>

#include <rtapi_math.h>
#include <float.h>
Expand Down
Loading