Created
August 7, 2017 19:08
-
-
Save heuripedes/614530744e798bfa0d22aae7676958c0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import re | |
from os import path | |
import json | |
if len(sys.argv) < 2: | |
print('usage:',sys.argv[0],'project_name') | |
sys.exit(-1) | |
project_name = sys.argv[1] | |
basedir = os.getcwd() | |
commands = json.load(open('compile_commands.json')) | |
sources = [] | |
defines = {} | |
includes = {} | |
for command in commands: | |
for param in command['command'].split(' '): | |
param = param.strip() | |
matches = re.match('-D([^=]+)(=.+)?', param) | |
if matches: | |
value = matches[2][1:] if matches[2] else '1' | |
defines[matches[1]] = value | |
matches = re.match('-I(.+)', param) | |
if matches: | |
includes[matches[1]] = 1 | |
filename = path.relpath(command['file'], basedir) | |
name, ext = path.splitext(filename) | |
sources.append(filename) | |
if ext == '.cpp' or ext == '.cxx' or ext == '.cc': | |
for e in ['.hpp', '.hxx', '.hh', '.h']: | |
if path.exists(name + e): | |
sources.append(name + e) | |
elif ext == '.c': | |
if path.exists(name + '.h'): | |
sources.append(name + '.h') | |
with open(project_name + '.config', 'w') as f: | |
for k, v in defines.items(): | |
f.write('#define ' + k + ' ' + str(v) + "\n") | |
with open(project_name + '.files', 'w') as f: | |
for file in sources: | |
f.write(file + "\n") | |
with open(project_name + '.includes', 'w') as f: | |
for file in includes.keys(): | |
f.write(file + "\n") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment