waf

FORK: waf with some random patches
git clone https://git.neptards.moe/neptards/waf.git
Log | Files | Refs | README

gnu_dirs.py (5182B)


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