Last active
October 5, 2015 17:37
-
-
Save mback2k/2845076 to your computer and use it in GitHub Desktop.
Compile debug release of PureBasic project
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
#!/usr/bin/python | |
from xml.etree import ElementTree | |
import sys, subprocess | |
NAMESPACE = r'{' + r'http://www.purebasic.com/namespace' + r'}' + r'%s' | |
COMPILER = { | |
'x64': r'C:\Program Files\PureBasic\Compilers\pbcompiler.exe', | |
'x86': r'C:\Program Files (x86)\PureBasic\Compilers\pbcompiler.exe', | |
} | |
def compile_target(target, command): | |
try: | |
return subprocess.call(command) | |
except: | |
return -1 | |
def build_target(target): | |
print '='*78 | |
print 'Building target', target.attrib['name'] | |
compiler = COMPILER[target.find(NAMESPACE % 'compiler').attrib['version'][-4:-1]] | |
inputfile = target.find(NAMESPACE % 'inputfile').attrib['value'] | |
outputfile = target.find(NAMESPACE % 'outputfile').attrib['value'] | |
executable = target.find(NAMESPACE % 'executable').attrib['value'] | |
options = target.find(NAMESPACE % 'options').attrib | |
icon = target.find(NAMESPACE % 'icon') | |
iconfile = icon.text.strip() if icon.attrib['enable'] else None | |
format = target.find(NAMESPACE % 'format').attrib | |
build = target.find(NAMESPACE % 'buildcount').attrib | |
buildcount = build['value'] if build['enable'] == '1' else None | |
resources = target.find(NAMESPACE % 'resources').getchildren() | |
command = [compiler, '/DEBUGGER', '/PURIFIER'] | |
if 'exe' in format: | |
if format['exe'] == 'default': | |
command += ['/EXE', executable] | |
elif format['exe'] == 'console': | |
command += ['/EXE', executable, '/CONSOLE'] | |
elif format['exe'] == 'dll': | |
command += ['/EXE', executable, '/DLL'] | |
if 'cpu' in format: | |
if format['cpu'] == '1': | |
command += ['/DYNAMICCPU'] | |
elif format['cpu'] == '2': | |
command += ['/MMX'] | |
elif format['cpu'] == '3': | |
command += ['/3DNOW'] | |
elif format['cpu'] == '4': | |
command += ['/SSE'] | |
elif format['cpu'] == '5': | |
command += ['/SSE2'] | |
if 'asm' in options and options['asm'] == '1': | |
command += ['/INLINEASM'] | |
if 'unicode' in options and options['unicode'] == '1': | |
command += ['/UNICODE'] | |
if 'thread' in options and options['thread'] == '1': | |
command += ['/THREAD'] | |
if 'xpskin' in options and options['xpskin'] == '1': | |
command += ['/XP'] | |
if 'user' in options and options['user'] == '1': | |
command += ['/USER'] | |
if 'admin' in options and options['admin'] == '1': | |
command += ['/ADMINISTRATOR'] | |
if 'onerror' in options and options['onerror'] == '1': | |
command += ['/LINENUMBERING'] | |
if iconfile: | |
command += ['/ICON', iconfile] | |
if buildcount: | |
command += ['/CONSTANT', 'PB_Editor_BuildCount=%s' % buildcount] | |
for resource in resources: | |
command += ['/RESOURCE', resource.attrib['value']] | |
command += [inputfile] | |
compile_target(target, command) | |
def parse_target(target): | |
if target.tag == NAMESPACE % 'target' and target.attrib['enabled'] == '1': | |
build_target(target) | |
def parse_section(section): | |
if section.tag == NAMESPACE % 'section' and section.attrib['name'] == 'targets': | |
targets = section.getchildren() | |
for target in targets: | |
parse_target(target) | |
def parse_project(filename): | |
xml = ElementTree.parse(filename) | |
project = xml.getroot() | |
sections = project.getchildren() | |
for section in sections: | |
parse_section(section) | |
def main(): | |
parse_project(sys.argv[1]) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment