For _GNU_SOURCE
and the autotools in particular, you could use AC_USE_SYSTEM_EXTENSIONS
(citing liberally from the autoconf manual here):
-- Macro: AC_USE_SYSTEM_EXTENSIONS
This macro was introduced in Autoconf 2.60. If possible, enable
extensions to C or Posix on hosts that normally disable the
extensions, typically due to standards-conformance namespace
issues. This should be called before any macros that run the C
compiler. The following preprocessor macros are defined where
appropriate:
_GNU_SOURCE
Enable extensions on GNU/Linux.
__EXTENSIONS__
Enable general extensions on Solaris.
_POSIX_PTHREAD_SEMANTICS
Enable threading extensions on Solaris.
_TANDEM_SOURCE
Enable extensions for the HP NonStop platform.
_ALL_SOURCE
Enable extensions for AIX 3, and for Interix.
_POSIX_SOURCE
Enable Posix functions for Minix.
_POSIX_1_SOURCE
Enable additional Posix functions for Minix.
_MINIX
Identify Minix platform. This particular preprocessor macro
is obsolescent, and may be removed in a future release of
Autoconf.
For _FILE_OFFSET_BITS
, you need to call AC_SYS_LARGEFILE
and AC_FUNC_FSEEKO
:
— Macro: AC_SYS_LARGEFILE
Arrange for 64-bit file offsets, known as large-file support. On some hosts, one must use special compiler options to build programs that can access large files. Append any such options to the output variable CC
. Define _FILE_OFFSET_BITS
and _LARGE_FILES
if necessary.
Large-file support can be disabled by configuring with the --disable-largefile
option.
If you use this macro, check that your program works even when off_t
is wider than long int
, since this is common when large-file support is enabled. For example, it is not correct to print an arbitrary off_t
value X
with printf("%ld", (long int) X)
.
The LFS introduced the fseeko
and ftello
functions to replace their C counterparts fseek
and ftell
that do not use off_t
. Take care to use AC_FUNC_FSEEKO
to make their prototypes available when using them and large-file support is enabled.
If you are using autoheader
to generate a config.h
, you could define the other macros you care about using AC_DEFINE
or AC_DEFINE_UNQUOTED
:
AC_DEFINE([FUSE_VERSION], [28], [FUSE Version.])
The definition will then get passed to the command line or placed in config.h
, if you're using autoheader. The real benefit of AC_DEFINE
is that it easily allows preprocessor definitions as a result of configure checks and separates system-specific cruft from the important details.
When writing the .c
file, #include "config.h"
first, then the interface header (e.g., foo.h
for foo.c
- this ensures that the header has no missing dependencies), then all other headers.