gnu_dirs.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. # Ali Sabil, 2007
  4. """
  5. Sets various standard variables such as INCLUDEDIR. SBINDIR and others. To use this module just call::
  6. opt.load('gnu_dirs')
  7. and::
  8. conf.load('gnu_dirs')
  9. Add options for the standard GNU directories, this tool will add the options
  10. found in autotools, and will update the environment with the following
  11. installation variables:
  12. ============== ========================================= =======================
  13. Variable Description Default Value
  14. ============== ========================================= =======================
  15. PREFIX installation prefix /usr/local
  16. EXEC_PREFIX installation prefix for binaries PREFIX
  17. BINDIR user commands EXEC_PREFIX/bin
  18. SBINDIR system binaries EXEC_PREFIX/sbin
  19. LIBEXECDIR program-specific binaries EXEC_PREFIX/libexec
  20. SYSCONFDIR host-specific configuration PREFIX/etc
  21. SHAREDSTATEDIR architecture-independent variable data PREFIX/com
  22. LOCALSTATEDIR variable data PREFIX/var
  23. LIBDIR object code libraries EXEC_PREFIX/lib
  24. INCLUDEDIR header files PREFIX/include
  25. OLDINCLUDEDIR header files for non-GCC compilers /usr/include
  26. DATAROOTDIR architecture-independent data root PREFIX/share
  27. DATADIR architecture-independent data DATAROOTDIR
  28. INFODIR GNU "info" documentation DATAROOTDIR/info
  29. LOCALEDIR locale-dependent data DATAROOTDIR/locale
  30. MANDIR manual pages DATAROOTDIR/man
  31. DOCDIR documentation root DATAROOTDIR/doc/APPNAME
  32. HTMLDIR HTML documentation DOCDIR
  33. DVIDIR DVI documentation DOCDIR
  34. PDFDIR PDF documentation DOCDIR
  35. PSDIR PostScript documentation DOCDIR
  36. ============== ========================================= =======================
  37. """
  38. import os, re
  39. from waflib import Utils, Options, Context
  40. gnuopts = '''
  41. bindir, user commands, ${EXEC_PREFIX}/bin
  42. sbindir, system binaries, ${EXEC_PREFIX}/sbin
  43. libexecdir, program-specific binaries, ${EXEC_PREFIX}/libexec
  44. sysconfdir, host-specific configuration, ${PREFIX}/etc
  45. sharedstatedir, architecture-independent variable data, ${PREFIX}/com
  46. localstatedir, variable data, ${PREFIX}/var
  47. libdir, object code libraries, ${EXEC_PREFIX}/lib%s
  48. includedir, header files, ${PREFIX}/include
  49. oldincludedir, header files for non-GCC compilers, /usr/include
  50. datarootdir, architecture-independent data root, ${PREFIX}/share
  51. datadir, architecture-independent data, ${DATAROOTDIR}
  52. infodir, GNU "info" documentation, ${DATAROOTDIR}/info
  53. localedir, locale-dependent data, ${DATAROOTDIR}/locale
  54. mandir, manual pages, ${DATAROOTDIR}/man
  55. docdir, documentation root, ${DATAROOTDIR}/doc/${PACKAGE}
  56. htmldir, HTML documentation, ${DOCDIR}
  57. dvidir, DVI documentation, ${DOCDIR}
  58. pdfdir, PDF documentation, ${DOCDIR}
  59. psdir, PostScript documentation, ${DOCDIR}
  60. ''' % Utils.lib64()
  61. _options = [x.split(', ') for x in gnuopts.splitlines() if x]
  62. def configure(conf):
  63. """
  64. Reads the command-line options to set lots of variables in *conf.env*. The variables
  65. BINDIR and LIBDIR will be overwritten.
  66. """
  67. def get_param(varname, default):
  68. return getattr(Options.options, varname, '') or default
  69. env = conf.env
  70. env.LIBDIR = env.BINDIR = []
  71. env.EXEC_PREFIX = get_param('EXEC_PREFIX', env.PREFIX)
  72. env.PACKAGE = getattr(Context.g_module, 'APPNAME', None) or env.PACKAGE
  73. complete = False
  74. iter = 0
  75. while not complete and iter < len(_options) + 1:
  76. iter += 1
  77. complete = True
  78. for name, help, default in _options:
  79. name = name.upper()
  80. if not env[name]:
  81. try:
  82. env[name] = Utils.subst_vars(get_param(name, default).replace('/', os.sep), env)
  83. except TypeError:
  84. complete = False
  85. if not complete:
  86. lst = [x for x, _, _ in _options if not env[x.upper()]]
  87. raise conf.errors.WafError('Variable substitution failure %r' % lst)
  88. def options(opt):
  89. """
  90. Adds lots of command-line options, for example::
  91. --exec-prefix: EXEC_PREFIX
  92. """
  93. inst_dir = opt.add_option_group('Installation prefix',
  94. 'By default, "waf install" will put the files in\
  95. "/usr/local/bin", "/usr/local/lib" etc. An installation prefix other\
  96. than "/usr/local" can be given using "--prefix", for example "--prefix=$HOME"')
  97. for k in ('--prefix', '--destdir'):
  98. option = opt.parser.get_option(k)
  99. if option:
  100. opt.parser.remove_option(k)
  101. inst_dir.add_option(option)
  102. inst_dir.add_option('--exec-prefix',
  103. help = 'installation prefix for binaries [PREFIX]',
  104. default = '',
  105. dest = 'EXEC_PREFIX')
  106. dirs_options = opt.add_option_group('Installation directories')
  107. for name, help, default in _options:
  108. option_name = '--' + name
  109. str_default = default
  110. str_help = '%s [%s]' % (help, re.sub(r'\$\{([^}]+)\}', r'\1', str_default))
  111. dirs_options.add_option(option_name, help=str_help, default='', dest=name.upper())