diff --git a/kernel/GNUmakefile b/kernel/GNUmakefile index b8b68eb..df8b312 100644 --- a/kernel/GNUmakefile +++ b/kernel/GNUmakefile @@ -225,6 +225,18 @@ override OBJ += $(addprefix obj-$(ARCH)/,$(NASMFILES:.asm=.asm.o)) endif override HEADER_DEPS := $(addprefix obj-$(ARCH)/,$(CFILES:.c=.c.d) $(CXXFILES:.cpp=.cpp.d) $(OBJCFILES:.mm=.mm.d) $(ASFILES:.S=.S.d)) +# Build number. src/Api/BuildNo.hpp holds MONTAUK_BUILD_NUMBER and is included +# (transitively) only by Api/Syscall.cpp. We regenerate (bump) it whenever any +# kernel object OR any userspace source changes, so the number embedded in the +# kernel tracks real rebuilds of the kernel/userspace. Api/Syscall.cpp.o is +# excluded from the prerequisites to avoid a dependency cycle (it depends on the +# header), and a clean build bumps exactly once. +override BUILDNO_HDR := src/Api/BuildNo.hpp +override BUILDNO_OBJ := obj-$(ARCH)/Api/Syscall.cpp.o +override PROG_SRC := $(shell find ../programs/src ../programs/include ../programs/lib \ + -type f \( -name '*.c' -o -name '*.cpp' -o -name '*.h' -o -name '*.hpp' \ + -o -name '*.S' -o -name '*.asm' \) 2>/dev/null) + # Default target. This must come first, before header dependencies. .PHONY: all all: bin-$(ARCH)/$(OUTPUT) @@ -232,6 +244,15 @@ all: bin-$(ARCH)/$(OUTPUT) # Include header dependencies. -include $(HEADER_DEPS) +# Bump the build number when any kernel object or userspace source is newer. +$(BUILDNO_HDR): $(filter-out $(BUILDNO_OBJ),$(OBJ)) $(PROG_SRC) + ../scripts/bump-build.sh $@ + +# Force Syscall.cpp.o to recompile (and the kernel to relink) in the same pass +# the header is bumped, so the embedded number always matches BuildNo.hpp even +# on a clean build (where no .d dependency exists yet). +$(BUILDNO_OBJ): $(BUILDNO_HDR) + # Link rules for building the C compiler runtime. cc-runtime-$(ARCH)/cc-runtime.a: GNUmakefile cc-runtime/* rm -rf cc-runtime-$(ARCH) diff --git a/kernel/src/Api/BuildNo.hpp b/kernel/src/Api/BuildNo.hpp new file mode 100644 index 0000000..47643ad --- /dev/null +++ b/kernel/src/Api/BuildNo.hpp @@ -0,0 +1,15 @@ +/* + * BuildNo.hpp + * Monotonic kernel build number. + * + * This file is the source of truth for the build number. It is regenerated + * (incremented) by scripts/bump-build.sh whenever the kernel or userspace + * sources change, via a rule in kernel/GNUmakefile. Do not edit the number + * by hand; the build system manages it. + * + * Copyright (c) 2026 Daniel Hammer +*/ + +#pragma once + +#define MONTAUK_BUILD_NUMBER 1 diff --git a/kernel/src/Api/Info.hpp b/kernel/src/Api/Info.hpp index ee54402..a484f29 100644 --- a/kernel/src/Api/Info.hpp +++ b/kernel/src/Api/Info.hpp @@ -7,6 +7,7 @@ #pragma once #include +#include "BuildNo.hpp" #include "Syscall.hpp" namespace Montauk { @@ -22,7 +23,8 @@ namespace Montauk { for (int i = 0; ver[i]; i++) outInfo->osVersion[i] = ver[i]; outInfo->osVersion[5] = '\0'; - outInfo->apiVersion = 3; + outInfo->apiVersion = 4; outInfo->maxProcesses = Sched::MaxProcesses; + outInfo->buildNumber = MONTAUK_BUILD_NUMBER; } }; diff --git a/kernel/src/Api/Syscall.hpp b/kernel/src/Api/Syscall.hpp index fcc8eb1..1bd1982 100644 --- a/kernel/src/Api/Syscall.hpp +++ b/kernel/src/Api/Syscall.hpp @@ -282,6 +282,7 @@ namespace Montauk { char osVersion[32]; uint32_t apiVersion; uint32_t maxProcesses; + uint32_t buildNumber; // monotonic kernel build number (see BuildNo.hpp) }; struct NetCfg { diff --git a/programs/include/Api/Syscall.hpp b/programs/include/Api/Syscall.hpp index be5ae99..30d4be1 100644 --- a/programs/include/Api/Syscall.hpp +++ b/programs/include/Api/Syscall.hpp @@ -243,6 +243,7 @@ namespace Montauk { char osVersion[32]; uint32_t apiVersion; uint32_t maxProcesses; + uint32_t buildNumber; // monotonic kernel build number }; struct KeyEvent { diff --git a/programs/lib/tls/libtls.a b/programs/lib/tls/libtls.a index 0981a3f..3923261 100644 Binary files a/programs/lib/tls/libtls.a and b/programs/lib/tls/libtls.a differ diff --git a/programs/lib/tls/obj/tls.o b/programs/lib/tls/obj/tls.o index db78f78..cb811c2 100644 Binary files a/programs/lib/tls/obj/tls.o and b/programs/lib/tls/obj/tls.o differ diff --git a/programs/libs/libprintersapplet/obj/src/libprintersapplet.o b/programs/libs/libprintersapplet/obj/src/libprintersapplet.o index 7901812..bacff44 100644 Binary files a/programs/libs/libprintersapplet/obj/src/libprintersapplet.o and b/programs/libs/libprintersapplet/obj/src/libprintersapplet.o differ diff --git a/programs/libs/libtimezonesapplet/obj/src/libtimezonesapplet.o b/programs/libs/libtimezonesapplet/obj/src/libtimezonesapplet.o index 48292a5..dd3f781 100644 Binary files a/programs/libs/libtimezonesapplet/obj/src/libtimezonesapplet.o and b/programs/libs/libtimezonesapplet/obj/src/libtimezonesapplet.o differ diff --git a/programs/src/desktop/apps/settings/about.cpp b/programs/src/desktop/apps/settings/about.cpp index efb90d2..6f53d73 100644 --- a/programs/src/desktop/apps/settings/about.cpp +++ b/programs/src/desktop/apps/settings/about.cpp @@ -23,14 +23,15 @@ void settings_draw_about(Canvas& c, SettingsState* st) { ? fonts::system_font->get_line_height(fonts::LARGE_SIZE) : (FONT_HEIGHT * 2); y += large_h + 8; - snprintf(line, sizeof(line), "Version %s", st->sys_info.osVersion); + snprintf(line, sizeof(line), "Version %s (Build %u)", + st->sys_info.osVersion, (unsigned)st->sys_info.buildNumber); c.text(x, y, line, theme.text); y += line_h + 8; mtk::draw_separator(c, x, y, c.w - 2 * x, theme); y += 12; - snprintf(line, sizeof(line), "API version: %d", (int)st->sys_info.apiVersion); + snprintf(line, sizeof(line), "Build number: %u", (unsigned)st->sys_info.buildNumber); c.kv_line(x, &y, line, theme.text, line_h); int up_sec = (int)(st->uptime_ms / 1000); diff --git a/scripts/bump-build.sh b/scripts/bump-build.sh new file mode 100755 index 0000000..2ea009e --- /dev/null +++ b/scripts/bump-build.sh @@ -0,0 +1,44 @@ +#!/bin/sh +# bump-build.sh - Increment the MontaukOS kernel build number. +# +# Reads the current MONTAUK_BUILD_NUMBER from the given header, increments it, +# and rewrites the header in place. Invoked by kernel/GNUmakefile whenever the +# kernel or userspace sources change, so the build number reflects real builds. +# +# Usage: ./scripts/bump-build.sh + +set -e + +HDR="$1" +if [ -z "$HDR" ] || [ ! -f "$HDR" ]; then + echo "bump-build.sh: header not found: $HDR" >&2 + exit 1 +fi + +cur=$(sed -n 's/^#define MONTAUK_BUILD_NUMBER \([0-9][0-9]*\).*/\1/p' "$HDR") +if [ -z "$cur" ]; then + echo "bump-build.sh: could not parse MONTAUK_BUILD_NUMBER in $HDR" >&2 + exit 1 +fi + +next=$((cur + 1)) + +cat > "$HDR" < $next"