1#!/usr/bin/env python 2# encoding: utf-8 3# Ali Sabil, 2007 4 5""" 6Sets various standard variables such as INCLUDEDIR. SBINDIR and others. To use this module just call:: 7 8 opt.load('gnu_dirs') 9 10and:: 11 12 conf.load('gnu_dirs') 13 14Add options for the standard GNU directories, this tool will add the options 15found in autotools, and will update the environment with the following 16installation variables: 17 18============== ========================================= ======================= 19Variable Description Default Value 20============== ========================================= ======================= 21PREFIX installation prefix /usr/local 22EXEC_PREFIX installation prefix for binaries PREFIX 23BINDIR user commands EXEC_PREFIX/bin 24SBINDIR system binaries EXEC_PREFIX/sbin 25LIBEXECDIR program-specific binaries EXEC_PREFIX/libexec 26SYSCONFDIR host-specific configuration PREFIX/etc 27SHAREDSTATEDIR architecture-independent variable data PREFIX/com 28LOCALSTATEDIR variable data PREFIX/var 29LIBDIR object code libraries EXEC_PREFIX/lib 30INCLUDEDIR header files PREFIX/include 31OLDINCLUDEDIR header files for non-GCC compilers /usr/include 32DATAROOTDIR architecture-independent data root PREFIX/share 33DATADIR architecture-independent data DATAROOTDIR 34INFODIR GNU "info" documentation DATAROOTDIR/info 35LOCALEDIR locale-dependent data DATAROOTDIR/locale 36MANDIR manual pages DATAROOTDIR/man 37DOCDIR documentation root DATAROOTDIR/doc/APPNAME 38HTMLDIR HTML documentation DOCDIR 39DVIDIR DVI documentation DOCDIR 40PDFDIR PDF documentation DOCDIR 41PSDIR PostScript documentation DOCDIR 42============== ========================================= ======================= 43""" 44 45import os, re 46from waflib import Utils, Options, Context 47 48gnuopts = ''' 49bindir, user commands, ${EXEC_PREFIX}/bin 50sbindir, system binaries, ${EXEC_PREFIX}/sbin 51libexecdir, program-specific binaries, ${EXEC_PREFIX}/libexec 52sysconfdir, host-specific configuration, ${PREFIX}/etc 53sharedstatedir, architecture-independent variable data, ${PREFIX}/com 54localstatedir, variable data, ${PREFIX}/var 55libdir, object code libraries, ${EXEC_PREFIX}/lib%s 56includedir, header files, ${PREFIX}/include 57oldincludedir, header files for non-GCC compilers, /usr/include 58datarootdir, architecture-independent data root, ${PREFIX}/share 59datadir, architecture-independent data, ${DATAROOTDIR} 60infodir, GNU "info" documentation, ${DATAROOTDIR}/info 61localedir, locale-dependent data, ${DATAROOTDIR}/locale 62mandir, manual pages, ${DATAROOTDIR}/man 63docdir, documentation root, ${DATAROOTDIR}/doc/${PACKAGE} 64htmldir, HTML documentation, ${DOCDIR} 65dvidir, DVI documentation, ${DOCDIR} 66pdfdir, PDF documentation, ${DOCDIR} 67psdir, PostScript documentation, ${DOCDIR} 68''' % Utils.lib64() 69 70_options = [x.split(', ') for x in gnuopts.splitlines() if x] 71 72def 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 102def 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 132