setup.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2019 The MMGen Project <mmgen@tuta.io>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. import sys,os,subprocess
  19. from shutil import copy2
  20. ver = sys.version_info[:2]
  21. min_ver = (3,5)
  22. if ver[0] < min_ver[0] or ver[1] < min_ver[1]:
  23. m = '{}.{}: wrong Python version. MMGen requires Python {M}.{m} or greater\n'
  24. sys.stderr.write(m.format(*ver,M=min_ver[0],m=min_ver[1]))
  25. sys.exit(1)
  26. _gvi = subprocess.check_output(['gcc','--version']).decode().splitlines()[0]
  27. have_mingw64 = 'x86_64' in _gvi and 'MinGW' in _gvi
  28. have_arm = subprocess.check_output(['uname','-m']).strip() == 'aarch64'
  29. # Zipfile module under Windows (MinGW) can't handle UTF-8 filenames.
  30. # Move it so that distutils will use the 'zip' utility instead.
  31. def divert_zipfile_module():
  32. msg1 = 'Unable to divert zipfile module. UTF-8 filenames may be broken in the Python archive.'
  33. def return_warn(m):
  34. sys.stderr.write('WARNING: {}\n'.format(m))
  35. return False
  36. dirname = os.path.dirname(sys.modules['os'].__file__)
  37. if not dirname: return return_warn(msg1)
  38. stem = os.path.join(dirname,'zipfile')
  39. a,b = stem+'.py',stem+'-is-broken.py'
  40. try: os.stat(a)
  41. except: return
  42. try:
  43. sys.stderr.write('moving {} -> {}\n'.format(a,b))
  44. os.rename(a,b)
  45. except:
  46. return return_warn(msg1)
  47. else:
  48. try:
  49. os.unlink(stem+'.pyc')
  50. os.unlink(stem+'.pyo')
  51. except:
  52. pass
  53. if have_mingw64:
  54. # import zipfile
  55. # sys.exit()
  56. divert_zipfile_module()
  57. from distutils.core import setup,Extension
  58. from distutils.command.build_ext import build_ext
  59. from distutils.command.install_data import install_data
  60. # install extension module in repository after building
  61. class my_build_ext(build_ext):
  62. def build_extension(self,ext):
  63. build_ext.build_extension(self,ext)
  64. ext_src = self.get_ext_fullpath(ext.name)
  65. ext_dest = os.path.join('mmgen','secp256k1.so')
  66. try: os.unlink(ext_dest)
  67. except: pass
  68. os.chmod(ext_src,0o755)
  69. print('copying {} to {}'.format(ext_src,ext_dest))
  70. copy2(ext_src,ext_dest)
  71. class my_install_data(install_data):
  72. def run(self):
  73. for f in 'mmgen.cfg','mnemonic.py','mn_wordlist.c':
  74. os.chmod(os.path.join('data_files',f),0o644)
  75. install_data.run(self)
  76. module1 = Extension(
  77. name = 'mmgen.secp256k1',
  78. sources = ['extmod/secp256k1mod.c'],
  79. libraries = ['secp256k1'],
  80. library_dirs = ['/usr/local/lib',r'c:\msys\local\lib'],
  81. # mingw32 needs this, Linux can use it, but it breaks mingw64
  82. extra_link_args = (['-lgmp'],[])[have_mingw64],
  83. include_dirs = ['/usr/local/include',r'c:\msys\local\include'],
  84. )
  85. from mmgen.globalvars import g
  86. setup(
  87. name = 'mmgen',
  88. description = 'A complete Bitcoin offline/online wallet solution for the command line',
  89. version = g.version,
  90. author = g.author,
  91. author_email = g.email,
  92. url = g.proj_url,
  93. license = 'GNU GPL v3',
  94. platforms = 'Linux, MS Windows, Raspberry Pi/Raspbian, Orange Pi/Armbian',
  95. keywords = g.keywords,
  96. cmdclass = { 'build_ext': my_build_ext, 'install_data': my_install_data },
  97. ext_modules = [module1],
  98. data_files = [('share/mmgen', [
  99. 'data_files/mmgen.cfg', # source files must have 0644 mode
  100. 'data_files/mn_wordlist.c',
  101. 'data_files/mnemonic.py'
  102. ]),],
  103. py_modules = [
  104. 'mmgen.__init__',
  105. 'mmgen.addr',
  106. 'mmgen.altcoin',
  107. 'mmgen.bech32',
  108. 'mmgen.color',
  109. 'mmgen.common',
  110. 'mmgen.crypto',
  111. 'mmgen.ed25519',
  112. 'mmgen.ed25519ll_djbec',
  113. 'mmgen.exception',
  114. 'mmgen.filename',
  115. 'mmgen.globalvars',
  116. 'mmgen.license',
  117. 'mmgen.mn_electrum',
  118. 'mmgen.mn_tirosh',
  119. 'mmgen.obj',
  120. 'mmgen.opts',
  121. 'mmgen.protocol',
  122. 'mmgen.regtest',
  123. 'mmgen.rpc',
  124. 'mmgen.seed',
  125. 'mmgen.sha256',
  126. 'mmgen.term',
  127. 'mmgen.test',
  128. 'mmgen.tool',
  129. 'mmgen.tw',
  130. 'mmgen.tx',
  131. 'mmgen.util',
  132. 'mmgen.altcoins.__init__',
  133. 'mmgen.altcoins.eth.__init__',
  134. 'mmgen.altcoins.eth.contract',
  135. 'mmgen.altcoins.eth.obj',
  136. 'mmgen.altcoins.eth.tx',
  137. 'mmgen.altcoins.eth.tw',
  138. 'mmgen.main',
  139. 'mmgen.main_addrgen',
  140. 'mmgen.main_addrimport',
  141. 'mmgen.main_autosign',
  142. 'mmgen.main_passgen',
  143. 'mmgen.main_regtest',
  144. 'mmgen.main_split',
  145. 'mmgen.main_tool',
  146. 'mmgen.main_txbump',
  147. 'mmgen.main_txcreate',
  148. 'mmgen.main_txdo',
  149. 'mmgen.main_txsend',
  150. 'mmgen.main_txsign',
  151. 'mmgen.main_wallet',
  152. 'mmgen.txsign',
  153. 'mmgen.share.__init__',
  154. 'mmgen.share.Opts',
  155. ],
  156. scripts = [
  157. 'cmds/mmgen-addrgen',
  158. 'cmds/mmgen-keygen',
  159. 'cmds/mmgen-passgen',
  160. 'cmds/mmgen-addrimport',
  161. 'cmds/mmgen-passchg',
  162. 'cmds/mmgen-regtest',
  163. 'cmds/mmgen-walletchk',
  164. 'cmds/mmgen-walletconv',
  165. 'cmds/mmgen-walletgen',
  166. 'cmds/mmgen-split',
  167. 'cmds/mmgen-txcreate',
  168. 'cmds/mmgen-txbump',
  169. 'cmds/mmgen-txsign',
  170. 'cmds/mmgen-txsend',
  171. 'cmds/mmgen-txdo',
  172. 'cmds/mmgen-tool',
  173. 'cmds/mmgen-autosign'
  174. ]
  175. )