Skip to content

Commit e9436c6

Browse files
committed
dynanically set the app version during compile time
1 parent f8bdbbc commit e9436c6

File tree

4 files changed

+58
-24
lines changed

4 files changed

+58
-24
lines changed

Core/Chip8.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
#include "Input.h"
77
#include "Audio.h"
88

9-
#define APPNAME_VERSION "Kiwi8 v1.03"
9+
// APPNAME_VERSION is defined by the compiler via -DAPPNAME_VERSION="..."
10+
// Falls back to generic name if not defined (shouldn't happen in normal builds)
11+
#ifndef APPNAME_VERSION
12+
#define APPNAME_VERSION "Kiwi8"
13+
#endif
14+
1015
#define MEM_SIZE 4096
1116
#define NUM_REGISTERS 16
1217
#define STACK_DEPTH 16

MacOS/makefile

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
1+
APP_NAME = Kiwi8
2+
3+
# Auto-detect version: use GITHUB_REF_NAME if set (CI), else git describe, else git branch
4+
ifeq ($(origin GITHUB_REF_NAME), environment)
5+
VERSION := $(GITHUB_REF_NAME)
6+
else
7+
VERSION := $(shell git describe --tags --exact-match 2>/dev/null || git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown")
8+
endif
9+
10+
APP_NAME_VERSION = $(APP_NAME) $(VERSION)
11+
APP_BUNDLE = release/$(APP_NAME).app
12+
APP_EXE = $(APP_BUNDLE)/Contents/MacOS/$(APP_NAME)
13+
114
CC = clang++
2-
CFLAGS = -std=c++17 -g -Wall -mmacosx-version-min=11.0 -arch x86_64 -arch arm64 -MMD -MP
15+
CFLAGS = -std=c++17 -g -Wall -mmacosx-version-min=11.0 -arch x86_64 -arch arm64 -MMD -MP -DAPPNAME_VERSION='"Kiwi8 $(VERSION)"'
316
LFLAGS = -mmacosx-version-min=11.0
417
INCS = -I$(CURDIR)/frameworks/sdl/include/ \
518
-I$(CURDIR)/../frameworks/imgui/
@@ -23,10 +36,6 @@ MACOS_SRCS = src/file_dialog.mm
2336
OBJS = $(notdir $(CORE_SRCS:.cc=.o)) $(notdir $(IMGUI_SRCS:.cpp=.o)) $(notdir $(MACOS_SRCS:.mm=.o))
2437
DEPS = $(OBJS:.o=.d)
2538

26-
APP_NAME = Kiwi8
27-
APP_BUNDLE = release/$(APP_NAME).app
28-
APP_EXE = $(APP_BUNDLE)/Contents/MacOS/$(APP_NAME)
29-
3039
# Include auto-generated dependency files (must be before targets)
3140
-include $(DEPS)
3241

README.txt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
Kiwi8 v1.03
1+
Kiwi8
22

3-
A cross-platform Chip-8 interpreter written
3+
A cross-platform Chip-8 interpreter written
44
in C++ using SDL2, ImGui, and OpenGL.
55

66
For more information about the Chip-8 visit:
@@ -12,8 +12,8 @@ and MacOS (.exe file and .app bundle respectively)
1212
You can download them here:
1313
https://github.com/tomdaley92/Kiwi8/releases
1414

15-
The interpreter passes "SC Test.ch8" up to
16-
error 23, which is the first SCHIP opcode
15+
The interpreter passes "SC Test.ch8" up to
16+
error 23, which is the first SCHIP opcode
1717
encountered.
1818

1919
ROM Compatibility is discussed here:
@@ -40,21 +40,21 @@ mute m
4040
How to compile:
4141

4242
Windows:
43-
Microsoft's Visual C++ Build Tools
44-
(vcvarsall/cl/nmake) are assumed to be
43+
Microsoft's Visual C++ Build Tools
44+
(vcvarsall/cl/nmake) are assumed to be
4545
installed and added to PATH.
46-
1) Open the command prompt and navigate
46+
1) Open the command prompt and navigate
4747
to the Kiwi8/Windows directory.
48-
2) Type "vcvarsall x86" to load the
48+
2) Type "vcvarsall x86" to load the
4949
windows development environment.
5050
3) Type "nmake".
5151

5252
MacOS:
53-
Apple's Xcode command line tools
54-
(clang++/make/install_name_tool)
55-
are assumed to be installed and
53+
Apple's Xcode command line tools
54+
(clang++/make/install_name_tool)
55+
are assumed to be installed and
5656
added to PATH.
57-
1) Open the terminal and navigate
57+
1) Open the terminal and navigate
5858
to the Kiwi8/MacOS directory.
5959
2) Type "make".
6060

Windows/makefile

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
1+
APP_NAME = Kiwi8
2+
3+
# Auto-detect version: use GITHUB_REF_NAME if set (CI), else git describe, else git branch
4+
!IFNDEF GITHUB_REF_NAME
5+
# Try git describe for exact tag match
6+
!IF [git describe --tags --exact-match > .version.tmp 2>nul] == 0
7+
!INCLUDE .version.tmp
8+
# Try git branch name
9+
!ELSE IF [git rev-parse --abbrev-ref HEAD > .version.tmp 2>nul] == 0
10+
!INCLUDE .version.tmp
11+
!ELSE
12+
VERSION = unknown
13+
!ENDIF
14+
# Clean up temp file
15+
!IF [del .version.tmp 2>nul]
16+
!ENDIF
17+
!ELSE
18+
VERSION = $(GITHUB_REF_NAME)
19+
!ENDIF
20+
21+
APP_NAME_VERSION = $(APP_NAME) $(VERSION)
22+
APP_EXE = $(APP_NAME).exe
23+
APP_PDB = $(APP_NAME).pdb
24+
APP_RES = $(APP_NAME).res
25+
126
CC = CL
2-
CFLAGS = /MD /nologo /W3 /w44996
27+
CFLAGS = /MD /nologo /W3 /w44996 /DAPPNAME_VERSION=\"$(APP_NAME_VERSION)\"
328
LFLAGS = /link \
429
/LIBPATH:frameworks\sdl\lib \
530
/ENTRY:mainCRTStartup
@@ -31,11 +56,6 @@ OBJS = Audio.obj Chip8.obj Display.obj Gui.obj imgui_impl_sdl.obj Input.obj \
3156
imgui_draw.obj file_dialog.obj
3257

3358

34-
APP_NAME = Kiwi8
35-
APP_EXE = $(APP_NAME).exe
36-
APP_PDB = $(APP_NAME).pdb
37-
APP_RES = $(APP_NAME).res
38-
3959
# Default target
4060
all: debug\$(APP_EXE) release\$(APP_EXE)
4161

0 commit comments

Comments
 (0)