3 This tool is used to generate user-config.jam and site-config.jam
4 for boost library automatically.
9 __author__ = "Tianjiao Yin (ytj000@gamil.com)"
10 __date__ = "Fri, 24 Jun 2011 18:58:58 +0800"
11 __copyright__ = "Copyright 2011 Tianjiao Yin"
12 __license__ = "WTFPLv2"
16 site_path = "/etc/site-config.jam"
17 boostbook_path = "/usr/share/boostbook"
19 # Constant default path
20 QT_PATH = "/usr/share/qt" # useless useless
21 DOCBOOK_PATH = "/usr/share/xml/docbook/"
24 TOOLS_LIST = ("specific_gcc", "python", "mpi", "boostbook")
26 # "using name ;" if name is executable
27 # Trivial tools don't need a special function.
28 # May be I should remove this and write functions for all;
29 TRIVIAL_TOOLS = ("gcc", "doxygen", "quickbook")
31 SITE_DATA = r'''# Copyright 2003, 2005 Douglas Gregor
32 # Copyright 2004 John Maddock
33 # Copyright 2002, 2003, 2004, 2007 Vladimir Prus
34 # Distributed under the Boost Software License, Version 1.0.
35 # (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
37 # This file is used to configure your Boost.Build installation. You can modify
38 # this file in place, or you can place it in a permanent location so that it
39 # does not get overwritten should you get a new version of Boost.Build. See:
41 # http://www.boost.org/boost-build2/doc/html/bbv2/overview/configuration.html
43 # for documentation about possible permanent locations.
45 # This file specifies which toolsets (C++ compilers), libraries, and other
46 # tools are available. Often, you should be able to just uncomment existing
47 # example lines and adjust them to taste. The complete list of supported tools,
48 # and configuration instructions can be found at:
50 # http://boost.org/boost-build2/doc/html/bbv2/reference/tools.html
53 # This file uses Jam language syntax to describe available tools. Mostly,
54 # there are 'using' lines, that contain the name of the used tools, and
55 # parameters to pass to those tools -- where paremeters are separated by
56 # semicolons. Important syntax notes:
58 # - Both ':' and ';' must be separated from other tokens by whitespace
59 # - The '\' symbol is a quote character, so when specifying Windows paths you
60 # should use '/' or '\\' instead.
62 # More details about the syntax can be found at:
64 # http://boost.org/boost-build2/doc/html/bbv2/advanced.html#bbv2.advanced.jam_language
72 # Configure msvc (default version, searched for in standard locations and PATH).
75 # Configure specific msvc version (searched for in standard locations and PATH).
79 # ----------------------
80 # Borland configuration.
81 # ----------------------
85 # ----------------------
86 # STLPort configuration.
87 # ----------------------
89 # Configure specifying location of STLPort headers. Libraries must be either
90 # not needed or available to the compiler by default.
91 # using stlport : : /usr/include/stlport ;
93 # Configure specifying location of both headers and libraries explicitly.
94 # using stlport : : /usr/include/stlport /usr/lib ;
101 # Configure gcc (default version).
104 # Configure specific gcc version, giving alternative name to use.
112 # Configure assuming QTDIR gives the installation prefix.
115 # Configure with an explicit installation prefix.
116 # using qt : /usr/opt/qt ;
118 # ---------------------
119 # Python configuration.
120 # ---------------------
122 # Configure specific Python version.
132 # ------------------------
133 # BoostBook configuration.
134 # ------------------------
138 # ----------------------
139 # Doxygen configuration.
140 # ----------------------
144 # ------------------------
145 # Quickbook configuration.
146 # ------------------------
150 # --------------------
151 # Extra configuration.
152 # --------------------
157 Find all executable files.
158 Return file_names_dict, paths_list
161 return os.path.exists(fpath) and os.access(fpath, os.X_OK)
164 for path in os.environ["PATH"].split(os.pathsep):
165 if os.path.exists(path):
166 for name in os.listdir(path):
167 exe_file = os.path.join(path, name)
168 if name not in rec and is_exe(exe_file):
173 all_name, all_path = get_all_exec()
178 if len(i) > 4 and i[:4] == "g++-":
179 gccs.append("using gcc : {} : {} ;\n".format(i[4:], i))
180 return "\n".join(gccs)
189 getpyver(python_path) --> python_version
192 getpyver("python3") --> "3.2"
195 p = subprocess.Popen((cmd, "--version"), stderr=subprocess.PIPE)
197 p = p.stderr.read().decode('ascii')
198 p = p.split()[1].split('.')
199 return p[0] + '.' + p[1]
203 Get python configure.
206 pyinc = "/usr/include/python{}mu".format(pyv)
207 if not os.path.isdir(pyinc):
208 pyinc = "/usr/include/python{}".format(pyv)
210 fpath, fname = os.path.split(i)
211 if "python{}".format(pyv[0]) == fname:
214 py = "using python : {} : {} : {} : /usr/lib ;"
215 return py.format(pyv, loca, pyinc)
219 # We choose python2 as default, so python2 must appear before than python3.
220 if "python2" in all_name:
221 pys.append(get_cpy("python2"))
222 if "python3" in all_name:
223 pys.append(get_cpy("python3"))
224 return "\n".join(pys)
227 if "mpicc" in all_name:
232 if not os.path.isdir(boostbook_path):
234 if not os.path.isdir(DOCBOOK_PATH):
236 s = "using boostbook\n: {DOCBOOK_XSL_DIR}\n: {DOCBOOK_DTD_DIR}\n: {BOOSTBOOK_DIR} ;"
238 path = (os.path.join(DOCBOOK_PATH, name) for name in os.listdir(DOCBOOK_PATH))
239 l = [i for i in path if os.path.isdir(i)]
247 if not xsl or not xml:
250 # Find the newest version
251 def version_key(version):
253 return re.split('\D*', version)
255 ret["BOOSTBOOK_DIR"] = boostbook_path
256 ret["DOCBOOK_XSL_DIR"] = max(xsl, key = version_key)
257 ret["DOCBOOK_DTD_DIR"] = max(xml, key = version_key)
258 return s.format(**ret)
262 for name in TRIVIAL_TOOLS:
263 conf[name] = "using {} ;".format(name) if name in all_name else ""
264 for name in TOOLS_LIST:
265 conf[name] = globals()[name]()
270 Generate configuration file for boost build automatically.
273 global boostbook_path
275 parser = argparse.ArgumentParser(
276 # display before help
277 description=main.__doc__,
279 epilog=("License {}. This is free software. "
280 "If you are lucky, this program will not delete your /usr. "
281 "However, It has not been tested widely."
282 ).format(__license__),
284 parser.add_argument('-s', '--setup',
287 help="You have to input this argument, otherwise it will not proceed."
289 parser.add_argument('--version',
291 version='%(prog)s ' + __version__
293 parser.add_argument('-o',
295 help="Place the configuration into %(metavar)s (default: %(default)s)",
298 parser.add_argument('-b', "--boostbook_path",
299 default=boostbook_path,
300 help="Boost book directory (default: %(default)s)",
303 parser.add_argument('-a', "--add_tools",
306 # If using nargs='*' instead,
307 # No need to type quotation marks.
308 # However, it will confuse the user.
310 help=('Force to add a tool. '
311 'Simple usage: -a gcc "using gcc : : \\"distcc g++\\" ;" '
313 metavar=("<name>", "<information>")
315 args = parser.parse_args()
317 boostbook_path = args.boostbook_path
320 for i in args.add_tools:
321 add_conf[i[0]] = " ".join(i[1:])
323 conf.update(add_conf)
326 if i not in TOOLS_LIST and i not in TRIVIAL_TOOLS:
327 data += "{" + i + "}\n"
328 data = data.format(**conf)
329 open(site_path,"w").write(data)
331 if __name__ == "__main__":