dev: automatic version.h generation

also added compiler information as a feature
This commit is contained in:
javalsai 2025-07-04 15:19:25 +02:00
parent 3ec1eec56f
commit 19a1355b06
Signed by: javalsai
SSH Key Fingerprint: SHA256:3G83yKhBUWVABVX/vPWH88xnK4+ptMtHkZGCRXD4Mk8
5 changed files with 66 additions and 17 deletions

2
.gitignore vendored
View File

@ -8,3 +8,5 @@ valgrind-out.txt
# nix build result
result
include/version.h

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -4,17 +4,20 @@
#include <string.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
#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;