setup.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2020 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. have_arm = subprocess.check_output(['uname','-m']).strip() == b'aarch64'
  27. have_msys2 = subprocess.check_output(['uname','-s']).strip()[:7] == b'MSYS_NT'
  28. from distutils.core import setup,Extension
  29. from distutils.command.build_ext import build_ext
  30. from distutils.command.install_data import install_data
  31. cwd = os.getcwd()
  32. def copy_owner(a,b):
  33. st = os.stat(a)
  34. try: os.chown(b,st.st_uid,st.st_gid,follow_symlinks=False)
  35. except: pass
  36. # install extension module in repository after building
  37. class my_build_ext(build_ext):
  38. def build_extension(self,ext):
  39. build_ext.build_extension(self,ext)
  40. ext_src = self.get_ext_fullpath(ext.name)
  41. ext_dest = os.path.join('mmgen',os.path.basename(ext_src))
  42. try: os.unlink(ext_dest)
  43. except: pass
  44. os.chmod(ext_src,0o755)
  45. print('copying {} to {}'.format(ext_src,ext_dest))
  46. copy2(ext_src,ext_dest)
  47. copy_owner(cwd,ext_dest)
  48. def link_or_copy(tdir,a,b):
  49. os.chdir(tdir)
  50. try: os.unlink(b)
  51. except FileNotFoundError: pass
  52. copy2(a,b) if have_msys2 else os.symlink(a,b)
  53. copy_owner(a,b)
  54. os.chdir(cwd)
  55. class my_install_data(install_data):
  56. def run(self):
  57. for f in 'mmgen.cfg','mnemonic.py','mn_wordlist.c':
  58. os.chmod(os.path.join('data_files',f),0o644)
  59. link_or_copy('test','start-coin-daemons.py','stop-coin-daemons.py')
  60. install_data.run(self)
  61. module1 = Extension(
  62. name = 'mmgen.secp256k1',
  63. sources = ['extmod/secp256k1mod.c'],
  64. libraries = ['secp256k1'] + ([],['gmp'])[have_msys2],
  65. library_dirs = ['/usr/local/lib',r'C:\msys64\mingw64\lib',r'C:\msys64\usr\lib'],
  66. include_dirs = ['/usr/local/include',r'C:\msys64\mingw64\include',r'C:\msys64\usr\include'],
  67. )
  68. from mmgen.globalvars import g
  69. setup(
  70. name = 'mmgen',
  71. description = 'A complete Bitcoin offline/online wallet solution for the command line',
  72. version = g.version,
  73. author = g.author,
  74. author_email = g.email,
  75. url = g.proj_url,
  76. license = 'GNU GPL v3',
  77. platforms = 'Linux, MS Windows, Raspberry Pi/Raspbian, Orange Pi/Armbian',
  78. keywords = g.keywords,
  79. cmdclass = { 'build_ext': my_build_ext, 'install_data': my_install_data },
  80. ext_modules = [module1],
  81. data_files = [('share/mmgen', [
  82. 'data_files/mmgen.cfg', # source files must have 0644 mode
  83. 'data_files/mn_wordlist.c',
  84. 'data_files/mnemonic.py'
  85. ]),],
  86. py_modules = [
  87. 'mmgen.__init__',
  88. 'mmgen.addr',
  89. 'mmgen.altcoin',
  90. 'mmgen.baseconv',
  91. 'mmgen.bech32',
  92. 'mmgen.bip39',
  93. 'mmgen.color',
  94. 'mmgen.common',
  95. 'mmgen.crypto',
  96. 'mmgen.devtools',
  97. 'mmgen.ed25519',
  98. 'mmgen.ed25519ll_djbec',
  99. 'mmgen.exception',
  100. 'mmgen.filename',
  101. 'mmgen.globalvars',
  102. 'mmgen.keccak',
  103. 'mmgen.license',
  104. 'mmgen.mn_electrum',
  105. 'mmgen.mn_monero',
  106. 'mmgen.mn_tirosh',
  107. 'mmgen.obj',
  108. 'mmgen.opts',
  109. 'mmgen.protocol',
  110. 'mmgen.regtest',
  111. 'mmgen.rpc',
  112. 'mmgen.seed',
  113. 'mmgen.sha2',
  114. 'mmgen.term',
  115. 'mmgen.daemon',
  116. 'mmgen.tool',
  117. 'mmgen.tw',
  118. 'mmgen.tx',
  119. 'mmgen.txsign',
  120. 'mmgen.util',
  121. 'mmgen.altcoins.__init__',
  122. 'mmgen.altcoins.eth.__init__',
  123. 'mmgen.altcoins.eth.contract',
  124. 'mmgen.altcoins.eth.obj',
  125. 'mmgen.altcoins.eth.tx',
  126. 'mmgen.altcoins.eth.tw',
  127. 'mmgen.altcoins.eth.pyethereum.__init__',
  128. 'mmgen.altcoins.eth.pyethereum.transactions',
  129. 'mmgen.altcoins.eth.pyethereum.utils',
  130. 'mmgen/altcoins/eth/rlp/__init__',
  131. 'mmgen/altcoins/eth/rlp/atomic',
  132. 'mmgen/altcoins/eth/rlp/codec',
  133. 'mmgen/altcoins/eth/rlp/exceptions',
  134. 'mmgen/altcoins/eth/rlp/sedes/__init__',
  135. 'mmgen/altcoins/eth/rlp/sedes/big_endian_int',
  136. 'mmgen/altcoins/eth/rlp/sedes/binary',
  137. 'mmgen/altcoins/eth/rlp/sedes/boolean',
  138. 'mmgen/altcoins/eth/rlp/sedes/lists',
  139. 'mmgen/altcoins/eth/rlp/sedes/raw',
  140. 'mmgen/altcoins/eth/rlp/sedes/serializable',
  141. 'mmgen/altcoins/eth/rlp/sedes/text',
  142. 'mmgen.main',
  143. 'mmgen.main_addrgen',
  144. 'mmgen.main_addrimport',
  145. 'mmgen.main_autosign',
  146. 'mmgen.main_passgen',
  147. 'mmgen.main_regtest',
  148. 'mmgen.main_seedjoin',
  149. 'mmgen.main_split',
  150. 'mmgen.main_tool',
  151. 'mmgen.main_txbump',
  152. 'mmgen.main_txcreate',
  153. 'mmgen.main_txdo',
  154. 'mmgen.main_txsend',
  155. 'mmgen.main_txsign',
  156. 'mmgen.main_wallet',
  157. 'mmgen.share.__init__',
  158. 'mmgen.share.Opts',
  159. ],
  160. scripts = [
  161. 'cmds/mmgen-addrgen',
  162. 'cmds/mmgen-keygen',
  163. 'cmds/mmgen-passgen',
  164. 'cmds/mmgen-addrimport',
  165. 'cmds/mmgen-passchg',
  166. 'cmds/mmgen-regtest',
  167. 'cmds/mmgen-subwalletgen',
  168. 'cmds/mmgen-walletchk',
  169. 'cmds/mmgen-walletconv',
  170. 'cmds/mmgen-walletgen',
  171. 'cmds/mmgen-seedsplit',
  172. 'cmds/mmgen-seedjoin',
  173. 'cmds/mmgen-split',
  174. 'cmds/mmgen-txcreate',
  175. 'cmds/mmgen-txbump',
  176. 'cmds/mmgen-txsign',
  177. 'cmds/mmgen-txsend',
  178. 'cmds/mmgen-txdo',
  179. 'cmds/mmgen-tool',
  180. 'cmds/mmgen-autosign'
  181. ]
  182. )