[关闭]
@lupnfer 2016-12-19T13:17:03.000000Z 字数 16714 阅读 779

OpenSource

工作


  1. .
  2. ├── build_opensource.py F主编译脚本
  3. ├── build_scripts D子库编译脚本
  4.    ├── build_boost.py
  5.    ├── build_curl.py
  6.    ├── build_gflags.py
  7.    ├── build_glog.py
  8.    ├── build_googletest.py
  9.    ├── build_gperftools.py
  10.    ├── build_jsoncpp.py
  11.    ├── build_libevent.py
  12.    ├── build_libodb_boost.py
  13.    ├── build_libodb_pgsql.py
  14.    ├── build_libodb.py
  15.    ├── build_libodb_sqlite.py
  16.    ├── build_libpq.py
  17.    ├── build_openssl.py
  18.    ├── build_protobuf.py
  19.    ├── build_sqlite.py
  20.    ├── build_thrift.py
  21.    ├── build_zeromq.py
  22.    ├── build_zlib.py
  23.    └── common.py F基础函数
  24. ├── makefiles
  25.    ├── boost-common
  26.    ├── boost-cygwin
  27.    ├── boost-linux
  28.    ├── boost-windows
  29.    ├── libevent-windows
  30.    ├── libodb-windows
  31.    ├── sqlite-windows
  32.    ├── thrift-cpp-windows
  33.    ├── zeromq-windows
  34.    └── zlib-windows
  35. ├── packages D基础库第三方库源
  36.    ├── boost_1_61_0.tar.bz2
  37.    ├── curl-7.46.0.tar.bz2
  38.    ├── gflags
  39.    ├── glog
  40.    ├── googletest
  41.    ├── gperftools
  42.    ├── jsoncpp
  43.    ├── libevent-2.0.22-stable.tar.gz
  44.    ├── libodb-2.4.0.tar.bz2
  45.    ├── libodb-boost-2.4.0.tar.bz2
  46.    ├── libodb-pgsql-2.4.0.tar.bz2
  47.    ├── libodb-sqlite-2.4.0.tar.bz2
  48.    ├── openssl-1.0.2h.tar.gz
  49.    ├── postgresql-9.4.5.tar.bz2
  50.    ├── protobuf-cpp-3.1.0.tar.gz
  51.    ├── sqlite-autoconf-3100200.tar.gz
  52.    ├── thrift-0.9.3.tar.gz
  53.    ├── zeromq-4.1.3.tar.gz
  54.    └── zlib-1.2.8.tar.gz
  55. ├── README.md
  56. └── source_include
  57. └── boost

build_opensource.py

  1. #!/usr/bin/env python
  2. #encoding: utf-8
  3. #
  4. # opensource build scripts for IA10K project
  5. # Author: jibin 00081
  6. #
  7. import os
  8. import sys
  9. import glob
  10. import shutil
  11. import tarfile
  12. import platform
  13. import subprocess
  14. import logging
  15. import time
  16. import re
  17. import optparse
  18. sys.path.append(os.path.join(os.path.dirname(__file__), 'build_scripts'))
  19. from common import *
  20. if __name__ == '__main__':
  21. parser = optparse.OptionParser()
  22. parser.add_option('-D', '--debug',
  23. help='show debug when build.',
  24. dest='debug',
  25. action='store_true',
  26. default=False)
  27. parser.add_option('-q', '--quiet',
  28. help='not show verbose when build.',
  29. dest='verbose',
  30. action='store_false',
  31. default=True)
  32. parser.add_option('-f', '--force',
  33. help='force to rebuild.',
  34. dest='force',
  35. action='store_true',
  36. default=False)
  37. parser.add_option('-c', '--compiler',
  38. help='compiler to build. valid: %s' % ','.join(get_compiler_list()),
  39. dest='compiler',
  40. default=get_default_compiler())
  41. parser.add_option('-p', '--package',
  42. help='module to build. valid: %s' % ','.join(get_package_list()),
  43. dest='package',
  44. default=get_package_default())
  45. parser.add_option('-a', '--arch',
  46. help='arch to build. valid: %s' % ','.join(get_arch_list()),
  47. dest='arch',
  48. default=get_arch_default())
  49. parser.add_option('-t', '--target',
  50. help='target to build. valid: %s' % ','.join(get_target_list()),
  51. dest='target',
  52. default=get_target_default())
  53. parser.add_option('-m', '--no-yum',
  54. help='compile all source, default is using yum devel package instead of compile it self',
  55. dest='yum',
  56. action='store_false',
  57. default=True)
  58. (options, args) = parser.parse_args()
  59. # set logging level
  60. logging_level = logging.WARN
  61. if options.verbose:
  62. logging_level=logging.INFO
  63. if options.debug:
  64. logging_level=logging.DEBUG
  65. logging.basicConfig(
  66. level=logging_level,
  67. format='[%(asctime)s] [%(filename)s:%(lineno)d] [%(levelname)s] %(message)s',
  68. datefmt='%Y-%m-%d %H:%M:%S',
  69. )
  70. c = options.compiler
  71. ps = options.package.split(',')
  72. ar = options.arch.split(',')
  73. ts = options.target.split(',')
  74. if options.package == 'all':
  75. ps = get_package_list()
  76. if options.arch == 'all':
  77. ar = get_arch_list()
  78. if options.target == 'all':
  79. ts = get_target_list()
  80. for p in ps:
  81. for a in ar:
  82. for t in ts:
  83. logging.info('build %s %s %s using %s', p, a, t, c)
  84. bc = BuilderFactory(p)
  85. b = bc(a, t, c, options.force)
  86. b.verbose = options.verbose
  87. b.debug = options.debug
  88. b.yum = options.yum
  89. try:
  90. b.build()
  91. except Exception, ex:
  92. logging.error('build %s %s %s using %s failed.', p, a, t, c)
  93. import traceback
  94. traceback.print_exc(ex)
  95. sys.exit(1)

common.py

  1. #!/usr/bin/env python
  2. #encoding: utf-8
  3. import sys
  4. import os
  5. import glob
  6. import logging
  7. import shutil
  8. import time
  9. import subprocess
  10. import re
  11. import multiprocessing
  12. _vc_lists_ = ['vc14', 'vc12', 'vc11', 'vc10']
  13. def get_vcvarsall(ver):
  14. """
  15. get where vc is installed, return the full-path of vcvarsall.bat
  16. """
  17. try:
  18. import _winreg
  19. rp = ''
  20. if sys.maxsize > 2**32:
  21. rp = 'Software\Wow6432Node\Microsoft\VisualStudio\%.1f\Setup\VC' % float(ver)
  22. else:
  23. rp = 'Software\Microsoft\VisualStudio\%.1f\Setup\VC' % float(ver)
  24. key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, rp)
  25. vs = _winreg.QueryValueEx(key, 'ProductDir')
  26. if os.path.isfile(os.path.join(vs[0], 'vcvarsall.bat')):
  27. return os.path.join(vs[0], 'vcvarsall.bat')
  28. except Exception, ex:
  29. pass
  30. return None
  31. def get_gcc_march():
  32. return 'core2'
  33. def get_compiler_list():
  34. if sys.platform.startswith('linux'):
  35. return ['gcc']
  36. elif sys.platform == 'cygwin':
  37. return ['gcc']
  38. elif sys.platform == 'win32':
  39. return _vc_lists_
  40. def get_default_compiler():
  41. if sys.platform.startswith('linux'):
  42. return 'gcc'
  43. elif sys.platform == 'cygwin':
  44. return 'gcc'
  45. elif sys.platform == 'win32':
  46. for vc in _vc_lists_:
  47. ver = vc.replace('vc', '')
  48. if get_vcvarsall(ver):
  49. return vc
  50. return 'NONE'
  51. def get_package_list():
  52. ret = []
  53. for x in os.listdir(os.path.dirname(__file__)):
  54. if x.endswith('.py') and x.startswith('build_'):
  55. mx = x.replace('.py', '').replace('build_', '')
  56. ret.append(mx)
  57. return ret
  58. def get_package_default():
  59. return ','.join(get_package_list())
  60. def get_target_list():
  61. return ['Debug', 'RelWithDebInfo']
  62. def get_target_default():
  63. return 'RelWithDebInfo'
  64. def get_arch_list():
  65. if sys.platform == 'cygwin':
  66. return ['x64']
  67. else:
  68. return ['x86', 'x64']
  69. def get_arch_default():
  70. return 'x64'
  71. def patch_textfile_(filename, pattern, replace):
  72. content = None
  73. with open(filename) as fp:
  74. content = fp.read()
  75. if content:
  76. content = re.sub(pattern, replace, content)
  77. with open(filename, 'w') as fp:
  78. fp.write(content)
  79. def cleanup_build_(build_parent, pattern):
  80. for x in glob.glob(os.path.join(build_parent, pattern)):
  81. logging.info('cleanup deleting %s' % x)
  82. try:
  83. shutil.rmtree(x)
  84. except Exception:
  85. pass
  86. time.sleep(1)
  87. def BuilderFactory(package):
  88. try:
  89. exec('from build_%s import %sBuilder' % (package, package))
  90. exec('x=%sBuilder' % package)
  91. return x
  92. except Exception:
  93. logging.error('no class %sBuilder found' % package)
  94. return None
  95. class BasicBuilder():
  96. def __init__(self, package, arch, target, compiler, force):
  97. self.package = package
  98. self.arch = arch
  99. self.target = target
  100. self.compiler = compiler
  101. self.force = force
  102. self.build_parent = os.path.realpath(os.path.join('build', compiler, arch, target))
  103. self.build_touch = os.path.join(self.build_parent, 'buildstamp_%s' % package)
  104. self.windows = False
  105. self.linux = False
  106. self.cygwin = False
  107. self.vc_ver = 0
  108. self.verbose = True
  109. self.debug = False
  110. self.cpu = multiprocessing.cpu_count()
  111. if self.compiler.startswith('vc'):
  112. self.vc_ver = int(self.compiler.replace('vc', ''))
  113. self.platform = ''
  114. if sys.platform.startswith('linux'):
  115. self.linux = True
  116. self.platform = 'linux'
  117. os.environ['BUILD_TOOL_CMAKE'] = os.path.realpath('../tools/cmake/bin/cmake')
  118. elif sys.platform == 'cygwin':
  119. self.cygwin = True
  120. self.platform = 'cygwin'
  121. os.environ['BUILD_TOOL_CMAKE'] = 'cmake'
  122. elif sys.platform == 'win32':
  123. self.windows = True
  124. self.platform = 'windows'
  125. os.environ['BUILD_TOOL_CMAKE'] = os.path.realpath('../tools/cmake/bin/cmake.exe')
  126. self.install_dir = os.path.realpath(os.path.join('dest', self.platform, arch, compiler, target))
  127. self.install_inc_dir = os.path.join(self.install_dir, 'include')
  128. self.install_lib_dir = os.path.join(self.install_dir, 'lib')
  129. if self.linux or self.cygwin:
  130. os.environ['PKG_CONFIG_PATH'] = os.path.join(self.install_lib_dir, 'pkgconfig')
  131. def depends(self):
  132. raise Exception('not impl!')
  133. def build(self):
  134. if self.package not in get_package_list():
  135. logging.warn('package %s is not valid', self.package)
  136. return
  137. if self.arch not in get_arch_list():
  138. logging.warn('arch %s is not valid', sefl.arch)
  139. return
  140. if self.target not in get_target_list():
  141. logging.warn('target %s is not valid', self.target)
  142. return
  143. # do build depends
  144. for p in self.depends():
  145. BC = BuilderFactory(p)
  146. pb = BC(self.arch, self.target, self.compiler, False)
  147. pb.verbose = self.verbose
  148. pb.debug = self.debug
  149. pb.yum = self.yum
  150. pb.build()
  151. do_build = True
  152. if not self.force:
  153. if os.path.isfile(self.build_touch):
  154. st0 = os.stat(self.build_touch)
  155. mts = []
  156. # mts.append(os.stat(__file__).st_mtime)
  157. # mts.append(os.stat(sys.argv[0]).st_mtime)
  158. mts.append(os.stat(os.path.join('build_scripts', 'build_%s.py' % self.package)).st_mtime)
  159. for p in self.depends():
  160. ptouch = os.path.join(self.build_parent, 'buildstamp_%s' % p)
  161. mts.append(os.stat(ptouch).st_mtime)
  162. do_build = False
  163. for mt in mts:
  164. if st0.st_mtime < mt:
  165. do_build = True
  166. break
  167. if do_build:
  168. if not os.path.isdir(self.build_parent):
  169. os.makedirs(self.build_parent)
  170. oldllp = None
  171. if os.environ.has_key('LD_LIBRARY_PATH'):
  172. oldllp = os.environ['LD_LIBRARY_PATH']
  173. oldpath = None
  174. if os.environ.has_key('PATH'):
  175. oldpath = os.environ['PATH']
  176. os.environ['LD_LIBRARY_PATH'] = os.path.join(self.install_lib_dir)
  177. os.environ['PATH'] = '%s:%s' % (os.path.join(self.install_dir, 'bin'), oldpath)
  178. self.prebuild()
  179. self.compile()
  180. self.install()
  181. self.postbuild()
  182. del os.environ['LD_LIBRARY_PATH']
  183. if oldllp:
  184. os.environ['LD_LIBRARY_PATH'] = oldllp
  185. del os.environ['PATH']
  186. if oldpath:
  187. os.environ['PATH'] = oldpath
  188. with open(self.build_touch, 'w') as fp:
  189. fp.write('ok')
  190. else:
  191. logging.warn('build %s %s %s using %s skipped.', self.package, self.arch, self.target, self.compiler)
  192. def prebuild(self):
  193. raise Exception('not impl')
  194. def compile(self):
  195. raise Exception('not impl')
  196. def install(self):
  197. raise Exception('not impl')
  198. def postbuild(self):
  199. raise Exception('not impl')
  200. def find_build_(self, pattern):
  201. fd = glob.glob(os.path.join(self.build_parent, pattern))
  202. if len(fd) != 1 or (not os.path.isdir(fd[0])):
  203. return None
  204. else:
  205. logging.info('find build dir %s', fd[0])
  206. return fd[0]
  207. def find_package_(self, pattern):
  208. fs = glob.glob(os.path.join('packages', pattern))
  209. if len(fs) != 1:
  210. raise Exception('unexpected source packages got: %s', fs)
  211. return fs[0]
  212. def extract_(self, pattern, dest_pattern):
  213. fs = glob.glob(os.path.join('packages', pattern))
  214. if len(fs) != 1:
  215. raise Exception('unexpected source packages got: %s', fs)
  216. logging.info('extracting source %s -> %s', fs[0], self.build_parent)
  217. tool7za = None
  218. if self.cygwin or self.windows:
  219. tool7za = os.path.realpath('../tools/7z/7za.exe')
  220. bp = self.build_parent
  221. np = fs[0]
  222. if self.cygwin:
  223. # translate to windows path
  224. fp = subprocess.Popen(['cygpath', '-d', self.build_parent], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  225. bp = fp.stdout.read().strip().replace('\\', '/')
  226. fp = subprocess.Popen(['cygpath', '-d', fs[0]], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  227. np = fp.stdout.read().strip().replace('\\', '/')
  228. if self.linux:
  229. if np.endswith('tar') or np.endswith('tar.gz') or np.endswith('tar.bz2'):
  230. os.system('tar xf %s -C %s' % (np, bp))
  231. else:
  232. if np.endswith('tar.gz') or np.endswith('tar.bz2'):
  233. os.system('%s x -mmt -so %s | %s x -si -aoa -ttar -o%s' % (tool7za, np, tool7za, bp))
  234. elif np.endswith('tar') or np.endswith('zip'):
  235. os.system('%s x -mmt -aoa -o%s %s' % (tool7za, bp, np))
  236. fd = glob.glob(os.path.join(self.build_parent, dest_pattern))
  237. if len(fd) != 1 or (not os.path.isdir(fd[0])):
  238. raise Exception('unexpected source build dirs got: %s', fd)
  239. logging.info('extract success %s -> %s', fs[0], fd[0])
  240. return fd[0]
  241. def cleanup_build_(self, pattern):
  242. for x in glob.glob(os.path.join(self.build_parent, pattern)):
  243. logging.info('cleanup deleting %s' % x)
  244. try:
  245. shutil.rmtree(x)
  246. except Exception:
  247. pass
  248. time.sleep(1)
  249. def install_(self, dest_dir, patterns):
  250. """
  251. install files from build_dir -> dest_dir, match patterns(using glob)
  252. pattern is glob based, and base dir is build dir
  253. """
  254. if type(patterns) == type(''):
  255. patterns = [patterns]
  256. for pattern in patterns:
  257. fs = glob.glob(os.path.join(self.build_dir, pattern))
  258. for f in fs:
  259. if not os.path.isdir(dest_dir):
  260. os.makedirs(dest_dir)
  261. if os.path.isfile(f):
  262. logging.info('install %s -> %s', f, dest_dir)
  263. dest_file = os.path.join(dest_dir, os.path.basename(f))
  264. try:
  265. os.unlink(dest_file)
  266. except Exception:
  267. pass
  268. if os.path.islink(f):
  269. os.symlink(os.readlink(f), dest_file)
  270. else:
  271. shutil.copy2(f, dest_dir)
  272. elif os.path.isdir(f):
  273. logging.info('install %s -> %s', f, dest_dir)
  274. d2 = os.path.join(dest_dir, os.path.basename(f))
  275. if os.path.isdir(d2):
  276. # need to remove first
  277. logging.info('delete %s', d2)
  278. shutil.rmtree(d2)
  279. logging.info('copy %s -> %s', f, dest_dir)
  280. shutil.copytree(f, d2)
  281. def get_cmake_generator_(self):
  282. gtable = {
  283. 14: "Visual Studio 14 2015",
  284. 12: "Visual Studio 12 2013",
  285. 11: "Visual Studio 11 2012",
  286. 10: "Visual Studio 10 2010",
  287. 9: "Visual Studio 9 2008",
  288. }
  289. if self.windows:
  290. generator = gtable[self.vc_ver]
  291. if self.arch.find('64') >= 0:
  292. generator += ' Win64'
  293. return generator
  294. elif self.linux or self.cygwin:
  295. return 'Unix Makefiles'
  296. def cmake_(self, defines={}):
  297. old_pwd = os.getcwd()
  298. os.chdir(self.build_dir)
  299. throw_ex = None
  300. try:
  301. cmake_cmd = ['cmake', '-G', self.get_cmake_generator_()]
  302. if os.environ.has_key('BUILD_TOOL_CMAKE'):
  303. cmake_cmd = [os.environ['BUILD_TOOL_CMAKE'], '-G', self.get_cmake_generator_()]
  304. for d in defines:
  305. cmake_cmd.append('-D')
  306. cmake_cmd.append('%s=%s' % (d, defines[d]))
  307. cmake_cmd.append('.')
  308. logging.info('starting cmake using: %s', cmake_cmd)
  309. fd = None
  310. if self.debug or self.verbose:
  311. fd = subprocess.Popen(cmake_cmd)
  312. else:
  313. fd = subprocess.Popen(cmake_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  314. fd.wait()
  315. if fd.returncode != 0:
  316. raise Exception('cmake return failed, ret=%d' % fd.returncode)
  317. except Exception, ex:
  318. throw_ex = ex
  319. finally:
  320. os.chdir(old_pwd)
  321. if throw_ex:
  322. raise throw_ex
  323. logging.info('cmake success')
  324. def msbuild_(self, sln, proj):
  325. vcvarsall = get_vcvarsall(self.vc_ver)
  326. if not vcvarsall:
  327. raise Exception('vc%d is not found' % vc_ver)
  328. old_pwd = os.getcwd()
  329. os.chdir(self.build_dir)
  330. throw_ex = None
  331. try:
  332. cmd = 'msbuild %s' % sln
  333. cmd += ' /p:Configuration=%s' % self.target
  334. if proj:
  335. cmd += ' /t:%s' % proj
  336. logging.info('starting msbuild using: %s', cmd)
  337. fd = None
  338. if self.debug or self.verbose:
  339. fd = subprocess.Popen('"%s" x86 & %s' % (vcvarsall, cmd))
  340. else:
  341. fd = subprocess.Popen('"%s" x86 & %s' % (vcvarsall, cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  342. fd.wait()
  343. if fd.returncode != 0:
  344. raise Exception('msbuild return failed, ret=%d' % fd.returncode)
  345. except Exception, ex:
  346. throw_ex = ex
  347. finally:
  348. os.chdir(old_pwd)
  349. if throw_ex:
  350. raise throw_ex
  351. logging.info('msbuild success')
  352. def build_shell_(self, cmd):
  353. old_pwd = os.getcwd()
  354. os.chdir(self.build_dir)
  355. throw_ex = None
  356. try:
  357. logging.info('starting run: %s', cmd)
  358. fd = None
  359. if self.windows:
  360. if self.debug or self.verbose:
  361. fd = subprocess.Popen('cmd.exe /c %s' % cmd)
  362. else:
  363. fd = subprocess.Popen('cmd.exe /c %s' % cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  364. elif self.linux or self.cygwin:
  365. if self.debug or self.verbose:
  366. fd = subprocess.Popen(['bash', '-c', '%s' % cmd])
  367. else:
  368. fd = subprocess.Popen(['bash', '-c', '%s' % cmd], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  369. fd.wait()
  370. if fd.returncode != 0:
  371. raise Exception('run cmd failed, ret=%d' % fd.returncode)
  372. except Exception, ex:
  373. throw_ex = ex
  374. finally:
  375. os.chdir(old_pwd)
  376. if throw_ex:
  377. raise throw_ex
  378. def nmake_(self, makefile=None, options=None, target=None):
  379. """
  380. call nmake to build on windows system
  381. makefile: makefile filename, if not given, using default(Makefile)
  382. options: make options
  383. target: build target, if not given, using default.
  384. """
  385. arch = 'x86'
  386. if self.arch.find('64') >= 0:
  387. arch = 'amd64'
  388. vcvarsall = get_vcvarsall(self.vc_ver)
  389. if not vcvarsall:
  390. raise Exception('vc%d is not found' % self.vc_ver)
  391. old_pwd = os.getcwd()
  392. os.chdir(self.build_dir)
  393. throw_ex = None
  394. try:
  395. make_cmd = 'nmake /nologo'
  396. if makefile:
  397. make_cmd += ' /f %s' % makefile
  398. if options:
  399. for o in options:
  400. make_cmd += ' %s' % o
  401. if target:
  402. make_cmd += ' %s' % target
  403. logging.info('starting nmake using: %s', make_cmd)
  404. fd = subprocess.Popen('"%s" %s & %s' % (vcvarsall, self.arch, make_cmd))
  405. fd.wait()
  406. if fd.returncode != 0:
  407. raise Exception('nmake return failed, ret=%d' % fd.returncode)
  408. except Exception, ex:
  409. throw_ex = ex
  410. finally:
  411. os.chdir(old_pwd)
  412. if throw_ex:
  413. raise throw_ex
  414. logging.info('nmake success')

build_curl.py

  1. #!/usr/bin/env python
  2. #encoding: utf-8
  3. from common import *
  4. class curlBuilder(BasicBuilder):
  5. def __init__(self, arch, target, compiler, force):
  6. BasicBuilder.__init__(self, 'curl', arch, target, compiler, force)
  7. def depends(self):
  8. return ['zlib', 'openssl']
  9. def prebuild(self):
  10. if self.yum:
  11. return
  12. self.cleanup_build_('curl-*')
  13. self.build_dir = self.extract_('curl-*.tar.*', 'curl-*')
  14. options = {}
  15. options['BUILD_CURL_EXE'] = 'OFF'
  16. options['BUILD_CURL_TESTS'] = 'OFF'
  17. options['CURL_DISABLE_GOPHER'] = 'ON'
  18. options['CURL_DISABLE_IMAP'] = 'ON'
  19. options['CURL_DISABLE_LDAP'] = 'ON'
  20. options['CURL_DISABLE_LDAPS'] = 'ON'
  21. options['CURL_DISABLE_POP3'] = 'ON'
  22. options['CURL_DISABLE_RTSP'] = 'ON'
  23. options['CURL_DISABLE_SMTP'] = 'ON'
  24. options['CURL_DISABLE_TELNET'] = 'ON'
  25. options['CURL_DISABLE_TFTP'] = 'ON'
  26. options['CURL_STATICLIB'] = 'ON'
  27. options['ENABLE_THREADED_RESOLVER'] = 'ON'
  28. options['ENABLE_MANUAL'] = 'OFF'
  29. options['CMAKE_BUILD_TYPE'] = 'RelWithDebInfo'
  30. if self.target == 'Debug':
  31. options['CMAKE_BUILD_TYPE'] = 'Debug'
  32. options['OPENSSL_INCLUDE_DIR'] = self.install_inc_dir
  33. options['ZLIB_INCLUDE_DIR'] = self.install_inc_dir
  34. if self.windows:
  35. options['OPENSSL_CRYPTO_LIBRARY'] = os.path.join(self.install_lib_dir, 'libeay32.lib')
  36. options['OPENSSL_SSL_LIBRARY'] = os.path.join(self.install_lib_dir, 'ssleay32.lib')
  37. options['ZLIB_LIBRARY'] = os.path.join(self.install_lib_dir, 'zlib.lib')
  38. elif self.linux or self.cygwin:
  39. options['OPENSSL_CRYPTO_LIBRARY'] = os.path.join(self.install_lib_dir, 'libcrypto.a')
  40. options['OPENSSL_SSL_LIBRARY'] = os.path.join(self.install_lib_dir, 'libssl.a')
  41. options['ZLIB_LIBRARY'] = os.path.join(self.install_lib_dir, 'libz.a')
  42. if self.arch == 'x86':
  43. options['CMAKE_C_FLAGS'] = '-m32'
  44. else:
  45. options['CMAKE_C_FLAGS'] = '-m64'
  46. options['CMAKE_C_FLAGS'] += ' -march=%s -g' % get_gcc_march()
  47. options['CMAKE_INSTALL_PREFIX'] = self.install_dir
  48. # cmake generate
  49. self.cmake_(defines=options)
  50. if self.windows:
  51. # patch using /Z7 for debug
  52. patch_textfile_(
  53. os.path.join(self.build_dir, 'lib', 'libcurl.vcxproj'),
  54. r'<DebugInformationFormat>.+</DebugInformationFormat>',
  55. r'<DebugInformationFormat>OldStyle</DebugInformationFormat>'
  56. )
  57. def compile(self):
  58. if self.yum:
  59. return
  60. if self.windows:
  61. self.msbuild_('CURL.sln', 'libcurl')
  62. elif self.linux or self.cygwin:
  63. self.build_shell_('make -j %d' % self.cpu)
  64. def install(self):
  65. if self.yum:
  66. return
  67. if self.windows:
  68. self.install_(self.install_lib_dir, 'lib\\%s\\*.lib' % self.target)
  69. self.install_(os.path.join(self.install_inc_dir, 'curl'), 'include\\curl\\*.h')
  70. elif self.linux or self.cygwin:
  71. self.build_shell_('make install')
  72. def postbuild(self):
  73. if self.yum:
  74. os.system('yum -y install libcurl libcurl-devel')
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注