From e6780f2bee69aec3770066ee6ba91c3b3c656f1e Mon Sep 17 00:00:00 2001 From: Eidolon Date: Wed, 16 Nov 2022 02:38:04 +0000 Subject: [PATCH] Merge branch 'comptime-no-fail' into 'master' Minor comptime refactoring. See merge request STJr/SRB2!1776 (cherry picked from commit dc02339cc9ea73ac56bddfce4b792644cacc66a1) 9bfc82a1 Prevent comptime.* from failing compilation a614865d Make comptime.sh conform to POSIX and less redundant, among other improvements b7711b2b Pass argument list directly to functions that use them; quote arguments when used. --- comptime.sh | 54 +++++++++++++++++++++------------------------------- src/Makefile | 4 ++-- 2 files changed, 24 insertions(+), 34 deletions(-) diff --git a/comptime.sh b/comptime.sh index d5ef7271a..ce771f631 100755 --- a/comptime.sh +++ b/comptime.sh @@ -1,54 +1,44 @@ -#!/bin/bash -e +#!/bin/sh path="." if [ x"$1" != x ]; then path="$1" fi -versiongit() { - gitbranch=`git rev-parse --abbrev-ref HEAD` - gitversion=`git rev-parse HEAD` - cat < $path/comptime.h +version() { + cat < "$path/comptime.h" // Do not edit! This file was autogenerated // by the $0 script with git // -const char* compbranch = "$gitbranch"; -const char* comprevision = "${gitversion:0:8}"; +const char* compbranch = "$1"; +const char* comprevision = "$2"; EOF -exit 0 +} + +versiongit() { + gitbranch="$(git rev-parse --abbrev-ref HEAD)" + gitversion="$(git rev-parse HEAD | cut -c -8)" + version "$gitbranch" "$gitversion"; + exit 0 } versionsvn() { - svnrevision=`svnversion -n $1` - cat < $path/comptime.h - -// Do not edit! This file was autogenerated -// by the $0 script with subversion -// -const char* compbranch = "Subversion"; -const char* comprevision = "r$svnrevision"; -EOF -exit 0 + svnrevision="$(svnversion -n "$1")" + version "Subversion" "r$svnrevision"; + exit 0 } versionfake() { - cat < $path/comptime.h - -// Do not edit! This file was autogenerated -// by the $0 script with an unknown or nonexist SCM -// -const char* compbranch = "Unknown"; -const char* comprevision = "illegal"; -EOF + version "Unknown" "illegal"; } compversion() { -touch $path/comptime.c -versionfake -test -d $path/.svn && versionsvn -test -d $path/../.git && versiongit -exit 1 + touch "$path/comptime.c" + versionfake + [ -d "$path/.svn" ] && versionsvn "$@" + [ -d "$path/../.git" ] && versiongit + exit 1 } -test -f $path/comptime.c && compversion +[ -f "$path/comptime.c" ] && compversion "$@" exit 2 diff --git a/src/Makefile b/src/Makefile index 9cab3e487..7571c8089 100644 --- a/src/Makefile +++ b/src/Makefile @@ -357,9 +357,9 @@ $(dbg).txt : $(dbg) # this really updates comptime.h comptime.c :: ifdef WINDOWSHELL - $(.)..\comptime.bat . + -$(.)..\comptime.bat . else - $(.)../comptime.sh . + -$(.)../comptime.sh . endif # I wish I could make dependencies out of rc files :(