KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
version.h
Go to the documentation of this file.
1
2/* KallistiOS ##version##
3
4 include/kos/version.h
5 Copyright (C) 2024 Falco Girgis
6 Copyright (C) 2024 Donald Haase
7 Copyright (C) 2024 Luke Benstead
8
9*/
10
11/** \file
12 \brief API versioning and requirements checks.
13 \ingroup version
14
15 This file contains the current KOS version information as well as utilities
16 for enforcing and checking for certain version ranges.
17
18 \author Falco Girgis
19 \author Donald Haase
20 \author Luke Benstead
21*/
22
23#ifndef __KOS_VERSION_H
24#define __KOS_VERSION_H
25
26/** \defgroup version Versioning
27 \brief KOS version information and utility API
28
29 This API provides both access to the current KOS version as well as
30 utilities that can be used to check for or require a particular version.
31
32 ## Format
33 KOS's versioning scheme follows the following format: `major.minor.patch`
34 where a change in the revision number of any component typically suggests:
35
36 |Component|Description
37 |---------|-----------
38 |Major |Massive, sweeping changes to major APIs and subsystems.
39 |Minor |Small, incremental updates and new features.
40 |Patch |Usually simply bugfixes.
41
42 ## Version Types
43 The versioning information is split into two different groups:
44
45 |Version Type|Description
46 |------------|-----------
47 |\ref version_comptime|The version of KOS your code is being compiled against.
48 |\ref version_runtime |The version of KOS your code has been linked against.
49
50 Ideally, these two versions would be the same; however, it is possible for
51 them to differ in certain circumstances:
52
53 - You pulled down a new version of KOS, rebuilt your code, but did not
54 rebuild the KOS library.
55 - You use dynamically loaded libraries which may have been built
56 against different versions of KOS than what you are currently
57 linking against.
58
59 ## Version Checking
60 Version checks are handled differently depending on whether you want to use
61 the version at compile-time or run-time.
62
63 |Version Type|Mechanism
64 |------------|-----------
65 |\ref version_comptime_check "Compile-Time"|Preprocessor directives, conditional compilation.
66 |\ref version_runtime_check "Run-Time"|if statements, conditional branches
67
68 \warning
69 It is very important that you use the provided version-check mechanisms when
70 comparing two different versions together, as no assurance is made that
71 versions can be correctly compared as integers.
72
73 ## App Versioning
74 The same \ref version_utils used to implement the KOS versioning
75 API are available as part of the public API so that they may be used to
76 implement your own similar versioning scheme at the app-level.
77
78 @{
79*/
80
81/** \defgroup version_comptime Compile-Time
82 \brief API providing compile-time KOS version and utilties.
83
84 This API is is specifically for the compile-time versioning. As such,
85 its API is implemented via C macros, which can easily be used with the
86 preprocessor for conditional compilation.
87
88 @{
89*/
90
91/** \defgroup version_comptime_current Current
92 \brief Current compile-time version of KOS
93
94 These macros provide information about the current version of KOS at
95 compile-time.
96
97 @{
98*/
99
100#define KOS_VERSION_MAJOR 2 /**< KOS's current major revision number. */
101#define KOS_VERSION_MINOR 1 /**< KOS's current minor revision number. */
102#define KOS_VERSION_PATCH 0 /**< KOS's current patch revision number. */
103
104/** KOS's current version as an integer ID. */
105#define KOS_VERSION \
106 KOS_VERSION_MAKE(KOS_VERSION_MAJOR, KOS_VERSION_MINOR, KOS_VERSION_PATCH)
107
108/** KOS's current version as a string literal. */
109#define KOS_VERSION_STRING \
110 KOS_VERSION_MAKE_STRING(KOS_VERSION_MAJOR, \
111 KOS_VERSION_MINOR, \
112 KOS_VERSION_PATCH)
113/** @} */
114
115/** \defgroup version_comptime_check Checks
116 \brief Compile-time checks against KOS's current version.
117
118 This API provides several utility macros to check for a particular
119 exact, min, or max compile-time version for KOS.
120
121 They are meant to be used with the preprocessor like so:
122
123 \code{.c}
124 #if KOS_VERSION_MIN(2, 0, 0)
125 // Do something requiring at least KOS 2.0.0 to compile.
126 #elif KOS_VERSION_BELOW(2, 5, 1)
127 // Do something that was deprecated in KOS 2.5.1.
128 #elif KOS_VERSION_IS(3, 1, 2)
129 // Do something for an exact version match.
130 #endif
131 \endcode
132
133 @{
134*/
135
136/** Compile-time check for being above a given KOS version.
137
138 Checks to see whether the current KOS version is higher than the given
139 version.
140
141 \param major Major version component.
142 \param minor Minor version component.
143 \param patch Patch version component.
144
145 \retval true KOS's version is higher.
146 \retval false KOS's version is the same or lower.
147
148*/
149#define KOS_VERSION_ABOVE(major, minor, patch) \
150 KOS_VERSION_MAKE_ABOVE(major, minor, patch, KOS_VERSION)
151
152/** Compile-time check for a minimum KOS version.
153
154 Checks to see whether the current KOS version is the same or higher than
155 the given version.
156
157 \param major Major version component.
158 \param minor Minor version component.
159 \param patch Patch version component.
160
161 \retval true KOS's version is the same or higher.
162 \retval false KOS's version is lower.
163
164*/
165#define KOS_VERSION_MIN(major, minor, patch) \
166 KOS_VERSION_MAKE_MIN(major, minor, patch, KOS_VERSION)
167
168/** Compile-time check for an exact KOS version.
169
170 Checks to see whether the current KOS version matches the given version.
171
172 \param major Major version component.
173 \param minor Minor version component.
174 \param patch Patch version component.
175
176 \retval true KOS's version is the same.
177 \retval false KOS's version is different.
178*/
179#define KOS_VERSION_IS(major, minor, patch) \
180 KOS_VERSION_MAKE_IS(major, minor, patch, KOS_VERSION)
181
182/** Compile-time check for a maximum KOS version.
183
184 Checks to see whether the current KOS version is the same or lower than the
185 given version.
186
187 \param major Major version component.
188 \param minor Minor version component.
189 \param patch Patch version component.
190
191 \retval true KOS's version is the the same or lower.
192 \retval false KOS's version is higher.
193*/
194#define KOS_VERSION_MAX(major, minor, patch) \
195 KOS_VERSION_MAKE_MAX(major, minor, patch, KOS_VERSION)
196
197/** Compile-time check for being below a given KOS version.
198
199 Checks to see whether the current KOS version is lower than the given
200 version.
201
202 \param major Major version component.
203 \param minor Minor version component.
204 \param patch Patch version component.
205
206 \retval true KOS's version is lower.
207 \retval false KOS's version is the same or higher.
208
209*/
210#define KOS_VERSION_BELOW(major, minor, patch) \
211 KOS_VERSION_MAKE_BELOW(major, minor, patch, KOS_VERSION)
212
213/** @} */
214
215/** @} */
216
217/** \defgroup version_utils Utilities
218 \brief Utilities for creating version info and checks.
219
220 These are generalized utilities for construction of version info at
221 compile-time. They are what KOS uses internally, but they can also
222 be used externally to generate version info and version check utilities
223 for your application.
224
225 \note
226 The ranges for the components of a version ID are as follows:
227
228 |Component|Bits|Range
229 |---------|----|------
230 |Major |8 |0-255
231 |Minor |8 |0-255
232 |Patch |8 |0-255
233
234 @{
235*/
236
237/** \name Version Encoding
238 \brief Utilities for encoding a version from its components.
239 @{
240*/
241/** Creates a version identifier from its constituents.
242
243 Used to create a version identifier at compile-time from its components.
244
245 \param major Major version component.
246 \param minor Minor version component.
247 \param patch Patch version component.
248
249 \returns Packed version identifier.
250*/
251#define KOS_VERSION_MAKE(major, minor, patch) \
252 ((kos_version_t)((major) << 16) | ((minor) << 8) | (patch))
253
254/** Creates a version string from its constituents.
255
256 Used to create a compile-time string literal from version components.
257
258 \param major Major version component.
259 \param minor Minor version component.
260 \param patch patch versoin component.
261
262 \returns `NULL`-terminated C string literal in the format
263 `major.minor.patch`
264*/
265#define KOS_VERSION_MAKE_STRING(major, minor, patch) \
266 KOS_STRINGIFY(major) "." \
267 KOS_STRINGIFY(minor) "." \
268 KOS_STRINGIFY(patch)
269/** @} */
270
271/** \name Version Checking
272 \brief Utilities for creating version checks.
273 @{
274*/
275/** Creates a generic check against a given version.
276
277 Bottom-level macro used to create all compile-time comparison checks against
278 other versions.
279
280 \param major Major version component.
281 \param minor Minor version component.
282 \param patch Patch version component.
283 \param op Integer comparison operator (`<=`, `>=`, `!=`, `==`, etc)/
284 \param version Encoded version to compare against.
285
286 \returns Boolean value for the given version compared against
287 \p version using \p op.
288*/
289#define KOS_VERSION_MAKE_COMPARISON(major, minor, patch, op, version) \
290 (KOS_VERSION_MAKE(major, minor, patch) op (version & 0xffffff))
291
292/** Creates a check for being above a given version.
293
294 Used to create a compile-time greater-than check against another version.
295
296 \note
297 Simply wrap this in a function to implement a runtime check.
298
299 \param major Major version component.
300 \param minor Minor version component.
301 \param patch Patch version component.
302 \param version The reference version ID.
303
304 \retval true The given version is above \p version.
305 \retval false The given version is at or below \p version.
306*/
307#define KOS_VERSION_MAKE_ABOVE(major, minor, patch, version) \
308 (KOS_VERSION_MAKE_COMPARISON(major, minor, patch, >, version))
309
310/** Creates a minimum version check.
311
312 Used to create a compile-time minimum version check.
313
314 \note
315 Simply wrap this in a function to implement a runtime check.
316
317 \param major Major version component.
318 \param minor Minor version component.
319 \param patch Patch version component.
320 \param version The minimum version ID.
321
322 \retval true The given version is at or above \p version.
323 \retval false The given version is below \p version.
324*/
325#define KOS_VERSION_MAKE_MIN(major, minor, patch, version) \
326 (KOS_VERSION_MAKE_COMPARISON(major, minor, patch, >=, version))
327
328/** Creates an exact version check.
329
330 Used to create a compile-time exact version check.
331
332 \note
333 Simply wrap this in a function to implement a runtime check.
334
335 \param major Major version component.
336 \param minor Minor version component.
337 \param patch Patch version component.
338 \param version The exact version ID to match.
339
340 \retval true The given version matches \p version exactly.
341 \retval false The given version does not match \p version.
342*/
343#define KOS_VERSION_MAKE_IS(major, minor, patch, version) \
344 (KOS_VERSION_MAKE_COMPARISON(major, minor, patch, ==, version))
345
346/** Creates a maximum version check.
347
348 Used to create a compile-time maximum version check.
349
350 \note
351 Simply wrap this in a function to implement a runtime check.
352
353 \param major Major version component.
354 \param minor Minor version component.
355 \param patch Patch version component.
356 \param version The maximum version ID.
357
358 \retval true The given version is at or below \p version.
359 \retval false The given version is above \p version.
360
361*/
362#define KOS_VERSION_MAKE_MAX(major, minor, patch, version) \
363 (KOS_VERSION_MAKE_COMPARISON(major, minor, patch, <=, version))
364
365/** Creates a check for being below a given version.
366
367 Used to create a compile-time less-than check against another version.
368
369 \note
370 Simply wrap this in a function to implement a runtime check.
371
372 \param major Major version component.
373 \param minor Minor version component.
374 \param patch Patch version component.
375 \param version The reference version ID.
376
377 \retval true The given version is below \p version.
378 \retval false The given version is at or above \p version.
379*/
380#define KOS_VERSION_MAKE_BELOW(major, minor, patch, version) \
381 (KOS_VERSION_MAKE_COMPARISON(major, minor, patch, <, version))
382/** @} */
383
384/** \cond INTERNAL */
385#define KOS_STRINGIFY(str) #str
386/** \endcond */
387
388/** @} */
389
390#include <kos/cdefs.h>
391__BEGIN_DECLS
392
393#include <stdint.h>
394#include <stdbool.h>
395
396/** \defgroup version_runtime Run-Time
397 \brief API providing run-time KOS version and utilties.
398
399 This API is is specifically for the run-time versioning. As such this
400 API operates on the KOS version that was linked against and is not suited
401 for use at the preprocessor level.
402
403 @{
404*/
405
406/** Type of a KOS version identifier.
407
408 This identifier packs the 3 version components into a single opaque ID.
409
410 \warning
411 It is not safe to compare two different versions together as if they were
412 regular integral types. You must use the Run-time
413 \ref version_runtime_check API.
414*/
415typedef uint32_t kos_version_t;
416
417/** \defgroup version_runtime_current Current
418 \brief Current run-time version of KOS
419
420 These functions provide information about the current version of KOS at
421 run-time (ie the version you have linked against).
422
423 @{
424*/
425
426/** Returns the current KOS version ID at run-time.
427
428 This function is used to fetch the current KOS version ID at run-time,
429 meaning it will return the version of KOS you have \e linked to, rather
430 than the one you were necessarily compiling against.
431
432 \returns KOS's current version identifier
433*/
435
436/** Returns the string representation of the current KOS version at run-time
437
438 This function fetches the current run-time version of KOS as a string.
439
440 \note
441 The string is a NULL-terminated character array in the format:
442 `major.minor.patch`.
443
444 \returns KOS's current version as a printable string.
445*/
446const char* kos_version_string(void);
447
448/** @} */
449
450/** \defgroup version_runtime_check Checks
451 \brief Run-time checks against KOS's current version.
452
453 This API provides several utility functions to check for a particular
454 exact, min, or max run-time version for KOS.
455
456 They are meant to be used as conditional expressions as such:
457
458 \code{.c}
459 if(kos_version_min(2, 0, 0))
460 // Do something requiring at least KOS 2.0.0 to compile.
461 else if(kos_version_below(2, 5, 1))
462 // Do something that was deprecated in KOS 2.5.1.
463 else if(kos_version_is(3, 1, 2))
464 // Do something for an exact version match.
465 \endcode
466
467 @{
468*/
469
470/** Above version run-time check for KOS.
471
472 Check whether the current run-time version of KOS is above the
473 given version.
474
475 \param major Major version component.
476 \param minor Minor version component.
477 \param patch Patch version component.
478
479 \retval true KOS is above the given version.
480 \retval false KOS is at or below the given version.
481*/
482bool kos_version_above(uint8_t major, uint16_t minor, uint8_t patch);
483
484/** Minimum version run-time check for KOS
485
486 Check whether the current run-time version of KOS is at least the
487 given version.
488
489 \param major Major version component.
490 \param minor Minor version component.
491 \param patch patch version component.
492
493 \retval true KOS is at or above the minimum version.
494 \retval false KOS is below teh minimum version.
495*/
496bool kos_version_min(uint8_t major, uint16_t minor, uint8_t patch);
497
498/** Exact version run-time check for KOS
499
500 Checks whether the current run-time version of KOS matches the given
501 version.
502
503 \param major Major version component.
504 \param minor Minor version component.
505 \param patch Patch version component.
506
507 \retval true The version matches exactly.
508 \retval false The version does not match.
509*/
510bool kos_version_is(uint8_t major, uint16_t minor, uint8_t patch);
511
512/** Maximum version run-time check for KOS
513
514 Checks whether the current run-time version of KOS is at most the
515 given version.
516
517 \param major Major version component.
518 \param minor Minor version component.
519 \param patch Patch version component.
520
521 \retval true KOS is at or below the maximum version.
522 \retval false KOS is above the maximum version.
523
524*/
525bool kos_version_max(uint8_t major, uint16_t minor, uint8_t patch);
526
527/** Below version run-time check for KOS
528
529 Checks whether the current run-time version of KOS is below the given
530 version.
531
532 \param major Major version component.
533 \param minor Minor version component.
534 \param patch Patch version component.
535
536 \retval true KOS is below the given version.
537 \retval false KOS is at or above the given version.
538
539*/
540bool kos_version_below(uint8_t major, uint16_t minor, uint8_t patch);
541
542/** @} */
543
544/** @} */
545
546/** @} */
547
548__END_DECLS
549
550#endif /* __KOS_VERSION_H */
Definitions for builtin attributes and compiler directives.
bool kos_version_min(uint8_t major, uint16_t minor, uint8_t patch)
Minimum version run-time check for KOS.
bool kos_version_below(uint8_t major, uint16_t minor, uint8_t patch)
Below version run-time check for KOS.
bool kos_version_max(uint8_t major, uint16_t minor, uint8_t patch)
Maximum version run-time check for KOS.
bool kos_version_is(uint8_t major, uint16_t minor, uint8_t patch)
Exact version run-time check for KOS.
bool kos_version_above(uint8_t major, uint16_t minor, uint8_t patch)
Above version run-time check for KOS.
kos_version_t kos_version(void)
Returns the current KOS version ID at run-time.
const char * kos_version_string(void)
Returns the string representation of the current KOS version at run-time.
uint32_t kos_version_t
Type of a KOS version identifier.
Definition version.h:415