diff --git a/comp_features.h b/comp_features.h new file mode 100644 index 0000000..691107d --- /dev/null +++ b/comp_features.h @@ -0,0 +1,73 @@ +#ifndef _SINK_FEATURES_H +#define _SINK_FEATURES_H + +// REPLACE_STDERR +#ifdef FEATURE_REPLACE_STDERR +#define _FEATURE_REPLACE_STDERR 1 +#else +#define _FEATURE_REPLACE_STDERR 0 +#endif + +// NO_SEARCH_PATH +#ifdef FEATURE_NO_SEARCH_PATH +#define _FEATURE_NO_SEARCH_PATH 1 +#else +#define _FEATURE_NO_SEARCH_PATH 0 +#endif + +// NO_ENV +#ifdef FEATURE_NO_ENV +#define _FEATURE_NO_ENV 1 +#else +#define _FEATURE_NO_ENV 0 +#endif + +// DEBUG_IGNORE_SPLASH +#ifdef FEATURE_DEBUG_IGNORE_SPLASH +#define _FEATURE_DEBUG_IGNORE_SPLASH 1 +#else +#define _FEATURE_DEBUG_IGNORE_SPLASH 0 +#endif + +// Modes + +#ifdef DEBUG +#define _FEATURE_MODE_DEBUG 1 +#else +#define _FEATURE_MODE_DEBUG 0 +#endif + +#ifdef RELEASE +#define _FEATURE_MODE_RELEASE 1 +#else +#define _FEATURE_MODE_RELEASE 0 +#endif + +#define _FEATURE_NAME_(name) _FEATURE_ ## name + +#define FEATURE_HAS_FLAG(name) (_FEATURE_NAME_(name) == 1) +#define FEATURE_GET_FLAG(name) (FEATURE_HAS_FLAG(name) ? CF_ ## name : 0) + +enum compiled_features { + CF_REPLACE_STDERR = 1 << 0, + CF_NO_SEARCH_PATH = 1 << 1, + CF_NO_ENV = 1 << 2, + CF_DEBUG_IGNORE_SPLASH = 1 << 3, + + CF_MODE_DEBUG = 1 << 4, + CF_MODE_RELEASE = 1 << 5, + CF_MODES = CF_MODE_DEBUG | CF_MODE_RELEASE +}; + +#define FEATURE_FLAGS ((enum compiled_features) \ + ( FEATURE_GET_FLAG(REPLACE_STDERR) \ + | FEATURE_GET_FLAG(NO_SEARCH_PATH) \ + | FEATURE_GET_FLAG(NO_ENV) \ + | FEATURE_GET_FLAG(DEBUG_IGNORE_SPLASH) \ + | FEATURE_GET_FLAG(MODE_DEBUG) \ + | FEATURE_GET_FLAG(MODE_RELEASE) \ + )) + +#define FEATURE_STRING(flags, name) ((((flags) & FEATURE_GET_FLAG(name)) != 0) ? "+" # name : "-" # name ) + +#endif /* _SINK_FEATURES_H */ diff --git a/sink.c b/sink.c index 23963fe..00d9c47 100644 --- a/sink.c +++ b/sink.c @@ -6,6 +6,10 @@ #include #include +#include "comp_features.h" + +static const enum compiled_features compiled_features = FEATURE_FLAGS; + #define r_stdin 0 #define r_stdout 1 #define r_stderr 2 @@ -149,15 +153,41 @@ static inline size_t count_list(const void*const* p) while(*p++) n+=1; return n; } +static void print_compiled_features() +{ +#define _X "\t%s\n" +#define X(name) fprintf(stderr, _X, FEATURE_STRING(FEATURE_FLAGS, name)) + X(REPLACE_STDERR); + X(NO_SEARCH_PATH); + X(NO_ENV); + X(DEBUG_IGNORE_SPLASH); + fprintf(stderr, "Build mode: \n\t" +#if defined(DEBUG) && defined(RELEASE) + "release (+debug paths)" +#elif defined(DEBUG) + "debug" +#elif degined(RELEASE) + "release" +#else + "unknown" +#endif + "\n"); + +#undef X +#undef _X +} static void print_debug_info(int argc, char* const* argv, char* const* envp) { fprintf(stderr, "[DEBUG BUILD]\n"); -#ifndef DEBUG_IGNORE_SPLASH +#if ! FEATURE_HAS_FLAG(DEBUG_IGNORE_SPLASH) fprintf(stderr, _PROJECT " v" _VERSION ": " _DESCRIPTION "\n"); fprintf(stderr, " :: written by " _AUTHOR " with <3 (License " _LICENSE ")\n---\n"); #endif + fprintf(stderr, "> features:\n"); + print_compiled_features(); + fprintf(stderr, "> program: %s (path lookup: " -#ifdef NO_SEARCH_PATH +#if FEATURE_HAS_FLAG(NO_SEARCH_PATH) "false" #else "true"