mirror of https://github.com/flysand7/ciabatta.git
Add data model macro setting
This commit is contained in:
parent
2166660b93
commit
8efd9b7c7a
|
@ -2,6 +2,7 @@
|
|||
/lib
|
||||
/a
|
||||
/src/ciabatta.c
|
||||
/src/include/conf.h
|
||||
a.out
|
||||
*.a
|
||||
*.so
|
||||
|
|
17
build.py
17
build.py
|
@ -62,7 +62,7 @@ dependencies.append(args.compiler)
|
|||
|
||||
|
||||
# Figure out the flags
|
||||
includes = ['include']
|
||||
includes = ['src/include']
|
||||
cc = args.compiler
|
||||
cc_defines = []
|
||||
cc_flags = ['-nostdlib']
|
||||
|
@ -77,7 +77,6 @@ else: # 'debug'
|
|||
cc_defines.append('_DEBUG')
|
||||
if target != 'windows':
|
||||
cc_flags.append('-fpic')
|
||||
cc_defines.append(f'_CIA_OS_{target.upper()}')
|
||||
|
||||
# Check dependencies
|
||||
print(colors.grey, '==> Checking dependencies...', colors.reset, end='', sep='')
|
||||
|
@ -188,6 +187,8 @@ except Exception as error:
|
|||
print(colors.red, f" ERROR writing file '{ciabatta_header_path}':", sep='')
|
||||
print(f" {error}", colors.reset)
|
||||
sys.exit(1)
|
||||
print(colors.grey, f"==> Generating cia-conf.h", colors.reset, sep='')
|
||||
|
||||
|
||||
def quote(s):
|
||||
return '"' + s + '"'
|
||||
|
@ -202,6 +203,18 @@ cc_flags_str = ' '.join(
|
|||
list(map(prefix_quote('-I '), includes)))
|
||||
|
||||
print(colors.grey, f"==> Compiling {lib_file}", colors.reset, sep='')
|
||||
try:
|
||||
with open(os.path.join('src', 'include', 'cia-conf.h'), 'w') as conf_file:
|
||||
os_config = open(os.path.join('src', target, 'conf.h'))
|
||||
conf_file.write('\n')
|
||||
conf_file.write('// This file is AUTO-GENERATED\n')
|
||||
conf_file.write('// See os folder (e.g. src/linux) for conf.h file\n')
|
||||
conf_file.write(os_config.read())
|
||||
os_config.close()
|
||||
except Exception as error:
|
||||
print(colors.red, f" ERROR writing file '{ciabatta_header_path}':", sep='')
|
||||
print(f" {error}", colors.reset)
|
||||
sys.exit(1)
|
||||
|
||||
def assemble(src, out):
|
||||
format = 'elf64'
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
// This file is AUTO-GENERATED
|
||||
// See os folder (e.g. src/linux) for conf.h file
|
||||
|
||||
#define _CIA_OS_LINUX
|
||||
#define _CIA_DATA_LP64
|
|
@ -1,13 +1,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
// Since we're re-defining noreturn below, this would mess
|
||||
// with __declspec(noreturn) in windows headers, which
|
||||
// is hidden behind a define. Good thing, because now we
|
||||
// can override that define over here.
|
||||
#if defined(_CIA_OS_WINDOWS)
|
||||
#define DECLSPEC_NORETURN __declspec("noreturn")
|
||||
#endif
|
||||
// Include platform stuff
|
||||
#include <cia-conf.h>
|
||||
|
||||
// Pre-C23 keyword macros and stddef
|
||||
#define static_assert _Static_assert
|
|
@ -5,9 +5,9 @@ static_assert(sizeof(char) == 1, "Char isn't 1 bytes long");
|
|||
static_assert(sizeof(short) == 2, "Short isn't 2 bytes long");
|
||||
static_assert(sizeof(int) == 4, "Int isn't 4 bytes long");
|
||||
static_assert(sizeof(long long int) == 8, "Long long isn't 8 bytes long");
|
||||
#if defined(_CIA_OS_LINUX)
|
||||
#if defined(_CIA_DATA_LP64)
|
||||
static_assert(sizeof(long) == 8, "Long on linux isn't 8 bytes");
|
||||
#elif defined(_CIA_OS_WINDOWS)
|
||||
#elif defined(_CIA_DATA_LLP64)
|
||||
static_assert(sizeof(long) == 4, "Long on windows isn't 4 bytes");
|
||||
#endif
|
||||
|
||||
|
@ -17,14 +17,14 @@ typedef signed short int16_t;
|
|||
typedef unsigned short uint16_t;
|
||||
typedef signed int int32_t;
|
||||
typedef unsigned int uint32_t;
|
||||
#if defined(_CIA_OS_LINUX)
|
||||
#if defined(_CIA_DATA_LP64)
|
||||
typedef signed long int64_t;
|
||||
typedef unsigned long uint64_t;
|
||||
#elif defined(_CIA_OS_WINDOWS)
|
||||
#elif defined(_CIA_DATA_LLP64)
|
||||
typedef signed long long int64_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
#else
|
||||
#error "Platform not implemented"
|
||||
#error "Data model not implemented"
|
||||
#endif
|
||||
|
||||
typedef int8_t int_fast8_t, int_least8_t;
|
||||
|
@ -50,18 +50,18 @@ typedef uint64_t uintptr_t;
|
|||
#define UINT16_C(n) (n)
|
||||
#define UINT32_C(n) (n)
|
||||
|
||||
#if defined(_CIA_OS_LINUX)
|
||||
#if defined(_CIA_DATA_LP64)
|
||||
#define INT64_C(n) (n ## L)
|
||||
#define INTMAX_C(n) (n ## L)
|
||||
#define UINT64_C(n) (n ## UL)
|
||||
#define UINTMAX_C(n) (n ## UL)
|
||||
#elif defined(_CIA_OS_WINDOWS)
|
||||
#elif defined(_CIA_DATA_LLP64)
|
||||
#define INT64_C(n) (n ## LL)
|
||||
#define INTMAX_C(n) (n ## LL)
|
||||
#define UINT64_C(n) (n ## ULL)
|
||||
#define UINTMAX_C(n) (n ## ULL)
|
||||
#else
|
||||
#error "Platform functionality not defined"
|
||||
#error "Data model not defined"
|
||||
#endif
|
||||
|
||||
#define INT8_WIDTH 8
|
|
@ -0,0 +1,3 @@
|
|||
|
||||
#define _CIA_OS_LINUX
|
||||
#define _CIA_DATA_LP64
|
|
@ -0,0 +1,3 @@
|
|||
|
||||
#define _CIA_OS_WINDOWS
|
||||
#define _CIA_DATA_LLP64
|
Loading…
Reference in New Issue