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
- genQtProFile.py
- py
- py
- py
- py
- py
- py
- py
- Py
- bin2hex.py && hex2bin.py
- web.py (url.py)
- [py]py存放家具
- Xctf之调皮的py-py-py
- dir_size.py
- sendEmail.py
- Html.py
- web.py
- mail.py
- 怎么样自定义ecplise中代码提示
- 如何查看mysql数据库的大小
- P98
- TreeList控件复选框需要点击两次才能选中(打勾)
- Web Mercator 公开的小秘密
- genQtProFile.py
- 第三章 45
- 命名空间函数用法及例子
- STL 之fill和fill_n
- 智能社JavaScript学习笔记——12-DOM操作应用
- UISearchbar去除背景色的方法,适合iOS5/6/7/8.0beta
- Oracle学习笔记(13)------------ 视图、同义词、索引
- 归并排序
- STL 之generate和generate_n