Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
jovanlanik committed Sep 26, 2022
1 parent e8f57db commit 676cb5c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 31 deletions.
8 changes: 5 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
# Makefile

NAME := gtklock
MAJOR_VERSION := 1
MINOR_VERSION := 4
MICRO_VERSION := 0

PREFIX = /usr/local
INSTALL = install

include util/version.mk

LIBS := pam wayland-client gtk+-wayland-3.0 gtk-layer-shell-0 gmodule-no-export-2.0
CFLAGS += -std=c11 -DVERSION=$(VERSION) -DPREFIX=$(PREFIX) -Iinclude $(shell pkg-config --cflags $(LIBS))
CFLAGS += -std=c11 -Iinclude -DPREFIX=$(PREFIX) $(shell pkg-config --cflags $(LIBS))
CFLAGS += -DMAJOR_VERSION=$(MAJOR_VERSION) -DMINOR_VERSION=$(MINOR_VERSION) -DMICRO_VERSION=$(MICRO_VERSION)
LDLIBS += -Wl,--export-dynamic $(shell pkg-config --libs $(LIBS))

SRC = $(wildcard src/*.c)
Expand Down
36 changes: 28 additions & 8 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,25 @@

// Module support

#include "util.h"
#include "module.h"

#ifndef PREFIX
#warning PREFIX not defined.
#define PREFIX /usr/local
#endif

#ifndef VERSION
#warning VERSION not defined.
#define VERSION unknown
#ifndef MAJOR_VERSION
#warning MAJOR_VERSION not defined.
#define MAJOR_VERSION 0
#endif
#ifndef MINOR_VERSION
#warning MINOR_VERSION not defined.
#define MINOR_VERSION 0
#endif
#ifndef MICRO_VERSION
#warning MICRO_VERSION not defined.
#define MICRO_VERSION 0
#endif

#define _STR(x) #x
Expand Down Expand Up @@ -40,11 +49,22 @@ GModule *module_load(const char *name) {
return NULL;
}

gchar *module_version = NULL;
if(g_module_symbol(module, "module_version", (gpointer *)&module_version)) {
if(g_strcmp0(STR(VERSION), module_version) != 0)
g_warning("%s: module has mismatched version, may be incompatible", name);
} else g_warning("%s: module has no version info, may be incompatible", name);
guint *major = NULL;
guint *minor = NULL;
gboolean has_major = g_module_symbol(module, "module_major_version", (gpointer *)&major);
gboolean has_minor = g_module_symbol(module, "module_minor_version", (gpointer *)&minor);
if(has_major && has_minor) {
if(*major != MAJOR_VERSION) report_error_and_exit("%s: module has mismatched major version (%u), is incompatible", name, *major);
else if(*minor != MINOR_VERSION) g_warning("%s: module has mismatched minor version (%u), may be incompatible", name, *minor);
}
else {
const gchar *gtklock_version = "v" STR(MAJOR_VERSION) "." STR(MINOR_VERSION) "." STR(MICRO_VERSION);
const gchar *module_version = NULL;
if(g_module_symbol(module, "module_version", (gpointer *)&module_version)) {
if(g_strcmp0(gtklock_version, module_version) != 0)
g_warning("%s: module has mismatched version, may be incompatible", name);
} else g_warning("%s: module has no version info, may be incompatible", name);
}

return module;
}
Expand Down
16 changes: 12 additions & 4 deletions src/source.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,17 @@
#include "module.h"
#include "xdg.h"

#ifndef VERSION
#warning VERSION not defined.
#define VERSION unknown
#ifndef MAJOR_VERSION
#warning MAJOR_VERSION not defined.
#define MAJOR_VERSION 0
#endif
#ifndef MINOR_VERSION
#warning MINOR_VERSION not defined.
#define MINOR_VERSION 0
#endif
#ifndef MICRO_VERSION
#warning MICRO_VERSION not defined.
#define MICRO_VERSION 0
#endif

#define _STR(x) #x
Expand Down Expand Up @@ -263,7 +271,7 @@ int main(int argc, char **argv) {
report_error_and_exit("Option parsing failed: %s\n", error->message);

if(show_version) {
g_print("gtklock %s\n", STR(VERSION));
g_print("gtklock %s\n", "v" STR(MAJOR_VERSION) "." STR(MINOR_VERSION) "." STR(MICRO_VERSION));
return 0;
}

Expand Down
16 changes: 0 additions & 16 deletions util/version.mk

This file was deleted.

0 comments on commit 676cb5c

Please sign in to comment.