genQtProFile.py

来源:互联网 发布:淘宝水果模特 编辑:程序博客网 时间:2024/06/13 14:45
import os,sys,reimport shutil,string#[OK]#global var for app#calc the baseLen, we should add the divator char '/' or '\'gBaseLen = len(os.getcwd()) + 1gSrcList = "SOURCES += \\" + "\n"gHeadList = "HEADERS += \\" + "\n"gUiList = "FORMS += \\" + "\n"gTarget = "Test"argLen = len(sys.argv)if argLen >= 2:gTarget = sys.argv[1]#[OK]#walk the dirname,#if type is file,then call pFunc to process it.#if type is dir,then recurse to walk the dir.def getList(dirname,pFunc):    try:        ls=os.listdir(dirname)    except:        print dirname,'is access deny'    else:        for file in ls:            temp = os.path.join(dirname,file)            if(os.path.isdir(temp)):                getList(temp,pFunc)            else:                pFunc(dirname,file)#[OK]#this function is used to process the certain file && dirname.def printFile(dirname,file):global gSrcList,gHeadList,gUiListnewPath = ""if len(dirname) == gBaseLen:newPath = fileelse:newPath = dirname[gBaseLen:] + "/" + file#filterif newPath[0] == '/':newPath = newPath[1:]#print newPath#newPath = convertDivChar(newPath)if re.search("\.h$",newPath):gHeadList = gHeadList + "\t" + newPath + " \\" + "\n"if re.search("\.hpp$",newPath):gHeadList = gHeadList + "\t" + newPath + " \\" + "\n"if re.search("\.cpp$",newPath):gSrcList = gSrcList + "\t" + newPath + " \\" + "\n"if re.search("\.c$",newPath):gSrcList = gSrcList + "\t" + newPath + " \\" + "\n"if re.search("\.ui$",newPath):gUiList = gUiList + "\t" + newPath + " \\" + "\n"def printProFile(target):global gSrcList,gHeadList,gUiListprint "QT+= core gui"print "TARGET = %s" % (target)print "TEMPLATE = app"print "\n"print "#LIBS+= -L/usr/lib/mysql -lmysqlclient\n"print "#INCLUDEPATH += /usr/include/mysql\n"print "\n"print gSrcListprint gHeadListprint gUiList#this function is the main point.getList(os.getcwd(),printFile)printProFile(gTarget)
</pre><pre name="code" class="python">genQtProFile.py [projectName]
应用:(组织编译复杂的项目、生成静态库、生成动态库都很方便)
1、直接编译报错。   gcc main_c.c -o main<span style="white-space:pre"></span>//缺少函数add、sub的实现2、实现的c文件一起加入编译成功。   gcc main_c.c my_math.c -o main3、借助于genProFile.py生成pro/makefile的方式管理编译代码。    topro main > main.pro    qmake    make    成功

脚本自动生成pro文件(人工再微调一下):
QT      += core guiTARGET = mathLibTEMPLATE = libconfig += static#LIBS   += -L/usr/lib/mysql -lmysqlclient#INCLUDEPATH += /usr/include/mysqlSOURCES += \        my_math.c \        main_c.c \        main_cpp.cpp \HEADERS += \        my_math.h \FORMS += \


0 0
原创粉丝点击