Commit 97152deb authored by nextime's avatar nextime

first commit

parents
#!/usr/bin/env python
from ConfigParser import SafeConfigParser as cp
import sys
import os
def main(mcp):
c = cp()
try:
c.read(mcp)
pname = mcp[:-4]
f=open("Makefile", "w")
f.write("# Makefile generated by mplab2makefile\n\n")
f.write("CC=mcc18\n")
f.write("LD=mplink\n")
f.write("AS=MPASMWIN\n")
f.write("AR=mplib\n")
f.write("RM=rm\n\n")
outdirs = c.get("PATH_INFO", "dir_bin")
objdirs = c.get("PATH_INFO", "dir_tmp")
incdirs = c.get("PATH_INFO", "dir_inc")
lkrdirs = c.get("PATH_INFO", "dir_lkr")
libdirs = c.get("PATH_INFO", "dir_lib")
mcu = c.get("HEADER", "device").replace("PIC", "")
f.write("MCU="+mcu+"\n")
if outdirs=="":
outdirs="."
else:
outdirs=outdirs.replace("\\", "/")
if objdirs=="":
objdirs="."
else:
objdirs=objdirs.replace("\\", "/")
f.write("BINDIR_="+outdirs+"/\n")
f.write("NAME="+pname+"\n")
f.write("#VERSION=0.1\n")
f.write("#DATE=$(shell date -I)\n")
f.write("#TARGETBASE=${NAME}-v${VERSION}_build-${DATE}\n\n")
f.write("TARGETBASE=${NAME}\n\n")
includes=""
for inc in incdirs.split(";"):
if len(includes)==0:
includes+="\""+inc.replace("\\", "/")+"\""
else:
includes+=" -I\""+inc.replace("\\", "/")+"\""
f.write("INCLUDES="+includes+"\n")
f.write("CFLAGS= -k -sco -mL\n\n")
clist = []
hlist = []
llist = []
lkr = False
for idx, cf in c.items("FILE_INFO"):
cf = cf.replace("\\", "/").replace(" ", "\\ ")
if cf[-1:] == 'c':
clist.append(cf)
elif cf[-1:] == 'h':
hlist.append(cf)
elif cf[-3:] == 'lib':
llist.append(cf)
elif cf[-3:] == 'lkr':
lkr = cf
f.write("build:\n")
for cfile in clist:
f.write("\t$(CC) -p=${MCU} /i${INCLUDES} \""+cfile+"\" -fo=\""+objdirs+"/"+os.path.basename(cfile)[:-1]+"o\" ${CFLAGS}\n")
f.write("\n")
f.write("\t${LD} /p${MCU} /l\""+libdirs.replace("\\", "/")+"\"")
if lkr:
f.write(" \""+lkr+"\"")
f.write(" \\\n")
for cfile in clist:
f.write("\t\t\""+objdirs+"/"+os.path.basename(cfile)[:-1]+"o\" \\\n")
for lfile in llist:
f.write("\t\t\""+lfile+"\" \\\n")
f.write("\t\t/u_CRUNTIME /z__MPLAB_BUILD=1 /m\"${BINDIR_}/${TARGETBASE}.map\" /w /o\"${BINDIR_}/${TARGETBASE}.cof\" /i")
f.write("\n\n")
f.write("clean:\n")
f.write("\t${RM} "+objdirs+"/*.o\n")
f.write("\t${RM} ${BINDIR_}/*.cof ${BINDIR_}/*.lst ${BINDIR_}/*.map ${BINDIR_}/*.hex\n")
except:
print 'this isn\'t a valid MPLAB Project file!'
if __name__ == "__main__":
if len(sys.argv) > 1:
mcp = sys.argv[1]
if os.path.isfile(mcp):
main(mcp)
else:
print mcp+" Is not a file!"
else:
print "please tell me where is the file to open!"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment