diff --git a/gen_pro.py b/gen_pro.py index f1e2d98..ddd30d5 100644 --- a/gen_pro.py +++ b/gen_pro.py @@ -1,4 +1,6 @@ import os +import re +from pathlib import Path, PurePath header = """ TEMPLATE = app @@ -13,6 +15,7 @@ headers = [] sources = [] include_path = set() + for path, dirs, files in os.walk('.'): if '.git' in dirs: dirs.remove('.git') @@ -20,18 +23,26 @@ for afile in files: if afile.endswith('.c') or afile.endswith('.cpp') or afile.endswith('.cc'): rel_path = os.path.join(path, afile) - rel_path = rel_path.replace('\\', '/', 1000) + #rel_path = rel_path.replace('\\', '/', 1000) sources.append(rel_path) continue if afile.endswith('.h') or afile.endswith('.hpp'): rel_path = os.path.join(path, afile) - rel_path = rel_path.replace('\\', '/', 1000) + #rel_path = rel_path.replace('\\', '/', 1000) headers.append(rel_path) - include_path.add(os.path.dirname(rel_path)) + + p = Path(path) + segments = p.parts + path_seg = [] + for segment in segments: + path_seg.append(segment) + if segment == 'include': # this is an include path, stop here. + break + include_path.add(os.path.join(*path_seg)) continue -print('INCLUDEPATH +=', '\\\n'.join(include_path)) +print('INCLUDEPATH +=', ' \\\n'.join(sorted(include_path))) print() print('HEADERS +=', '\\\n'.join(headers))