build.py 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. #!/usr/bin/env python
  2. #
  3. # Copyright 2014 wkhtmltopdf authors
  4. #
  5. # This file is part of wkhtmltopdf.
  6. #
  7. # wkhtmltopdf is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Lesser General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # wkhtmltopdf is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Lesser General Public License
  18. # along with wkhtmltopdf. If not, see <http:#www.gnu.org/licenses/>.
  19. # --------------------------------------------------------------- CONFIGURATION
  20. OPENSSL = {
  21. 'repository': 'https://github.com/openssl/openssl.git',
  22. 'branch' : 'OpenSSL_1_0_1-stable',
  23. 'tag' : 'OpenSSL_1_0_1g',
  24. 'build' : {
  25. 'msvc*-win32*': {
  26. 'configure' : 'VC-WIN32 no-asm',
  27. 'build' : ['ms\\do_ms.bat', 'nmake /f ms\\nt.mak install'],
  28. 'libs' : ['ssleay32.lib', 'libeay32.lib'],
  29. 'os_libs' : '-lUser32 -lAdvapi32 -lGdi32 -lCrypt32'
  30. },
  31. 'msvc*-win64*': {
  32. 'configure' : 'VC-WIN64A',
  33. 'build' : ['ms\\do_win64a.bat', 'nmake /f ms\\nt.mak install'],
  34. 'libs' : ['ssleay32.lib', 'libeay32.lib'],
  35. 'os_libs' : '-lUser32 -lAdvapi32 -lGdi32 -lCrypt32'
  36. },
  37. 'mingw-w64-cross-win32': {
  38. 'configure' : '--cross-compile-prefix=i686-w64-mingw32- no-shared no-asm mingw64',
  39. 'build' : ['make', 'make install'],
  40. 'libs' : ['libssl.a', 'libcrypto.a'],
  41. 'os_libs' : '-lws2_32 -lgdi32 -lcrypt32'
  42. },
  43. 'mingw-w64-cross-win64': {
  44. 'configure' : '--cross-compile-prefix=x86_64-w64-mingw32- no-shared no-asm mingw64',
  45. 'build' : ['make', 'make install'],
  46. 'libs' : ['libssl.a', 'libcrypto.a'],
  47. 'os_libs' : '-lws2_32 -lgdi32 -lcrypt32'
  48. }
  49. }
  50. }
  51. QT_CONFIG = {
  52. 'common' : [
  53. '-opensource',
  54. '-confirm-license',
  55. '-fast',
  56. '-release',
  57. '-static',
  58. '-graphicssystem raster',
  59. '-webkit',
  60. '-exceptions', # required by XmlPatterns
  61. '-xmlpatterns', # required for TOC support
  62. '-qt-zlib', # use bundled versions of libraries
  63. '-qt-libpng',
  64. '-qt-libjpeg',
  65. '-no-libmng',
  66. '-no-libtiff',
  67. '-no-accessibility',
  68. '-no-stl',
  69. '-no-qt3support',
  70. '-no-phonon',
  71. '-no-phonon-backend',
  72. '-no-opengl',
  73. '-no-declarative',
  74. '-no-scripttools',
  75. '-no-sql-ibase',
  76. '-no-sql-mysql',
  77. '-no-sql-odbc',
  78. '-no-sql-psql',
  79. '-no-sql-sqlite',
  80. '-no-sql-sqlite2',
  81. '-no-mmx',
  82. '-no-3dnow',
  83. '-no-sse',
  84. '-no-sse2',
  85. '-no-multimedia',
  86. '-nomake demos',
  87. '-nomake docs',
  88. '-nomake examples',
  89. '-nomake tools',
  90. '-nomake tests',
  91. '-nomake translations'
  92. ],
  93. 'msvc': [
  94. '-mp',
  95. '-no-script',
  96. '-qt-style-windows',
  97. '-qt-style-cleanlooks',
  98. '-no-style-windowsxp',
  99. '-no-style-windowsvista',
  100. '-no-style-plastique',
  101. '-no-style-motif',
  102. '-no-style-cde',
  103. '-openssl-linked' # static linkage for OpenSSL
  104. ],
  105. 'posix': [
  106. '-silent', # perform a silent build
  107. '-script', # "make install" does not copy QtScript/qscriptengine.h
  108. '-xrender', # xrender support is required
  109. '-largefile',
  110. '-rpath',
  111. '-openssl', # load OpenSSL binaries at runtime
  112. '-no-dbus',
  113. '-no-nis',
  114. '-no-cups',
  115. '-no-iconv',
  116. '-no-pch',
  117. '-no-gtkstyle',
  118. '-no-nas-sound',
  119. '-no-sm',
  120. '-no-xshape',
  121. '-no-xinerama',
  122. '-no-xcursor',
  123. '-no-xfixes',
  124. '-no-xrandr',
  125. '-no-mitshm',
  126. '-no-xinput',
  127. '-no-xkb',
  128. '-no-glib',
  129. '-no-gstreamer',
  130. '-D ENABLE_VIDEO=0', # required as otherwise gstreamer gets linked in
  131. '-no-openvg',
  132. '-no-xsync',
  133. '-no-audio-backend',
  134. '-no-sse3',
  135. '-no-ssse3',
  136. '-no-sse4.1',
  137. '-no-sse4.2',
  138. '-no-avx',
  139. '-no-neon'
  140. ],
  141. 'mingw-w64-cross' : [
  142. '-silent', # perform a silent build
  143. '-script', # "make install" does not copy QtScript/qscriptengine.h
  144. '-openssl-linked', # static linkage for OpenSSL
  145. '-no-reduce-exports',
  146. '-no-rpath',
  147. '-xplatform win32-g++-4.6'
  148. ]
  149. }
  150. BUILDERS = {
  151. 'msvc2008-win32': 'msvc',
  152. 'msvc2008-win64': 'msvc',
  153. 'msvc2010-win32': 'msvc',
  154. 'msvc2010-win64': 'msvc',
  155. 'msvc2012-win32': 'msvc',
  156. 'msvc2012-win64': 'msvc',
  157. 'msvc2013-win32': 'msvc',
  158. 'msvc2013-win64': 'msvc',
  159. 'msvc-winsdk71-win32': 'msvc_winsdk71',
  160. 'msvc-winsdk71-win64': 'msvc_winsdk71',
  161. 'centos5-i386': 'linux_schroot',
  162. 'centos5-amd64': 'linux_schroot',
  163. 'wheezy-i386': 'linux_schroot',
  164. 'wheezy-amd64': 'linux_schroot',
  165. 'mingw-w64-cross-win32': 'mingw64_cross',
  166. 'mingw-w64-cross-win64': 'mingw64_cross'
  167. }
  168. BUILDER_FLAGS = {
  169. 'msvc': ['clean', 'debug'],
  170. 'msvc_winsdk71': ['clean', 'debug'],
  171. 'linux_schroot': ['clean'],
  172. 'mingw64_cross': ['clean'],
  173. }
  174. FLAG_HELP = {
  175. 'clean': 'performs a clean build (instead of an incremental build)',
  176. 'debug': 'performs a debug build'
  177. }
  178. # --------------------------------------------------------------- HELPERS
  179. import os, sys, subprocess, shutil, fnmatch, multiprocessing
  180. from os.path import exists
  181. CPU_COUNT = max(2, multiprocessing.cpu_count()-1) # leave one CPU free
  182. def error(msg):
  183. print msg
  184. sys.exit(1)
  185. def shell(cmd):
  186. ret = os.system(cmd)
  187. if ret != 0:
  188. error("command failed: exit code %d" % ret)
  189. def rmdir(path):
  190. if exists(path):
  191. shutil.rmtree(path)
  192. def mkdir_p(path):
  193. if not exists(path):
  194. os.makedirs(path)
  195. def get_version(basedir):
  196. text = open(os.path.join(basedir, '..', 'VERSION'), 'r').read()
  197. if '-' not in text:
  198. return (text, text)
  199. version = text[:text.index('-')]
  200. os.chdir(os.path.join(basedir, '..'))
  201. try:
  202. hash = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD'], stderr=subprocess.STDOUT).strip()
  203. except subprocess.CalledProcessError:
  204. return (text, version)
  205. return ('%s-%s' % (version, hash), version)
  206. def build_openssl(config, basedir):
  207. cfg = None
  208. for key in OPENSSL['build']:
  209. if fnmatch.fnmatch(config, key):
  210. cfg = key
  211. if not cfg:
  212. return
  213. srcdir = os.path.join(basedir, 'openssl')
  214. dstdir = os.path.join(basedir, config, 'openssl')
  215. def is_compiled():
  216. compiled = exists(os.path.join(dstdir, 'include', 'openssl', 'ssl.h'))
  217. for lib in OPENSSL['build'][cfg]['libs']:
  218. compiled = compiled and exists(os.path.join(dstdir, 'lib', lib))
  219. return compiled
  220. if not exists(os.path.join(srcdir, '.git')):
  221. rmdir(srcdir)
  222. rmdir(dstdir)
  223. os.chdir(basedir)
  224. shell('git clone --branch %s --single-branch %s openssl' % (OPENSSL['branch'], OPENSSL['repository']))
  225. os.chdir(srcdir)
  226. shell('git clean -fdx')
  227. shell('git reset --hard HEAD')
  228. shell('git checkout %s' % (OPENSSL['tag']))
  229. if not is_compiled():
  230. opts = OPENSSL['build'][cfg]
  231. shell('perl Configure --openssldir=%s %s' % (dstdir, opts['configure']))
  232. for cmd in opts['build']:
  233. shell(cmd)
  234. shell('git clean -fdx')
  235. if not is_compiled():
  236. error("Unable to compile OpenSSL for your system, aborting.")
  237. return OPENSSL['build'][cfg]['os_libs']
  238. # --------------------------------------------------------------- MSVC (2008-2013)
  239. MSVC_LOCATION = {
  240. 'msvc2008': 'VS90COMNTOOLS',
  241. 'msvc2010': 'VS100COMNTOOLS',
  242. 'msvc2012': 'VS110COMNTOOLS',
  243. 'msvc2013': 'VS120COMNTOOLS'
  244. }
  245. def check_msvc(config):
  246. version, arch = config.split('-')
  247. env_var = MSVC_LOCATION[version]
  248. if not env_var in os.environ:
  249. error("%s does not seem to be installed." % version)
  250. vcdir = os.path.join(os.environ[env_var], '..', '..', 'VC')
  251. if not exists(os.path.join(vcdir, 'vcvarsall.bat')):
  252. error("%s: unable to find vcvarsall.bat" % version)
  253. if arch == 'win32' and not exists(os.path.join(vcdir, 'bin', 'cl.exe')):
  254. error("%s: unable to find the x86 compiler" % version)
  255. if arch == 'win64' and not exists(os.path.join(vcdir, 'bin', 'amd64', 'cl.exe')) \
  256. and not exists(os.path.join(vcdir, 'bin', 'x86_amd64', 'cl.exe')):
  257. error("%s: unable to find the amd64 compiler" % version)
  258. def build_msvc(config, basedir, clean, debug):
  259. msvc, arch = config.split('-')
  260. vcdir = os.path.join(os.environ[MSVC_LOCATION[msvc]], '..', '..', 'VC')
  261. vcarg = 'x86'
  262. if arch == 'win64':
  263. if exists(os.path.join(vcdir, 'bin', 'amd64', 'cl.exe')):
  264. vcarg = 'amd64'
  265. else:
  266. vcarg = 'x86_amd64'
  267. python = sys.executable
  268. process = subprocess.Popen('("%s" %s>nul)&&"%s" -c "import os; print repr(os.environ)"' % (
  269. os.path.join(vcdir, 'vcvarsall.bat'), vcarg, python), stdout=subprocess.PIPE, shell=True)
  270. stdout, _ = process.communicate()
  271. exitcode = process.wait()
  272. if exitcode != 0:
  273. error("%s: unable to initialize the environment" % msvc)
  274. os.environ.update(eval(stdout.strip()))
  275. build_msvc_common(config, basedir, clean, debug)
  276. # --------------------------------------------------------------- MSVC via Windows SDK 7.1
  277. def check_msvc_winsdk71(config):
  278. for pfile in ['ProgramFiles(x86)', 'ProgramFiles']:
  279. if pfile in os.environ and exists(os.path.join(os.environ[pfile], 'Microsoft SDKs', 'Windows', 'v7.1', 'Bin', 'SetEnv.cmd')):
  280. return
  281. error("Unable to detect the location of Windows SDK 7.1")
  282. def build_msvc_winsdk71(config, basedir, clean, debug):
  283. arch = config[config.rindex('-'):]
  284. setenv = None
  285. for pfile in ['ProgramFiles(x86)', 'ProgramFiles']:
  286. if not pfile in os.environ:
  287. continue
  288. setenv = os.path.join(os.environ[pfile], 'Microsoft SDKs', 'Windows', 'v7.1', 'Bin', 'SetEnv.cmd')
  289. mode = debug and '/Debug' or '/Release'
  290. if arch == 'win64':
  291. args = '/2008 /x64 %s' % mode
  292. else:
  293. args = '/2008 /x86 %s' % mode
  294. python = sys.executable
  295. process = subprocess.Popen('("%s" %s>nul)&&"%s" -c "import os; print repr(os.environ)"' % (
  296. setenv, args, python), stdout=subprocess.PIPE, shell=True)
  297. stdout, _ = process.communicate()
  298. exitcode = process.wait()
  299. if exitcode != 0:
  300. error("unable to initialize the environment for Windows SDK 7.1")
  301. os.environ.update(eval(stdout.strip()))
  302. build_msvc_common(config, basedir, clean, debug)
  303. def build_msvc_common(config, basedir, clean, debug):
  304. if debug:
  305. ssl = OPENSSL['build']
  306. cfg = QT_CONFIG['common']
  307. for key in ssl:
  308. if fnmatch.fnmatch(config, key):
  309. ssl[key]['configure'] = 'debug-'+ssl[key]['configure']
  310. cfg[cfg.index('-release')] = '-debug'
  311. cfg[cfg.index('-webkit')] = '-webkit-debug'
  312. config += '-dbg'
  313. if clean:
  314. rmdir(os.path.join(basedir, config))
  315. version, simple_version = get_version(basedir)
  316. ssl_libs = build_openssl(config, basedir)
  317. ssldir = os.path.join(basedir, config, 'openssl')
  318. qtdir = os.path.join(basedir, config, 'qt')
  319. mkdir_p(qtdir)
  320. args = []
  321. args.extend(QT_CONFIG['common'])
  322. args.extend(QT_CONFIG['msvc'])
  323. args.append('-I %s\\include' % ssldir)
  324. args.append('-L %s\\lib' % ssldir)
  325. args.append('OPENSSL_LIBS="-L%s -lssleay32 -llibeay32 %s"' % \
  326. (ssldir.replace('\\', '\\\\'), ssl_libs))
  327. os.chdir(qtdir)
  328. if not exists('is_configured'):
  329. shell('%s\\..\\qt\\configure.exe %s' % (basedir, ' '.join(args)))
  330. open('is_configured', 'w').write('')
  331. shell('nmake')
  332. appdir = os.path.join(basedir, config, 'app')
  333. mkdir_p(appdir)
  334. os.chdir(appdir)
  335. rmdir('bin')
  336. mkdir_p('bin')
  337. os.environ['WKHTMLTOX_VERSION'] = version
  338. shell('%s\\bin\\qmake %s\\..\\wkhtmltopdf.pro' % (qtdir, basedir))
  339. shell('nmake')
  340. found = False
  341. for pfile in ['ProgramFiles(x86)', 'ProgramFiles']:
  342. if not pfile in os.environ or not exists(os.path.join(os.environ[pfile], 'NSIS', 'makensis.exe')):
  343. continue
  344. found = True
  345. makensis = os.path.join(os.environ[pfile], 'NSIS', 'makensis.exe')
  346. os.chdir(os.path.join(basedir, '..'))
  347. shell('"%s" /DVERSION=%s /DSIMPLE_VERSION=%s /DTARGET=%s wkhtmltox.nsi' % \
  348. (makensis, version, simple_version, config))
  349. if not found:
  350. print "\n\nCould not build installer as NSIS was not found."
  351. # ------------------------------------------------ MinGW-W64 Cross Environment
  352. MINGW_W64_PREFIX = {
  353. 'mingw-w64-cross-win32' : 'i686-w64-mingw32',
  354. 'mingw-w64-cross-win64' : 'x86_64-w64-mingw32',
  355. }
  356. def check_mingw64_cross(config):
  357. shell('%s-gcc --version' % MINGW_W64_PREFIX[config])
  358. def build_mingw64_cross(config, basedir, clean):
  359. if clean:
  360. rmdir(os.path.join(basedir, config))
  361. version, simple_version = get_version(basedir)
  362. ssl_libs = build_openssl(config, basedir)
  363. ssldir = os.path.join(basedir, config, 'openssl')
  364. build = os.path.join(basedir, config, 'qt_build')
  365. qtdir = os.path.join(basedir, config, 'qt')
  366. mkdir_p(build)
  367. args = []
  368. args.extend(QT_CONFIG['common'])
  369. args.extend(QT_CONFIG['mingw-w64-cross'])
  370. args.append('--prefix=%s' % qtdir)
  371. args.append('-I %s/include' % ssldir)
  372. args.append('-L %s/lib' % ssldir)
  373. args.append('-device-option CROSS_COMPILE=%s-' % MINGW_W64_PREFIX[config])
  374. os.environ['OPENSSL_LIBS'] = '-lssl -lcrypto -L %s/lib %s' % (ssldir, ssl_libs)
  375. os.chdir(build)
  376. if not exists('is_configured'):
  377. shell('%s/../qt/configure %s' % (basedir, ' '.join(args)))
  378. shell('touch is_configured')
  379. shell('make -j%d' % CPU_COUNT)
  380. shell('make install')
  381. appdir = os.path.join(basedir, config, 'app')
  382. mkdir_p(appdir)
  383. os.chdir(appdir)
  384. shell('rm -f bin/*')
  385. # set up cross compiling prefix correctly (isn't set by make install)
  386. os.environ['QTDIR'] = qtdir
  387. os.environ['WKHTMLTOX_VERSION'] = version
  388. shell('%s/bin/qmake -set CROSS_COMPILE %s-' % (qtdir, MINGW_W64_PREFIX[config]))
  389. shell('%s/bin/qmake -spec win32-g++-4.6 %s/../wkhtmltopdf.pro' % (qtdir, basedir))
  390. shell('make')
  391. shutil.copy('bin/libwkhtmltox0.a', 'bin/wkhtmltox.lib')
  392. os.chdir(os.path.join(basedir, '..'))
  393. shell('makensis -DVERSION=%s -DSIMPLE_VERSION=%s -DTARGET=%s wkhtmltox.nsi' % \
  394. (version, simple_version, config))
  395. # -------------------------------------------------- Linux schroot environment
  396. def check_linux_schroot(config):
  397. shell('schroot -c wkhtmltopdf-%s -- gcc --version' % config)
  398. def build_linux_schroot(config, basedir, clean):
  399. if clean:
  400. rmdir(os.path.join(basedir, config))
  401. version, simple_version = get_version(basedir)
  402. dir = os.path.join(basedir, config)
  403. script = os.path.join(dir, 'build.sh')
  404. dist = os.path.join(dir, 'wkhtmltox-%s' % version)
  405. mkdir_p(os.path.join(dir, 'qt_build'))
  406. mkdir_p(os.path.join(dir, 'app'))
  407. rmdir(dist)
  408. mkdir_p(os.path.join(dist, 'bin'))
  409. mkdir_p(os.path.join(dist, 'include', 'wkhtmltox'))
  410. mkdir_p(os.path.join(dist, 'lib'))
  411. args = []
  412. args.extend(QT_CONFIG['common'])
  413. args.extend(QT_CONFIG['posix'])
  414. args.append('--prefix=../qt')
  415. lines = ['#!/bin/bash']
  416. lines.append('# start of autogenerated build script')
  417. lines.append('cd qt_build')
  418. if config == 'centos5-i386':
  419. lines.append('export CFLAGS=-march=i486')
  420. lines.append('export CXXFLAGS=-march=i486')
  421. lines.append('if [ ! -f is_configured ]; then')
  422. lines.append(' ../../../qt/configure %s || exit 1' % ' '.join(args))
  423. lines.append(' touch is_configured')
  424. lines.append('fi')
  425. lines.append('if ! make -j%d -q; then\n make -j%d || exit 1\nfi' % (CPU_COUNT, CPU_COUNT))
  426. lines.append('make install || exit 1')
  427. lines.append('cd ../app')
  428. lines.append('rm -f bin/*')
  429. lines.append('export WKHTMLTOX_VERSION=%s' % version)
  430. lines.append('../qt/bin/qmake ../../../wkhtmltopdf.pro')
  431. lines.append('make -j%d || exit 1' % CPU_COUNT)
  432. lines.append('strip bin/wkhtmltopdf bin/wkhtmltoimage')
  433. lines.append('cp bin/wkhtmlto* ../wkhtmltox-%s/bin' % version)
  434. lines.append('cp -P bin/libwkhtmltox*.so.* ../wkhtmltox-%s/lib' % version)
  435. lines.append('cp ../../../include/wkhtmltox/*.h ../wkhtmltox-%s/include/wkhtmltox' % version)
  436. lines.append('cp ../../../include/wkhtmltox/dll*.inc ../wkhtmltox-%s/include/wkhtmltox' % version)
  437. lines.append('cd ..')
  438. lines.append('tar -c -v -f ../wkhtmltox-%s_linux-%s.tar wkhtmltox-%s/' % (version, config, version))
  439. lines.append('xz --compress -9 ../wkhtmltox-%s_linux-%s.tar' % (version, config))
  440. lines.append('# end of build script')
  441. open(script, 'w').write('\n'.join(lines))
  442. os.chdir(dir)
  443. shell('chmod +x build.sh')
  444. shell('schroot -c wkhtmltopdf-%s -- ./build.sh' % config)
  445. # --------------------------------------------------------------- command line
  446. def usage(exit_code=2):
  447. print "Usage: scripts/build.py <target> [flags]\n\nThe supported targets and associated flags are:\n",
  448. opts = list(BUILDERS.keys())
  449. size = 1 + max([len(opt) for opt in opts])
  450. opts.sort()
  451. for opt in opts:
  452. flags = BUILDER_FLAGS.get(BUILDERS[opt])
  453. if flags:
  454. print '* %s[-%s]' % (opt.ljust(size), '] [-'.join(flags))
  455. else:
  456. print '* %s' % opt.ljust(size)
  457. size = max([len(key) for key in FLAG_HELP])
  458. print "\nFlags:"
  459. for flag in FLAG_HELP:
  460. print "-%s: %s" % (flag.ljust(size), FLAG_HELP[flag])
  461. sys.exit(exit_code)
  462. def main():
  463. basedir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'static-build')
  464. mkdir_p(basedir)
  465. if len(sys.argv) == 1:
  466. usage(0)
  467. config = sys.argv[1]
  468. if config not in BUILDERS:
  469. usage()
  470. args = { 'config': config, 'basedir': os.path.realpath(basedir) }
  471. flags = BUILDER_FLAGS.get(BUILDERS[config]) or []
  472. for arg in sys.argv[2:]:
  473. if not arg.startswith('-') or arg[1:] not in flags:
  474. usage()
  475. for flag in flags:
  476. args[flag.replace('-', '_')] = '-'+flag in sys.argv[2:]
  477. globals()['check_%s' % BUILDERS[config]](config)
  478. globals()['build_%s' % BUILDERS[config]](**args)
  479. if __name__ == '__main__':
  480. main()