compilers.py 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551
  1. # Copyright 2012-2014 The Meson development team
  2. # Licensed under the Apache License, Version 2.0 (the "License");
  3. # you may not use this file except in compliance with the License.
  4. # You may obtain a copy of the License at
  5. # http://www.apache.org/licenses/LICENSE-2.0
  6. # Unless required by applicable law or agreed to in writing, software
  7. # distributed under the License is distributed on an "AS IS" BASIS,
  8. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. # See the License for the specific language governing permissions and
  10. # limitations under the License.
  11. import subprocess, os.path
  12. import tempfile
  13. import mesonlib
  14. import mlog
  15. from coredata import MesonException
  16. """This file contains the data files of all compilers Meson knows
  17. about. To support a new compiler, add its information below.
  18. Also add corresponding autodetection code in environment.py."""
  19. header_suffixes = ['h', 'hh', 'hpp', 'hxx', 'H', 'moc', 'vapi']
  20. cpp_suffixes = ['cc', 'cpp', 'cxx', 'h', 'hh', 'hpp', 'hxx', 'c++']
  21. c_suffixes = ['c']
  22. clike_suffixes = c_suffixes + cpp_suffixes
  23. obj_suffixes = ['o', 'obj']
  24. def is_header(fname):
  25. if hasattr(fname, 'fname'):
  26. fname = fname.fname
  27. suffix = fname.split('.')[-1]
  28. return suffix in header_suffixes
  29. def is_source(fname):
  30. if hasattr(fname, 'fname'):
  31. fname = fname.fname
  32. suffix = fname.split('.')[-1]
  33. return suffix in clike_suffixes
  34. def is_object(fname):
  35. if hasattr(fname, 'fname'):
  36. fname = fname.fname
  37. suffix = fname.split('.')[-1]
  38. return suffix in obj_suffixes
  39. gnulike_buildtype_args = {'plain' : [],
  40. 'debug' : ['-g'],
  41. 'debugoptimized' : ['-O2', '-g'],
  42. 'release' : ['-O3']}
  43. msvc_buildtype_args = {'plain' : [],
  44. 'debug' : ["/MDd", "/Zi", "/Ob0", "/Od", "/RTC1"],
  45. 'debugoptimized' : ["/MD", "/Zi", "/O2", "/Ob1", "/D"],
  46. 'release' : ["/MD", "/O2", "/Ob2"]}
  47. gnulike_buildtype_linker_args = {}
  48. if mesonlib.is_osx():
  49. gnulike_buildtype_linker_args.update({'plain' : [],
  50. 'debug' : [],
  51. 'debugoptimized' : [],
  52. 'release' : [],
  53. })
  54. else:
  55. gnulike_buildtype_linker_args.update({'plain' : [],
  56. 'debug' : [],
  57. 'debugoptimized' : [],
  58. 'release' : ['-Wl,-O1'],
  59. })
  60. msvc_buildtype_linker_args = {'plain' : [],
  61. 'debug' : [],
  62. 'debugoptimized' : [],
  63. 'release' : []}
  64. java_buildtype_args = {'plain' : [],
  65. 'debug' : ['-g'],
  66. 'debugoptimized' : ['-g'],
  67. 'release' : []}
  68. rust_buildtype_args = {'plain' : [],
  69. 'debug' : ['-g'],
  70. 'debugoptimized' : ['-g', '--opt-level', '2'],
  71. 'release' : ['--opt-level', '3']}
  72. mono_buildtype_args = {'plain' : [],
  73. 'debug' : ['-debug'],
  74. 'debugoptimized': ['-debug', '-optimize+'],
  75. 'release' : ['-optimize+']}
  76. def build_unix_rpath_args(build_dir, rpath_paths, install_rpath):
  77. if len(rpath_paths) == 0 and len(install_rpath) == 0:
  78. return []
  79. paths = ':'.join([os.path.join(build_dir, p) for p in rpath_paths])
  80. if len(paths) < len(install_rpath):
  81. padding = 'X'*(len(install_rpath) - len(paths))
  82. if len(paths) == 0:
  83. paths = padding
  84. else:
  85. paths = paths + ':' + padding
  86. return ['-Wl,-rpath,' + paths]
  87. class EnvironmentException(MesonException):
  88. def __init(self, *args, **kwargs):
  89. Exception.__init__(self, *args, **kwargs)
  90. class CrossNoRunException(MesonException):
  91. def __init(self, *args, **kwargs):
  92. Exception.__init__(self, *args, **kwargs)
  93. class RunResult():
  94. def __init__(self, compiled, returncode=999, stdout='UNDEFINED', stderr='UNDEFINED'):
  95. self.compiled = compiled
  96. self.returncode = returncode
  97. self.stdout = stdout
  98. self.stderr = stderr
  99. class CCompiler():
  100. def __init__(self, exelist, version, is_cross, exe_wrapper=None):
  101. if type(exelist) == type(''):
  102. self.exelist = [exelist]
  103. elif type(exelist) == type([]):
  104. self.exelist = exelist
  105. else:
  106. raise TypeError('Unknown argument to CCompiler')
  107. self.version = version
  108. self.language = 'c'
  109. self.default_suffix = 'c'
  110. self.id = 'unknown'
  111. self.is_cross = is_cross
  112. if isinstance(exe_wrapper, str):
  113. self.exe_wrapper = [exe_wrapper]
  114. else:
  115. self.exe_wrapper = exe_wrapper
  116. def needs_static_linker(self):
  117. return True # When compiling static libraries, so yes.
  118. def get_always_args(self):
  119. return []
  120. def get_linker_always_args(self):
  121. return []
  122. def get_soname_args(self, shlib_name, path, soversion):
  123. return []
  124. def split_shlib_to_parts(self, fname):
  125. return (None, fname)
  126. # The default behaviour is this, override in
  127. # OSX and MSVC.
  128. def build_rpath_args(self, build_dir, rpath_paths, install_rpath):
  129. return build_unix_rpath_args(build_dir, rpath_paths, install_rpath)
  130. def get_id(self):
  131. return self.id
  132. def get_dependency_gen_args(self, outtarget, outfile):
  133. return ['-MMD', '-MQ', outtarget, '-MF', outfile]
  134. def get_depfile_suffix(self):
  135. return 'd'
  136. def get_language(self):
  137. return self.language
  138. def get_default_suffix(self):
  139. return self.default_suffix
  140. def get_exelist(self):
  141. return self.exelist[:]
  142. def get_linker_exelist(self):
  143. return self.exelist[:]
  144. def get_compile_only_args(self):
  145. return ['-c']
  146. def get_output_args(self, target):
  147. return ['-o', target]
  148. def get_linker_output_args(self, outputname):
  149. return ['-o', outputname]
  150. def get_coverage_args(self):
  151. return ['--coverage']
  152. def get_coverage_link_args(self):
  153. return ['-lgcov']
  154. def get_werror_args(self):
  155. return ['-Werror']
  156. def get_std_exe_link_args(self):
  157. return []
  158. def get_include_args(self, path):
  159. return ['-I' + path]
  160. def get_std_shared_lib_link_args(self):
  161. return ['-shared']
  162. def can_compile(self, filename):
  163. suffix = filename.split('.')[-1]
  164. if suffix == 'c' or suffix == 'h':
  165. return True
  166. return False
  167. def get_pic_args(self):
  168. return ['-fPIC']
  169. def name_string(self):
  170. return ' '.join(self.exelist)
  171. def get_pch_use_args(self, pch_dir, header):
  172. return ['-include', os.path.split(header)[-1]]
  173. def get_pch_name(self, header_name):
  174. return os.path.split(header_name)[-1] + '.' + self.get_pch_suffix()
  175. def sanity_check(self, work_dir):
  176. source_name = os.path.join(work_dir, 'sanitycheckc.c')
  177. binary_name = os.path.join(work_dir, 'sanitycheckc')
  178. ofile = open(source_name, 'w')
  179. ofile.write('int main(int argc, char **argv) { int class=0; return class; }\n')
  180. ofile.close()
  181. pc = subprocess.Popen(self.exelist + [source_name, '-o', binary_name])
  182. pc.wait()
  183. if pc.returncode != 0:
  184. raise EnvironmentException('Compiler %s can not compile programs.' % self.name_string())
  185. if self.is_cross:
  186. if self.exe_wrapper is None:
  187. # Can't check if the binaries run so we have to assume they do
  188. return
  189. cmdlist = self.exe_wrapper + [binary_name]
  190. else:
  191. cmdlist = [binary_name]
  192. pe = subprocess.Popen(cmdlist)
  193. pe.wait()
  194. if pe.returncode != 0:
  195. raise EnvironmentException('Executables created by C compiler %s are not runnable.' % self.name_string())
  196. def has_header(self, hname):
  197. templ = '''#include<%s>
  198. int someSymbolHereJustForFun;
  199. '''
  200. return self.compiles(templ % hname)
  201. def compiles(self, code):
  202. mlog.debug('Running compile test:\n\n', code)
  203. suflen = len(self.default_suffix)
  204. (fd, srcname) = tempfile.mkstemp(suffix='.'+self.default_suffix)
  205. os.close(fd)
  206. ofile = open(srcname, 'w')
  207. ofile.write(code)
  208. ofile.close()
  209. commands = self.get_exelist()
  210. commands += self.get_compile_only_args()
  211. commands.append(srcname)
  212. p = subprocess.Popen(commands, cwd=os.path.split(srcname)[0], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  213. (stde, stdo) = p.communicate()
  214. stde = stde.decode()
  215. stdo = stdo.decode()
  216. mlog.debug('Compiler stdout:\n', stdo)
  217. mlog.debug('Compiler stderr:\n', stde)
  218. os.remove(srcname)
  219. try:
  220. trial = srcname[:-suflen] + 'o'
  221. os.remove(trial)
  222. except FileNotFoundError:
  223. pass
  224. try:
  225. os.remove(srcname[:-suflen] + 'obj')
  226. except FileNotFoundError:
  227. pass
  228. return p.returncode == 0
  229. def run(self, code):
  230. mlog.debug('Running code:\n\n', code)
  231. if self.is_cross and self.exe_wrapper is None:
  232. raise CrossNoRunException('Can not run test applications in this cross environment.')
  233. (fd, srcname) = tempfile.mkstemp(suffix='.'+self.default_suffix)
  234. os.close(fd)
  235. ofile = open(srcname, 'w')
  236. ofile.write(code)
  237. ofile.close()
  238. exename = srcname + '.exe' # Is guaranteed to be executable on every platform.
  239. commands = self.get_exelist()
  240. commands.append(srcname)
  241. commands += self.get_output_args(exename)
  242. p = subprocess.Popen(commands, cwd=os.path.split(srcname)[0], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  243. (stdo, stde) = p.communicate()
  244. stde = stde.decode()
  245. stdo = stdo.decode()
  246. mlog.debug('Compiler stdout:\n', stdo)
  247. mlog.debug('Compiler stderr:\n', stde)
  248. os.remove(srcname)
  249. if p.returncode != 0:
  250. return RunResult(False)
  251. if self.is_cross:
  252. cmdlist = self.exe_wrapper + [exename]
  253. else:
  254. cmdlist = exename
  255. pe = subprocess.Popen(cmdlist, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  256. (so, se) = pe.communicate()
  257. so = so.decode()
  258. se = se.decode()
  259. mlog.debug('Program stdout:\n', so)
  260. mlog.debug('Program stderr:\n', se)
  261. os.remove(exename)
  262. return RunResult(True, pe.returncode, so, se)
  263. def sizeof(self, element, prefix, env):
  264. templ = '''#include<stdio.h>
  265. %s
  266. int main(int argc, char **argv) {
  267. printf("%%ld\\n", (long)(sizeof(%s)));
  268. return 0;
  269. };
  270. '''
  271. varname = 'sizeof ' + element
  272. varname = varname.replace(' ', '_')
  273. if self.is_cross:
  274. val = env.cross_info.config['properties'][varname]
  275. if val is not None:
  276. if isinstance(val, int):
  277. return val
  278. raise EnvironmentException('Cross variable {0} is not an integer.'.format(varname))
  279. cross_failed = False
  280. try:
  281. res = self.run(templ % (prefix, element))
  282. except CrossNoRunException:
  283. cross_failed = True
  284. if cross_failed:
  285. message = '''Can not determine size of {0} because cross compiled binaries are not runnable.
  286. Please define the corresponding variable {1} in your cross compilation definition file.'''.format(element, varname)
  287. raise EnvironmentException(message)
  288. if not res.compiled:
  289. raise EnvironmentException('Could not compile sizeof test.')
  290. if res.returncode != 0:
  291. raise EnvironmentException('Could not run sizeof test binary.')
  292. return int(res.stdout)
  293. def alignment(self, typename, env):
  294. templ = '''#include<stdio.h>
  295. #include<stddef.h>
  296. struct tmp {
  297. char c;
  298. %s target;
  299. };
  300. int main(int argc, char **argv) {
  301. printf("%%d", (int)offsetof(struct tmp, target));
  302. return 0;
  303. }
  304. '''
  305. varname = 'alignment ' + typename
  306. varname = varname.replace(' ', '_')
  307. if self.is_cross:
  308. val = env.cross_info.config['properties'][varname]
  309. if val is not None:
  310. if isinstance(val, int):
  311. return val
  312. raise EnvironmentException('Cross variable {0} is not an integer.'.format(varname))
  313. cross_failed = False
  314. try:
  315. res = self.run(templ % typename)
  316. except CrossNoRunException:
  317. cross_failed = True
  318. if cross_failed:
  319. message = '''Can not determine alignment of {0} because cross compiled binaries are not runnable.
  320. Please define the corresponding variable {1} in your cross compilation definition file.'''.format(typename, varname)
  321. raise EnvironmentException(message)
  322. if not res.compiled:
  323. raise EnvironmentException('Could not compile alignment test.')
  324. if res.returncode != 0:
  325. raise EnvironmentException('Could not run alignment test binary.')
  326. align = int(res.stdout)
  327. if align == 0:
  328. raise EnvironmentException('Could not determine alignment of %s. Sorry. You might want to file a bug.' % typename)
  329. return align
  330. def has_function(self, funcname, prefix, env):
  331. # This fails (returns true) if funcname is a ptr or a variable.
  332. # The correct check is a lot more difficult.
  333. # Fix this to do that eventually.
  334. templ = '''%s
  335. int main(int argc, char **argv) {
  336. void *ptr = (void*)(%s);
  337. return 0;
  338. };
  339. '''
  340. varname = 'has function ' + funcname
  341. varname = varname.replace(' ', '_')
  342. if self.is_cross:
  343. val = env.cross_info.config['properties'].get(varname, None)
  344. if val is not None:
  345. if isinstance(val, bool):
  346. return val
  347. raise EnvironmentException('Cross variable {0} is not an boolean.'.format(varname))
  348. return self.compiles(templ % (prefix, funcname))
  349. def has_member(self, typename, membername, prefix):
  350. templ = '''%s
  351. void bar() {
  352. %s foo;
  353. foo.%s;
  354. };
  355. '''
  356. return self.compiles(templ % (prefix, typename, membername))
  357. def has_type(self, typename, prefix):
  358. templ = '''%s
  359. void bar() {
  360. sizeof(%s);
  361. };
  362. '''
  363. return self.compiles(templ % (prefix, typename))
  364. def thread_flags(self):
  365. return ['-pthread']
  366. def thread_link_flags(self):
  367. return ['-pthread']
  368. class CPPCompiler(CCompiler):
  369. def __init__(self, exelist, version, is_cross, exe_wrap):
  370. CCompiler.__init__(self, exelist, version, is_cross, exe_wrap)
  371. self.language = 'cpp'
  372. self.default_suffix = 'cpp'
  373. def can_compile(self, filename):
  374. suffix = filename.split('.')[-1]
  375. if suffix in cpp_suffixes:
  376. return True
  377. return False
  378. def sanity_check(self, work_dir):
  379. source_name = os.path.join(work_dir, 'sanitycheckcpp.cc')
  380. binary_name = os.path.join(work_dir, 'sanitycheckcpp')
  381. ofile = open(source_name, 'w')
  382. ofile.write('class breakCCompiler;int main(int argc, char **argv) { return 0; }\n')
  383. ofile.close()
  384. pc = subprocess.Popen(self.exelist + [source_name, '-o', binary_name])
  385. pc.wait()
  386. if pc.returncode != 0:
  387. raise EnvironmentException('Compiler %s can not compile programs.' % self.name_string())
  388. if self.is_cross:
  389. if self.exe_wrapper is None:
  390. # Can't check if the binaries run so we have to assume they do
  391. return
  392. cmdlist = self.exe_wrapper + [binary_name]
  393. else:
  394. cmdlist = [binary_name]
  395. pe = subprocess.Popen(cmdlist)
  396. pe.wait()
  397. if pe.returncode != 0:
  398. raise EnvironmentException('Executables created by C++ compiler %s are not runnable.' % self.name_string())
  399. class ObjCCompiler(CCompiler):
  400. def __init__(self, exelist, version, is_cross, exe_wrap):
  401. CCompiler.__init__(self, exelist, version, is_cross, exe_wrap)
  402. self.language = 'objc'
  403. self.default_suffix = 'm'
  404. def can_compile(self, filename):
  405. suffix = filename.split('.')[-1]
  406. if suffix == 'm' or suffix == 'h':
  407. return True
  408. return False
  409. def sanity_check(self, work_dir):
  410. source_name = os.path.join(work_dir, 'sanitycheckobjc.m')
  411. binary_name = os.path.join(work_dir, 'sanitycheckobjc')
  412. ofile = open(source_name, 'w')
  413. ofile.write('#import<stdio.h>\nint main(int argc, char **argv) { return 0; }\n')
  414. ofile.close()
  415. pc = subprocess.Popen(self.exelist + [source_name, '-o', binary_name])
  416. pc.wait()
  417. if pc.returncode != 0:
  418. raise EnvironmentException('ObjC compiler %s can not compile programs.' % self.name_string())
  419. pe = subprocess.Popen(binary_name)
  420. pe.wait()
  421. if pe.returncode != 0:
  422. raise EnvironmentException('Executables created by ObjC compiler %s are not runnable.' % self.name_string())
  423. class ObjCPPCompiler(CPPCompiler):
  424. def __init__(self, exelist, version, is_cross, exe_wrap):
  425. CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrap)
  426. self.language = 'objcpp'
  427. self.default_suffix = 'mm'
  428. def can_compile(self, filename):
  429. suffix = filename.split('.')[-1]
  430. if suffix == 'mm' or suffix == 'h':
  431. return True
  432. return False
  433. def sanity_check(self, work_dir):
  434. source_name = os.path.join(work_dir, 'sanitycheckobjcpp.mm')
  435. binary_name = os.path.join(work_dir, 'sanitycheckobjcpp')
  436. ofile = open(source_name, 'w')
  437. ofile.write('#import<stdio.h>\nclass MyClass;int main(int argc, char **argv) { return 0; }\n')
  438. ofile.close()
  439. pc = subprocess.Popen(self.exelist + [source_name, '-o', binary_name])
  440. pc.wait()
  441. if pc.returncode != 0:
  442. raise EnvironmentException('ObjC++ compiler %s can not compile programs.' % self.name_string())
  443. pe = subprocess.Popen(binary_name)
  444. pe.wait()
  445. if pe.returncode != 0:
  446. raise EnvironmentException('Executables created by ObjC++ compiler %s are not runnable.' % self.name_string())
  447. class MonoCompiler():
  448. def __init__(self, exelist, version):
  449. if type(exelist) == type(''):
  450. self.exelist = [exelist]
  451. elif type(exelist) == type([]):
  452. self.exelist = exelist
  453. else:
  454. raise TypeError('Unknown argument to Mono compiler')
  455. self.version = version
  456. self.language = 'cs'
  457. self.default_suffix = 'cs'
  458. self.id = 'mono'
  459. self.monorunner = 'mono'
  460. def get_always_args(self):
  461. return []
  462. def get_output_args(self, fname):
  463. return ['-out:' + fname]
  464. def get_linker_always_args(self):
  465. return []
  466. def get_link_args(self, fname):
  467. return ['-r:' + fname]
  468. def get_soname_args(self, shlib_name, path, soversion):
  469. return []
  470. def get_werror_args(self):
  471. return ['-warnaserror']
  472. def split_shlib_to_parts(self, fname):
  473. return (None, fname)
  474. def build_rpath_args(self, build_dir, rpath_paths, install_rpath):
  475. return []
  476. def get_id(self):
  477. return self.id
  478. def get_dependency_gen_args(self, outtarget, outfile):
  479. return []
  480. def get_language(self):
  481. return self.language
  482. def get_default_suffix(self):
  483. return self.default_suffix
  484. def get_exelist(self):
  485. return self.exelist[:]
  486. def get_linker_exelist(self):
  487. return self.exelist[:]
  488. def get_compile_only_args(self):
  489. return []
  490. def get_linker_output_args(self, outputname):
  491. return []
  492. def get_coverage_args(self):
  493. return []
  494. def get_coverage_link_args(self):
  495. return []
  496. def get_std_exe_link_args(self):
  497. return []
  498. def get_include_args(self, path):
  499. return []
  500. def get_std_shared_lib_link_args(self):
  501. return []
  502. def can_compile(self, filename):
  503. suffix = filename.split('.')[-1]
  504. if suffix == 'cs':
  505. return True
  506. return False
  507. def get_pic_args(self):
  508. return []
  509. def name_string(self):
  510. return ' '.join(self.exelist)
  511. def get_pch_use_args(self, pch_dir, header):
  512. return []
  513. def get_pch_name(self, header_name):
  514. return ''
  515. def sanity_check(self, work_dir):
  516. src = 'sanity.cs'
  517. obj = 'sanity.exe'
  518. source_name = os.path.join(work_dir, src)
  519. ofile = open(source_name, 'w')
  520. ofile.write('''public class Sanity {
  521. static public void Main () {
  522. }
  523. }
  524. ''')
  525. ofile.close()
  526. pc = subprocess.Popen(self.exelist + [src], cwd=work_dir)
  527. pc.wait()
  528. if pc.returncode != 0:
  529. raise EnvironmentException('Mono compiler %s can not compile programs.' % self.name_string())
  530. cmdlist = [self.monorunner, obj]
  531. pe = subprocess.Popen(cmdlist, cwd=work_dir)
  532. pe.wait()
  533. if pe.returncode != 0:
  534. raise EnvironmentException('Executables created by Mono compiler %s are not runnable.' % self.name_string())
  535. def needs_static_linker(self):
  536. return False
  537. def has_header(self, hname):
  538. raise EnvironmentException('Mono does not support header checks.')
  539. def compiles(self, code):
  540. raise EnvironmentException('Mono does not support compile checks.')
  541. def run(self, code):
  542. raise EnvironmentException('Mono does not support run checks.')
  543. def sizeof(self, element, prefix, env):
  544. raise EnvironmentException('Mono does not support sizeof checks.')
  545. def alignment(self, typename, env):
  546. raise EnvironmentException('Mono does not support alignment checks.')
  547. def has_function(self, funcname, prefix, env):
  548. raise EnvironmentException('Mono does not support function checks.')
  549. def get_buildtype_args(self, buildtype):
  550. return mono_buildtype_args[buildtype]
  551. class JavaCompiler():
  552. def __init__(self, exelist, version):
  553. if type(exelist) == type(''):
  554. self.exelist = [exelist]
  555. elif type(exelist) == type([]):
  556. self.exelist = exelist
  557. else:
  558. raise TypeError('Unknown argument to JavaCompiler')
  559. self.version = version
  560. self.language = 'java'
  561. self.default_suffix = 'java'
  562. self.id = 'unknown'
  563. self.javarunner = 'java'
  564. def get_always_args(self):
  565. return []
  566. def get_linker_always_args(self):
  567. return []
  568. def get_soname_args(self, shlib_name, path, soversion):
  569. return []
  570. def get_werror_args(self):
  571. return ['-Werror']
  572. def split_shlib_to_parts(self, fname):
  573. return (None, fname)
  574. def build_rpath_args(self, build_dir, rpath_paths, install_rpath):
  575. return []
  576. def get_id(self):
  577. return self.id
  578. def get_dependency_gen_args(self, outtarget, outfile):
  579. return []
  580. def get_language(self):
  581. return self.language
  582. def get_default_suffix(self):
  583. return self.default_suffix
  584. def get_exelist(self):
  585. return self.exelist[:]
  586. def get_linker_exelist(self):
  587. return self.exelist[:]
  588. def get_compile_only_args(self):
  589. return []
  590. def get_output_args(self, subdir):
  591. if subdir == '':
  592. subdir = './'
  593. return ['-d', subdir, '-s', subdir]
  594. def get_linker_output_args(self, outputname):
  595. return []
  596. def get_coverage_args(self):
  597. return []
  598. def get_coverage_link_args(self):
  599. return []
  600. def get_std_exe_link_args(self):
  601. return []
  602. def get_include_args(self, path):
  603. return []
  604. def get_std_shared_lib_link_args(self):
  605. return []
  606. def can_compile(self, filename):
  607. suffix = filename.split('.')[-1]
  608. if suffix == 'java':
  609. return True
  610. return False
  611. def get_pic_args(self):
  612. return []
  613. def name_string(self):
  614. return ' '.join(self.exelist)
  615. def get_pch_use_args(self, pch_dir, header):
  616. return []
  617. def get_pch_name(self, header_name):
  618. return ''
  619. def get_buildtype_args(self, buildtype):
  620. return java_buildtype_args[buildtype]
  621. def sanity_check(self, work_dir):
  622. src = 'SanityCheck.java'
  623. obj = 'SanityCheck'
  624. source_name = os.path.join(work_dir, src)
  625. ofile = open(source_name, 'w')
  626. ofile.write('''class SanityCheck {
  627. public static void main(String[] args) {
  628. int i;
  629. }
  630. }
  631. ''')
  632. ofile.close()
  633. pc = subprocess.Popen(self.exelist + [src], cwd=work_dir)
  634. pc.wait()
  635. if pc.returncode != 0:
  636. raise EnvironmentException('Java compiler %s can not compile programs.' % self.name_string())
  637. cmdlist = [self.javarunner, obj]
  638. pe = subprocess.Popen(cmdlist, cwd=work_dir)
  639. pe.wait()
  640. if pe.returncode != 0:
  641. raise EnvironmentException('Executables created by Java compiler %s are not runnable.' % self.name_string())
  642. def needs_static_linker(self):
  643. return False
  644. def has_header(self, hname):
  645. raise EnvironmentException('Java does not support header checks.')
  646. def compiles(self, code):
  647. raise EnvironmentException('Java does not support compile checks.')
  648. def run(self, code):
  649. raise EnvironmentException('Java does not support run checks.')
  650. def sizeof(self, element, prefix, env):
  651. raise EnvironmentException('Java does not support sizeof checks.')
  652. def alignment(self, typename, env):
  653. raise EnvironmentException('Java does not support alignment checks.')
  654. def has_function(self, funcname, prefix, env):
  655. raise EnvironmentException('Java does not support function checks.')
  656. class ValaCompiler():
  657. def __init__(self, exelist, version):
  658. if isinstance(exelist, str):
  659. self.exelist = [exelist]
  660. elif type(exelist) == type([]):
  661. self.exelist = exelist
  662. else:
  663. raise TypeError('Unknown argument to Vala compiler')
  664. self.version = version
  665. self.id = 'unknown'
  666. self.language = 'vala'
  667. def name_string(self):
  668. return ' '.join(self.exelist)
  669. def needs_static_linker(self):
  670. return False # Because compiles into C.
  671. def get_exelist(self):
  672. return self.exelist
  673. def get_werror_args(self):
  674. return ['--fatal-warnings']
  675. def get_language(self):
  676. return self.language
  677. def sanity_check(self, work_dir):
  678. src = 'valatest.vala'
  679. source_name = os.path.join(work_dir, src)
  680. ofile = open(source_name, 'w')
  681. ofile.write('''class SanityCheck : Object {
  682. }
  683. ''')
  684. ofile.close()
  685. pc = subprocess.Popen(self.exelist + ['-C', '-c', src], cwd=work_dir)
  686. pc.wait()
  687. if pc.returncode != 0:
  688. raise EnvironmentException('Vala compiler %s can not compile programs.' % self.name_string())
  689. def can_compile(self, filename):
  690. suffix = filename.split('.')[-1]
  691. return suffix in ('vala', 'vapi')
  692. class RustCompiler():
  693. def __init__(self, exelist, version):
  694. if isinstance(exelist, str):
  695. self.exelist = [exelist]
  696. elif type(exelist) == type([]):
  697. self.exelist = exelist
  698. else:
  699. raise TypeError('Unknown argument to Rust compiler')
  700. self.version = version
  701. self.id = 'unknown'
  702. self.language = 'rust'
  703. def needs_static_linker(self):
  704. return False
  705. def name_string(self):
  706. return ' '.join(self.exelist)
  707. def get_exelist(self):
  708. return self.exelist
  709. def get_id(self):
  710. return self.id
  711. def get_language(self):
  712. return self.language
  713. def sanity_check(self, work_dir):
  714. source_name = os.path.join(work_dir, 'sanity.rs')
  715. output_name = os.path.join(work_dir, 'rusttest')
  716. ofile = open(source_name, 'w')
  717. ofile.write('''fn main() {
  718. }
  719. ''')
  720. ofile.close()
  721. pc = subprocess.Popen(self.exelist + ['-o', output_name, source_name], cwd=work_dir)
  722. pc.wait()
  723. if pc.returncode != 0:
  724. raise EnvironmentException('Rust compiler %s can not compile programs.' % self.name_string())
  725. if subprocess.call(output_name) != 0:
  726. raise EnvironmentException('Executables created by Rust compiler %s are not runnable.' % self.name_string())
  727. def can_compile(self, fname):
  728. return fname.endswith('.rs')
  729. def get_dependency_gen_args(self, outfile):
  730. return ['--dep-info', outfile]
  731. def get_buildtype_args(self, buildtype):
  732. return rust_buildtype_args[buildtype]
  733. class VisualStudioCCompiler(CCompiler):
  734. std_warn_args = ['/W3']
  735. std_opt_args= ['/O2']
  736. vs2010_always_args = ['/nologo', '/showIncludes']
  737. vs2013_always_args = ['/nologo', '/showIncludes', '/FS']
  738. def __init__(self, exelist, version, is_cross, exe_wrap):
  739. CCompiler.__init__(self, exelist, version, is_cross, exe_wrap)
  740. self.id = 'msvc'
  741. if int(version.split('.')[0]) > 17:
  742. self.always_args = VisualStudioCCompiler.vs2013_always_args
  743. else:
  744. self.always_args = VisualStudioCCompiler.vs2010_always_args
  745. def get_always_args(self):
  746. return self.always_args
  747. def get_std_warn_args(self):
  748. return self.std_warn_args
  749. def get_buildtype_args(self, buildtype):
  750. return msvc_buildtype_args[buildtype]
  751. def get_buildtype_linker_args(self, buildtype):
  752. return msvc_buildtype_linker_args[buildtype]
  753. def get_pch_suffix(self):
  754. return 'pch'
  755. def get_pch_name(self, header):
  756. chopped = os.path.split(header)[-1].split('.')[:-1]
  757. chopped.append(self.get_pch_suffix())
  758. pchname = '.'.join(chopped)
  759. return pchname
  760. def get_pch_use_args(self, pch_dir, header):
  761. base = os.path.split(header)[-1]
  762. pchname = self.get_pch_name(header)
  763. return ['/FI' + base, '/Yu' + base, '/Fp' + os.path.join(pch_dir, pchname)]
  764. def get_compile_only_args(self):
  765. return ['/c']
  766. def get_output_args(self, target):
  767. if target.endswith('.exe'):
  768. return ['/Fe' + target]
  769. return ['/Fo' + target]
  770. def get_dependency_gen_args(self, outtarget, outfile):
  771. return []
  772. def get_linker_exelist(self):
  773. return ['link'] # FIXME, should have same path as compiler.
  774. def get_linker_always_args(self):
  775. return ['/nologo']
  776. def get_linker_output_args(self, outputname):
  777. return ['/OUT:' + outputname]
  778. def get_pic_args(self):
  779. return ['/LD']
  780. def get_std_shared_lib_link_args(self):
  781. return ['/DLL']
  782. def gen_pch_args(self, header, source, pchname):
  783. objname = os.path.splitext(pchname)[0] + '.obj'
  784. return (objname, ['/Yc' + header, '/Fp' + pchname, '/Fo' + objname ])
  785. def sanity_check(self, work_dir):
  786. source_name = 'sanitycheckc.c'
  787. binary_name = 'sanitycheckc'
  788. ofile = open(os.path.join(work_dir, source_name), 'w')
  789. ofile.write('int main(int argc, char **argv) { return 0; }\n')
  790. ofile.close()
  791. pc = subprocess.Popen(self.exelist + [source_name, '/Fe' + binary_name],
  792. stdout=subprocess.DEVNULL,
  793. stderr=subprocess.DEVNULL,
  794. cwd=work_dir)
  795. pc.wait()
  796. if pc.returncode != 0:
  797. raise EnvironmentException('Compiler %s can not compile programs.' % self.name_string())
  798. pe = subprocess.Popen(os.path.join(work_dir, binary_name))
  799. pe.wait()
  800. if pe.returncode != 0:
  801. raise EnvironmentException('Executables created by C++ compiler %s are not runnable.' % self.name_string())
  802. def build_rpath_args(self, build_dir, rpath_paths, install_rpath):
  803. return []
  804. # FIXME, no idea what these should be.
  805. def thread_flags(self):
  806. return []
  807. def thread_link_flags(self):
  808. return []
  809. class VisualStudioCPPCompiler(VisualStudioCCompiler):
  810. def __init__(self, exelist, version, is_cross, exe_wrap):
  811. VisualStudioCCompiler.__init__(self, exelist, version, is_cross, exe_wrap)
  812. self.language = 'cpp'
  813. self.default_suffix = 'cpp'
  814. def can_compile(self, filename):
  815. suffix = filename.split('.')[-1]
  816. if suffix in cpp_suffixes:
  817. return True
  818. return False
  819. def sanity_check(self, work_dir):
  820. source_name = 'sanitycheckcpp.cpp'
  821. binary_name = 'sanitycheckcpp'
  822. ofile = open(os.path.join(work_dir, source_name), 'w')
  823. ofile.write('class BreakPlainC;int main(int argc, char **argv) { return 0; }\n')
  824. ofile.close()
  825. pc = subprocess.Popen(self.exelist + [source_name, '/Fe' + binary_name],
  826. stdout=subprocess.DEVNULL,
  827. stderr=subprocess.DEVNULL,
  828. cwd=work_dir)
  829. pc.wait()
  830. if pc.returncode != 0:
  831. raise EnvironmentException('Compiler %s can not compile programs.' % self.name_string())
  832. pe = subprocess.Popen(os.path.join(work_dir, binary_name))
  833. pe.wait()
  834. if pe.returncode != 0:
  835. raise EnvironmentException('Executables created by C++ compiler %s are not runnable.' % self.name_string())
  836. GCC_STANDARD = 0
  837. GCC_OSX = 1
  838. GCC_MINGW = 2
  839. def get_gcc_soname_args(gcc_type, shlib_name, path, soversion):
  840. if soversion is None:
  841. sostr = ''
  842. else:
  843. sostr = '.' + soversion
  844. if gcc_type == GCC_STANDARD:
  845. return ['-Wl,-soname,lib%s.so%s' % (shlib_name, sostr)]
  846. elif gcc_type == GCC_OSX:
  847. return ['-install_name', os.path.join(path, 'lib' + shlib_name + '.dylib')]
  848. else:
  849. raise RuntimeError('Not implemented yet.')
  850. class GnuCCompiler(CCompiler):
  851. old_warn = ['-Wall', '-pedantic', '-Winvalid-pch']
  852. new_warn = ['-Wall', '-Wpedantic', '-Winvalid-pch']
  853. def __init__(self, exelist, version, gcc_type, is_cross, exe_wrapper=None):
  854. CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper)
  855. self.id = 'gcc'
  856. self.gcc_type = gcc_type
  857. if mesonlib.version_compare(version, ">=4.9.0"):
  858. self.warn_args= GnuCCompiler.new_warn
  859. else:
  860. self.warn_args = GnuCCompiler.old_warn
  861. def get_always_args(self):
  862. return ['-pipe']
  863. def get_std_warn_args(self):
  864. return self.warn_args
  865. def get_buildtype_args(self, buildtype):
  866. return gnulike_buildtype_args[buildtype]
  867. def get_buildtype_linker_args(self, buildtype):
  868. return gnulike_buildtype_linker_args[buildtype]
  869. def get_pch_suffix(self):
  870. return 'gch'
  871. def split_shlib_to_parts(self, fname):
  872. return (os.path.split(fname)[0], fname)
  873. def get_soname_args(self, shlib_name, path, soversion):
  874. return get_gcc_soname_args(self.gcc_type, shlib_name, path, soversion)
  875. def can_compile(self, filename):
  876. return super().can_compile(filename) or filename.split('.')[-1].lower() == 's' # Gcc can do asm, too.
  877. class GnuObjCCompiler(ObjCCompiler):
  878. std_warn_args = ['-Wall', '-Wpedantic', '-Winvalid-pch']
  879. def __init__(self, exelist, version, is_cross, exe_wrapper=None):
  880. ObjCCompiler.__init__(self, exelist, version, is_cross, exe_wrapper)
  881. self.id = 'gcc'
  882. # Not really correct, but GNU objc is only used on non-OSX non-win. File a bug
  883. # if this breaks your use case.
  884. self.gcc_type = GCC_STANDARD
  885. def get_std_warn_args(self):
  886. return GnuObjCCompiler.std_warn_args
  887. def get_buildtype_args(self, buildtype):
  888. return gnulike_buildtype_args[buildtype]
  889. def get_buildtype_linker_args(self, buildtype):
  890. return gnulike_buildtype_linker_args[buildtype]
  891. def get_pch_suffix(self):
  892. return 'gch'
  893. def get_soname_args(self, shlib_name, path, soversion):
  894. return get_gcc_soname_args(self.gcc_type, shlib_name, path, soversion)
  895. class GnuObjCPPCompiler(ObjCPPCompiler):
  896. std_warn_args = ['-Wall', '-Wpedantic', '-Winvalid-pch']
  897. std_opt_args = ['-O2']
  898. def __init__(self, exelist, version, is_cross, exe_wrapper=None):
  899. ObjCCompiler.__init__(self, exelist, version, is_cross, exe_wrapper)
  900. self.id = 'gcc'
  901. # Not really correct, but GNU objc is only used on non-OSX non-win. File a bug
  902. # if this breaks your use case.
  903. self.gcc_type = GCC_STANDARD
  904. def get_std_warn_args(self):
  905. return GnuObjCPPCompiler.std_warn_args
  906. def get_buildtype_args(self, buildtype):
  907. return gnulike_buildtype_args[buildtype]
  908. def get_buildtype_linker_args(self, buildtype):
  909. return gnulike_buildtype_linker_args[buildtype]
  910. def get_pch_suffix(self):
  911. return 'gch'
  912. def get_soname_args(self, shlib_name, path, soversion):
  913. return get_gcc_soname_args(self.gcc_type, shlib_name, path, soversion)
  914. class ClangObjCCompiler(GnuObjCCompiler):
  915. def __init__(self, exelist, version, is_cross, exe_wrapper=None):
  916. super().__init__(exelist, version, is_cross, exe_wrapper)
  917. self.id = 'clang'
  918. class ClangObjCPPCompiler(GnuObjCPPCompiler):
  919. def __init__(self, exelist, version, is_cross, exe_wrapper=None):
  920. super().__init__(exelist, version, is_cross, exe_wrapper)
  921. self.id = 'clang'
  922. class ClangCCompiler(CCompiler):
  923. std_warn_args = ['-Wall', '-Wpedantic', '-Winvalid-pch']
  924. def __init__(self, exelist, version, is_cross, exe_wrapper=None):
  925. CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper)
  926. self.id = 'clang'
  927. def get_std_warn_args(self):
  928. return ClangCCompiler.std_warn_args
  929. def get_buildtype_args(self, buildtype):
  930. return gnulike_buildtype_args[buildtype]
  931. def get_buildtype_linker_args(self, buildtype):
  932. return gnulike_buildtype_linker_args[buildtype]
  933. def get_pch_suffix(self):
  934. return 'pch'
  935. def can_compile(self, filename):
  936. return super().can_compile(filename) or filename.split('.')[-1].lower() == 's' # Clang can do asm, too.
  937. def get_pch_use_args(self, pch_dir, header):
  938. # Workaround for Clang bug http://llvm.org/bugs/show_bug.cgi?id=15136
  939. # This flag is internal to Clang (or at least not documented on the man page)
  940. # so it might change semantics at any time.
  941. return ['-include-pch', os.path.join (pch_dir, self.get_pch_name (header))]
  942. class GnuCPPCompiler(CPPCompiler):
  943. new_warn = ['-Wall', '-Wpedantic', '-Winvalid-pch', '-Wnon-virtual-dtor']
  944. old_warn = ['-Wall', '-pedantic', '-Winvalid-pch', '-Wnon-virtual-dtor']
  945. # may need to separate the latter to extra_debug_args or something
  946. std_debug_args = ['-g']
  947. def __init__(self, exelist, version, gcc_type, is_cross, exe_wrap):
  948. CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrap)
  949. self.id = 'gcc'
  950. self.gcc_type = gcc_type
  951. if mesonlib.version_compare(version, ">=4.9.0"):
  952. self.warn_args= GnuCPPCompiler.new_warn
  953. else:
  954. self.warn_args = GnuCPPCompiler.old_warn
  955. def get_always_args(self):
  956. return ['-pipe']
  957. def get_std_warn_args(self):
  958. return self.warn_args
  959. def get_buildtype_args(self, buildtype):
  960. return gnulike_buildtype_args[buildtype]
  961. def get_buildtype_linker_args(self, buildtype):
  962. return gnulike_buildtype_linker_args[buildtype]
  963. def get_pch_suffix(self):
  964. return 'gch'
  965. def get_soname_args(self, shlib_name, path, soversion):
  966. return get_gcc_soname_args(self.gcc_type, shlib_name, path, soversion)
  967. class ClangCPPCompiler(CPPCompiler):
  968. std_warn_args = ['-Wall', '-Wpedantic', '-Winvalid-pch', '-Wnon-virtual-dtor']
  969. def __init__(self, exelist, version, is_cross, exe_wrapper=None):
  970. CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrapper)
  971. self.id = 'clang'
  972. def get_std_warn_args(self):
  973. return ClangCPPCompiler.std_warn_args
  974. def get_buildtype_args(self, buildtype):
  975. return gnulike_buildtype_args[buildtype]
  976. def get_buildtype_linker_args(self, buildtype):
  977. return gnulike_buildtype_linker_args[buildtype]
  978. def get_pch_suffix(self):
  979. return 'pch'
  980. def get_pch_use_args(self, pch_dir, header):
  981. # Workaround for Clang bug http://llvm.org/bugs/show_bug.cgi?id=15136
  982. # This flag is internal to Clang (or at least not documented on the man page)
  983. # so it might change semantics at any time.
  984. return ['-include-pch', os.path.join (pch_dir, self.get_pch_name (header))]
  985. class FortranCompiler():
  986. std_warn_args = ['-Wall']
  987. def __init__(self, exelist, version,is_cross, exe_wrapper=None):
  988. super().__init__()
  989. self.exelist = exelist
  990. self.version = version
  991. self.is_cross = is_cross
  992. self.exe_wrapper = exe_wrapper
  993. self.language = 'fortran'
  994. # Not really correct but I don't have Fortran compilers to test with. Sorry.
  995. self.gcc_type = GCC_STANDARD
  996. self.id = "IMPLEMENTATION CLASSES MUST SET THIS"
  997. def get_id(self):
  998. return self.id
  999. def name_string(self):
  1000. return ' '.join(self.exelist)
  1001. def get_exelist(self):
  1002. return self.exelist
  1003. def get_language(self):
  1004. return self.language
  1005. def needs_static_linker(self):
  1006. return True
  1007. def sanity_check(self, work_dir):
  1008. source_name = os.path.join(work_dir, 'sanitycheckf.f90')
  1009. binary_name = os.path.join(work_dir, 'sanitycheckf')
  1010. ofile = open(source_name, 'w')
  1011. ofile.write('''program prog
  1012. print *, "Fortran compilation is working."
  1013. end program prog
  1014. ''')
  1015. ofile.close()
  1016. pc = subprocess.Popen(self.exelist + [source_name, '-o', binary_name])
  1017. pc.wait()
  1018. if pc.returncode != 0:
  1019. raise EnvironmentException('Compiler %s can not compile programs.' % self.name_string())
  1020. if self.is_cross:
  1021. if self.exe_wrapper is None:
  1022. # Can't check if the binaries run so we have to assume they do
  1023. return
  1024. cmdlist = self.exe_wrapper + [binary_name]
  1025. else:
  1026. cmdlist = [binary_name]
  1027. pe = subprocess.Popen(cmdlist, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
  1028. pe.wait()
  1029. if pe.returncode != 0:
  1030. raise EnvironmentException('Executables created by Fortran compiler %s are not runnable.' % self.name_string())
  1031. def get_always_args(self):
  1032. return ['-pipe']
  1033. def get_linker_always_args(self):
  1034. return []
  1035. def get_std_warn_args(self):
  1036. return FortranCompiler.std_warn_args
  1037. def get_buildtype_args(self, buildtype):
  1038. return gnulike_buildtype_args[buildtype]
  1039. def get_buildtype_linker_args(self, buildtype):
  1040. return gnulike_buildtype_linker_args[buildtype]
  1041. def split_shlib_to_parts(self, fname):
  1042. return (os.path.split(fname)[0], fname)
  1043. def get_soname_args(self, shlib_name, path, soversion):
  1044. return get_gcc_soname_args(self.gcc_type, shlib_name, path, soversion)
  1045. def get_dependency_gen_args(self, outtarget, outfile):
  1046. # Disabled until this is fixed:
  1047. # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62162
  1048. #return ['-cpp', '-MMD', '-MQ', outtarget]
  1049. return []
  1050. def get_output_args(self, target):
  1051. return ['-o', target]
  1052. def get_compile_only_args(self):
  1053. return ['-c']
  1054. def get_linker_exelist(self):
  1055. return self.exelist[:]
  1056. def get_linker_output_args(self, outputname):
  1057. return ['-o', outputname]
  1058. def can_compile(self, src):
  1059. if hasattr(src, 'fname'):
  1060. src = src.fname
  1061. suffix = os.path.splitext(src)[1].lower()
  1062. if suffix == '.f' or suffix == '.f95' or suffix == '.f90':
  1063. return True
  1064. return False
  1065. def get_include_args(self, path):
  1066. return ['-I' + path]
  1067. def get_module_outdir_args(self, path):
  1068. return ['-J' + path]
  1069. def get_depfile_suffix(self):
  1070. return 'd'
  1071. def get_std_exe_link_args(self):
  1072. return []
  1073. def build_rpath_args(self, build_dir, rpath_paths, install_rpath):
  1074. return build_unix_rpath_args(build_dir, rpath_paths, install_rpath)
  1075. def module_name_to_filename(self, module_name):
  1076. return module_name.lower() + '.mod'
  1077. class GnuFortranCompiler(FortranCompiler):
  1078. def __init__(self, exelist, version, gcc_type, is_cross, exe_wrapper=None):
  1079. super().__init__(exelist, version, is_cross, exe_wrapper=None)
  1080. self.gcc_type = gcc_type
  1081. self.id = 'gcc'
  1082. class G95FortranCompiler(FortranCompiler):
  1083. def __init__(self, exelist, version, is_cross, exe_wrapper=None):
  1084. super().__init__(exelist, version, is_cross, exe_wrapper=None)
  1085. self.id = 'g95'
  1086. def get_module_outdir_args(self, path):
  1087. return ['-fmod='+path]
  1088. class SunFortranCompiler(FortranCompiler):
  1089. def __init__(self, exelist, version, is_cross, exe_wrapper=None):
  1090. super().__init__(exelist, version, is_cross, exe_wrapper=None)
  1091. self.id = 'sun'
  1092. def get_dependency_gen_args(self, outtarget, outfile):
  1093. return ['-fpp']
  1094. def get_always_args(self):
  1095. return []
  1096. def get_std_warn_args(self):
  1097. return []
  1098. def get_module_outdir_args(self, path):
  1099. return ['-moddir='+path]
  1100. class IntelFortranCompiler(FortranCompiler):
  1101. std_warn_args = ['-warn', 'all']
  1102. def __init__(self, exelist, version, is_cross, exe_wrapper=None):
  1103. super().__init__(exelist, version, is_cross, exe_wrapper=None)
  1104. self.id = 'intel'
  1105. def get_module_outdir_args(self, path):
  1106. return ['-module', path]
  1107. def get_always_args(self):
  1108. return []
  1109. def can_compile(self, src):
  1110. suffix = os.path.splitext(src)[1].lower()
  1111. if suffix == '.f' or suffix == '.f90':
  1112. return True
  1113. return False
  1114. def get_std_warn_args(self):
  1115. return IntelFortranCompiler.std_warn_args
  1116. class PathScaleFortranCompiler(FortranCompiler):
  1117. std_warn_args = ['-fullwarn']
  1118. def __init__(self, exelist, version, is_cross, exe_wrapper=None):
  1119. super().__init__(exelist, version, is_cross, exe_wrapper=None)
  1120. self.id = 'pathscale'
  1121. def get_module_outdir_args(self, path):
  1122. return ['-module', path]
  1123. def get_always_args(self):
  1124. return []
  1125. def can_compile(self, src):
  1126. suffix = os.path.splitext(src)[1].lower()
  1127. if suffix == '.f' or suffix == '.f90' or suffix == '.f95':
  1128. return True
  1129. return False
  1130. def get_std_warn_args(self):
  1131. return PathScaleFortranCompiler.std_warn_args
  1132. class PGIFortranCompiler(FortranCompiler):
  1133. std_warn_args = ['-Minform=inform']
  1134. def __init__(self, exelist, version, is_cross, exe_wrapper=None):
  1135. super().__init__(exelist, version, is_cross, exe_wrapper=None)
  1136. self.id = 'pgi'
  1137. def get_module_outdir_args(self, path):
  1138. return ['-module', path]
  1139. def get_always_args(self):
  1140. return []
  1141. def can_compile(self, src):
  1142. suffix = os.path.splitext(src)[1].lower()
  1143. if suffix == '.f' or suffix == '.f90' or suffix == '.f95':
  1144. return True
  1145. return False
  1146. def get_std_warn_args(self):
  1147. return PGIFortranCompiler.std_warn_args
  1148. class Open64FortranCompiler(FortranCompiler):
  1149. std_warn_args = ['-fullwarn']
  1150. def __init__(self, exelist, version, is_cross, exe_wrapper=None):
  1151. super().__init__(exelist, version, is_cross, exe_wrapper=None)
  1152. self.id = 'open64'
  1153. def get_module_outdir_args(self, path):
  1154. return ['-module', path]
  1155. def get_always_args(self):
  1156. return []
  1157. def can_compile(self, src):
  1158. suffix = os.path.splitext(src)[1].lower()
  1159. if suffix == '.f' or suffix == '.f90' or suffix == '.f95':
  1160. return True
  1161. return False
  1162. def get_std_warn_args(self):
  1163. return Open64FortranCompiler.std_warn_args
  1164. class NAGFortranCompiler(FortranCompiler):
  1165. std_warn_args = []
  1166. def __init__(self, exelist, version, is_cross, exe_wrapper=None):
  1167. super().__init__(exelist, version, is_cross, exe_wrapper=None)
  1168. self.id = 'nagfor'
  1169. def get_module_outdir_args(self, path):
  1170. return ['-mdir', path]
  1171. def get_always_args(self):
  1172. return []
  1173. def can_compile(self, src):
  1174. suffix = os.path.splitext(src)[1].lower()
  1175. if suffix == '.f' or suffix == '.f90' or suffix == '.f95':
  1176. return True
  1177. return False
  1178. def get_std_warn_args(self):
  1179. return NAGFortranCompiler.std_warn_args
  1180. class VisualStudioLinker():
  1181. always_args = ['/NOLOGO']
  1182. def __init__(self, exelist):
  1183. self.exelist = exelist
  1184. def get_exelist(self):
  1185. return self.exelist
  1186. def get_std_link_args(self):
  1187. return []
  1188. def get_buildtype_linker_args(self, buildtype):
  1189. return []
  1190. def get_output_args(self, target):
  1191. return ['/OUT:' + target]
  1192. def get_coverage_link_args(self):
  1193. return []
  1194. def get_always_args(self):
  1195. return VisualStudioLinker.always_args
  1196. def get_linker_always_args(self):
  1197. return VisualStudioLinker.always_args
  1198. def build_rpath_args(self, build_dir, rpath_paths, install_rpath):
  1199. return []
  1200. def thread_link_flags(self):
  1201. return []
  1202. class ArLinker():
  1203. std_args = ['csr']
  1204. def __init__(self, exelist):
  1205. self.exelist = exelist
  1206. self.id = 'ar'
  1207. def build_rpath_args(self, build_dir, rpath_paths, install_rpath):
  1208. return []
  1209. def get_exelist(self):
  1210. return self.exelist
  1211. def get_std_link_args(self):
  1212. return self.std_args
  1213. def get_output_args(self, target):
  1214. return [target]
  1215. def get_buildtype_linker_args(self, buildtype):
  1216. return []
  1217. def get_linker_always_args(self):
  1218. return []
  1219. def get_coverage_link_args(self):
  1220. return []
  1221. def get_always_args(self):
  1222. return []
  1223. def thread_link_flags(self):
  1224. return []