~ubuntu-branches/ubuntu/natty/sunpinyin/natty

« back to all changes in this revision

Viewing changes to .pc/disable-lm-dict-compile.patch/SConstruct

  • Committer: Bazaar Package Importer
  • Author(s): Zhengpeng Hou
  • Date: 2010-09-06 12:23:46 UTC
  • Revision ID: james.westby@ubuntu.com-20100906122346-ekmzay09hi2yknso
Tags: 2.0.2-0ubuntu1
Initial Ubuntu upload, LP: #631472, LP: #631459

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import platform
 
2
import os
 
3
import sys
 
4
 
 
5
cflags='-O2 -pipe -DHAVE_CONFIG_H '
 
6
prefix='/usr/local'
 
7
rpath=''
 
8
 
 
9
slmsource=['src/slm/ids2ngram/ids2ngram.cpp',
 
10
           'src/slm/ids2ngram/idngram_merge.cpp',
 
11
           'src/slm/mmseg/mmseg.cpp',
 
12
           'src/slm/tslminfo/tslminfo.cpp',
 
13
           'src/slm/tslmpack/arpa_slm.cpp',
 
14
           'src/slm/tslmpack/arpa_conv.cpp',
 
15
           'src/slm/tslmpack/slmpack.cpp',
 
16
           'src/slm/slm.cpp',
 
17
           'src/slm/slminfo/slminfo.cpp',
 
18
           'src/slm/sim_sen.cpp',
 
19
           'src/slm/sim_slm.cpp',
 
20
           'src/slm/getWordFreq/getWordFreq.cpp',
 
21
           'src/slm/slmseg/slmseg.cpp',
 
22
           'src/slm/thread/slmthread.cpp',
 
23
           'src/slm/thread/test_vc.cpp',
 
24
           'src/slm/thread/ValueCompress.cpp',
 
25
           'src/slm/slmbuild/slmbuild.cpp',
 
26
           'src/slm/slmprune/slmprune.cpp',
 
27
           'src/slm/sim_slmbuilder.cpp',
 
28
           'src/slm/tslmendian/slm_endian.cpp',
 
29
           'src/slm/tslmendian/writer.cpp',
 
30
           'src/slm/tslmendian/slm_file.cpp',
 
31
           'src/slm/sim_dict.cpp',
 
32
           'src/portability.cpp',
 
33
           'src/lexicon/trie_writer.cpp',
 
34
           'src/lexicon/genPYT.cpp',
 
35
           'src/lexicon/pytrie_gen.cpp',
 
36
           'src/lexicon/pytrie.cpp',
 
37
           'src/pinyin/pinyin_data.cpp']
 
38
 
 
39
imesource=['src/portability.cpp',
 
40
           'src/slm/slm.cpp',
 
41
           'src/lexicon/pytrie.cpp',
 
42
           'src/pinyin/pinyin_data.cpp',
 
43
           'src/pinyin/pinyin_seg.cpp',
 
44
           'src/pinyin/shuangpin_data.cpp',
 
45
           'src/pinyin/shuangpin_seg.cpp',
 
46
           'src/ime-core/imi_context.cpp',
 
47
           'src/ime-core/imi_data.cpp',
 
48
           'src/ime-core/lattice_states.cpp',
 
49
           'src/ime-core/imi_view.cpp',
 
50
           'src/ime-core/imi_uiobjects.cpp',
 
51
           'src/ime-core/imi_view_classic.cpp',
 
52
           'src/ime-core/imi_winHandler.cpp',
 
53
           'src/ime-core/ic_history.cpp',
 
54
           'src/ime-core/imi_funcobjs.cpp',
 
55
           'src/ime-core/imi_options.cpp',
 
56
           'src/ime-core/imi_option_event.cpp',
 
57
           'src/ime-core/userdict.cpp']
 
58
 
 
59
headers=['src/slm/ids2ngram/idngram.h',
 
60
         'src/slm/ids2ngram/idngram_merge.h',
 
61
         'src/slm/slm.h',
 
62
         'src/slm/tslmpack/arpa_slm.h',
 
63
         'src/slm/tslmpack/common.h',
 
64
         'src/slm/tslmpack/arpa_conv.h',
 
65
         'src/slm/sim_dict.h',
 
66
         'src/slm/sim_sen.h',
 
67
         'src/slm/sim_slm.h',
 
68
         'src/slm/thread/ValueCompress.h',
 
69
         'src/slm/sim_fmerge.h',
 
70
         'src/slm/sim_slmbuilder.h',
 
71
         'src/slm/tslmendian/slm_file.h',
 
72
         'src/slm/tslmendian/writer.h',
 
73
         'src/lexicon/pytrie_gen.h',
 
74
         'src/lexicon/trie_writer.h',
 
75
         'src/lexicon/pytrie.h',
 
76
         'src/ime-core/imi_view_classic.h',
 
77
         'src/ime-core/imi_uiobjects.h',
 
78
         'src/ime-core/lattice_states.h',
 
79
         'src/ime-core/ic_history.h',
 
80
         'src/ime-core/imi_funcobjs.h',
 
81
         'src/ime-core/imi_context.h',
 
82
         'src/ime-core/imi_winHandler.h',
 
83
         'src/ime-core/userdict.h',
 
84
         'src/ime-core/imi_option_event.h',
 
85
         'src/ime-core/imi_data.h',
 
86
         'src/ime-core/utils.h',
 
87
         'src/ime-core/imi_keys.h',
 
88
         'src/ime-core/imi_option_keys.h',
 
89
         'src/ime-core/imi_options.h',
 
90
         'src/ime-core/imi_defines.h',
 
91
         'src/ime-core/imi_view.h',
 
92
         'src/portability.h',
 
93
         'src/pinyin/segmentor.h',
 
94
         'src/pinyin/shuangpin_seg.h',
 
95
         'src/pinyin/datrie.h',
 
96
         'src/pinyin/quanpin_trie.h',
 
97
         'src/pinyin/pinyin_seg.h',
 
98
         'src/pinyin/pinyin_data.h',
 
99
         'src/pinyin/syllable.h',
 
100
         'src/pinyin/shuangpin_data.h',
 
101
         'src/pinyin/datrie_impl.h',
 
102
         'src/host_os.h',
 
103
         'src/sunpinyin.h']
 
104
 
 
105
AddOption('--prefix', dest='prefix', type='string', nargs=1,
 
106
          action='store', metavar='DIR', help='installation prefix')
 
107
AddOption('--rpath', dest='rpath', type='string', nargs=1,
 
108
          action='store', metavar='DIR', help='encode rpath in the executables')
 
109
 
 
110
if GetOption('prefix') is not None:
 
111
    prefix = GetOption('prefix')
 
112
if GetOption('rpath') is not None:
 
113
    rpath = GetOption('rpath')
 
114
 
 
115
cflags += ('-DSUNPINYIN_DATA_DIR=\'"%s/lib/sunpinyin/data"\'' % (prefix,))
 
116
libdir = prefix+'/lib'
 
117
libdatadir = libdir+'/sunpinyin/data'
 
118
headersdir = prefix+'/include/sunpinyin-2.0'
 
119
 
 
120
abi_major = 3
 
121
abi_minor = 0
 
122
 
 
123
#
 
124
#==============================environment==============================
 
125
#
 
126
#
 
127
def allinc():
 
128
    inc=[]
 
129
    for root, dirs, files in os.walk('src'):
 
130
        inc.append(root)
 
131
    return inc
 
132
 
 
133
def GetOS():
 
134
    return platform.uname()[0]
 
135
 
 
136
def CreateEnvironment():
 
137
    tar = 'tar'
 
138
    make = 'make'
 
139
    wget = 'wget'
 
140
    if GetOS() == 'Darwin':
 
141
        wget = 'curl -O'
 
142
    elif GetOS() == 'SunOS':
 
143
        tar = 'gtar'
 
144
        make = 'gmake'
 
145
 
 
146
    return Environment(ENV=os.environ, CFLAGS=cflags, CXXFLAGS=cflags,
 
147
                       TAR=tar, MAKE=make, WGET=wget,
 
148
                       CPPPATH=['.'] + allinc(), PREFIX=prefix)
 
149
 
 
150
env = CreateEnvironment()
 
151
 
 
152
if GetOS() != 'Darwin':
 
153
    env.Append(LINKFLAGS=['-Wl,-soname=libsunpinyin.so.%d' % abi_major])
 
154
 
 
155
if rpath != '' and GetOS() != 'Darwin':
 
156
    env.Append(LINKFLAGS='-Wl,-R -Wl,%s' % rpath)
 
157
 
 
158
if 'CC' in os.environ:
 
159
    print 'Warning: you\'ve set %s as C compiler' % os.environ['CC']
 
160
    env['CC']=os.environ['CC']
 
161
    
 
162
if 'CXX' in os.environ:
 
163
    print 'Warning: you\'ve set %s as C++ compiler' % os.environ['CXX']
 
164
    env['CXX']=os.environ['CXX']
 
165
 
 
166
if 'CFLAGS' in os.environ:
 
167
    print 'Warning: you\'ve set an external compiler flags for C.'
 
168
    env['CFLAGS'] = os.environ['CFLAGS']
 
169
 
 
170
if 'CXXFLAGS' in os.environ:
 
171
    print 'Warning: you\'ve set an external compiler flags for C++.'
 
172
    env['CXXFLAGS'] = os.environ['CXXFLAGS']
 
173
 
 
174
if 'TAR' in os.environ:
 
175
    print 'Warning: you\'ve set %s as tar' % os.environ['TAR']
 
176
    env['TAR'] = os.environ['TAR']
 
177
 
 
178
if 'MAKE' in os.environ:
 
179
    print 'Warning: you\'ve set %s as make' % os.environ['MAKE']
 
180
    env['MAKE'] = os.environ['MAKE']
 
181
 
 
182
if 'WGET' in os.environ:
 
183
    print 'Warning: you\'ve set %s as wget' % os.environ['WGET']
 
184
    env['WGET'] = os.environ['WGET']
 
185
    
 
186
#
 
187
#==============================configure================================
 
188
#
 
189
def CheckPKGConfig(context, version='0.12.0'):
 
190
    context.Message( 'Checking for pkg-config... ' )
 
191
    ret = context.TryAction('pkg-config --atleast-pkgconfig-version=%s' % version)[0]
 
192
    context.Result(ret)
 
193
    return ret
 
194
 
 
195
def CheckPKG(context, name):
 
196
    context.Message( 'Checking for %s... ' % name )
 
197
    ret = context.TryAction('pkg-config --exists \'%s\'' % name)[0]
 
198
    context.Result(ret)
 
199
    return ret
 
200
 
 
201
conf = Configure(env, custom_tests={'CheckPKGConfig' : CheckPKGConfig,
 
202
                                    'CheckPKG' : CheckPKG})
 
203
 
 
204
config_h_content = ''
 
205
 
 
206
def AddConfigItem(macro_name, res):
 
207
    global config_h_content
 
208
    config_h_content += ('#define %s %s\n\n' % (macro_name, res))
 
209
 
 
210
def AddTestHeader(header):
 
211
    macro_name = header.replace('.', '_').replace('-', '_').replace('/', '_').upper()
 
212
    macro_name = 'HAVE_' + macro_name
 
213
    if conf.CheckCHeader(header):
 
214
        AddConfigItem(macro_name, 1)
 
215
 
 
216
def AddTestFunction(funcname):
 
217
    macro_name = funcname.upper()
 
218
    macro_name = 'HAVE_' + macro_name
 
219
    if conf.CheckFunc(funcname):
 
220
        AddConfigItem(macro_name, 1)
 
221
 
 
222
def LinkOSHeader():
 
223
    osstring = GetOS()
 
224
    header = ''
 
225
    if osstring == 'Linux':
 
226
        header = 'linux.h'
 
227
    elif osstring == 'SunOS':
 
228
        header = 'solaris.h'
 
229
    elif osstring == 'Darwin':
 
230
        header = 'mac.h'
 
231
 
 
232
    os.system('ln -sf ./config/%s ./src/host_os.h' % (header,));
 
233
 
 
234
def AppendEndianCheck():
 
235
    global config_h_content
 
236
    config_h_content += r'''
 
237
#if defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)
 
238
# define WORDS_BIGENDIAN 1
 
239
 
 
240
#elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)
 
241
# undef WORDS_BIGENDIAN
 
242
 
 
243
#elif defined(__sparc) || defined(__sparc__) \
 
244
  || defined(_POWER) || defined(__powerpc__) \
 
245
  || defined(__ppc__) || defined(__hpux) || defined(__hppa) \
 
246
  || defined(_MIPSEB) || defined(_POWER) \
 
247
  || defined(__s390__)
 
248
# define WORDS_BIGENDIAN 1
 
249
 
 
250
#elif defined(__i386__) || defined(__alpha__) || defined(__i386) \
 
251
  || defined(__ia64) || defined(__ia64__) \
 
252
  || defined(_M_IX86) || defined(_M_IA64) \
 
253
  || defined(_M_ALPHA) || defined(__amd64) \
 
254
  || defined(__amd64__) || defined(_M_AMD64) \
 
255
  || defined(__x86_64) || defined(__x86_64__) \
 
256
  || defined(_M_X64) || defined(__bfin__)
 
257
# undef WORDS_BIGENDIAN
 
258
 
 
259
#else
 
260
# error can not detect the endianness!
 
261
#endif
 
262
'''
 
263
 
 
264
def DoConfigure():
 
265
    if GetOption('clean'):
 
266
        return
 
267
 
 
268
    if GetOS() == 'Darwin':
 
269
        if not conf.CheckLibWithHeader('sqlite3', 'sqlite3.h', 'C'):
 
270
            Exit(1)
 
271
        if not conf.CheckLibWithHeader('iconv', 'iconv.h', 'C'):
 
272
            Exit(1)
 
273
    else:
 
274
        if not conf.CheckPKGConfig():
 
275
            Exit(1)
 
276
        if not conf.CheckPKG('sqlite3'):
 
277
            Exit(1)
 
278
 
 
279
    AddConfigItem('ENABLE_NLS', 1)
 
280
    AddConfigItem('GETTEXT_PACKAGE', '"sunpinyin2"')
 
281
    AddTestHeader('assert.h')
 
282
    AddTestFunction('bind_textdomain_codeset')
 
283
    AddTestFunction('dcgettext')
 
284
    AddTestHeader('dlfcn.h')
 
285
    AddTestFunction('exp2')
 
286
    AddTestHeader('fcntl.h')
 
287
    AddTestHeader('getopt.h')
 
288
    AddTestFunction('getopt_long')
 
289
    AddTestFunction('getpagesize')
 
290
    AddTestFunction('get_opt')
 
291
    AddTestHeader('iconv.h')
 
292
    AddTestHeader('inttypes.h')
 
293
    AddTestHeader('locale.h')
 
294
    AddTestHeader('libintl.h')
 
295
    AddTestHeader('limits.h')
 
296
    AddTestHeader('locale.h')
 
297
    AddTestFunction('log2')
 
298
    AddTestHeader('memory.h')
 
299
    AddTestFunction('memset')
 
300
    AddTestFunction('mmap')
 
301
    AddTestFunction('munmap')
 
302
    AddTestFunction('setlocale')
 
303
    AddTestFunction('strndup')
 
304
    AddTestHeader('sys/mman.h')
 
305
    AddTestHeader('sys/param.h')
 
306
    AddTestHeader('sys/stat.h')
 
307
    AddTestHeader('sys/types.h')
 
308
    AddTestHeader('unistd.h')
 
309
    AddTestHeader('wchar.h')
 
310
 
 
311
    # add essential package requirements
 
312
    AddConfigItem('PACKAGE', '"sunpinyin"')
 
313
    AddConfigItem('PACKAGE_NAME', '"sunpinyin"')
 
314
    AddConfigItem('PACKAGE_STRING', '"sunpinyin 2.0"')
 
315
    AddConfigItem('PACKAGE_TARNAME', '"sunpinyin"')
 
316
    AddConfigItem('PACKAGE_VERSION', '"2.0"')
 
317
    AddConfigItem('VRESION', '"2.0"')
 
318
 
 
319
    # append endianness checking defines
 
320
    AppendEndianCheck()
 
321
    
 
322
    # generate config.h
 
323
    f = file('config.h', 'w')
 
324
    f.write(config_h_content)
 
325
    f.close()
 
326
 
 
327
    # generate sunpinyin.pc
 
328
    f = file('sunpinyin-2.0.pc', 'w')
 
329
    content = (
 
330
        'prefix='+prefix,
 
331
        'exec_prefix=${prefix}',
 
332
        'libdir=${exec_prefix}/lib',
 
333
        'includedir=${exec_prefix}/include/sunpinyin-2.0',
 
334
        '',
 
335
        'Name: libsunpinyin',
 
336
        'Description: IME library based on Statistical Language Model',
 
337
        'Version: 2.0.1',
 
338
        'Requires: sqlite3',
 
339
        'Libs: -L${libdir} -lsunpinyin',
 
340
        'Cflags: ' + reduce(lambda a, b: a + ' ' + b,
 
341
                            map(lambda x: '-I${includedir}' + x[3:],
 
342
                                allinc()))
 
343
        )
 
344
    f.write(reduce(lambda a, b: a + '\n' + b, content))
 
345
    f.close()
 
346
    env = conf.Finish()
 
347
 
 
348
    if GetOS() != 'Darwin':
 
349
        env.ParseConfig('pkg-config sqlite3 --libs --cflags')
 
350
 
 
351
    LinkOSHeader()
 
352
 
 
353
DoConfigure()
 
354
 
 
355
#
 
356
#==============================compile==============================
 
357
#
 
358
env.Object(slmsource)
 
359
 
 
360
SConscript(['build/SConscript'], exports='env')
 
361
 
 
362
libname = 'libsunpinyin.so.%d.%d' % (abi_major, abi_minor)
 
363
libname_soname = 'libsunpinyin.so.%d' % abi_major
 
364
libname_link = 'libsunpinyin.so'
 
365
 
 
366
lib = env.SharedLibrary('sunpinyin-%d.%d' % (abi_major, abi_minor),
 
367
                        source=imesource)
 
368
 
 
369
env.Command('rawlm', 'build/tslmpack',
 
370
            '$MAKE -C raw WGET="$WGET" TAR="$TAR"')
 
371
 
 
372
env.Command('lm', 'rawlm',
 
373
            '$MAKE -C data WGET="$WGET" TAR="$TAR"')
 
374
 
 
375
if GetOption('clean'):
 
376
    os.environ['TAR'] = env['TAR']
 
377
    os.environ['MAKE'] = env['MAKE']
 
378
    os.system('$MAKE -C raw clean WGET="$WGET" TAR="$TAR"')
 
379
    os.system('$MAKE -C data clean WGET="$WGET" TAR="$TAR"')
 
380
 
 
381
def DoInstall():
 
382
    if not 'install' in COMMAND_LINE_TARGETS:
 
383
        return
 
384
 
 
385
    lib_target = None
 
386
    if GetOS() == 'Darwin':
 
387
        lib_target = env.Install(libdir, lib)
 
388
    else:
 
389
        lib_target_bin = env.InstallAs(libdir + '/' + libname, lib)
 
390
        install_path = os.path.dirname(str(lib_target_bin[0])) + '/'
 
391
        lib_target = [
 
392
            lib_target_bin,
 
393
            env.Command(install_path + libname_soname, lib_target_bin,
 
394
                        'cd %s && ln -sf %s %s' %
 
395
                        (install_path, libname, libname_soname)),
 
396
            env.Command(install_path + libname_link, lib_target_bin,
 
397
                        'cd %s && ln -sf %s %s' %
 
398
                        (install_path, libname, libname_link))
 
399
            ]
 
400
 
 
401
    lib_pkgconfig_target = env.Install(libdir+'/pkgconfig',
 
402
                                       ['sunpinyin-2.0.pc'])
 
403
    libdata_target = env.Install(libdatadir,
 
404
                                 ['data/lm_sc.t3g',
 
405
                                  'data/pydict_sc.bin'])
 
406
    header_targets = []
 
407
    for header in headers:
 
408
        header_targets.append(env.InstallAs(headersdir + header[3:], header))
 
409
    env.Alias('install-headers', header_targets)
 
410
    env.Alias('install-lib', lib_target + [lib_pkgconfig_target])
 
411
    env.Alias('install-libdata', libdata_target)
 
412
 
 
413
DoInstall()
 
414
env.Alias('install', ['install-lib', 'install-libdata', 'install-headers'])
 
415