From ebb8a91859bbd038af490718e75b8dfbbb0a1024 Mon Sep 17 00:00:00 2001 From: lohhiiccc Date: Mon, 18 May 2026 12:07:28 +0200 Subject: [PATCH] feat: --version --- includes/compiler.h | 6 ++++++ includes/internal/dependencies.h | 29 +++++++++++++++++++++++++++++ libcli | 2 +- libft_ssl | 2 +- src/Makefile.am | 1 + src/cli/handlers/handle_version.c | 3 ++- src/cli/version.c | 26 ++++++++++++++++++++++++++ 7 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 includes/internal/dependencies.h create mode 100644 src/cli/version.c diff --git a/includes/compiler.h b/includes/compiler.h index 17f557a..306d42f 100644 --- a/includes/compiler.h +++ b/includes/compiler.h @@ -8,9 +8,15 @@ #define STATIC_ARRAY_FOREACH(arr, ptr) \ for ((ptr) = (arr); (ptr) < (arr) + COUNT_OF(arr); (ptr)++) +#define STRX(x) #x +#define STR(x) STRX(x) + #define HAS_FLAG(flags, flag) ((flags) & (flag)) #define SET_FLAG(flags, flag) ((flags) |= (flag)) #define CLEAR_FLAG(flags, flag) ((flags) &= ~(flag)) #define TOGGLE_FLAG(flags, flag) ((flags) ^= (flag)) +#define FOREACH_SECTION(item, type, section) \ + for (type *item = __start_##section; item < __stop_##section; ++item) + #endif diff --git a/includes/internal/dependencies.h b/includes/internal/dependencies.h new file mode 100644 index 0000000..98f3f54 --- /dev/null +++ b/includes/internal/dependencies.h @@ -0,0 +1,29 @@ +#ifndef DEPENDENCIES_H +#define DEPENDENCIES_H + +#include +#include + +#include "compiler.h" + +struct dep +{ + const char *name; + const char *version; + const char *extra; +}; + +#define ADD_DEPENDENCY(NAME, VER_MACRO, HAS_GIT_COMMIT_MACRO, GIT_COMMIT_MACRO) \ + static const struct dep dep_##NAME __attribute__((used, section("ft_ssl_deps"))) = { \ + .name = STR(NAME), \ + .version = (VER_MACRO), \ + .extra = (HAS_GIT_COMMIT_MACRO) ? " (" GIT_COMMIT_MACRO ")" : "" \ + }; + +extern const struct dep __start_ft_ssl_deps[] __attribute__((weak)); +extern const struct dep __stop_ft_ssl_deps[] __attribute__((weak)); + +ADD_DEPENDENCY(libcli, LIBCLI_VERSION, LIBCLI_HAS_GIT_COMMIT, LIBCLI_GIT_COMMIT) +ADD_DEPENDENCY(libtf_ssl, LIBFT_SSL_VERSION, LIBFT_SSL_HAS_GIT_COMMIT, LIBFT_SSL_GIT_COMMIT) + +#endif diff --git a/libcli b/libcli index 9f179fa..17ba957 160000 --- a/libcli +++ b/libcli @@ -1 +1 @@ -Subproject commit 9f179fa596b1f50007d4995256f47cf5edb4f5dc +Subproject commit 17ba957ed647364f8f21e43ebf2445410dc5c494 diff --git a/libft_ssl b/libft_ssl index f15a0a5..0da22db 160000 --- a/libft_ssl +++ b/libft_ssl @@ -1 +1 @@ -Subproject commit f15a0a5cf2b0d4cf8e3eb509dde0b2a0acf9d5ab +Subproject commit 0da22db6fadfc1d55acc35715e0bb065ed17c289 diff --git a/src/Makefile.am b/src/Makefile.am index 217dbfd..c95ddf3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -48,6 +48,7 @@ ft_ssl_SOURCES = \ ssl/digest.c \ ssl/output.c \ cli/parse.c \ + cli/version.c \ cli/interactive.c \ cli/handlers/option_map.c \ cli/handlers/handle_help.c \ diff --git a/src/cli/handlers/handle_version.c b/src/cli/handlers/handle_version.c index b5157a1..9e64fe6 100644 --- a/src/cli/handlers/handle_version.c +++ b/src/cli/handlers/handle_version.c @@ -3,10 +3,11 @@ #include #include "compiler.h" +void print_version(void); int cli_handle_version(__unused const char *arg, __unused void *config_void) { - printf("version x\n"); + print_version(); return CLI_EXIT_SUCCESS; } diff --git a/src/cli/version.c b/src/cli/version.c new file mode 100644 index 0000000..2994e3d --- /dev/null +++ b/src/cli/version.c @@ -0,0 +1,26 @@ +#include + +#include "version_gen.h" +#include "internal/dependencies.h" + +void +print_version(void) +{ + printf("%s version %s\n", g_prog_name, FT_SSL_VERSION); + + printf("Copyright (C) 2026 lohhiicccc\n"); + printf("License GPLv3+:"); + printf("GNU GPL version 3 or later \n"); + printf("This is free software: "); + printf("you are free to change and redistribute it.\n"); + printf("There is NO WARRANTY, to the extent permitted by law.\n"); +#if FT_SSL_HAS_GIT_COMMIT + printf("Build: %s (commit %s)\n", FT_SSL_BUILD_DATE, FT_SSL_GIT_COMMIT); +#endif + printf("\n"); + + printf("\nDependencies:\n"); + FOREACH_SECTION(p, const struct dep, ft_ssl_deps) + printf("%-15s %s%s\n", p->name, p->version, p->extra); +} +