Marcel Moolenaar
2016-09-26 16:05:51 UTC
Background:
In order for a select set of FreeBSD utilities to compile on non-FreeBSD (specifically macOS and Linux) as build tools, we need some portability tweaks.
Problem:
mkimg(1) includes disk partitioning headers like <sys/disklabel.h>, <sys/diskmbr.h> and <sys/diskpc98.h> and those headers themselves include <sys/ioccom.h> for ioctl(2) definitions. The <sys/ioccom.h> header does not typically exist on the host weâre being, causing build failures.
Proposal:
What I like is to be able to use FreeBSDâs headers, but not pull in FreeBSD-specifics like ioctl(2) definitions.
Solutions:
1. Split off the definitions relating to the partitioning into a separate header (e.g. <sys/bsdlabel.h>) and keep the FreeBSD-centric definitions (e.g. for ioctl(2)) in the original header (e.g. <sys/disklabel.h>. The original header will include the new header so that thereâs no change to applications that include the original header. Portable tools like mkimg can include the new split-off header to get just the structure definitions and defines.
2. Expect portable utilities to define a pre-processor macro (e.g. PORTABLE_DEFINITIONS_ONLY) and make FreeBSD-specific definitions conditional upon the *absence* of the preprocessor macro.
3. (Ab)use _POSIX_SOURCE to achieve the same as point 2.
4. Get rid of the utilities that still use the ioctl(2) interface and fix ports that do the same.
5. Others?
Notes:
1. Attached a hack to allow mkimg(1) to use FreeBSDâs headers for partitioning schemes. It shows what exactly the problem is without suggesting a solution. Itâs a minimal change for a reason and not to be discussed as if it was a solution.
2. mkimg(1) is one example. Other utilities include makefs, mtree, etc. Please consider an approach that serves as a good precedence for other utilities if and when a similar situation is encountered.
In order for a select set of FreeBSD utilities to compile on non-FreeBSD (specifically macOS and Linux) as build tools, we need some portability tweaks.
Problem:
mkimg(1) includes disk partitioning headers like <sys/disklabel.h>, <sys/diskmbr.h> and <sys/diskpc98.h> and those headers themselves include <sys/ioccom.h> for ioctl(2) definitions. The <sys/ioccom.h> header does not typically exist on the host weâre being, causing build failures.
Proposal:
What I like is to be able to use FreeBSDâs headers, but not pull in FreeBSD-specifics like ioctl(2) definitions.
Solutions:
1. Split off the definitions relating to the partitioning into a separate header (e.g. <sys/bsdlabel.h>) and keep the FreeBSD-centric definitions (e.g. for ioctl(2)) in the original header (e.g. <sys/disklabel.h>. The original header will include the new header so that thereâs no change to applications that include the original header. Portable tools like mkimg can include the new split-off header to get just the structure definitions and defines.
2. Expect portable utilities to define a pre-processor macro (e.g. PORTABLE_DEFINITIONS_ONLY) and make FreeBSD-specific definitions conditional upon the *absence* of the preprocessor macro.
3. (Ab)use _POSIX_SOURCE to achieve the same as point 2.
4. Get rid of the utilities that still use the ioctl(2) interface and fix ports that do the same.
5. Others?
Notes:
1. Attached a hack to allow mkimg(1) to use FreeBSDâs headers for partitioning schemes. It shows what exactly the problem is without suggesting a solution. Itâs a minimal change for a reason and not to be discussed as if it was a solution.
2. mkimg(1) is one example. Other utilities include makefs, mtree, etc. Please consider an approach that serves as a good precedence for other utilities if and when a similar situation is encountered.