[原创]分享本人自己PY写的BOOST编译程序(源码)

本程序WINDOWS专用,只做抛砖引玉,希望诸位按照各自需求自行修改,主要目的是为了让诸位编译时可以省一些组合指令的时间,只需要修改几个参数即可自动编译。

支持64位编译模式。

改进版本:http://www.cnblogs.com/koangel/p/5673827.html

本程序只是1.0版本,可能不是特别完善,主要是针对我在编译WIN32 BOOST时候的一些需求,已测试过BOOST 1.61。

  1 # boost 全自动编译工具,仅用于WIN32编译 #
  2 import os
  3 import sys
  4 import string
  5 import signal
  6 import platform
  7 import time
  8 
  9 reload(sys)
 10 
 11 # 全局变量设置 #
 12 # boost的源码路径
 13 boost_work_path = "E:/boost/boost_1_61_0"
 14 
 15 # build log文件名
 16 build_log_file_name     = "build_log.txt"
 17 
 18 # 启动环境变量输出
 19 is_write_evn_log    = False
 20 
 21 # 原始目录
 22 temp_old_path = ""
 23 
 24 ISOTIMEFORMAT='%Y-%m-%d %X'
 25 # vc环境
 26 g_vs_env_data = [
 27     # env , vc ver
 28     ["VS100COMNTOOLS","VC100","Visual Studio 2010",False,"Microsoft Visual Studio 10.0"],
 29     ["VS110COMNTOOLS","VC110","Visual Studio 2012",False,"Microsoft Visual Studio 11.0"],
 30     ["VS120COMNTOOLS","VC120","Visual Studio 2013",False,"Microsoft Visual Studio 12.0"],
 31     ["VS140COMNTOOLS","VC140","Visual Studio 2015",False,"Microsoft Visual Studio 14.0"],
 32     ["VS150COMNTOOLS","VC150","Visual Studio 2016",False,"Microsoft Visual Studio 15.0"],
 33 ]
 34 
 35 vaild_vs_num = 0
 36 
 37 VERSION_KEY = 'VISUALSTUDIOVERSION'
 38 
 39 # boost编译选项 ,请在此处调整
 40 # 输出目录
 41 build_install_path = "E:/boost/boost_1_61_0"
 42 # 构建32位还是64位
 43 build_is_x64    = False
 44 # 线程模式(不建议修改 ,保持默认)
 45 build_threading_link = "multi"
 46 # 链接模式
 47 build_is_shared_link = False
 48 # 运行库链接模式
 49 build_is_shared_runtime = False
 50 # 编译模式(不建议调试)
 51 build_variant = "debug,release"
 52 # 某些特殊编译模式
 53 build_is_with_python = False
 54 build_is_with_MPI = False
 55 
 56 
 57 def getLogPath():
 58     return boost_work_path + "/" + build_log_file_name
 59 
 60 # 写出函数
 61 def logtofile(str):
 62     type = sys.getfilesystemencoding()
 63     timeStr = time.strftime(ISOTIMEFORMAT,time.localtime(time.time()))
 64     print("["+ timeStr + "] " +str.decode('utf-8').encode(type))
 65     os.system("echo " + "["+ timeStr + "] " + str.decode('utf-8').encode(type) + " >> " + getLogPath())
 66 
 67 def build_b2_tools():
 68     logtofile("正在构建B2工具集,请耐心等待....")
 69     os.system("bootstrap.bat >> " + getLogPath() )
 70     logtofile("构建B2工具集完成...")
 71 
 72 def check_compiler_env() : 
 73     logtofile("开始检测VS环境是否有效...")
 74     isFindVC = False
 75     vaild_vs_num = 0
 76     for vi in g_vs_env_data:
 77         if os.environ.has_key(vi[0]) :
 78             logtofile("     环境:" + vi[2] + " 有效...")
 79             vi[3] = True
 80             vaild_vs_num = vaild_vs_num+1
 81         else:
 82             logtofile("     环境:" +vi[2] + " 无效...")
 83             isFindVC = True
 84 
 85     return isFindVC
 86 
 87 def write_env_data():
 88     if is_write_evn_log :
 89         logtofile("输出全部环境变量:")
 90         for ev in os.environ.data:
 91             logtofile("环境变量:" + str(ev) + " data:" + os.environ[ev])
 92             
 93 
 94 def main():
 95     print("===========================================================================")
 96     print(" Boost Auto Build Tools for Windows Version 1.0 beta")
 97     print(" Code by Koangel , Using Python 2.7 ")
 98     print(" weibo: http:\\www.weibo.com/koangel")
 99     print(" Visual Studio for vs2010 or newer ")
100     print(" Boost for boost 1.53 or newer ")
101     print("===========================================================================")
102 
103     sys.setdefaultencoding('gbk')
104     #os.remove(getLogPath())
105     logtofile("检测是否为WINDOWS...")
106     if (os.name != 'nt'):
107         logtofile("非WINDOWS环境,无法运行...")
108         return
109 
110     write_env_data()
111         
112     temp_old_path = os.path
113     # 进入BOOST目录
114     logtofile("跳转进入工作目录...")
115     os.chdir(boost_work_path);
116 
117     # 检查编译环境
118     logtofile("检测是否安装VS环境....")
119     if (check_compiler_env() == False) :
120         logtofile("未安装VS环境无法继续...")
121         return
122 
123     if (os.environ.has_key(VERSION_KEY) == False) :
124         logtofile("未检测到VS环境,自动输出使用方法:")
125         logtofile("    首先使用指定版本的VC工具性运行命令行,具体方法为打开,请尽量使用x86_x64兼容命令行。")
126         logtofile("    以VS2010为例:从vs2010的工具菜单进入命令提示窗口(单击“开始”按钮,指向“所有程序”,指向“Microsoft Visual Studio 2010”,指向“Visual Studio tools(工具)”,然后单击“Visual Studio 2010 command prompt(命令提示)”")
127         logtofile("    之后运行本Python程序即可,Coding by koangel。")
128         return
129 
130     toVersion = str(os.environ[VERSION_KEY])
131 
132     # 写出选项
133     logtofile("检测B2工具集....")
134     if (os.access("b2.exe",os.F_OK) == False) :
135         build_b2_tools()
136 
137     # X86 还是 X64选项
138     cpuMode = "86"
139     if build_is_x64:
140         cpuMode = "64"
141     
142     logtofile("检测并构建编译命令...")
143     boost_cmd = "b2 --toolset=msvc-" + toVersion.strip()
144     if (build_is_with_python == False ):
145         boost_cmd += " --without-python"
146 
147     if (build_is_with_MPI == False ):
148         boost_cmd += " --without-mpi"
149 
150     boost_cmd += " threading=" + build_threading_link
151     boost_cmd += " link="
152     if build_is_shared_link:
153          boost_cmd += "shared"
154     else:
155         boost_cmd += "static"
156 
157     boost_cmd += " runtime-link="
158     if build_is_shared_runtime:
159         boost_cmd += "shared"
160     else:
161         boost_cmd += "static"
162 
163     boost_cmd += " variant=" + build_variant
164     boost_cmd += " --address-model="+cpuMode
165 
166     boost_cmd += ' --prefix="' + build_install_path + '"'
167 
168     if build_is_x64 :
169         boost_cmd += ' --stagedir=".\bin\x64"'
170 
171     logtofile("生成指令:" + boost_cmd)
172 
173     # 开始编译
174     os.system(boost_cmd) 
175 
176     # 生成完毕
177     logtofile("生成BOOST完成,请检查是否存在具体错误。")
178 
179     # 开始安装
180     logtofile("开始安装BOOST...")
181     os.system(boost_cmd + " install")
182     
183 
184 # ################################################################################
185 # =========================
186 # 入口函数
187 # =========================
188 if __name__ == '__main__':
189     main()

 

posted @ 2016-07-10 18:51  koangel  阅读(626)  评论(0编辑  收藏  举报