Next: , Up: Shell commands


12.1 Determining the platform

Sometimes it is desirable for an input file to know which platform m4 is running on. GNU m4 provides several macros that are predefined to expand to the empty string; checking for their existence will confirm platform details.

— Optional builtin: __gnu__
— Optional builtin: __os2__
— Optional builtin: os2
— Optional builtin: __unix__
— Optional builtin: unix
— Optional builtin: __windows__
— Optional builtin: windows

Each of these macros is conditionally defined as needed to describe the environment of m4. If defined, each macro expands to the empty string.

When GNU extensions are in effect (that is, when you did not use the -G option, see Invoking m4), GNU m4 will define the macro __gnu__ to expand to the empty string.

     __gnu__
     =>
     ifdef(`__gnu__', `Extensions are active')
     =>Extensions are active

On UNIX systems, GNU m4 will define __unix__ by default, or unix when the -G option is specified.

On native Windows systems, GNU m4 will define __windows__ by default, or windows when the -G option is specified.

On OS/2 systems, GNU m4 will define __os2__ by default, or os2 when the -G option is specified.

If GNU m4 does not provide a platform macro for your system, please report that as a bug.

     define(`provided', `0')
     =>
     ifdef(`__unix__', `define(`provided', incr(provided))')
     =>
     ifdef(`__windows__', `define(`provided', incr(provided))')
     =>
     ifdef(`__os2__', `define(`provided', incr(provided))')
     =>
     provided
     =>1