diff --git a/.gitignore b/.gitignore index 097f96e..34588b2 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ valgrind-out.txt # nix build result result + +include/version.h diff --git a/Makefile b/Makefile index 668abe0..f7955de 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,6 @@ +VERSION = 1.1.1 +.DEFAULT_GOAL := lidm + CDIR=src LDIR=lib IDIR=include @@ -8,7 +11,7 @@ PREFIX=/usr CC?=gcc CFLAGS?=-O3 -Wall _CFLAGS=-I$(DIR) -BUILD_FLAGS=-DLIDM_GIT_DESCRIPTION="\"$(shell git describe --long --tags --always || echo ?)\"" -DLIDM_BUILD_DATE="\"$(shell date -u +"%Y-%m-%dT%H:%M:%SZ" || echo ?)\"" +BUILD_FLAGS= ALLFLAGS=$(CFLAGS) -I$(IDIR) $(BUILD_FLAGS) LIBS=-lpam @@ -19,6 +22,17 @@ 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 OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ)) +$(IDIR)/version.h: Makefile .git/HEAD + @tmp=$$(mktemp); \ + printf '' > $$tmp; \ + echo '#define LIDM_VERSION "'$(VERSION)'"' >> $$tmp; \ + echo '#define LIDM_GIT_REV "'$$(git describe --long --tags --always)'"' >> $$tmp; \ + echo '#define LIDM_BUILD_TS '$$(date +%s) >> $$tmp; \ + if ! cmp -s $$tmp $@; then \ + mv $$tmp $@; \ + fi; \ + rm -f $$tmp; + $(ODIR)/%.o: $(CDIR)/%.c $(DEPS) @mkdir -p $(ODIR) $(CC) -c -o $@ $< $(ALLFLAGS) @@ -26,7 +40,6 @@ $(ODIR)/%.o: $(CDIR)/%.c $(DEPS) lidm: $(OBJ) $(CC) -o $@ $^ $(ALLFLAGS) $(LIBS) -.PHONY: clean clean: rm -f $(ODIR)/*.o lidm @@ -79,3 +92,13 @@ pre-commit: find . -type f -name '*.sh' -not -path './assets/pkg/aur/*/src/*' | xargs shellcheck clang-format -i $$(git ls-files "*.c" "*.h") clang-tidy -p . $$(git ls-files "*.c" "*.h") + +.PHONY: clean \ + install uninstall \ + install-service \ + install-service-s6 \ + install-service-dinit \ + install-service-runit \ + install-service-openrc \ + install-service-systemd \ + pre-commit diff --git a/include/macros.h b/include/macros.h index c549cf1..ad0f718 100644 --- a/include/macros.h +++ b/include/macros.h @@ -20,6 +20,16 @@ #define UNULLABLE #endif +#if defined(__clang__) +#define COMPILER_VERSION __VERSION__ +#elif defined(__GNUC__) +#define xstr(s) str(s) +#define str(s) #s + +#define COMPILER_VERSION \ +"GCC " xstr(__GNUC__) "." xstr(__GNUC_MINOR__) "." xstr(__GNUC_PATCHLEVEL__) +#endif + #define LEN(X) (sizeof(X) / sizeof((X)[0])) #endif diff --git a/include/version.h b/include/version.h deleted file mode 100644 index df9d7f2..0000000 --- a/include/version.h +++ /dev/null @@ -1,9 +0,0 @@ -#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 186a85d..41bdd53 100644 --- a/src/main.c +++ b/src/main.c @@ -4,17 +4,20 @@ #include #include #include +#include #include #include "chvt.h" #include "config.h" #include "log.h" +#include "macros.h" #include "sessions.h" #include "ui.h" #include "users.h" #include "util.h" #include "version.h" +#define DATESTR_MAXBUFSIZE 0x20 int main(int argc, char* argv[]) { // Logger char* log_output = getenv("LIDM_LOG"); @@ -31,20 +34,40 @@ int main(int argc, char* argv[]) { 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); + char* version = "?"; + char* revision = "?"; + char* builddate = "?"; + char* compilever = "?"; +#ifdef LIDM_VERSION + version = LIDM_VERSION; +#endif +#ifdef LIDM_GIT_REV + revision = LIDM_GIT_REV; +#endif +#ifdef LIDM_BUILD_TS + time_t ts = LIDM_BUILD_TS; + char date_buf[DATESTR_MAXBUFSIZE]; + builddate = date_buf; + if (strftime(date_buf, 0xff, "%Y-%m-%dT%H:%M:%SZ", localtime(&ts)) > 0) + builddate = date_buf; +#endif +#ifdef COMPILER_VERSION + compilever = COMPILER_VERSION; +#endif + printf("lidm version %s (git %s, build date %s, compiler %s)\n", version, + revision, builddate, compilever); return 0; - } else if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) { + } + 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]); } + // Chvt + chvt_str(argv[1]); } struct config config = DEFAULT_CONFIG;