| 1 |
miniaudio_h := <../miniaudio.h>; |
| 2 |
miniaudio_c := <../miniaudio.c>; |
| 3 |
dr_wav_h :: <../../dr_libs/dr_wav.h>; |
| 4 |
dr_flac_h :: <../../dr_libs/dr_flac.h>; |
| 5 |
dr_mp3_h :: <../../dr_libs/dr_mp3.h>; |
| 6 |
c89atomic_h :: <../../c89atomic/c89atomic.h>; |
| 7 |
c89atomic_c :: <../../c89atomic/c89atomic.c>; |
| 8 |
|
| 9 |
minify :: function(src:string) string |
| 10 |
{ |
| 11 |
return @(src) |
| 12 |
["/\*[^*]*\*+(?:[^/*][^*]*\*+)*/"] <= "" // Remove all block comments to keep things clean. |
| 13 |
["(?m)^\s*\R"] <= "" // Remove all empty lines to compress it all down. |
| 14 |
["[ \t]+(?=(?:\R|$))"] <= "" // Remove trailing whitespace. |
| 15 |
; |
| 16 |
} |
| 17 |
|
| 18 |
|
| 19 |
// dr_wav |
| 20 |
rename_wav_namespace :: function(src:string) string |
| 21 |
{ |
| 22 |
return @(src) |
| 23 |
["\bdrwav"] <= "ma_dr_wav" |
| 24 |
["\bDRWAV"] <= "MA_DR_WAV" |
| 25 |
["\bdr_wav"] <= "ma_dr_wav" |
| 26 |
["\bDR_WAV"] <= "MA_DR_WAV" |
| 27 |
["\bg_drwav"] <= "ma_dr_wav_g" |
| 28 |
|
| 29 |
// Some common tokens will be namespaced as "ma_dr_wav" when we really want them to be "ma_". |
| 30 |
["\bma_dr_wav_int"] <= "ma_int" |
| 31 |
["\bma_dr_wav_uint"] <= "ma_uint" |
| 32 |
["\bma_dr_wav_bool"] <= "ma_bool" |
| 33 |
["\bma_dr_wav_uintptr"] <= "ma_uintptr" |
| 34 |
["\bMA_DR_WAV_TRUE"] <= "MA_TRUE" |
| 35 |
["\bMA_DR_WAV_FALSE"] <= "MA_FALSE" |
| 36 |
["\bMA_DR_WAV_UINT64_MAX"] <= "MA_UINT64_MAX" |
| 37 |
["\bMA_DR_WAV_32BIT"] <= "MA_32BIT" |
| 38 |
["\bMA_DR_WAV_64BIT"] <= "MA_64BIT" |
| 39 |
["\bMA_DR_WAV_ARM32"] <= "MA_ARM32" |
| 40 |
["\bMA_DR_WAV_ARM64"] <= "MA_ARM64" |
| 41 |
["\bMA_DR_WAV_X64"] <= "MA_X64" |
| 42 |
["\bMA_DR_WAV_X86"] <= "MA_X86" |
| 43 |
["\bMA_DR_WAV_ARM"] <= "MA_ARM" |
| 44 |
["\bMA_DR_WAV_API"] <= "MA_API" |
| 45 |
["\bMA_DR_WAV_PRIVATE"] <= "MA_PRIVATE" |
| 46 |
["\bMA_DR_WAV_DLL"] <= "MA_DLL" |
| 47 |
["\bMA_DR_WAV_DLL_IMPORT"] <= "MA_DLL_IMPORT" |
| 48 |
["\bMA_DR_WAV_DLL_EXPORT"] <= "MA_DLL_EXPORT" |
| 49 |
["\bMA_DR_WAV_DLL_PRIVATE"] <= "MA_DLL_PRIVATE" |
| 50 |
["\bma_dr_wav_result"] <= "ma_result" |
| 51 |
["\bma_dr_wav_allocation_callbacks"] <= "ma_allocation_callbacks" |
| 52 |
["\bMA_DR_WAV_INLINE"] <= "MA_INLINE" |
| 53 |
["\bMA_DR_WAV_SIZE_MAX"] <= "MA_SIZE_MAX" |
| 54 |
["\bma_dr_wav_result_from_errno"] <= "ma_result_from_errno" |
| 55 |
["\bma_dr_wav_fopen"] <= "ma_fopen" |
| 56 |
["\bma_dr_wav_wfopen"] <= "ma_wfopen" |
| 57 |
|
| 58 |
// Result codes. |
| 59 |
["MA_DR_WAV_SUCCESS"] <= "MA_SUCCESS" |
| 60 |
["MA_DR_WAV_INVALID_ARGS"] <= "MA_INVALID_ARGS" |
| 61 |
["MA_DR_WAV_OUT_OF_MEMORY"] <= "MA_OUT_OF_MEMORY" |
| 62 |
["MA_DR_WAV_INVALID_FILE"] <= "MA_INVALID_FILE" |
| 63 |
["MA_DR_WAV_AT_END"] <= "MA_AT_END" |
| 64 |
["MA_DR_WAV_BAD_SEEK"] <= "MA_BAD_SEEK" |
| 65 |
; |
| 66 |
} |
| 67 |
|
| 68 |
convert_wav_h :: function(src:string) string |
| 69 |
{ |
| 70 |
stripped := @(src); |
| 71 |
stripped["/\* Sized Types \*/\R" : "\R/\* End Sized Types \*/" ] = ""; |
| 72 |
stripped["/\* Decorations \*/\R" : "\R/\* End Decorations \*/" ] = ""; |
| 73 |
stripped["/\* Result Codes \*/\R" : "\R/\* End Result Codes \*/" ] = ""; |
| 74 |
stripped["/\* Allocation Callbacks \*/\R" : "\R/\* End Allocation Callbacks \*/" ] = ""; |
| 75 |
|
| 76 |
return minify(rename_wav_namespace(stripped)); |
| 77 |
} |
| 78 |
|
| 79 |
convert_wav_c :: function(src:string) string |
| 80 |
{ |
| 81 |
stripped := @(src); |
| 82 |
stripped["/\* Architecture Detection \*/\R" : "\R/\* End Architecture Detection \*/"] = ""; |
| 83 |
stripped["/\* Inline \*/\R" : "\R/\* End Inline \*/" ] = ""; |
| 84 |
stripped["/\* SIZE_MAX \*/\R" : "\R/\* End SIZE_MAX \*/" ] = ""; |
| 85 |
stripped["/\* Errno \*/\R" : "\R/\* End Errno \*/" ] = ""; |
| 86 |
stripped["/\* fopen \*/\R" : "\R/\* End fopen \*/" ] = ""; |
| 87 |
|
| 88 |
return minify(rename_wav_namespace(stripped)); |
| 89 |
} |
| 90 |
|
| 91 |
miniaudio_h("/\* dr_wav_h begin \*/\R":"\R/\* dr_wav_h end \*/") = convert_wav_h(@(dr_wav_h["#ifndef dr_wav_h\R":"\R#endif /\* dr_wav_h \*/"])); |
| 92 |
miniaudio_h("/\* dr_wav_c begin \*/\R":"\R/\* dr_wav_c end \*/") = convert_wav_c(@(dr_wav_h["#ifndef dr_wav_c\R":"\R#endif /\* dr_wav_c \*/"])); |
| 93 |
|
| 94 |
|
| 95 |
// dr_flac |
| 96 |
rename_flac_namespace :: function(src:string) string |
| 97 |
{ |
| 98 |
return @(src) |
| 99 |
["\bdrflac"] <= "ma_dr_flac" |
| 100 |
["\bDRFLAC"] <= "MA_DR_FLAC" |
| 101 |
["\bdr_flac"] <= "ma_dr_flac" |
| 102 |
["\bDR_FLAC"] <= "MA_DR_FLAC" |
| 103 |
["\bg_drflac"] <= "ma_dr_flac_g" |
| 104 |
|
| 105 |
// Some common tokens will be namespaced as "ma_dr_flac" when we really want them to be "ma_". |
| 106 |
["\bma_dr_flac_int"] <= "ma_int" |
| 107 |
["\bma_dr_flac_uint"] <= "ma_uint" |
| 108 |
["\bma_dr_flac_bool"] <= "ma_bool" |
| 109 |
["\bma_dr_flac_uintptr"] <= "ma_uintptr" |
| 110 |
["\bMA_DR_FLAC_TRUE"] <= "MA_TRUE" |
| 111 |
["\bMA_DR_FLAC_FALSE"] <= "MA_FALSE" |
| 112 |
["\bMA_DR_FLAC_UINT64_MAX"] <= "MA_UINT64_MAX" |
| 113 |
["\bMA_DR_FLAC_32BIT"] <= "MA_32BIT" |
| 114 |
["\bMA_DR_FLAC_64BIT"] <= "MA_64BIT" |
| 115 |
["\bMA_DR_FLAC_ARM32"] <= "MA_ARM32" |
| 116 |
["\bMA_DR_FLAC_ARM64"] <= "MA_ARM64" |
| 117 |
["\bMA_DR_FLAC_X64"] <= "MA_X64" |
| 118 |
["\bMA_DR_FLAC_X86"] <= "MA_X86" |
| 119 |
["\bMA_DR_FLAC_ARM"] <= "MA_ARM" |
| 120 |
["\bMA_DR_FLAC_API"] <= "MA_API" |
| 121 |
["\bMA_DR_FLAC_PRIVATE"] <= "MA_PRIVATE" |
| 122 |
["\bMA_DR_FLAC_DLL"] <= "MA_DLL" |
| 123 |
["\bMA_DR_FLAC_DLL_IMPORT"] <= "MA_DLL_IMPORT" |
| 124 |
["\bMA_DR_FLAC_DLL_EXPORT"] <= "MA_DLL_EXPORT" |
| 125 |
["\bMA_DR_FLAC_DLL_PRIVATE"] <= "MA_DLL_PRIVATE" |
| 126 |
["\bma_dr_flac_result"] <= "ma_result" |
| 127 |
["\bma_dr_flac_allocation_callbacks"] <= "ma_allocation_callbacks" |
| 128 |
["\bMA_DR_FLAC_INLINE"] <= "MA_INLINE" |
| 129 |
["\bMA_DR_FLAC_SIZE_MAX"] <= "MA_SIZE_MAX" |
| 130 |
["\bma_dr_flac_result_from_errno"] <= "ma_result_from_errno" |
| 131 |
["\bma_dr_flac_fopen"] <= "ma_fopen" |
| 132 |
["\bma_dr_flac_wfopen"] <= "ma_wfopen" |
| 133 |
|
| 134 |
// Result codes. |
| 135 |
["MA_DR_FLAC_SUCCESS"] <= "MA_SUCCESS" |
| 136 |
["MA_DR_FLAC_ERROR"] <= "MA_ERROR" |
| 137 |
["MA_DR_FLAC_AT_END"] <= "MA_AT_END" |
| 138 |
["MA_DR_FLAC_CRC_MISMATCH"] <= "MA_CRC_MISMATCH" |
| 139 |
; |
| 140 |
} |
| 141 |
|
| 142 |
convert_flac_h :: function(src:string) string |
| 143 |
{ |
| 144 |
stripped := @(src); |
| 145 |
stripped["/\* Sized Types \*/\R" : "\R/\* End Sized Types \*/" ] = ""; |
| 146 |
stripped["/\* Architecture Detection \*/\R" : "\R/\* End Architecture Detection \*/"] = ""; |
| 147 |
stripped["/\* Decorations \*/\R" : "\R/\* End Decorations \*/" ] = ""; |
| 148 |
stripped["/\* Allocation Callbacks \*/\R" : "\R/\* End Allocation Callbacks \*/" ] = ""; |
| 149 |
|
| 150 |
return minify(rename_flac_namespace(stripped)); |
| 151 |
} |
| 152 |
|
| 153 |
convert_flac_c :: function(src:string) string |
| 154 |
{ |
| 155 |
stripped := @(src); |
| 156 |
stripped["/\* Result Codes \*/\R" : "\R/\* End Result Codes \*/" ] = ""; |
| 157 |
stripped["/\* Inline \*/\R" : "\R/\* End Inline \*/" ] = ""; |
| 158 |
stripped["/\* SIZE_MAX \*/\R" : "\R/\* End SIZE_MAX \*/" ] = ""; |
| 159 |
stripped["/\* Errno \*/\R" : "\R/\* End Errno \*/" ] = ""; |
| 160 |
stripped["/\* fopen \*/\R" : "\R/\* End fopen \*/" ] = ""; |
| 161 |
|
| 162 |
return minify(rename_flac_namespace(stripped)); |
| 163 |
} |
| 164 |
|
| 165 |
miniaudio_h("/\* dr_flac_h begin \*/\R":"\R/\* dr_flac_h end \*/") = convert_flac_h(@(dr_flac_h["#ifndef dr_flac_h\R":"\R#endif /\* dr_flac_h \*/"])); |
| 166 |
miniaudio_h("/\* dr_flac_c begin \*/\R":"\R/\* dr_flac_c end \*/") = convert_flac_c(@(dr_flac_h["#ifndef dr_flac_c\R":"\R#endif /\* dr_flac_c \*/"])); |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
// dr_mp3 |
| 171 |
rename_mp3_namespace :: function(src:string) string |
| 172 |
{ |
| 173 |
return @(src) |
| 174 |
["\bdrmp3"] <= "ma_dr_mp3" |
| 175 |
["\bDRMP3"] <= "MA_DR_MP3" |
| 176 |
["\bdr_mp3"] <= "ma_dr_mp3" |
| 177 |
["\bDR_MP3"] <= "MA_DR_MP3" |
| 178 |
["\bg_drmp3"] <= "ma_dr_mp3_g" |
| 179 |
|
| 180 |
// Some common tokens will be namespaced as "ma_dr_mp3" when we really want them to be "ma_". |
| 181 |
["\bma_dr_mp3_int"] <= "ma_int" |
| 182 |
["\bma_dr_mp3_uint"] <= "ma_uint" |
| 183 |
["\bma_dr_mp3_bool"] <= "ma_bool" |
| 184 |
["\bma_dr_mp3_uintptr"] <= "ma_uintptr" |
| 185 |
["\bMA_DR_MP3_TRUE"] <= "MA_TRUE" |
| 186 |
["\bMA_DR_MP3_FALSE"] <= "MA_FALSE" |
| 187 |
["\bMA_DR_MP3_UINT64_MAX"] <= "MA_UINT64_MAX" |
| 188 |
["\bMA_DR_MP3_32BIT"] <= "MA_32BIT" |
| 189 |
["\bMA_DR_MP3_64BIT"] <= "MA_64BIT" |
| 190 |
["\bMA_DR_MP3_ARM32"] <= "MA_ARM32" |
| 191 |
["\bMA_DR_MP3_ARM64"] <= "MA_ARM64" |
| 192 |
["\bMA_DR_MP3_X64"] <= "MA_X64" |
| 193 |
["\bMA_DR_MP3_X86"] <= "MA_X86" |
| 194 |
["\bMA_DR_MP3_ARM"] <= "MA_ARM" |
| 195 |
["\bMA_DR_MP3_API"] <= "MA_API" |
| 196 |
["\bMA_DR_MP3_PRIVATE"] <= "MA_PRIVATE" |
| 197 |
["\bMA_DR_MP3_DLL"] <= "MA_DLL" |
| 198 |
["\bMA_DR_MP3_DLL_IMPORT"] <= "MA_DLL_IMPORT" |
| 199 |
["\bMA_DR_MP3_DLL_EXPORT"] <= "MA_DLL_EXPORT" |
| 200 |
["\bMA_DR_MP3_DLL_PRIVATE"] <= "MA_DLL_PRIVATE" |
| 201 |
["\bma_dr_mp3_result"] <= "ma_result" |
| 202 |
["\bma_dr_mp3_allocation_callbacks"] <= "ma_allocation_callbacks" |
| 203 |
["\bMA_DR_MP3_INLINE"] <= "MA_INLINE" |
| 204 |
["\bMA_DR_MP3_SIZE_MAX"] <= "MA_SIZE_MAX" |
| 205 |
["\bma_dr_mp3_result_from_errno"] <= "ma_result_from_errno" |
| 206 |
["\bma_dr_mp3_fopen"] <= "ma_fopen" |
| 207 |
["\bma_dr_mp3_wfopen"] <= "ma_wfopen" |
| 208 |
|
| 209 |
// Result codes. |
| 210 |
["MA_DR_MP3_SUCCESS"] <= "MA_SUCCESS" |
| 211 |
; |
| 212 |
} |
| 213 |
|
| 214 |
convert_mp3_h :: function(src:string) string |
| 215 |
{ |
| 216 |
stripped := @(src); |
| 217 |
stripped["/\* Sized Types \*/\R" : "\R/\* End Sized Types \*/" ] = ""; |
| 218 |
stripped["/\* Decorations \*/\R" : "\R/\* End Decorations \*/" ] = ""; |
| 219 |
stripped["/\* Result Codes \*/\R" : "\R/\* End Result Codes \*/" ] = ""; |
| 220 |
stripped["/\* Inline \*/\R" : "\R/\* End Inline \*/" ] = ""; |
| 221 |
stripped["/\* Allocation Callbacks \*/\R" : "\R/\* End Allocation Callbacks \*/" ] = ""; |
| 222 |
|
| 223 |
return minify(rename_mp3_namespace(stripped)); |
| 224 |
} |
| 225 |
|
| 226 |
convert_mp3_c :: function(src:string) string |
| 227 |
{ |
| 228 |
stripped := @(src); |
| 229 |
stripped["/\* SIZE_MAX \*/\R" : "\R/\* End SIZE_MAX \*/" ] = ""; |
| 230 |
stripped["/\* Errno \*/\R" : "\R/\* End Errno \*/" ] = ""; |
| 231 |
stripped["/\* fopen \*/\R" : "\R/\* End fopen \*/" ] = ""; |
| 232 |
|
| 233 |
return minify(rename_mp3_namespace(stripped)); |
| 234 |
} |
| 235 |
|
| 236 |
miniaudio_h("/\* dr_mp3_h begin \*/\R":"\R/\* dr_mp3_h end \*/") = convert_mp3_h(@(dr_mp3_h["#ifndef dr_mp3_h\R":"\R#endif /\* dr_mp3_h \*/"])); |
| 237 |
miniaudio_h("/\* dr_mp3_c begin \*/\R":"\R/\* dr_mp3_c end \*/") = convert_mp3_c(@(dr_mp3_h["#ifndef dr_mp3_c\R":"\R#endif /\* dr_mp3_c \*/"])); |
| 238 |
|
| 239 |
|
| 240 |
// c89atomic |
| 241 |
rename_c89atomic_namespace :: function(src:string) string |
| 242 |
{ |
| 243 |
return @(src) |
| 244 |
["\bc89atomic"] <= "ma_atomic" |
| 245 |
["\bC89ATOMIC"] <= "MA_ATOMIC" |
| 246 |
|
| 247 |
// Some common tokens will be namespaced as "ma_atomic" when we really want them to be "ma_". |
| 248 |
["\bma_atomic_int"] <= "ma_int" |
| 249 |
["\bma_atomic_uint"] <= "ma_uint" |
| 250 |
["\bma_atomic_bool"] <= "ma_bool32" |
| 251 |
["\bMA_ATOMIC_32BIT"] <= "MA_32BIT" |
| 252 |
["\bMA_ATOMIC_64BIT"] <= "MA_64BIT" |
| 253 |
["\bMA_ATOMIC_ARM32"] <= "MA_ARM32" |
| 254 |
["\bMA_ATOMIC_ARM64"] <= "MA_ARM64" |
| 255 |
["\bMA_ATOMIC_X64"] <= "MA_X64" |
| 256 |
["\bMA_ATOMIC_X86"] <= "MA_X86" |
| 257 |
["\bMA_ATOMIC_ARM"] <= "MA_ARM" |
| 258 |
["\bMA_ATOMIC_INLINE"] <= "MA_INLINE" |
| 259 |
|
| 260 |
// We have an "extern c89atomic_spinlock" in c89atomic.h, but since we're putting this into the implementation section we can just |
| 261 |
// drop the extern and not bother importing anything from c89atomic.c. |
| 262 |
["\bextern ma_atomic_spinlock"] <= "ma_atomic_spinlock" |
| 263 |
; |
| 264 |
} |
| 265 |
|
| 266 |
convert_c89atomic_h :: function(src:string) string |
| 267 |
{ |
| 268 |
stripped := @(src); |
| 269 |
stripped["/\* Sized Types \*/\R" : "\R/\* End Sized Types \*/" ] = ""; |
| 270 |
stripped["/\* Architecture Detection \*/\R" : "\R/\* End Architecture Detection \*/"] = ""; |
| 271 |
stripped["/\* Inline \*/\R" : "\R/\* End Inline \*/" ] = ""; |
| 272 |
|
| 273 |
return minify(rename_c89atomic_namespace(stripped)); |
| 274 |
} |
| 275 |
|
| 276 |
miniaudio_h("/\* c89atomic.h begin \*/\R":"\R/\* c89atomic.h end \*/") = convert_c89atomic_h(@(c89atomic_h["#ifndef c89atomic_h\R":"\R#endif /\* c89atomic_h \*/"])); |
| 277 |
|
| 278 |
|
| 279 |
// Cleanup. If we don't normalize line endings we'll fail to compile on old versions of GCC. |
| 280 |
cleanup :: function(src:string) string |
| 281 |
{ |
| 282 |
return @(src) |
| 283 |
["\r\n"] <= "\n" // Normalize line endings to "\n". Needed for very old versions of GCC. |
| 284 |
["\t"] <= " " // Tabs to spaces. |
| 285 |
; |
| 286 |
} |
| 287 |
|
| 288 |
miniaudio_h = cleanup(@(miniaudio_h)); |
| 289 |
miniaudio_c = cleanup(@(miniaudio_c)); |