#!/usr/bin/env python import subprocess import sys import platform import os actionLine = sys.argv[1] projectFile = sys.argv[2] picprg = 'PK2' if len(sys.argv)>3: picprg = sys.argv[3] codeFile = open(projectFile+".gcb", 'r') startLine = codeFile.readline()[3:].strip() boardLine = codeFile.readline()[3:].strip() endLine = codeFile.readline()[3:].strip() codeFile.close() sistema=platform.system() family=boardLine.split(':')[0] processor=boardLine.split(':')[1] if (startLine != "########### start ###########" or endLine != "########### end ###########"): print("\nMake-GCB: Error in build-commands - can't process file") sys.exit() if sistema=='Windows': DIRGCB='E:/Progs/GreatCowBasic' elif sistema=='Darwin': DIRGCB='/Users/topicchi/Progs/GreatCowBasic' else: DIRGCB='/usr/share/GcBasic' CC='gcbasic' OBJDIR='./Release' if not (os.path.isdir(OBJDIR)): os.makedirs(OBJDIR) gcbCommand = "%s/%s -O:%s/%s.asm -A:GCASM -K:A -V -NP %s.gcb" %(DIRGCB, CC, OBJDIR, projectFile, projectFile) if picprg=='PK3': flashCommandPIC = "/opt/microchip/mplabx/mplab_ipe/ipecmd.sh -P%s -F%s/%s.hex -M -TPPK3 -W" %(processor[3:], OBJDIR, projectFile) else: flashCommandPIC = "pk2cmd -p%s -f%s/%s.hex -m -r -t" %(processor, OBJDIR, projectFile) flashCommandAVR = "avrdude -B 10 -c USBasp -p AT%s -U flash:w:%s/%s.hex:a" %(processor, OBJDIR, projectFile) #print flashCommandPIC presult=0 if actionLine=="build": print(gcbCommand) presult = subprocess.call(gcbCommand, shell=True) if actionLine=="flash": hexFile="%s/%s.hex" %(OBJDIR, projectFile) if not os.path.isfile(hexFile): print "\nMake-GCB: generating HEX: %s" %(hexFile) print(gcbCommand) presult = subprocess.call(gcbCommand, shell=True) if family=="pic": flashCommand=flashCommandPIC else: flashCommand=flashCommandAVR presult = subprocess.call(flashCommand, shell=True) if presult != 0: print("\nMake-GCB: Failed - result code = %s --" %(presult)) else: print("\nMake-GCB: -- Success --")