mirror of
https://github.com/javalsai/lidm.git
synced 2025-07-05 15:28:42 +02:00
dev: automatic version.h generation
also added compiler information as a feature
This commit is contained in:
parent
3ec1eec56f
commit
19a1355b06
2
.gitignore
vendored
2
.gitignore
vendored
@ -8,3 +8,5 @@ valgrind-out.txt
|
|||||||
|
|
||||||
# nix build result
|
# nix build result
|
||||||
result
|
result
|
||||||
|
|
||||||
|
include/version.h
|
||||||
|
27
Makefile
27
Makefile
@ -1,3 +1,6 @@
|
|||||||
|
VERSION = 1.1.1
|
||||||
|
.DEFAULT_GOAL := lidm
|
||||||
|
|
||||||
CDIR=src
|
CDIR=src
|
||||||
LDIR=lib
|
LDIR=lib
|
||||||
IDIR=include
|
IDIR=include
|
||||||
@ -8,7 +11,7 @@ PREFIX=/usr
|
|||||||
CC?=gcc
|
CC?=gcc
|
||||||
CFLAGS?=-O3 -Wall
|
CFLAGS?=-O3 -Wall
|
||||||
_CFLAGS=-I$(DIR)
|
_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)
|
ALLFLAGS=$(CFLAGS) -I$(IDIR) $(BUILD_FLAGS)
|
||||||
|
|
||||||
LIBS=-lpam
|
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 = 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))
|
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)
|
$(ODIR)/%.o: $(CDIR)/%.c $(DEPS)
|
||||||
@mkdir -p $(ODIR)
|
@mkdir -p $(ODIR)
|
||||||
$(CC) -c -o $@ $< $(ALLFLAGS)
|
$(CC) -c -o $@ $< $(ALLFLAGS)
|
||||||
@ -26,7 +40,6 @@ $(ODIR)/%.o: $(CDIR)/%.c $(DEPS)
|
|||||||
lidm: $(OBJ)
|
lidm: $(OBJ)
|
||||||
$(CC) -o $@ $^ $(ALLFLAGS) $(LIBS)
|
$(CC) -o $@ $^ $(ALLFLAGS) $(LIBS)
|
||||||
|
|
||||||
.PHONY: clean
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(ODIR)/*.o lidm
|
rm -f $(ODIR)/*.o lidm
|
||||||
|
|
||||||
@ -79,3 +92,13 @@ pre-commit:
|
|||||||
find . -type f -name '*.sh' -not -path './assets/pkg/aur/*/src/*' | xargs shellcheck
|
find . -type f -name '*.sh' -not -path './assets/pkg/aur/*/src/*' | xargs shellcheck
|
||||||
clang-format -i $$(git ls-files "*.c" "*.h")
|
clang-format -i $$(git ls-files "*.c" "*.h")
|
||||||
clang-tidy -p . $$(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
|
||||||
|
@ -20,6 +20,16 @@
|
|||||||
#define UNULLABLE
|
#define UNULLABLE
|
||||||
#endif
|
#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]))
|
#define LEN(X) (sizeof(X) / sizeof((X)[0]))
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -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
|
|
35
src/main.c
35
src/main.c
@ -4,17 +4,20 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "chvt.h"
|
#include "chvt.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "macros.h"
|
||||||
#include "sessions.h"
|
#include "sessions.h"
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
#include "users.h"
|
#include "users.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
|
#define DATESTR_MAXBUFSIZE 0x20
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
// Logger
|
// Logger
|
||||||
char* log_output = getenv("LIDM_LOG");
|
char* log_output = getenv("LIDM_LOG");
|
||||||
@ -31,20 +34,40 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
if (argc == 2) {
|
if (argc == 2) {
|
||||||
if (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0) {
|
if (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0) {
|
||||||
printf("lidm version %s (git %s, build date %s)\n", LIDM_VERSION,
|
char* version = "?";
|
||||||
LIDM_GIT_DESCRIPTION, LIDM_BUILD_DATE);
|
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;
|
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(
|
printf(
|
||||||
"Usage: lidm [vt number]\n"
|
"Usage: lidm [vt number]\n"
|
||||||
"Options:\n"
|
"Options:\n"
|
||||||
" -h, --help Display help menu\n"
|
" -h, --help Display help menu\n"
|
||||||
" -v, --version Display version information\n");
|
" -v, --version Display version information\n");
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
|
||||||
// Chvt
|
|
||||||
chvt_str(argv[1]);
|
|
||||||
}
|
}
|
||||||
|
// Chvt
|
||||||
|
chvt_str(argv[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct config config = DEFAULT_CONFIG;
|
struct config config = DEFAULT_CONFIG;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user