setup.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. #!/usr/bin/env python
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2018 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. _gvi = subprocess.check_output(['gcc','--version']).splitlines()[0]
  21. have_mingw64 = 'x86_64' in _gvi and 'MinGW' in _gvi
  22. have_arm = subprocess.check_output(['uname','-m']).strip() == 'aarch64'
  23. # Zipfile module under Windows (MinGW) can't handle UTF-8 filenames.
  24. # Move it so that distutils will use the 'zip' utility instead.
  25. def divert_zipfile_module():
  26. msg1 = 'Unable to divert zipfile module. UTF-8 filenames may be broken in the Python archive.'
  27. def return_warn(m):
  28. sys.stderr.write('WARNING: {}\n'.format(m))
  29. return False
  30. dirname = os.path.dirname(sys.modules['os'].__file__)
  31. if not dirname: return return_warn(msg1)
  32. stem = os.path.join(dirname,'zipfile')
  33. a,b = stem+'.py',stem+'-is-broken.py'
  34. try: os.stat(a)
  35. except: return
  36. try:
  37. sys.stderr.write('moving {} -> {}\n'.format(a,b))
  38. os.rename(a,b)
  39. except:
  40. return return_warn(msg1)
  41. else:
  42. try:
  43. os.unlink(stem+'.pyc')
  44. os.unlink(stem+'.pyo')
  45. except:
  46. pass
  47. if have_mingw64:
  48. # import zipfile
  49. # sys.exit()
  50. divert_zipfile_module()
  51. from distutils.core import setup,Extension
  52. from distutils.command.build_ext import build_ext
  53. from distutils.command.install_data import install_data
  54. # install extension module in repository after building
  55. class my_build_ext(build_ext):
  56. def build_extension(self,ext):
  57. build_ext.build_extension(self,ext)
  58. ext_src = self.get_ext_fullpath(ext.name)
  59. ext_dest = self.get_ext_filename(ext.name)
  60. try: os.unlink(ext_dest)
  61. except: pass
  62. os.chmod(ext_src,0755)
  63. print 'copying %s to %s' % (ext_src,ext_dest)
  64. copy2(ext_src,ext_dest)
  65. class my_install_data(install_data):
  66. def run(self):
  67. for f in 'mmgen.cfg','mnemonic.py','mn_wordlist.c':
  68. os.chmod(os.path.join('data_files',f),0644)
  69. install_data.run(self)
  70. module1 = Extension(
  71. name = 'mmgen.secp256k1',
  72. sources = ['extmod/secp256k1mod.c'],
  73. libraries = ['secp256k1'],
  74. library_dirs = ['/usr/local/lib',r'c:\msys\local\lib'],
  75. # mingw32 needs this, Linux can use it, but it breaks mingw64
  76. extra_link_args = (['-lgmp'],[])[have_mingw64],
  77. include_dirs = ['/usr/local/include',r'c:\msys\local\include'],
  78. )
  79. from mmgen.globalvars import g
  80. setup(
  81. name = 'mmgen',
  82. description = 'A complete Bitcoin offline/online wallet solution for the command line',
  83. version = g.version,
  84. author = g.author,
  85. author_email = g.email,
  86. url = g.proj_url,
  87. license = 'GNU GPL v3',
  88. platforms = 'Linux, MS Windows, Raspberry Pi/Raspbian, Orange Pi/Armbian',
  89. keywords = g.keywords,
  90. cmdclass = { 'build_ext': my_build_ext, 'install_data': my_install_data },
  91. ext_modules = [module1],
  92. data_files = [('share/mmgen', [
  93. 'data_files/mmgen.cfg', # source files must have 0644 mode
  94. 'data_files/mn_wordlist.c',
  95. 'data_files/mnemonic.py'
  96. ]),],
  97. py_modules = [
  98. 'mmgen.__init__',
  99. 'mmgen.addr',
  100. 'mmgen.altcoin',
  101. 'mmgen.bech32',
  102. 'mmgen.protocol',
  103. 'mmgen.color',
  104. 'mmgen.common',
  105. 'mmgen.crypto',
  106. 'mmgen.ed25519',
  107. 'mmgen.filename',
  108. 'mmgen.globalvars',
  109. 'mmgen.license',
  110. 'mmgen.mn_electrum',
  111. 'mmgen.mn_tirosh',
  112. 'mmgen.obj',
  113. 'mmgen.opts',
  114. 'mmgen.regtest',
  115. 'mmgen.rpc',
  116. 'mmgen.seed',
  117. 'mmgen.sha256',
  118. 'mmgen.term',
  119. 'mmgen.test',
  120. 'mmgen.tool',
  121. 'mmgen.tw',
  122. 'mmgen.tx',
  123. 'mmgen.util',
  124. 'mmgen.main',
  125. 'mmgen.main_addrgen',
  126. 'mmgen.main_addrimport',
  127. 'mmgen.main_autosign',
  128. 'mmgen.main_passgen',
  129. 'mmgen.main_regtest',
  130. 'mmgen.main_split',
  131. 'mmgen.main_tool',
  132. 'mmgen.main_txbump',
  133. 'mmgen.main_txcreate',
  134. 'mmgen.main_txdo',
  135. 'mmgen.main_txsend',
  136. 'mmgen.main_txsign',
  137. 'mmgen.main_wallet',
  138. 'mmgen.txsign',
  139. 'mmgen.share.__init__',
  140. 'mmgen.share.Opts',
  141. ],
  142. scripts = [
  143. 'cmds/mmgen-addrgen',
  144. 'cmds/mmgen-keygen',
  145. 'cmds/mmgen-passgen',
  146. 'cmds/mmgen-addrimport',
  147. 'cmds/mmgen-passchg',
  148. 'cmds/mmgen-regtest',
  149. 'cmds/mmgen-walletchk',
  150. 'cmds/mmgen-walletconv',
  151. 'cmds/mmgen-walletgen',
  152. 'cmds/mmgen-split',
  153. 'cmds/mmgen-txcreate',
  154. 'cmds/mmgen-txbump',
  155. 'cmds/mmgen-txsign',
  156. 'cmds/mmgen-txsend',
  157. 'cmds/mmgen-txdo',
  158. 'cmds/mmgen-tool',
  159. 'cmds/mmgen-autosign'
  160. ]
  161. )