genQtProFile.py

import os,sys,re
import shutil,string

#	[OK]
#	global var for app
#	calc the baseLen, we should add the divator char '/' or '\'
gBaseLen = len(os.getcwd()) + 1
gSrcList = "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,gUiList
	newPath = ""
	if len(dirname) == gBaseLen:
		newPath = file
	else:
		newPath = dirname[gBaseLen:] + "/" + file
	#filter
	if 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,gUiList
	print "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 gSrcList
	print gHeadList
	print 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 main


3、借助于genProFile.py生成pro/makefile的方式管理编译代码。
    topro main > main.pro
    qmake
    make
    成功

脚本自动生成pro文件(人工再微调一下):
QT      += core gui
TARGET = mathLib
TEMPLATE = lib
config += static

#LIBS   += -L/usr/lib/mysql -lmysqlclient
#INCLUDEPATH += /usr/include/mysql


SOURCES += \
        my_math.c \
        main_c.c \
        main_cpp.cpp \


HEADERS += \
        my_math.h \


FORMS += \


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值