summaryrefslogtreecommitdiffstats
path: root/source/base/base_include.h
blob: b4f65d9be596fb357da9f31d366f01f36aeccf89 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#ifndef BASE_INCLUDE_H
#define BASE_INCLUDE_H

// NOTE: glibc >= 2.38 redirects strtol & co to __isoc23_* when _GNU_SOURCE is on (g++ always
// turns it on), which makes the binary refuse to start on any older glibc. opt out so release
// builds run on glibc 2.35+ (ubuntu 22.04, debian 12).
#if defined(__linux__)
#include <features.h>
#undef __GLIBC_USE_C2X_STRTOL
#define __GLIBC_USE_C2X_STRTOL 0
#undef __GLIBC_USE_C23_STRTOL
#define __GLIBC_USE_C23_STRTOL 0
#endif

#if defined(__APPLE__)
#define PLATFORM_APPLE 1
#elif defined(__linux__)
#define PLATFORM_LINUX 1
#elif defined(_WIN32)
#define PLATFORM_WINDOWS 1
#else
#error Unsupported platform
#endif // platform definitions

#ifndef PLATFORM_APPLE
#define PLATFORM_APPLE 0
#endif
#ifndef PLATFORM_LINUX
#define PLATFORM_LINUX 0
#endif
#ifndef PLATFORM_WINDOWS
#define PLATFORM_WINDOWS 0
#endif
#ifndef DEBUG
#define DEBUG 0
#endif

#if PLATFORM_LINUX || PLATFORM_APPLE
#include <unistd.h>
#include <dirent.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/un.h>
#include <fcntl.h>
#include <dlfcn.h>
#include <signal.h>
#if PLATFORM_LINUX
#include <link.h>
#endif
#include <execinfo.h>
#include <pthread.h>
#include <stdlib.h>
#include <limits.h>
#if PLATFORM_APPLE
#include <mach-o/dyld.h>
#include <mach/mach.h>
#include <mach/mach_time.h>
#include <libkern/OSByteOrder.h>
extern char **environ;
#endif

#elif PLATFORM_WINDOWS
// NOTE: windows 10+. WaitOnAddress (futex), high resolution waitable timers, per monitor dpi v2
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0A00
#endif
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <windows.h>
#include <shellapi.h>
#include <io.h>
#include <direct.h>
#include <process.h>
#include <sys/stat.h>
#include <stdlib.h>
#undef interface
#endif // PLATFORM_LINUX - PLATFORM_WINDOWS

//-
#include <time.h>
#include <string.h>
#include <stdint.h>
#include <stdio.h>
#include <stdarg.h>
#include <errno.h>
#include <math.h>

//-
#include "base_core.h"
#include "base_embed.h"
#include "base_memory.h"

#include "base_arena.h"
#include "base_stack.h"
#include "base_string.h"
#include "base_thread.h"
#include "base_math.h"
#include "base_profile.h"

// NOTE: the *_linux files are plain posix (mmap, pthreads, open/read), macos uses them too
#if PLATFORM_LINUX || PLATFORM_APPLE
#include "base_arena_linux.h"
#include "base_stack_linux.h"
#include "base_thread_linux.h"
#include "base_platform_linux.h"
#elif PLATFORM_WINDOWS
#include "base_arena_win32.h"
#include "base_stack_win32.h"
#include "base_thread_win32.h"
#include "base_platform_win32.h"
#else
#error unsupported platform
#endif

#if ARCH_x86_64
#include "base_profile_x64.h"
#elif ARCH_ARM
#include "base_profile_arm.h"
#endif

#include "base_memory.cpp"
#include "base_arena.cpp"
#include "base_stack.cpp"
#include "base_string.cpp"
#include "base_math.cpp"
#include "base_simd.cpp"

#if PLATFORM_LINUX || PLATFORM_APPLE
#include "base_arena_linux.cpp"
#include "base_stack_linux.cpp"
#include "base_thread_linux.cpp"
#include "base_platform_linux.cpp"
#elif PLATFORM_WINDOWS
#include "base_arena_win32.cpp"
#include "base_stack_win32.cpp"
#include "base_thread_win32.cpp"
#include "base_platform_win32.cpp"
#endif

#if ARCH_x86_64
#include "base_profile_x64.cpp"
#elif ARCH_ARM
#include "base_profile_arm.cpp"
#else
#error platform not supported for profiling
#endif

#include "base_rand.cpp"

#endif // BASE_INCLUDE_H