mirror of
https://github.com/LANCommander/LANCommander.Interposer.git
synced 2026-08-01 03:08:17 -04:00
56 lines
2 KiB
PowerShell
56 lines
2 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
Generates version_info.h from the current git tag.
|
|
Falls back to 0.0.0 when git is unavailable or no tag is found.
|
|
.PARAMETER Output
|
|
Path to write version_info.h (default: version_info.h next to this script).
|
|
#>
|
|
param(
|
|
[string]$Output = "$PSScriptRoot\version_info.h",
|
|
[string]$Version = '' # Optional override (e.g. from CI tag); falls back to git describe.
|
|
)
|
|
|
|
$major = 0; $minor = 0; $patch = 0
|
|
|
|
$tag = $Version
|
|
if (-not $tag) {
|
|
try {
|
|
$tag = & git -C $PSScriptRoot describe --tags --exact-match HEAD 2>$null
|
|
if (-not $tag) {
|
|
$tag = & git -C $PSScriptRoot describe --tags --abbrev=0 2>$null
|
|
}
|
|
} catch {}
|
|
}
|
|
if ($tag -match '^v?(\d+)\.(\d+)\.(\d+)') {
|
|
$major = [int]$Matches[1]
|
|
$minor = [int]$Matches[2]
|
|
$patch = [int]$Matches[3]
|
|
}
|
|
|
|
$content = @"
|
|
#pragma once
|
|
// Auto-generated by generate_version.ps1 - do not edit by hand.
|
|
#define VER_MAJOR $major
|
|
#define VER_MINOR $minor
|
|
#define VER_PATCH $patch
|
|
#define VER_BUILD 0
|
|
#define VER_FILEVERSION $major,$minor,$patch,0
|
|
#define VER_PRODUCTVERSION $major,$minor,$patch,0
|
|
#define VER_FILEVERSION_STR "$major.$minor.$patch.0"
|
|
#define VER_PRODUCTVERSION_STR "$major.$minor.$patch.0"
|
|
#define VER_COMPANY_STR "LANCommander"
|
|
#define VER_PRODUCT_STR "LANCommander Interposer"
|
|
#define VER_COPYRIGHT_STR "Copyright (c) 2024-2026 LANCommander Contributors. MIT License."
|
|
"@
|
|
|
|
# Only write when content differs to avoid spurious rebuilds.
|
|
# Use .NET directly for UTF-8 without BOM (compatible with PowerShell 5.x and 7+).
|
|
$utf8NoBom = New-Object System.Text.UTF8Encoding $false
|
|
$existing = if (Test-Path $Output) { [System.IO.File]::ReadAllText($Output) } else { '' }
|
|
$content = $content + "`n"
|
|
if ($content -ne $existing) {
|
|
[System.IO.File]::WriteAllText($Output, $content, $utf8NoBom)
|
|
Write-Host "version_info.h: updated to $major.$minor.$patch"
|
|
} else {
|
|
Write-Host "version_info.h: up to date ($major.$minor.$patch)"
|
|
}
|