makebuildscripts.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/env python
  2. # Create the scripts that define linker flags needed for running an app under Graphite.
  3. import sys, os, subprocess
  4. sim_root, pin_home, cc, cxx, arch = sys.argv[1:]
  5. # Needed for sim_api.h
  6. includes = '-I${SNIPER_ROOT}/include'
  7. if arch == 'intel64':
  8. arch_cflags = ''
  9. arch_ldflags = ''
  10. elif arch == 'ia32':
  11. arch_cflags = '-m32'
  12. arch_ldflags = '-m32'
  13. else:
  14. raise ValueError('Unknown architecture %s' % arch)
  15. def determine_valid_flags(archname):
  16. possible_flags = ['-mno-sse4', '-mno-sse4.1', '-mno-sse4.2', '-mno-sse4a', '-mno-avx', '-mno-avx2']
  17. # Add additional flags to enable sse on 32-bit machines
  18. if archname == 'ia32':
  19. possible_flags = ['-mfpmath=sse', '-msse', '-msse2'] + possible_flags
  20. valid_flags = []
  21. for flag in possible_flags:
  22. rc = subprocess.call([cc,'-x','c','-c','/dev/null','-o','/dev/null',flag], stdout=open('/dev/null', 'w'), stderr=subprocess.STDOUT)
  23. if rc == 0:
  24. valid_flags.append(flag)
  25. return ' '.join(valid_flags)
  26. extra_cflags = determine_valid_flags(arch)
  27. flags = {}
  28. for f in ('SNIPER', 'GRAPHITE'):
  29. flags['%s_CFLAGS'%f] = '%(extra_cflags)s %(includes)s %(arch_cflags)s' % locals()
  30. flags['%s_CXXFLAGS'%f] = '%(extra_cflags)s %(includes)s %(arch_cflags)s' % locals()
  31. flags['%s_LDFLAGS'%f] = '-static -L${SNIPER_ROOT}/lib -pthread %(arch_ldflags)s' % locals()
  32. flags['%s_LD_LIBRARY_PATH'%f] = ''
  33. flags['%s_CC'%f] = cc
  34. flags['%s_CXX'%f] = cxx
  35. flags['%s_LD'%f] = cxx
  36. flags['PIN_HOME'] = pin_home
  37. upcc_link = ('%(SNIPER_CXX)s %(SNIPER_LDFLAGS)s' % flags).strip()
  38. for f in ('SNIPER', 'GRAPHITE'):
  39. flags['%s_UPCCFLAGS'%f] = "%(includes)s %(arch_cflags)s -link-with='%(upcc_link)s'" % locals()
  40. message = '# This file is auto-generated, changes made to it will be lost. Please edit %s instead.' % os.path.basename(__file__)
  41. env_check_sh = 'if [ -z "${SNIPER_ROOT}" ] ; then SNIPER_ROOT=$(readlink -f "$(dirname "${BASH_SOURCE[0]}")/..") ; fi'
  42. env_check_make = 'SELF_DIR := $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))\nSNIPER_ROOT ?= $(shell readlink -f $(SELF_DIR)/..)'
  43. file('config/buildconf.sh', 'w').write('\n'.join(
  44. [ message, '' ] +
  45. [ env_check_sh, '' ] +
  46. [ '%s="%s"' % i for i in sorted(flags.items(),key=lambda x:x[0]) ]
  47. ) + '\n')
  48. file('config/buildconf.makefile', 'w').write('\n'.join(
  49. [ message, '' ] +
  50. [ env_check_make, '' ] +
  51. [ '%s:=%s' % i for i in sorted(flags.items(),key=lambda x:x[0]) ]
  52. ) + '\n')