From 52b221cf733e70dbcfc467c1a3d2af737b2bb9c7 Mon Sep 17 00:00:00 2001 From: Aditya Gupta Date: Fri, 29 May 2026 11:17:28 +0530 Subject: [PATCH] feat: switch to git based versioning - Makefile computes version automatically - added version flag for splash cli --- Makefile | 3 +++ src/gsplash.c | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/Makefile b/Makefile index a68b66f..87b83d6 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,13 @@ # Makefile for gsplash (community-standard layout) +VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "unknown") + PREFIX ?= /usr/local bindir ?= $(PREFIX)/bin CC ?= gcc CFLAGS ?= -O2 -Wall -Wextra +CFLAGS += -DGSPLASH_VERSION=\"$(VERSION)\" PKG_CONFIG ?= pkg-config SDL_CFLAGS := $(shell $(PKG_CONFIG) --cflags sdl2 SDL2_image) diff --git a/src/gsplash.c b/src/gsplash.c index 20afab0..45722f0 100644 --- a/src/gsplash.c +++ b/src/gsplash.c @@ -96,6 +96,10 @@ int main(int argc, char* argv[]) { RenderMode render_mode = RENDER_CENTER; int arg_index = 1; +#ifndef GSPLASH_VERSION +#define GSPLASH_VERSION "unknown" +#endif + while (arg_index < argc && argv[arg_index][0] == '-') { if (strcmp(argv[arg_index], "--") == 0) { arg_index++; @@ -110,11 +114,16 @@ int main(int argc, char* argv[]) { } render_mode = parse_render_mode(argv[arg_index + 1]); arg_index += 2; + } else if (strcmp(argv[arg_index], "--version") == 0 || + strcmp(argv[arg_index], "-v") == 0) { + printf("gsplash version %s\n", GSPLASH_VERSION); + return 0; } else if (strcmp(argv[arg_index], "-h") == 0 || strcmp(argv[arg_index], "--help") == 0) { printf("Usage: %s [options] [args...]\n", argv[0]); printf("Options:\n"); + printf(" -v, --version Show version information\n"); printf( " -m, --mode=MODE Set render mode: stretch, center (default), " "crop\n");