SConstruct 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import os
  2. PROJECT_NAME = 'pixiv_down'
  3. PROJECT_VERSION = '2024.12.0'
  4. # Set up configuration
  5. CONFIG_FILENAME = 'scons.cfg'
  6. opts = Variables(CONFIG_FILENAME)
  7. opts.AddVariables(
  8. PathVariable('prefix',
  9. help='Installation prefix',
  10. default='/usr/local',
  11. validator=PathVariable.PathIsDir
  12. ),
  13. PathVariable('eprefix',
  14. help='Installation prefix for executable files',
  15. default='${prefix}',
  16. validator=PathVariable.PathIsDir
  17. ),
  18. PathVariable('bindir',
  19. help='Executable directory',
  20. default='${eprefix}/bin',
  21. validator=PathVariable.PathIsDir
  22. ),
  23. PathVariable('datarootdir',
  24. help='The root of the directory tree for read-only architecture-independent data files.',
  25. default='${prefix}/share',
  26. validator=PathVariable.PathIsDir
  27. ),
  28. PathVariable('datadir',
  29. help='The directory for installing read-only architecture-independent data files.',
  30. default='${datarootdir}',
  31. validator=PathVariable.PathIsDir
  32. ),
  33. PathVariable('includedir',
  34. help='The directory for installing header files to be included by other user programs.',
  35. default='${prefix}/include',
  36. validator=PathVariable.PathIsDir
  37. ),
  38. PathVariable('libdir',
  39. help='Shared object code libraries',
  40. default='${eprefix}/lib',
  41. validator=PathVariable.PathIsDir
  42. ),
  43. PathVariable('mandir',
  44. help='The top-level directory for installing the man pages.',
  45. default='${datarootdir}/man',
  46. validator=PathVariable.PathIsDir
  47. ),
  48. )
  49. # Make sure scons will use the correct D compiler (from DC)
  50. tools = ['dmd', 'cc', 'link']
  51. if 'DC' in os.environ:
  52. tools[0] = os.environ['DC'].lower()
  53. tools[0] = 'ldc' if tools[0] == 'ldc2' else tools[0]
  54. if 'CC' in os.environ:
  55. tools[1] = os.environ['CC'].lower()
  56. env = Environment(
  57. tools=tools,
  58. options=opts,
  59. PROJECT_NAME=PROJECT_NAME,
  60. PROJECT_VERSION=PROJECT_VERSION,
  61. )
  62. scons_version = (0, 0, 0)
  63. try:
  64. # GetSConsVersion is defined in 4.8.0
  65. scons_version = GetSConsVersion()
  66. except NameError:
  67. pass
  68. # SCons versions older than 4.6.0 don't correctly set GDC's version flag.
  69. if scons_version[0] < 4 or (scons_version[0] == 4 and scons_version[1] < 6):
  70. if env['DC'] == 'gdc':
  71. env['DVERPREFIX'] = '-fversion='
  72. # SCons doesn't set the correct version flag for ldc.
  73. if env['DC'] == 'ldc2' or env['DC'] == 'ldc':
  74. env['DVERPREFIX'] = '--d-version='
  75. # GDC has a linking issue in at least version 12.
  76. if env['DC'] == 'gdc':
  77. env.Append(DFLAGS=['-fall-instantiations'])
  78. opts.Save(CONFIG_FILENAME, env)
  79. Help(opts.GenerateHelpText(env))
  80. # Create pd_version.d
  81. def vcs_tag(self, *, command, fallback=env['PROJECT_VERSION'], input_file, output_file, replace_string='@VCS_TAG@'):
  82. import subprocess
  83. tag = fallback
  84. process = subprocess.run(command, capture_output=True)
  85. if process.returncode == 0:
  86. tag = process.stdout.decode('utf-8').strip()
  87. with open(input_file) as infile, open(output_file, 'w+') as outfile:
  88. content = infile.read()
  89. replaced = content.replace(replace_string, tag)
  90. outfile.write(replaced)
  91. return output_file
  92. env.AddMethod(vcs_tag)
  93. # Easier sharing of paths from SConscript to parent SConscript
  94. def files(self, *args):
  95. return list(map(lambda p: os.path.join(os.getcwd(), p), args))
  96. env.AddMethod(files, 'Files')
  97. # Build pixiv_down
  98. SConscript([
  99. 'docs/SConscript',
  100. 'source/SConscript',
  101. ], exports='env')
  102. # Install
  103. install_data = env.Alias('install-data', env['datarootdir'])
  104. install_exec = env.Alias('install-exec', env['eprefix'])
  105. env.Alias('install', [install_exec, install_data])