build: Skip vulkan parts in generated GLSL

Make the #include parsing script able to skip a predefined list of terms
with #ifdef

Put "VULKAN" in that list to skip the vulkan parts.
This commit is contained in:
Benjamin Otte
2024-07-25 00:37:02 +02:00
parent 5e7f227d92
commit 1f3c88b995
2 changed files with 26 additions and 2 deletions

View File

@@ -7,9 +7,13 @@ void main_clip_rounded (void);
#include "enums.glsl"
/* Needs to be exactly like this and not use #else
* because our include script is too dumb
*/
#ifdef VULKAN
#include "common-vulkan.glsl"
#else
#endif /* VULKAN */
#ifndef VULKAN
#include "common-gl.glsl"
#endif

View File

@@ -6,17 +6,37 @@ import os
loaded_files = []
check_defines = [ 'VULKAN' ]
def load (path):
if (path in loaded_files):
return
loaded_files.append (path)
skipping = ''
with open(path) as f:
lines = f.readlines()
for line in lines:
if skipping:
match = re.search (r"^#endif /\* (.*) \*/$", line)
if match and match.group(1) == skipping:
skipping = ''
continue
match = re.search (r"^#define (.*)$", line)
if match and match.group(1) in check_defines:
check_defines.remove (match.group(1))
print (line, end="")
continue
match = re.search (r"^#ifdef (.*)$", line)
if match and match.group(1) in check_defines:
skipping = match.group(1)
continue
match = re.search (r"^#include \"(.*)\"$", line)
if (match):
if match:
load (os.path.join (os.path.dirname(path), match.group(1)))
else:
print (line, end="")