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
|
#!/usr/bin/env python
# encoding: utf-8
Import('env')
Import('VERSION_MAJOR')
Import('VERSION_MINOR')
Import('VERSION_PATCH')
Import('VERSION_NAME')
Import('create_uninstall_target')
import os
import codecs
def build_config_template(target, source, env):
text = source[0].get_text_contents()
with codecs.open(target[0].get_abspath(), 'w') as handle:
config_h = text.format(
INSTALL_PREFIX=GetOption('actual_prefix') or GetOption('prefix'),
HAVE_LIBINTL=env['HAVE_GETTEXT'],
HAVE_LIBELF=env['HAVE_LIBELF'],
HAVE_JSON_GLIB=env['HAVE_JSON_GLIB'],
HAVE_GIO_UNIX=env['HAVE_GIO_UNIX'],
HAVE_FIEMAP=env['HAVE_FIEMAP'],
HAVE_XATTR=env['HAVE_XATTR'],
HAVE_LXATTR=env['HAVE_LXATTR'],
HAVE_SHA512=env['HAVE_SHA512'],
HAVE_BIGFILES=env['HAVE_BIGFILES'],
HAVE_STAT64=env['HAVE_BIG_STAT'],
HAVE_POSIX_FADVISE=env['HAVE_POSIX_FADVISE'],
HAVE_BIG_OFF_T=env['HAVE_BIG_OFF_T'],
HAVE_BLKID=env['HAVE_BLKID'],
HAVE_SYSBLOCK=env['HAVE_SYSBLOCK'],
HAVE_LINUX_LIMITS=env['HAVE_LINUX_LIMITS'],
HAVE_LINUX_FS_H=env['HAVE_LINUX_FS_H'],
HAVE_BTRFS_H=env['HAVE_BTRFS_H'],
HAVE_MM_CRC32_U64=env['HAVE_MM_CRC32_U64'],
HAVE_BUILTIN_CPU_SUPPORTS=env['HAVE_BUILTIN_CPU_SUPPORTS'],
HAVE_UNAME=env['HAVE_UNAME'],
HAVE_SYSMACROS_H=env['HAVE_SYSMACROS_H'],
VERSION_MAJOR=VERSION_MAJOR,
VERSION_MINOR=VERSION_MINOR,
VERSION_PATCH=VERSION_PATCH,
VERSION_NAME=VERSION_NAME,
VERSION_GIT_REVISION=env['gitrev'].strip(),
BUILD_DATE=env['BUILD_DATE'],
BUILD_TIME=env['BUILD_TIME']
)
handle.write(config_h)
def prepare_c_source(text, escape_percentages=True):
# Prepare the Python source to be compatible with C-strings
text = text.replace('"', '\\"')
text = text.replace('\\n', '\\\\n')
text = '\\n"\n"'.join(text.splitlines())
if escape_percentages:
text = text.replace('%', '%%')
text = text.replace('%%s', '%s')
return text
def build_python_formatter(target, source, env):
text = source[0].get_text_contents()
with codecs.open('lib/formats/py.py', 'r') as handle:
py_source = prepare_c_source(handle.read(), False)
with codecs.open(target[0].get_abspath(), 'w') as handle:
handle.write(text.replace('<<PYTHON_SOURCE>>', py_source))
def build_sh_formatter(target, source, env):
text = source[0].get_text_contents()
with codecs.open('lib/formats/sh.sh', 'r') as handle:
sh_source = prepare_c_source(handle.read())
with codecs.open(target[0].get_abspath(), 'w') as handle:
handle.write(text.replace('<<SH_SOURCE>>', sh_source))
config = env.Command(
'config.h', 'config.h.in', build_config_template
)
py_formatter = env.Command(
'formats/py.c', 'formats/py.c.in', build_python_formatter
)
sh_formatter = env.Command(
'formats/sh.c', 'formats/sh.c.in', build_sh_formatter
)
library = env.Library(
'../rmlint',
Glob('*.c') +
Glob('checksums/*.c') +
Glob('checksums/xxhash/*.c') +
Glob('checksums/blake2/*.c') +
Glob('checksums/sha3/*.c') +
Glob('formats/*.c') +
Glob('fts/*.c')
)
headers = Glob('*.h')
env.Depends(library, [config, py_formatter, sh_formatter])
env.AlwaysBuild(config)
env.AlwaysBuild(py_formatter)
env.AlwaysBuild(sh_formatter)
# Disable this for now until someone
# announces interest in this.
INSTALL_LIBRARY = False
if 'install' in COMMAND_LINE_TARGETS and INSTALL_LIBRARY:
env.Alias('install', env.Install('$PREFIX/' + GetOption('libdir'), [library]))
for header in headers:
env.Alias('install', env.Install('$PREFIX/include/rmlint', [header]))
if 'uninstall' in COMMAND_LINE_TARGETS and INSTALL_LIBRARY:
create_uninstall_target(env, "$PREFIX/{}/{}".format(
GetOption('libdir'),
os.path.basename(str(library[0]))
))
for header in headers:
create_uninstall_target(env, "$PREFIX/include/rmlint/" + str(header))
Return('library')
|