SConstruct 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # -*- mode: Python -*-
  2. # -*- coding: utf-8 -*-
  3. # (c) Daniel Llorens - 2015-2016
  4. # This library is free software; you can redistribute it and/or modify it under
  5. # the terms of the GNU Lesser General Public License as published by the Free
  6. # Software Foundation; either version 3 of the License, or (at your option) any
  7. # later version.
  8. # SConstruct for ra/examples
  9. # FIXME Shared pieces with {test,bench,doc}/SConstruct
  10. import os, string, atexit
  11. from colorama import Fore, Back, Style
  12. from os.path import join, abspath
  13. import imp
  14. ra = imp.load_source('ra', '../ra.py')
  15. # FIXME pick BLAS flags from here.
  16. try:
  17. Import('top')
  18. except:
  19. top = {}
  20. vars = Variables()
  21. vars.AddVariables(PathVariable('variant_dir', 'build directory', '.', PathVariable.PathIsDirCreate))
  22. env = Environment(options=vars,
  23. ENV=dict([(k, os.environ[k] if k in os.environ else '')
  24. for k in ['PATH', 'HOME', 'TERM', 'LD_RUN_PATH', 'DYLD_LIBRARY_PATH',
  25. 'RPATH', 'LIBRARY_PATH', 'TEXINPUTS', 'GCC_COLORS', 'BOOST_ROOT',
  26. 'RA_USE_BLAS']]))
  27. variant_dir = env['variant_dir']
  28. for var, default in [('CC', 'gcc'), ('CXX', 'g++'), ('FORTRAN', 'gfortran')]:
  29. ra.take_from_environ(env, var, default=default)
  30. for var in ['FORTRANFLAGS', 'LINKFLAGS', 'CCFLAGS', 'CXXFLAGS']:
  31. ra.take_from_environ(env, var, wrapper=string.split)
  32. for var in ['RPATH', 'LIBPATH']:
  33. ra.take_from_environ(env, var, wrapper=lambda x: [x])
  34. arch = os.popen('../config.guess').read()
  35. if arch.find('86-apple-darwin') >= 0:
  36. archflags=['-march=native', '-Wa,-q']
  37. ld_blas = {'LINKFLAGS': ' -framework vecLib ', 'LIBS': []}
  38. else:
  39. archflags=['-march=native']
  40. ld_blas = {'LINKFLAGS': '', 'LIBS': ['blas']}
  41. env.Append(CPPPATH=['..', '.'],
  42. CCFLAGS=archflags if str(env['CCFLAGS']).strip()=='' else '',
  43. CXXFLAGS=['-std=c++1z', '-Wall', '-Werror', '-fdiagnostics-color=always', '-Wno-unknown-pragmas',
  44. '-finput-charset=UTF-8', '-fextended-identifiers',
  45. '-Wno-error=strict-overflow',
  46. #'-Wconversion',
  47. # '-funsafe-math-optimizations', # TODO Test with this.
  48. ])
  49. env_blas = env.Clone()
  50. if 'RA_USE_BLAS' in env['ENV'] and env['ENV']['RA_USE_BLAS']=='1':
  51. print("[%s] BLAS will be used." % Dir('.').path)
  52. env_blas.Append(CPPDEFINES={'RA_USE_BLAS': 1})
  53. env_blas.Append(LINKFLAGS=ld_blas['LINKFLAGS'])
  54. env_blas.Append(LIBS=ld_blas['LIBS'])
  55. else:
  56. print("[%s] BLAS won't be used." % Dir('.').path)
  57. if 'skip_summary' not in top:
  58. atexit.register(lambda: ra.print_summary(GetBuildFailures, 'ra/examples'))
  59. [ra.to_test_ra(env, variant_dir)(example)
  60. for example in ['view', 'outer', 'slicing', 'where', 'rangexpr', 'useret', 'deriv',
  61. 'indirect', 'cast', 'nested', 'agreement', 'small',
  62. 'readme', 'explode-collapse',
  63. 'newton', 'maxwell', 'laplace2d', 'laplace3d']]