fix: PKGBUILD and makefile and rename binary

This commit is contained in:
2026-05-24 10:09:47 +05:30
parent 744e12a926
commit d3c0a3e58e
5 changed files with 131 additions and 55 deletions

2
.gitignore vendored
View File

@@ -51,5 +51,7 @@ Module.symvers
Mkfile.old
dkms.conf
pkg/
# debug information files
*.dwo

View File

@@ -4,29 +4,74 @@ CFLAGS = -O2 -Wall -Wextra $(shell pkg-config --cflags sdl2 SDL2_image)
LIBS = $(shell pkg-config --libs sdl2 SDL2_image)
# Project Structure
TARGET = game-splash
SRC = src/gsplash.c
# Package output path (default to pkg layout used in repository)
PKG_DIR ?= pkg/gsplash-git/usr
BIN_DIR := $(PKG_DIR)/bin
# Compiler settings
CC = gcc
CFLAGS = -O2 -Wall -Wextra $(shell pkg-config --cflags sdl2 SDL2_image)
LIBS = $(shell pkg-config --libs sdl2 SDL2_image)
SRC = src/gsplash.c
# Build output (temporary) and package layout
BUILD_DIR := build
BUILD_TARGET := $(BUILD_DIR)/gsplash
PKG_TOP ?= pkg/gsplash-git
PKG_DIR := $(PKG_TOP)/usr
BIN_DIR := $(PKG_DIR)/bin
PKG_TARGET := $(BIN_DIR)/game-splash
# Installation Paths (Defaults to user local bin)
PREFIX ?= /usr/local
# Default target run when typing just 'make'
all: $(TARGET)
# Default target: build the temporary artifact
all: $(BUILD_TARGET)
# Compilation rule
$(TARGET): $(SRC)
$(CC) $(CFLAGS) $(SRC) -o $(TARGET) $(LIBS)
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
# Install binary system-wide
install: $(TARGET)
install -Dm755 $(TARGET) $(DESTDIR)$(PREFIX)/bin/$(TARGET)
$(BIN_DIR):
mkdir -p $(BIN_DIR)
# Build rule: produce a temporary build artifact in build/
$(BUILD_TARGET): $(BUILD_DIR) $(SRC)
$(CC) $(CFLAGS) $(SRC) -o $(BUILD_TARGET) $(LIBS)
chmod 0755 $(BUILD_TARGET)
# Package: copy build artifact into pkg layout and create a tarball
.PHONY: package dist
package: $(BUILD_TARGET) $(BIN_DIR)
cp -a $(BUILD_TARGET) $(PKG_TARGET)
chmod 0755 $(PKG_TARGET)
mkdir -p dist
# Create a tarball of the package top-level directory
tar -C pkg -czf dist/$(notdir $(PKG_TOP)).tar.gz $(notdir $(PKG_TOP))
dist: package
# Lightweight smoke test (headless via SDL_VIDEODRIVER=dummy)
.PHONY: check
check: $(BUILD_TARGET)
@echo "Running smoke test (headless)..."
# Run with a non-existent image and a noop target (/bin/true) - exits quickly
SDL_VIDEODRIVER=dummy $(BUILD_TARGET) nonexistent.png /bin/true || true
@echo "Smoke test finished"
# Install binary system-wide (installs as game-splash)
install: $(BUILD_TARGET)
install -Dm755 $(BUILD_TARGET) $(DESTDIR)$(PREFIX)/bin/$(notdir $(PKG_TARGET))
# Remove binary from system
uninstall:
rm -f $(DESTDIR)$(PREFIX)/bin/$(TARGET)
rm -f $(DESTDIR)$(PREFIX)/bin/$(notdir $(PKG_TARGET))
# Clean build artifacts
# Clean build artifacts and package output
clean:
rm -f $(TARGET)
rm -f $(BUILD_TARGET) $(PKG_TARGET) dist/$(notdir $(PKG_TOP)).tar.gz
.PHONY: all install uninstall clean
uninstall:

View File

@@ -1,24 +1,22 @@
pkgname=gsplash-git
pkgver=0.1.0
pkgrel=1
pkgdesc="A lightweight SDL2 splash screen wrapper for game launchers."
pkgdesc="A lightweight native SDL2 splash screen wrapper for game launchers."
arch=('x86_64')
depends=('sdl2' 'sdl2_image')
makedepends=('make' 'gcc' 'pkgconf')
source=('src/splash.c' 'Makefile')
sha256sums=('SKIP' 'SKIP')
prepare() {
mkdir -p "$srcdir/src"
cp "$srcdir/splash.c" "$srcdir/src/"
}
# Leave this empty so makepkg doesn't look for external downloads or local copies
source=()
sha256sums=()
build() {
cd "$srcdir"
# Point directly to your active project folder where the Makefile lives
cd "$startdir"
make
}
package() {
cd "$srcdir"
cd "$startdir"
make DESTDIR="$pkgdir" PREFIX="/usr" install
}
}

View File

@@ -37,9 +37,9 @@ sudo make install
Build output installs to `/usr/local/bin` by default. Override with `PREFIX`.
```bash
game-splash <image_path> <game_executable> [game_arguments...]
gsplash <image_path> <game_executable> [game_arguments...]
```
```bash
game-splash assets/splash.jpg /path/to/game --fullscreen --profile=default
gsplash assets/splash.jpg /path/to/game --fullscreen --profile=default
```

View File

@@ -8,7 +8,8 @@
#include <errno.h>
#include <string.h>
static void log_info(const char* fmt, ...) {
static void log_info(const char *fmt, ...)
{
va_list args;
fprintf(stderr, "[splash] ");
va_start(args, fmt);
@@ -18,7 +19,8 @@ static void log_info(const char* fmt, ...) {
fflush(stderr);
}
static void log_error(const char* fmt, ...) {
static void log_error(const char *fmt, ...)
{
va_list args;
fprintf(stderr, "[splash][error] ");
va_start(args, fmt);
@@ -28,8 +30,10 @@ static void log_error(const char* fmt, ...) {
fflush(stderr);
}
int main(int argc, char* argv[]) {
if (argc < 3) {
int main(int argc, char *argv[])
{
if (argc < 3)
{
log_error("Usage: %s <image_path> <game_executable> [args...]", argv[0]);
return 1;
}
@@ -37,14 +41,16 @@ int main(int argc, char* argv[]) {
log_info("Starting splash: image='%s', game='%s'", argv[1], argv[2]);
// Initialize SDL2 Video subsystems
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
log_error("SDL Init Failed: %s", SDL_GetError());
return 1;
}
log_info("SDL initialized");
// Initialize JPEG and PNG decoders
if (!(IMG_Init(IMG_INIT_JPG | IMG_INIT_PNG) & (IMG_INIT_JPG | IMG_INIT_PNG))) {
if (!(IMG_Init(IMG_INIT_JPG | IMG_INIT_PNG) & (IMG_INIT_JPG | IMG_INIT_PNG)))
{
log_error("SDL_image Init Failed: %s", IMG_GetError());
SDL_Quit();
return 1;
@@ -52,14 +58,14 @@ int main(int argc, char* argv[]) {
log_info("SDL_image initialized (JPG/PNG)");
// Create a native borderless fullscreen window
SDL_Window* window = SDL_CreateWindow(
SDL_Window *window = SDL_CreateWindow(
"Game Splash Screen",
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
0, 0,
SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_BORDERLESS
);
SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_BORDERLESS);
if (!window) {
if (!window)
{
log_error("Window Creation Failed: %s", SDL_GetError());
IMG_Quit();
SDL_Quit();
@@ -70,19 +76,23 @@ int main(int argc, char* argv[]) {
SDL_ShowCursor(SDL_DISABLE); // Hide the mouse pointer
// Create a hardware-accelerated renderer
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
if (renderer) {
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
if (renderer)
{
log_info("Renderer created (accelerated)");
}
SDL_Texture* texture = IMG_LoadTexture(renderer, argv[1]);
SDL_Texture *texture = IMG_LoadTexture(renderer, argv[1]);
if (!texture) {
if (!texture)
{
log_error("Failed to load splash image '%s': %s; showing black screen", argv[1], IMG_GetError());
// Fallback: Clear to solid black if image file is broken
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
} else {
}
else
{
log_info("Splash image loaded");
SDL_RenderClear(renderer);
// Automatically scales your image to perfectly match the monitor aspect ratio
@@ -93,53 +103,73 @@ int main(int argc, char* argv[]) {
// Fork the process to run the game
log_info("Launching game executable");
pid_t pid = fork();
if (pid == 0) {
if (pid == 0)
{
// Inside Child Process: Hand over execution directly to the game binary
log_info("Execing game: %s", argv[2]);
execvp(argv[2], &argv[2]);
log_error("Failed to launch target game executable '%s': %s", argv[2], strerror(errno));
_exit(1);
} else if (pid < 0) {
}
else if (pid < 0)
{
log_error("Failed to fork process: %s", strerror(errno));
} else {
}
else
{
log_info("Game process started (pid=%d)", pid);
// Inside Parent Process: Manage splash screen lifecycle
int running = 1;
SDL_Event event;
while (running) {
while (running)
{
// Non-blocking check: Has the game quit?
int status;
pid_t result = waitpid(pid, &status, WNOHANG);
if (result > 0) {
if (WIFEXITED(status)) {
if (result > 0)
{
if (WIFEXITED(status))
{
log_info("Game exited (code=%d)", WEXITSTATUS(status));
} else if (WIFSIGNALED(status)) {
}
else if (WIFSIGNALED(status))
{
log_info("Game terminated by signal %d", WTERMSIG(status));
} else {
}
else
{
log_info("Game exited");
}
break; // Game closed, break the loop and close the script
} else if (result < 0) {
}
else if (result < 0)
{
log_error("waitpid failed: %s", strerror(errno));
break; // Process error safetynet
}
// Check desktop server window events
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
while (SDL_PollEvent(&event))
{
if (event.type == SDL_QUIT)
{
log_info("Splash dismissed via window close");
running = 0;
}
if (event.type == SDL_WINDOWEVENT) {
if (event.type == SDL_WINDOWEVENT)
{
// THE MOMENT THE GAME WINDOW STEALS FOCUS:
if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST) {
if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST)
{
log_info("Splash window hidden (focus lost)");
SDL_HideWindow(window); // Instantly make splash transparent/invisible
}
}
if (event.type == SDL_KEYDOWN) {
if (event.key.keysym.sym == SDLK_ESCAPE) {
if (event.type == SDL_KEYDOWN)
{
if (event.key.keysym.sym == SDLK_ESCAPE)
{
log_info("Splash dismissed via escape key");
running = 0; // Emergency escape key loop override
}
@@ -150,7 +180,8 @@ int main(int argc, char* argv[]) {
}
// Clean up memory space
if (texture) SDL_DestroyTexture(texture);
if (texture)
SDL_DestroyTexture(texture);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
IMG_Quit();