Search

Device::SerialPort on Redhat 8

0 views

Preparing Your RHEL 8 System for Serial Port Development

When Red Hat 6.2 reached its end of life in March, many remote sites that still ran that distribution had to decide whether to maintain legacy software or migrate to a newer platform. In my case, each branch office contains a T1 router that feeds critical data into our central monitoring system. The simplest way to capture that data is to listen directly on the router’s serial console and write the output to a plain text file. I already had a small Perl script - available

Prompt
perl Makefile.PL</p>

The output stopped at a list of ioctl names that could not be found, such as TIOCMBIS and CRTSCTS. The installer advised me to run h2ph against the system headers to generate the necessary .ph files. The h2ph tool is part of the extutils-cbuilder distribution and translates C header files into Perl header files that the XS compiler can use. Unfortunately, the default command suggested in the error message - cd /usr/include; h2ph -r -l . - did not resolve the problem on my RHEL 8 system. The build still reported the same missing ioctl definitions. I needed a more targeted approach that addressed the specific headers that contain those definitions.

Before diving into the solution, it is worth noting a few prerequisites. The Device::SerialPort module’s source code resides in a directory such as /usr/local/lib/perl5/vendor_perl/Device/SerialPort/. Inside that directory you will find the Makefile.PL script and a SerialPort.xs file. The build process relies on the ExtUtils::MakeMaker module to generate a Makefile that knows where to find both Perl and C header files. If ExtUtils::MakeMaker itself is missing, installing it from CPAN is the first step:

Prompt
sudo dnf install perl-ExtUtils-MakeMaker</p>

After confirming that ExtUtils::MakeMaker is present, the next step is to generate the .ph files for the ioctl constants. In RHEL 8 the relevant headers are located in /usr/include/asm, /usr/include/asm/termios.h, /usr/include/sys/termios.h, and /usr/include/sys/ttychars.h. The h2ph tool needs to be run on each of these headers in the correct order so that dependent definitions are available when subsequent headers are processed. The following sequence achieves that:

During this process, keep a clear record of the commands you run. The order matters; if you run h2ph asm/*.h before generating asm/termios.h specifically, the compiler may still miss definitions that depend on earlier includes. By generating each header file explicitly, you give h2ph a chance to resolve interdependencies more reliably.

Once the .ph files are in place, the Device::SerialPort module should build without complaint. The subsequent make and make test steps should finish quickly, and the module will be ready for use in the serial‑logging script.

Troubleshooting Device::SerialPort Installation on RHEL 8

At first glance, the error message from the Makefile.PL script looks like a simple compilation failure. However, the root cause lies deeper in the system’s header layout. The missing ioctl definitions indicate that the XS compiler cannot find the constants defined in the C headers that provide serial port control. On older systems these constants are tucked away in /usr/include/sys/termios.h or /usr/include/asm/termios.h, but RHEL 8’s header organization has changed, and some older paths may no longer exist or may point to alternative versions that omit the required symbols.

The first diagnostic step is to locate the header files that declare the missing constants. Open a terminal and use grep to search for one of the missing ioctl names:

Prompt
grep -R "TIOCMBIS" /usr/include | head</p>

If the search yields no results, you have confirmed that the constants are absent from the standard header tree. In that case, you must explicitly generate Perl header files from the available C headers using h2ph. RHEL 8 includes the extutils-cbuilder package, which provides h2ph as a separate utility. If it is not installed, run:

Prompt
sudo dnf install perl-ExtUtils-CBuilder</p>

Once h2ph is available, the next step is to decide which headers to process. The Device::SerialPort build requires several ioctl definitions that reside in asm/termios.h, sys/termios.h, and sys/ttychars.h. In addition, there are some auxiliary headers in asm that define bit masks and helper macros. Running h2ph asm/*.h alone is insufficient because the macro definitions in asm/termios.h reference symbols in sys/termios.h. The build process therefore needs a layered approach.

One pragmatic way to ensure coverage is to run h2ph on all headers that match the pattern *.h in the relevant directories. Use the following commands from the top of the Perl module source tree:

Each command produces a .ph file that mirrors the corresponding .h header. These generated files are placed in the same directory as the original headers, typically /usr/include/asm and /usr/include/sys. The presence of these .ph files allows the XS compiler to locate the constants during the Makefile.PL phase.

Suggest a Correction

Found an error or have a suggestion? Let us know and we'll review it.

Share this article

Comments (0)

Please sign in to leave a comment.

No comments yet. Be the first to comment!

Related Articles