commit fbfb555eae989614c8192d7c2e240b4c07161cdc Author: SoraKatadzuma Date: Thu Jul 9 01:38:50 2026 -0500 Initial commit diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..c6c8b36 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2903287 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.chinook +.environ +.vscode diff --git a/chinookfile b/chinookfile new file mode 100644 index 0000000..8e0e2dd --- /dev/null +++ b/chinookfile @@ -0,0 +1,10 @@ +name: config +gpid: malunal +semv: 1.0.0 + +targets: +- name: malunal.config + type: interface + +exports: +- malunal.config diff --git a/include/malunal/config.h b/include/malunal/config.h new file mode 100644 index 0000000..a04599e --- /dev/null +++ b/include/malunal/config.h @@ -0,0 +1,41 @@ +/** + * @file config.h + * @brief Includes headers which configure a project based on compiler, + * processor, and platform. + * @author John Christman (sorakatadzuma@gmail.com) + * @copyright Malunal Studios, LLC. + */ +#ifndef MALUNAL_CONFIG_HEADER +#define MALUNAL_CONFIG_HEADER + +// Check for compiler config. +#if !defined(MALUNAL_COMPILER_CONFIG) && \ + !defined(MALUNAL_NO_COMPILER_CONFIG) && \ + !defined(MALUNAL_NO_CONFIG) +# include "config/compiler.h" +#endif // Compiler config check. +#if defined(MALUNAL_COMPILER_CONFIG) +# include MALUNAL_COMPILER_CONFIG +#endif // Compiler config inclusion. + +// Check for processor config. +#if !defined(MALUNAL_PROCESSOR_CONFIG) && \ + !defined(MALUNAL_NO_PROCESSOR_CONFIG) && \ + !defined(MALUNAL_NO_CONFIG) +# include "config/processor.h" +#endif // Processor config check. +#if defined(MALUNAL_PROCESSOR_CONFIG) +# include MALUNAL_PROCESSOR_CONFIG +#endif // Processor config inclusion. + +// Check for platform config. +#if !defined(MALUNAL_PLATFORM_CONFIG) && \ + !defined(MALUNAL_NO_PLATFORM_CONFIG) && \ + !defined(MALUNAL_NO_CONFIG) +# include "config/platform.h" +#endif // Platform config check. +#if defined(MALUNAL_PLATFORM_CONFIG) +# include MALUNAL_PLATFORM_CONFIG +#endif // Platform config inclusion. + +#endif // MALUNAL_CONFIG_HEADER diff --git a/include/malunal/config/compiler.h b/include/malunal/config/compiler.h new file mode 100644 index 0000000..4ed9606 --- /dev/null +++ b/include/malunal/config/compiler.h @@ -0,0 +1,87 @@ +/** + * @file compiler.h + * @brief Selects a compiler specific header based on defined macros of that + * compiler, which includes settings for that compiler based on the + * version of that compiler. + * @author John Christman (sorakatadzuma@gmail.com) + * @copyright Malunal Studios, LLC. + */ +#ifndef MALUNAL_CONFIG_COMPILER_HEADER +#define MALUNAL_CONFIG_COMPILER_HEADER + +#if defined(__clang__) +# error "Clang unsupported at this time" +#elif defined(__GNUC__) +# define MALUNAL_COMPILER_CONFIG "./config/compiler/gcc.hpp" +#elif defined(_MSC_VER) +# error "MSVC unsupported at this time" +#else +# error "Unknown compiler" +#endif // Compiler selection. + +/** + * @def MALUNAL_STRINGIZE + * @brief Converts the provided value to a string, using the proprocessor. + * @param x The value that should be converted to a string. + * @returns The string value of the passed argument. + * @remarks If you pass a preprocessor macro directly into this, its name will + * get converted to a string, not the underlying value. To convert the + * value of a preprocessor macro to a string, use @c MALUNAL_TOSTRING. + */ +#define MALUNAL_STRINGIZE(x) #x + +/** + * @def MALUNAL_TOSTRING + * @brief Converts the provided value to a string, using the preprocessor. + * @param x The value that should be converted to a string. + * @returns The string value of the passed argument. + * @remarks If you pass a preprocessor macro directly into this, its value will + * get converted to a string. If you intend for the name of the macro + * to be converted to a string, use @c MALUNAL_STRINGIZE. + */ +#define MALUNAL_TOSTRING(x) MALUNAL_STRINGIZE(x) + +/** + * @def MALUNAL_PREPROCESSOR_JOIN2 + * @brief Joins two values together using the preprocessor. + * @param a The value to join to. + * @param b The value to join with. + * @returns The values joined together. + * @remarks If you pass preprocessor macros directly into this, their names will + * be joined together and not their values. To join the values of two + * preprocessor macros, use @c MALUNAL_PREPROCESSOR_JOIN instead. + */ +#define MALUNAL_PREPROCESSOR_JOIN2(a, b) a##b + +/** + * @def MALUNAL_PREPROCESSOR_JOIN1 + * @brief Joins two values together using the preprocessor. + * @param a The value to join to. + * @param b The value to join with. + * @returns The values joined together. + * @remarks This additional join layer forces @c a and @c b to be expanded + * before they go to @c MALUNAL_PREPROCESSOR_JOIN2 which will do the + * actual joining of the values. There are no reasons to call this + * yourself. + */ +#define MALUNAL_PREPROCESSOR_JOIN1(a, b) MALUNAL_PREPROCESSOR_JOIN2(a, b) + +/** + * @def MALUNAL_PREPROCESSOR_JOIN + * @brief Joins two values together using the preprocessor. + * @param a The value to join to. + * @param b The value to join with. + * @returns The values joined together. + * @remarks If you pass preprocessor macros direclty into this, their values + * will be joined together and not their names. If you intend for their + * names to be joined, use @c MALUNAL_PREPROCESSOR_JOIN2 instead. + */ +#define MALUNAL_PREPROCESSOR_JOIN(a, b) MALUNAL_PREPROCESSOR_JOIN1(a, b) + +/** + * @def MALUNAL_UNUSED + * @brief Makes it clear that a given variable or parameter is not used. + */ +#define MALUNAL_UNUSED(x) (void)x + +#endif /* MALUNAL_CONFIG_COMPILER_HEADER */ diff --git a/include/malunal/config/compiler/common.h b/include/malunal/config/compiler/common.h new file mode 100644 index 0000000..e1ad516 --- /dev/null +++ b/include/malunal/config/compiler/common.h @@ -0,0 +1,55 @@ +/** + * @file common.h + * @brief Contains things common to all compilers, assures inclusion through + * @c compiler.h + * @author John Christman (sorakatadzuma@gmail.com) + * @copyright Malunal Studios, LLC. + */ +#ifndef MALUNAL_CONFIG_COMPILER_HEADER +# error "This file should not be included standalone!" +#endif /* Inclusion Check. */ + +// Redefine the C99 Version ID. +#ifdef MALUNAL_C99_VERID +#undef MALUNAL_C99_VERID +#endif +#define MALUNAL_C99_VERID 199901L + +// Redefine the C11 Version ID. +#ifdef MALUNAL_C11_VERID +#undef MALUNAL_C11_VERID +#endif +#define MALUNAL_C11_VERID 201112L + +// Redefine the C17 Version ID. +#ifdef MALUNAL_C17_VERID +#undef MALUNAL_C17_VERID +#endif +#define MALUNAL_C17_VERID 201710L + +// Redefine the C23 Version ID. +#ifdef MALUNAL_C23_VERID +#undef MALUNAL_C23_VERID +#endif +#define MALUNAL_C23_VERID 202311L + +// Make sure this is not set, we set it ourselves. +#ifdef MALUNAL_STDCVER +#undef MALUNAL_STDCVER +#endif + +#ifdef __STDC_VERSION__ +# if __STDC_VERSION__ == MALUNAL_C99_VERID +# define MALUNAL_STDCVER MALUNAL_C99_VERID +# elif __STDC_VERSION__ == MALUNAL_C11_VERID +# define MALUNAL_STDCVER MALUNAL_C11_VERID +# elif __STDC_VERSION__ == MALUNAL_C17_VERID +# define MALUNAL_STDCVER MALUNAL_C17_VERID +# elif __STDC_VERSION__ == MALUNAL_C23_VERID +# define MALUNAL_STDCVER MALUNAL_C23_VERID +# else /* __STDC_VERSION__ Unknown */ +# error "Unknown STDC version" +# endif /* __STDC_VERSION__ Matching */ +#else /* __STDC_VERSION__ !Defined */ +# error "__STDC_VERSION__ Undefined!" +#endif /* __STDC_VERSION__ Defined */ diff --git a/include/malunal/config/compiler/gcc.h b/include/malunal/config/compiler/gcc.h new file mode 100644 index 0000000..c2b16d6 --- /dev/null +++ b/include/malunal/config/compiler/gcc.h @@ -0,0 +1,76 @@ +/** + * @file gcc.h + * @brief Contains macros pertaining to the GNUC (gcc, g++) set of compilers. + * @author John Christman (sorakatadzuma@gmail.com) + * @copyright Malunal Studios, LLC. + */ +#include "common.h" + +/** + * @def MALUNAL_MAKE_COMPILER_VERSION + * @brief Creates a comprehensible and standard compiler version for this + * library to be able to read and use. + * @param major The major version number for the compiler. + * @param minor The minor version number for the compiler. + * @param patch The patch version number for the compiler. + * @returns The compiler version number as a combined integer. + */ +#define MALUNAL_MAKE_COMPILER_VERSION(major, minor, patch) \ + (major * 1000 + minor * 100 + patch) + +/** + * @def MALUNAL_GCC_VERSION + * @brief Provides the current version for the GCC compiler. + */ +#define MALUNAL_GCC_VERSION \ + MALUNAL_MAKE_COMPILER_VERSION( \ + __GNUC__, \ + __GNUC_MINOR__, \ + __GNUC_PATCHLEVEL__ \ + ) + +/** + * @def MALUNAL_COMPILER_CLANG + * @brief This indicates whether the compiler is Clang. + * @remarks This is guaranteed to be defined unless you undefine it yourself. + */ +#define MALUNAL_COMPILER_CLANG 0 + +/** + * @def MALUNAL_COMPILER_GCC + * @brief This indicates whether the compiler is GNUC (gcc, g++). + * @remarks This is guaranteed to be defined unless you undefine it yourself. + */ +#define MALUNAL_COMPILER_GCC 1 + +/** + * @def MALUNAL_COMPILER_MSVC + * @brief This indicates whether the compiler is MSVC. + * @remarks This is guaranteed to be defined unless you undefine it yourself. + */ +#define MALUNAL_COMPILER_MSVC 0 + +/** + * @def MALUNAL_COMPILER_NAME + * @brief The name of the compiler currently recognized by this library. + * @remarks This is guaranteed to be defined unless you undefine it yourself. + */ +#define MALUNAL_COMPILER_NAME "GCC" + +/** + * @def MALUNAL_COMPILER_VERSION + * @brief The version of the compiler currently recognized by this library. + * @remarks This is guaranteed to be defined unless you undefine it yourself. + */ +#define MALUNAL_COMPILER_VERSION MALUNAL_GCC_VERSION + +/** + * @def MALUNAL_COMPILER_STRING + * @brief A comprehensive compiler string for logging purposes. + * @remarks This is guaranteed to be defined unless you undefine it yourself. + */ +#define MALUNAL_COMPILER_STRING \ + MALUNAL_COMPILER_NAME " " \ + MALUNAL_TOSTRING(__GNUC__) "." \ + MALUNAL_TOSTRING(__GNUC_MINOR__) "." \ + MALUNAL_TOSTRING(__GNUC_PATCHLEVEL__) diff --git a/include/malunal/config/platform.h b/include/malunal/config/platform.h new file mode 100644 index 0000000..bc25b89 --- /dev/null +++ b/include/malunal/config/platform.h @@ -0,0 +1,25 @@ +/** + * @file platform.hpp + * @brief Selects a platform specific header based on defined macros of that + * platform, which includes settings for that platform. + * @author John Christman (sorakatadzuma@gmail.com) + * @copyright Malunal Studios, LLC. + */ +#ifndef MALUNAL_CONFIG_PLATFORM_HEADER +#define MALUNAL_CONFIG_PLATFORM_HEADER + +#if defined(linux) || \ + defined(__linux) || \ + defined(__linux__) || \ + defined(__GNU__) || \ + defined(__GLIBC__) +# define MALUNAL_PLATFORM_CONFIG "./config/platform/linux.hpp" +#elif defined(WIN32) || \ + defined(_WIN32) || \ + defined(__WIN32__) +# define MALUNAL_PLATFORM_CONFIG "./config/platform/windows.hpp" +#else +# error "Unsupported platform" +#endif // Platform selection. + +#endif /* MALUNAL_CONFIG_PLATFORM_HEADER */ diff --git a/include/malunal/config/platform/common.h b/include/malunal/config/platform/common.h new file mode 100644 index 0000000..4332d9e --- /dev/null +++ b/include/malunal/config/platform/common.h @@ -0,0 +1,10 @@ +/** + * @file common.h + * @brief Contains things common to all platforms, assures inclusion through + * @c platform.h + * @author John Christman (sorakatadzuma@gmail.com) + * @copyright Malunal Studios, LLC. + */ +#ifndef MALUNAL_CONFIG_PLATFORM_HEADER +# error "This file should not be included standalone!" +#endif /* Inclusion Check. */ diff --git a/include/malunal/config/platform/linux.h b/include/malunal/config/platform/linux.h new file mode 100644 index 0000000..df93fd8 --- /dev/null +++ b/include/malunal/config/platform/linux.h @@ -0,0 +1,72 @@ +/** + * @file linux.h + * @brief Contains the configurations for linux based platforms. + * @author John Christman (sorakatadzuma@gmail.com) + * @copyright Malunal Studios, LLC. + */ +#include "common.hpp" + + +/** + * @def MALUNAL_PLATFORM_LINUX + * @brief Defines that the system, this library is being compiled for, is a + * linux system. + * @remarks This is guaranteed to be defined, unless you undefine it yourself. + */ +#define MALUNAL_PLATFORM_LINUX 1 + +/** + * @def MALUNAL_PLATFORM_WIN32 + * @brief Defines that the system, this library is being compiled for, is a + * Windows system. + * @remarks This is guaranteed to be defined, unless you undefine it yourself. + */ +#define MALUNAL_PLATFORM_WIN32 0 + +/** + * @def MALUNAL_PLATFORM_DESKTOP + * @brief Defines that the system, this library is being compiled for, is a + * desktop system. + * @remarks This is guaranteed to be defined, unless you undefine it yourself. + */ +#define MALUNAL_PLATFORM_DESKTOP 1 + +/** + * @def MALUNAL_PLATFORM_NAME + * @brief The name of the system this library is being compiled for. + * @remarks This is guaranteed to be defined, unless you undefine it yourself. + */ +#define MALUNAL_PLATFORM_NAME "linux" + +/** + * @def MALUNAL_PLATFORM_DESC + * @brief The descriptor of the system this library is being compiled for. + * @remarks This is guaranteed to be defined, unless you undefine it yourself. + */ +#define MALUNAL_PLATFORM_DESC \ + MALUNAL_PROCESSOR_NAME "-" MALUNAL_PLATFORM_NAME + + +// if the compiler is not gcc we still need to be able to parse +// the GNU system headers, some of which (mainly ) +// use GNU specific extensions: +#ifndef __GNUC__ +# ifndef __extension__ +# define __extension__ +# endif +# ifndef __const__ +# define __const__ const +# endif +# ifndef __volatile__ +# define __volatile__ volatile +# endif +# ifndef __signed__ +# define __signed__ signed +# endif +# ifndef __typeof__ +# define __typeof__ typeof +# endif +# ifndef __inline__ +# define __inline__ inline +# endif +#endif diff --git a/include/malunal/config/platform/windows.h b/include/malunal/config/platform/windows.h new file mode 100644 index 0000000..3912f8a --- /dev/null +++ b/include/malunal/config/platform/windows.h @@ -0,0 +1,55 @@ +/** + * @file windows.h + * @brief Contains the configurations for windows based platforms. + * @author John Christman (sorakatadzuma@gmail.com) + * @copyright Malunal Studios, LLC. + */ +#include "common.hpp" + + +/** + * @def MALUNAL_PLATFORM_LINUX + * @brief Defines that the system, this library is being compiled for, is a + * linux system. + * @remarks This is guaranteed to be defined, unless you undefine it yourself. + */ +#define MALUNAL_PLATFORM_LINUX 0 + +/** + * @def MALUNAL_PLATFORM_WIN32 + * @brief Defines that the system, this library is being compiled for, is a + * Windows system. + * @remarks This is guaranteed to be defined, unless you undefine it yourself. + */ +#define MALUNAL_PLATFORM_WIN32 1 + +/** + * @def MALUNAL_PLATFORM_DESKTOP + * @brief Defines that the system, this library is being compiled for, is a + * desktop system. + * @remarks This is guaranteed to be defined, unless you undefine it yourself. + */ +#define MALUNAL_PLATFORM_DESKTOP 1 + +/** + * @def MALUNAL_PLATFORM_NAME + * @brief The name of the system this library is being compiled for. + * @remarks This is guaranteed to be defined, unless you undefine it yourself. + */ +#define MALUNAL_PLATFORM_NAME "windows" + +/** + * @def MALUNAL_PLATFORM_DESC + * @brief The descriptor of the system this library is being compiled for. + * @remarks This is guaranteed to be defined, unless you undefine it yourself. + */ +#define MALUNAL_PLATFORM_DESC \ + MALUNAL_PROCESSOR_NAME "-" MALUNAL_PLATFORM_NAME + +// If the compiler doesn't support this, it should define them itself. +// It is valid for these to not have values that they expand to. +#ifndef MALUNAL_SYMBOL_EXPORT +# define MALUNAL_HAS_DECLSPEC +# define MALUNAL_SYMBOL_EXPORT __declspec(dllexport) +# define MALUNAL_SYMBOL_IMPORT __declspec(dllimport) +#endif /* MALUNAL_SYMBOL_EXPORT */ diff --git a/include/malunal/config/processor.h b/include/malunal/config/processor.h new file mode 100644 index 0000000..1dc6fb0 --- /dev/null +++ b/include/malunal/config/processor.h @@ -0,0 +1,20 @@ +/** + * @file processor.h + * @brief Selects a processor specific header based on defined macros of that + * processor, which include settings for that processor. + * @author John Christman (sorakatadzuma@gmail.com) + * @copyright Malunal Studios, LLC. + */ +#ifndef MALUNAL_CONFIG_PROCESSOR_CONFIG +#define MALUNAL_CONFIG_PROCESSOR_CONFIG + +#if defined(__i386__) || defined(__intel__) || defined(_M_IX86) +# define MALUNAL_PROCESSOR_CONFIG "./config/processor/x86.h" +#elif defined(__x86_64__) || defined(_AMD64_) || defined(_M_AMD64) +# define MALUNAL_PROCESSOR_CONFIG "./config/processor/x64.hpp" +#else +# error Unknown processor. +# error Unknown endianess. +#endif // Processor selection. + +#endif /* MALUNAL_CONFIG_PROCESSOR_CONFIG */ diff --git a/include/malunal/config/processor/common.h b/include/malunal/config/processor/common.h new file mode 100644 index 0000000..4e41650 --- /dev/null +++ b/include/malunal/config/processor/common.h @@ -0,0 +1,10 @@ +/** + * @file common.h + * @brief Contains things common to all processors, assures inclusion through + * @c processor.h + * @author John Christman (sorakatadzuma@gmail.com) + * @copyright Malunal Studios, LLC. + */ +#ifndef MALUNAL_CONFIG_PROCESSOR_HEADER +# error "This file should not be included standalone!" +#endif /* Inclusion Check. */ diff --git a/include/malunal/config/processor/x64.h b/include/malunal/config/processor/x64.h new file mode 100644 index 0000000..50e9e10 --- /dev/null +++ b/include/malunal/config/processor/x64.h @@ -0,0 +1,46 @@ +/** + * @file x86.hpp + * @brief Contains the configuration for x86 based processors. + * @author John Christman + * @copyright 2024-2025 Malunal Studios, LLC. + */ +#include "common.h" + +/** + * @def MALUNAL_PROCESSOR_X86 + * @brief Whether the processor, this library is being compiled for, is an x86 + * architecture CPU. + * @remarks This is guaranteed to be defined, unless you undefine it yourself. + */ +#define MALUNAL_PROCESSOR_X86 0 + +/** + * @def MALUNAL_PROCESSOR_X64 + * @brief Whether the processor, this library is being compiled for, is an x64 + * architecture CPU. + * @remarks This is guaranteed to be defined, unless you undefine it yourself. + */ +#define MALUNAL_PROCESSOR_X64 1 + +/** + * @def MALUNAL_PROCESSOR_LE + * @brief Whether the processor, this library is being compiled for, is a + * little endian CPU. + * @remarks This is guaranteed to be defined, unless you undefine it yourself. + */ +#define MALUNAL_PROCESSOR_LE 1 + +/** + * @def MALUNAL_PROCESSOR_BE + * @brief Whether the processor, this library is being compiled for, is a big + * endian CPU. + * @remarks This is guaranteed to be defined, unless you undefine it yourself. + */ +#define MALUNAL_PROCESSOR_BE 0 + +/** + * @def MALUNAL_PROCESSOR_NAME + * @brief The name of the processor this library is being compiled for. + * @remarks This is guaranteed to be defined, unless you undefine it yourself. + */ +#define MALUNAL_PROCESSOR_NAME "x86_64" diff --git a/include/malunal/config/processor/x86.h b/include/malunal/config/processor/x86.h new file mode 100644 index 0000000..23422ce --- /dev/null +++ b/include/malunal/config/processor/x86.h @@ -0,0 +1,46 @@ +/** + * @file x86.hpp + * @brief Contains the configuration for x86 based processors. + * @author John Christman + * @copyright 2024-2025 Malunal Studios, LLC. + */ +#include "common.h" + +/** + * @def MALUNAL_PROCESSOR_X86 + * @brief Whether the processor, this library is being compiled for, is an x86 + * architecture CPU. + * @remarks This is guaranteed to be defined, unless you undefine it yourself. + */ +#define MALUNAL_PROCESSOR_X86 1 + +/** + * @def MALUNAL_PROCESSOR_X64 + * @brief Whether the processor, this library is being compiled for, is an x64 + * architecture CPU. + * @remarks This is guaranteed to be defined, unless you undefine it yourself. + */ +#define MALUNAL_PROCESSOR_X64 0 + +/** + * @def MALUNAL_PROCESSOR_LE + * @brief Whether the processor, this library is being compiled for, is a + * little endian CPU. + * @remarks This is guaranteed to be defined, unless you undefine it yourself. + */ +#define MALUNAL_PROCESSOR_LE 1 + +/** + * @def MALUNAL_PROCESSOR_BE + * @brief Whether the processor, this library is being compiled for, is a big + * endian CPU. + * @remarks This is guaranteed to be defined, unless you undefine it yourself. + */ +#define MALUNAL_PROCESSOR_BE 0 + +/** + * @def MALUNAL_PROCESSOR_NAME + * @brief The name of the processor this library is being compiled for. + * @remarks This is guaranteed to be defined, unless you undefine it yourself. + */ +#define MALUNAL_PROCESSOR_NAME "x86"