Skip to content

Instantly share code, notes, and snippets.

@jef-sure
Last active April 30, 2021 12:27
Show Gist options
  • Save jef-sure/135190cf9fa6532fbfa9b93764dd5e65 to your computer and use it in GitHub Desktop.
Save jef-sure/135190cf9fa6532fbfa9b93764dd5e65 to your computer and use it in GitHub Desktop.
import glob
import os
import re
spath = os.path.dirname(os.path.realpath(__file__))
all_fonts = [fon[len(spath)+1:] for fon in glob.glob(spath + '/fonts/*.c')]
all_headers = [re.sub(r"\.c$", ".h", f) for f in all_fonts]
root = spath + "/../../..";
used = {}
for cdir, subdirs, files in os.walk(root):
for fname in files:
if re.search(r"\.(c|cc|cpp|cxx)$", fname, re.IGNORECASE) is not None:
fh = open(os.path.join(cdir, fname),mode='r')
content = fh.read()
fh.close()
for header in all_headers:
if re.search(r"^#include\s*\"" + header + "\"", content, re.MULTILINE) is not None:
used[re.sub(r"^fonts/", "", re.sub(r"\.h$", ".c", header))] = 1;
cmaketxt = "set(srcs \"" + str.join('" "', used.keys()) + "\")"
fh = open(spath + '/fonts/CMakeLists.txt', 'r')
if fh is not None:
content = fh.read()
fh.close()
if content != cmaketxt:
with open(spath + '/fonts/CMakeLists.txt', 'w') as cmt:
cmt.write(cmaketxt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment