buildglibc.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/usr/bin/env python3
  2. import os
  3. import shutil
  4. import subprocess
  5. import sys
  6. def prependText(filename, text) :
  7. data = ""
  8. with open(filename, 'r') as original:
  9. data = original.read()
  10. with open(filename, 'w') as modified:
  11. modified.write(text)
  12. modified.write(data)
  13. def appendText(filename, text) :
  14. with open(filename, "a") as myfile:
  15. myfile.write(text)
  16. home = os.getcwd()
  17. glibc = "glibc-2.19"
  18. glibcParent = "" # glibc parent directory
  19. glibcDir = "" # glibc dir (ex. glibc-2.19)
  20. buildDir = "glibc-build"
  21. installDir = os.path.dirname(home) + '/Runtime/'
  22. commandStr = ""
  23. commandOutput = ""
  24. quiet = False
  25. debug_flags = ""
  26. for arg in sys.argv[1:]:
  27. if arg == '--quiet' or arg == '-q':
  28. quiet = True
  29. if arg == '--debug':
  30. debug_flags = "-g"
  31. if True:
  32. #########################################
  33. #### get the locations of directories ###
  34. #########################################
  35. if not quiet:
  36. iput = input('use {0} as the source of GNU libc? ([y]/n):'.format(glibc)).lower()
  37. if not iput == 'y' and not iput == '' :
  38. glibc = input('enter the glibc source to install with: ')
  39. if not quiet:
  40. iput = input('{0} contains glibc code to compile? ([y]/n): '.format(glibc)).lower()
  41. if not iput == 'y' and not iput == '':
  42. glibc = input('directory containing glibc code to compile: ')
  43. if os.path.isdir(glibc) :
  44. glibc = os.path.abspath(glibc)
  45. glibcParent,glibcDir = os.path.split(glibc)
  46. print('building in {0}: {1}'.format(glibcParent, glibcDir))
  47. if not quiet:
  48. iput = input('use {0} as the directory to build glibc in? ([y]/n): '.format(buildDir)).lower()
  49. if not iput == 'y' and not iput == '':
  50. buildDir = input('the directory to build glibc in: ')
  51. buildDir = os.path.abspath(buildDir)
  52. print('using build dir: {0}'.format(buildDir))
  53. if os.path.isdir(buildDir) :
  54. if not quiet:
  55. clean = input('clean build (delete {0}, rerun configure, etc.)? ([y]/n): '.format(buildDir))
  56. else:
  57. clean = 'y'
  58. if clean == 'y' or clean == '':
  59. shutil.rmtree(buildDir)
  60. os.makedirs(buildDir)
  61. else :
  62. print('Then just go to {0} and type make...'.format(buildDir))
  63. exit(0)
  64. else :
  65. os.makedirs(buildDir)
  66. if not quiet:
  67. iput = input('use {0} as the directory to install glibc in? ([y]/n): '.format(installDir)).lower()
  68. if not iput == 'y' and not iput == '':
  69. installDir = input('the directory to install glibc in: ')
  70. installDir = os.path.abspath(installDir)
  71. print('using install dir: {0}'.format(installDir))
  72. if True:
  73. ################################
  74. #### doctor glibc's Makefile ###
  75. ################################
  76. os.chdir(buildDir)
  77. cflags = '{0} -O2 -U_FORTIFY_SOURCE -fno-stack-protector -Wno-unused-value'.format(debug_flags)
  78. extra_defs = ''
  79. disabled_features = { 'nscd' }
  80. extra_flags = '--with-tls --enable-add-ons=nptl --without-selinux --disable-test {0}'.format(' '.join(['--disable-' + f for f in disabled_features]))
  81. ## configure
  82. commandStr = r'CFLAGS="{2}" {3} {0}/configure --prefix={1} {4} | tee configure.out'.format(glibc, installDir, cflags, extra_defs, extra_flags)
  83. print(commandStr)
  84. commandOutput = subprocess.call(commandStr, shell=True)