From afd23657c0ff7219981288fc5744a9753f0e4ed4 Mon Sep 17 00:00:00 2001 From: grialion <48643945+grialion@users.noreply.github.com> Date: Fri, 4 Jul 2025 00:15:14 +0200 Subject: [PATCH] feat: help, version menu --- Makefile | 5 +++-- include/version.h | 9 +++++++++ src/main.c | 21 +++++++++++++++++++-- 3 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 include/version.h diff --git a/Makefile b/Makefile index 5929207..80de16a 100644 --- a/Makefile +++ b/Makefile @@ -8,11 +8,12 @@ PREFIX=/usr CC?=gcc CFLAGS?=-O3 -Wall _CFLAGS=-I$(DIR) -ALLFLAGS=$(CFLAGS) -I$(IDIR) +BUILD_FLAGS=-DLIDM_GIT_DESCRIPTION="\"$(shell git describe --long --tags || echo ?)\"" -DLIDM_BUILD_DATE="\"$(shell date -u +"%Y-%m-%dT%H:%M:%SZ" || echo ?)\"" +ALLFLAGS=$(CFLAGS) -I$(IDIR) $(BUILD_FLAGS) LIBS=-lpam -_DEPS = log.h util.h ui.h ui_state.h config.h desktop.h auth.h ofield.h efield.h keys.h users.h sessions.h chvt.h macros.h launch_state.h +_DEPS = version.h log.h util.h ui.h ui_state.h config.h desktop.h auth.h ofield.h efield.h keys.h users.h sessions.h chvt.h macros.h launch_state.h DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS)) _OBJ = main.o log.o util.o ui.o ui_state.o config.o desktop.o auth.o ofield.o efield.o users.o sessions.o chvt.o launch_state.o diff --git a/include/version.h b/include/version.h new file mode 100644 index 0000000..df9d7f2 --- /dev/null +++ b/include/version.h @@ -0,0 +1,9 @@ +#ifndef LIDM_VERSION +#define LIDM_VERSION "v1.1.1" +#endif +#ifndef LIDM_GIT_DESCRIPTION +#define LIDM_GIT_DESCRIPTION "?" +#endif +#ifndef LIDM_BUILD_DATE +#define LIDM_BUILD_DATE "?" +#endif diff --git a/src/main.c b/src/main.c index 3ec6f92..186a85d 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -12,6 +13,7 @@ #include "ui.h" #include "users.h" #include "util.h" +#include "version.h" int main(int argc, char* argv[]) { // Logger @@ -27,8 +29,23 @@ int main(int argc, char* argv[]) { log_init(log_fd); } - // Chvt - if (argc == 2) chvt_str(argv[1]); + if (argc == 2) { + if (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0) { + printf("lidm version %s (git %s, build date %s)\n", LIDM_VERSION, + LIDM_GIT_DESCRIPTION, LIDM_BUILD_DATE); + return 0; + } else if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) { + printf( + "Usage: lidm [vt number]\n" + "Options:\n" + " -h, --help Display help menu\n" + " -v, --version Display version information\n"); + return 0; + } else { + // Chvt + chvt_str(argv[1]); + } + } struct config config = DEFAULT_CONFIG; char* conf_override = getenv("LIDM_CONF");