mirror of https://github.com/nirenjan/pinelog.git
Remove the use of config.h
Prior to this change, pinelog relied on an autoconf generated config.h which checked if the compiler supports __attribute__ with constructor, destructor and format. However, most modern compilers already have support for this, and we can use the __has_attribute special operator instead to check for this at compile time. By eliminating the need to create a config.h file, it simplifies integration into other projects that may not have one.master
parent
8983bf8b28
commit
aa0a5545d0
|
@ -125,11 +125,3 @@ definitions.
|
||||||
Pinelog is intended to be integrated into your application source tree, either
|
Pinelog is intended to be integrated into your application source tree, either
|
||||||
by means of including the sources directly, or by including the repository as
|
by means of including the sources directly, or by including the repository as
|
||||||
a Git submodule or subtree.
|
a Git submodule or subtree.
|
||||||
|
|
||||||
The default build of Pinelog uses an autotools generated `config.h` file, which
|
|
||||||
includes checks for the following GCC attributes. If you don't care about these,
|
|
||||||
then either create a dummy config.h which includes the macros
|
|
||||||
`HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR`, `HAVE_FUNC_ATTRIBUTE_DESTRUCTOR` and
|
|
||||||
`HAVE_FUNC_ATTRIBUTE_FORMAT`, or use the `AX_GCC_FUNC_ATTRIBUTE` macro to check
|
|
||||||
for the `constructor`, `destructor` and `format` attributes in your
|
|
||||||
application's `configure.ac` file.
|
|
||||||
|
|
|
@ -16,14 +16,8 @@ LT_INIT
|
||||||
PKG_PROG_PKG_CONFIG
|
PKG_PROG_PKG_CONFIG
|
||||||
PKG_INSTALLDIR
|
PKG_INSTALLDIR
|
||||||
AX_COMPILER_FLAGS
|
AX_COMPILER_FLAGS
|
||||||
AX_GCC_FUNC_ATTRIBUTE([constructor])
|
|
||||||
AX_GCC_FUNC_ATTRIBUTE([destructor])
|
|
||||||
AX_GCC_FUNC_ATTRIBUTE([format])
|
|
||||||
|
|
||||||
AC_SUBST([PINELOG_CFLAGS])
|
AC_SUBST([PINELOG_CFLAGS])
|
||||||
|
|
||||||
# Configuration headers
|
|
||||||
AC_CONFIG_HEADERS([config.h])
|
|
||||||
|
|
||||||
AC_CONFIG_FILES([Makefile])
|
AC_CONFIG_FILES([Makefile])
|
||||||
AC_OUTPUT
|
AC_OUTPUT
|
||||||
|
|
13
pinelog.c
13
pinelog.c
|
@ -6,7 +6,6 @@
|
||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
@ -78,18 +77,22 @@ static FILE *output_stream = NULL;
|
||||||
static int log_level = PINELOG_DEFAULT_LEVEL;
|
static int log_level = PINELOG_DEFAULT_LEVEL;
|
||||||
|
|
||||||
/* Initialize defaults */
|
/* Initialize defaults */
|
||||||
#if HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR
|
#if defined __has_attribute
|
||||||
|
# if __has_attribute(constructor)
|
||||||
__attribute__((constructor))
|
__attribute__((constructor))
|
||||||
# endif
|
# endif
|
||||||
|
#endif
|
||||||
void pinelog_set_defaults(void)
|
void pinelog_set_defaults(void)
|
||||||
{
|
{
|
||||||
output_stream = PINELOG_DEFAULT_STREAM;
|
output_stream = PINELOG_DEFAULT_STREAM;
|
||||||
log_level = PINELOG_DEFAULT_LEVEL;
|
log_level = PINELOG_DEFAULT_LEVEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if HAVE_FUNC_ATTRIBUTE_DESTRUCTOR
|
#if defined __has_attribute
|
||||||
|
# if __has_attribute(destructor)
|
||||||
__attribute__((destructor))
|
__attribute__((destructor))
|
||||||
# endif
|
# endif
|
||||||
|
#endif
|
||||||
void pinelog_close_output_stream(void)
|
void pinelog_close_output_stream(void)
|
||||||
{
|
{
|
||||||
/* If current output stream is not stdout or stderr, then close it */
|
/* If current output stream is not stdout or stderr, then close it */
|
||||||
|
@ -167,7 +170,8 @@ void pinelog_log_message(int level, const char *file, int line, const char *fmt,
|
||||||
level = PINELOG_LVL_TRACE;
|
level = PINELOG_LVL_TRACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR
|
#if defined __has_attribute
|
||||||
|
#if !__has_attribute(constructor)
|
||||||
/*
|
/*
|
||||||
* Validate and set output stream. Only necessary if the compiler doesn't
|
* Validate and set output stream. Only necessary if the compiler doesn't
|
||||||
* support the constructor attribute
|
* support the constructor attribute
|
||||||
|
@ -176,6 +180,7 @@ void pinelog_log_message(int level, const char *file, int line, const char *fmt,
|
||||||
output_stream = PINELOG_DEFAULT_STREAM;
|
output_stream = PINELOG_DEFAULT_STREAM;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#if PINELOG_SHOW_DATE
|
#if PINELOG_SHOW_DATE
|
||||||
do {
|
do {
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
#ifndef LOGGING_H
|
#ifndef LOGGING_H
|
||||||
#define LOGGING_H
|
#define LOGGING_H
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#ifndef PINELOG_TEST
|
#ifndef PINELOG_TEST
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -123,10 +122,11 @@ int pinelog_get_level(void);
|
||||||
*
|
*
|
||||||
* @returns None
|
* @returns None
|
||||||
*/
|
*/
|
||||||
#if HAVE_FUNC_ATTRIBUTE_FORMAT
|
#if defined __has_attribute
|
||||||
|
# if __has_attribute(format)
|
||||||
__attribute__((format(printf, 4, 5)))
|
__attribute__((format(printf, 4, 5)))
|
||||||
# endif
|
# endif
|
||||||
|
#endif
|
||||||
void pinelog_log_message(int level, const char *file, int line, const char *fmt, ...);
|
void pinelog_log_message(int level, const char *file, int line, const char *fmt, ...);
|
||||||
|
|
||||||
// Test harness will redefine pinelog_exit
|
// Test harness will redefine pinelog_exit
|
||||||
|
|
Loading…
Reference in New Issue