| 1 |
import os |
| 2 |
|
| 3 |
sources = ['src/debug.cpp', |
| 4 |
'src/engine.cpp', |
| 5 |
'src/ibus_portable.cpp', |
| 6 |
'src/imi_ibus_win.cpp', |
| 7 |
'src/main.cpp', |
| 8 |
'src/sunpinyin_config.cpp', |
| 9 |
'src/sunpinyin_engine.cpp', |
| 10 |
'src/sunpinyin_engine_proxy.cpp', |
| 11 |
'src/sunpinyin_lookup_table.cpp', |
| 12 |
'src/sunpinyin_property.cpp'] |
| 13 |
|
| 14 |
locales = ['zh_CN'] |
| 15 |
|
| 16 |
cflags = '-O2 -g -pipe ' |
| 17 |
version = '2.0.3' |
| 18 |
|
| 19 |
AddOption('--prefix', dest='prefix', metavar='DIR', |
| 20 |
help='installation prefix') |
| 21 |
AddOption('--libdir', dest='libdir', metavar='DIR', |
| 22 |
help='installation libdir') |
| 23 |
AddOption('--libexecdir', dest='libexecdir', metavar='DIR', |
| 24 |
help='installation libexecdir') |
| 25 |
AddOption('--datadir', dest='datadir', metavar='DIR', |
| 26 |
help='installation datadir') |
| 27 |
AddOption('--rpath', dest='rpath', metavar='DIR', |
| 28 |
help='encode rpath in the executables') |
| 29 |
|
| 30 |
opts = Variables('configure.conf') |
| 31 |
opts.Add('PREFIX', default='/usr/local') |
| 32 |
opts.Add('LIBDIR', default='/usr/local/lib') |
| 33 |
opts.Add('LIBEXECDIR', default='/usr/local/lib') |
| 34 |
opts.Add('DATADIR', default='/usr/local/share') |
| 35 |
|
| 36 |
def PassVariables(envvar, env): |
| 37 |
for (x, y) in envvar: |
| 38 |
if x in os.environ: |
| 39 |
print('Warning: you\'ve set %s in the environmental variable!' % x) |
| 40 |
env[y] = os.environ[x] |
| 41 |
|
| 42 |
env = Environment(ENV=os.environ, |
| 43 |
CFLAGS=cflags, CXXFLAGS=cflags, |
| 44 |
CPPPATH=['.'], |
| 45 |
tools=['default', 'textfile']) |
| 46 |
opts.Update(env) |
| 47 |
|
| 48 |
if GetOption('prefix') is not None: |
| 49 |
env['PREFIX'] = GetOption('prefix') |
| 50 |
env['LIBDIR'] = env['PREFIX'] + '/lib' |
| •51 |
env['LIBEXECDIR'] = env['PREFIX'] + '/libexec/' |
| 52 |
env['DATADIR'] = env['PREFIX'] + '/share/' |
| 53 |
|
| 54 |
if GetOption('libdir') is not None: |
| 55 |
env['LIBDIR'] = GetOption('libdir') |
| 56 |
|
| 57 |
if GetOption('libexecdir') is not None: |
| 58 |
env['LIBEXECDIR'] = GetOption('libexecdir') |
| 59 |
|
| 60 |
if GetOption('datadir') is not None: |
| 61 |
env['DATADIR'] = GetOption('datadir') |
| 62 |
|
| 63 |
opts.Save('configure.conf', env) |
| 64 |
|
| 65 |
envvar = [('CC', 'CC'), |
| 66 |
('CXX', 'CXX'), |
| 67 |
('CFLAGS', 'CFLAGS'), |
| 68 |
('CXXFLAGS', 'CXXFLAGS'), |
| 69 |
('LDFLAGS', 'LINKFLAGS')] |
| 70 |
PassVariables(envvar, env) |
| 71 |
|
| 72 |
data_dir = env['DATADIR'] + '/ibus-sunpinyin' |
| 73 |
icons_dir = env['DATADIR'] + '/ibus-sunpinyin/icons' |
| •74 |
bin_dir = env['LIBEXECDIR'] + '/' |
| 75 |
gettext_package = 'ibus-sunpinyin' |
| 76 |
|
| 77 |
extra_cflags = ' -DIBUS_SUNPINYIN_LOCALEDIR=\'"%s"\'' % (env['DATADIR'] + '/locale') |
| 78 |
extra_cflags += ' -DIBUS_SUNPINYIN_ICON_DIR=\'"%s"\'' % icons_dir |
| 79 |
extra_cflags += ' -DLIBEXECDIR=\'"%s"\'' % bin_dir |
| 80 |
extra_cflags += ' -DGETTEXT_PACKAGE=\'"%s"\'' % gettext_package |
| 81 |
|
| 82 |
env.Append(CFLAGS=extra_cflags) |
| 83 |
env.Append(CXXFLAGS=extra_cflags) |
| 84 |
|
| 85 |
if GetOption('rpath') is not None: |
| 86 |
env.Append(LINKFLAGS=' -Wl,-R -Wl,%s' % GetOption('rpath')) |
| 87 |
|
| 88 |
# |
| 89 |
#==============================configure================================ |
| 90 |
# |
| 91 |
def CheckPKGConfig(context, version='0.12.0'): |
| 92 |
context.Message( 'Checking for pkg-config... ' ) |
| 93 |
ret = context.TryAction('pkg-config --atleast-pkgconfig-version=%s' % version)[0] |
| 94 |
context.Result(ret) |
| 95 |
return ret |
| 96 |
|
| 97 |
def CheckPKG(context, name): |
| 98 |
context.Message( 'Checking for %s... ' % name ) |
| 99 |
ret = context.TryAction('pkg-config --exists \'%s\'' % name)[0] |
| 100 |
context.Result(ret) |
| 101 |
return ret |
| 102 |
|
| 103 |
conf = Configure(env, custom_tests={'CheckPKGConfig' : CheckPKGConfig, |
| 104 |
'CheckPKG' : CheckPKG }) |
| 105 |
|
| 106 |
def DoConfigure(): |
| 107 |
if GetOption('clean'): |
| 108 |
return |
| 109 |
|
| 110 |
if not conf.CheckPKGConfig(): |
| 111 |
Exit(1) |
| 112 |
|
| 113 |
if not conf.CheckPKG('ibus-1.0'): |
| 114 |
Exit(1) |
| 115 |
|
| 116 |
if not conf.CheckPKG('sunpinyin-2.0'): |
| 117 |
Exit(1) |
| 118 |
env = conf.Finish() |
| 119 |
env.ParseConfig('pkg-config ibus-1.0 sunpinyin-2.0 --libs --cflags') |
| 120 |
|
| 121 |
DoConfigure() |
| 122 |
|
| 123 |
env.Program('ibus-engine-sunpinyin', source=sources) |
| 124 |
for locale in locales: |
| 125 |
mo = 'po/%s.mo' % (locale,) |
| 126 |
env.Command(mo, [], 'msgfmt po/%s.po -o %s' % (locale, mo)) |
| 127 |
|
| 128 |
sub = {'@LIBEXEC_DIR@': bin_dir, |
| 129 |
'@DATA_DIR@' : data_dir, |
| 130 |
'@ICON_DIR@': icons_dir, |
| 131 |
'@VERSION@' : version, |
| 132 |
'@INSTALL_PREFIX@': env['PREFIX']} |
| 133 |
env.Substfile('data/sunpinyin.xml.in', SUBST_DICT=sub) |
| 134 |
env.Substfile('setup/config.py.in', SUBST_DICT=sub) |
| 135 |
env.Substfile('setup/ibus-setup-sunpinyin.in', SUBST_DICT=sub) |
| 136 |
|
| 137 |
# |
| 138 |
#==============================install================================ |
| 139 |
# |
| 140 |
def DoInstall(): |
| 141 |
libexec_target = env.Install(bin_dir, ['ibus-engine-sunpinyin', |
| 142 |
'setup/ibus-setup-sunpinyin']) |
| 143 |
for exec_bin in libexec_target: |
| 144 |
env.AddPostAction(exec_bin, Chmod(str(exec_bin), 0o755)) |
| 145 |
|
| 146 |
setup_target = env.Install(data_dir + '/setup', |
| 147 |
['setup/setup.xml', |
| 148 |
'setup/main.py', |
| 149 |
'setup/config.py']) |
| 150 |
icons_target = env.Install(icons_dir, |
| 151 |
['icons/cnpunc.svg', |
| 152 |
'icons/eng.svg', |
| 153 |
'icons/enpunc.svg', |
| 154 |
'icons/fullwidth.svg', |
| 155 |
'icons/halfwidth.svg', |
| 156 |
'icons/han.svg', |
| 157 |
'icons/setup.svg', |
| 158 |
'icons/sunpinyin-logo.png']) |
| 159 |
component_target = env.Install(env['DATADIR'] + '/ibus/component', |
| 160 |
'data/sunpinyin.xml') |
| 161 |
locale_targets = [] |
| 162 |
for locale in locales: |
| 163 |
path = env['DATADIR'] + '/locale/%s/LC_MESSAGES/%s.mo' % \ |
| 164 |
(locale, gettext_package) |
| 165 |
locale_targets.append(env.InstallAs(path, 'po/%s.mo' % (locale,))) |
| 166 |
|
| 167 |
env.Alias('install-libexec', [libexec_target, setup_target]) |
| 168 |
env.Alias('install-data', [icons_target, component_target]) |
| 169 |
env.Alias('install-locale', locale_targets) |
| 170 |
|
| 171 |
DoInstall() |
| 172 |
env.Alias('install', ['install-libexec', 'install-data', 'install-locale']) |
| 173 |
|
| 174 |
# -*- indent-tabs-mode: nil -*- vim:et:ts=4 |