1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
#!/usr/bin/python3
# encoding=utf-8
#
# Copyright © 2016 Simon McVittie <smcv@debian.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# You can find the GPL license text on a Debian system under
# /usr/share/common-licenses/GPL-2.
'''
A broadly GNU-compatible configure script.
'''
# Magic tokens for <https://github.com/cgwalters/build-api>:
## buildapi-variable-no-builddir
import argparse
import os
import shlex
import sys
from game_data_packager.version import (
DISTRO,
FORMAT,
GAME_PACKAGE_VERSION,
)
class Configure:
def __init__(self):
self.consts = dict(
PACKAGE='game-data-packager',
VERSION=GAME_PACKAGE_VERSION,
)
self.vars = dict(
CFLAGS='',
CXXFLAGS='',
PYTHON=sys.executable,
RELEASE='',
)
for k in self.vars:
if k in os.environ:
self.vars[k] = os.environ[k]
self.dirs = dict(
bindir='${exec_prefix}/bin',
datadir='${datarootdir}',
datarootdir='${prefix}/share',
docdir='${datarootdir}/doc/${PACKAGE}',
dvidir='${docdir}',
exec_prefix='${prefix}',
htmldir='${docdir}',
includedir='${prefix}/include',
infodir='${datarootdir}/info',
libdir='${exec_prefix}/lib',
libexecdir='${exec_prefix}/libexec',
localedir='${datarootdir}/locale',
localstatedir='${prefix}/var',
mandir='${datarootdir}/man',
oldincludedir='/usr/include',
pdfdir='${docdir}',
prefix='/usr/local',
program_prefix='',
psdir='${docdir}',
runstatedir='${localstatedir}/run',
sbindir='${exec_prefix}/sbin',
sharedstatedir='${prefix}/com',
srcdir=os.path.dirname(sys.argv[0]) or '.',
sysconfdir='${prefix}/etc',
)
self.with_ = dict(
distro=DISTRO,
format=FORMAT,
gamedatadir='${datadir}',
)
self.parser = argparse.ArgumentParser(
allow_abbrev=False,
description='Configure game-data-packager',
)
for k, v in self.dirs.items():
self.parser.add_argument('--' + k.replace('_','-'), default=v)
for k, v in self.with_.items():
self.parser.add_argument('--with-' + k, default=v, dest=k)
self.parser.add_argument('--build', help='Ignored')
self.parser.add_argument('--host', help='Ignored')
self.parser.add_argument('--target', help='Ignored')
def warn(self, message):
sys.stderr.write('%s: warning: %s\n' % (sys.argv[0], message))
def run(self):
args, rest = self.parser.parse_known_args()
for k, v in vars(args).items():
if k in self.dirs:
self.dirs[k] = v
elif k in self.with_:
self.with_[k] = v
elif k in ('build', 'host', 'target'):
pass
else:
raise AssertionError('Unexpected: %r' % k)
for arg in rest:
if (arg.startswith('--with-') or arg.startswith('--without-') or
arg.startswith('--enable-') or
arg.startswith('--disable-')):
self.warn('Unknown with/without/enable/disable option %r' %
arg)
elif arg.startswith('-'):
self.parser.error('Unknown option %r' % arg)
elif '=' in arg:
k, v = arg.split('=', 1)
if k in self.vars:
self.vars[k] = v
else:
self.warn('Unknown variable %r' % arg)
else:
self.parser.error('Unknown argument %r' % arg)
command_line = ' '.join((shlex.quote(a) for a in sys.argv))
with open('config.status', 'w') as writer:
writer.write('#!/bin/sh\n')
writer.write('# Generated by the command below, do not edit\n')
writer.write(command_line)
writer.write('\n')
os.chmod('config.status', 0o755)
os.makedirs('out', exist_ok=True)
with open(os.path.join('out', 'version.py'), 'w') as writer:
writer.write('# Generated by %r, do not edit\n' % command_line)
writer.write('DISTRO = %r\n' % self.with_['distro'])
writer.write('FORMAT = %r\n' % self.with_['format'])
writer.write('GAME_PACKAGE_VERSION = %r\n' %
self.consts['VERSION'])
writer.write('GAME_PACKAGE_RELEASE = %r\n' %
self.vars['RELEASE'])
with open('configure.mk', 'w') as writer:
writer.write('# Generated by %r, do not edit\n' % command_line)
for k, v in sorted(self.consts.items()):
writer.write('%s = %s\n' % (k, v))
writer.write('\n')
for k, v in sorted(self.vars.items()):
writer.write('%s = %s\n' % (k, v))
writer.write('\n')
for k, v in sorted(self.dirs.items()):
writer.write('%s = %s\n' % (k, v))
writer.write('\n')
for k, v in sorted(self.with_.items()):
writer.write('%s = %s\n' % (k, v))
if __name__ == '__main__':
Configure().run()
|