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

« back to all changes in this revision

Viewing changes to .pc/bump-new-pkgconfig-version.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 'TAR' in os.environ:
 
167
    print 'Warning: you\'ve set %s as tar' % os.environ['TAR']
 
168
    env['TAR'] = os.environ['TAR']
 
169
 
 
170
if 'MAKE' in os.environ:
 
171
    print 'Warning: you\'ve set %s as make' % os.environ['MAKE']
 
172
    env['MAKE'] = os.environ['MAKE']
 
173
 
 
174
if 'WGET' in os.environ:
 
175
    print 'Warning: you\'ve set %s as wget' % os.environ['WGET']
 
176
    env['WGET'] = os.environ['WGET']
 
177
    
 
178
#
 
179
#==============================configure================================
 
180
#
 
181
def CheckPKGConfig(context, version='0.12.0'):
 
182
    context.Message( 'Checking for pkg-config... ' )
 
183
    ret = context.TryAction('pkg-config --atleast-pkgconfig-version=%s' % version)[0]
 
184
    context.Result(ret)
 
185
    return ret
 
186
 
 
187
def CheckPKG(context, name):
 
188
    context.Message( 'Checking for %s... ' % name )
 
189
    ret = context.TryAction('pkg-config --exists \'%s\'' % name)[0]
 
190
    context.Result(ret)
 
191
    return ret
 
192
 
 
193
conf = Configure(env, custom_tests={'CheckPKGConfig' : CheckPKGConfig,
 
194
                                    'CheckPKG' : CheckPKG})
 
195
 
 
196
config_h_content = ''
 
197
 
 
198
def AddConfigItem(macro_name, res):
 
199
    global config_h_content
 
200
    config_h_content += ('#define %s %s\n\n' % (macro_name, res))
 
201
 
 
202
def AddTestHeader(header):
 
203
    macro_name = header.replace('.', '_').replace('-', '_').replace('/', '_').upper()
 
204
    macro_name = 'HAVE_' + macro_name
 
205
    if conf.CheckCHeader(header):
 
206
        AddConfigItem(macro_name, 1)
 
207
 
 
208
def AddTestFunction(funcname):
 
209
    macro_name = funcname.upper()
 
210
    macro_name = 'HAVE_' + macro_name
 
211
    if conf.CheckFunc(funcname):
 
212
        AddConfigItem(macro_name, 1)
 
213
 
 
214
def LinkOSHeader():
 
215
    osstring = GetOS()
 
216
    header = ''
 
217
    if osstring == 'Linux':
 
218
        header = 'linux.h'
 
219
    elif osstring == 'SunOS':
 
220
        header = 'solaris.h'
 
221
    elif osstring == 'Darwin':
 
222
        header = 'mac.h'
 
223
 
 
224
    os.system('ln -sf ./config/%s ./src/host_os.h' % (header,));
 
225
 
 
226
def AppendEndianCheck():
 
227
    global config_h_content
 
228
    config_h_content += r'''
 
229
#if defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)
 
230
# define WORDS_BIGENDIAN 1
 
231
 
 
232
#elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)
 
233
# undef WORDS_BIGENDIAN
 
234
 
 
235
#elif defined(__sparc) || defined(__sparc__) \
 
236
  || defined(_POWER) || defined(__powerpc__) \
 
237
  || defined(__ppc__) || defined(__hpux) || defined(__hppa) \
 
238
  || defined(_MIPSEB) || defined(_POWER) \
 
239
  || defined(__s390__)
 
240
# define WORDS_BIGENDIAN 1
 
241
 
 
242
#elif defined(__i386__) || defined(__alpha__) || defined(__i386) \
 
243
  || defined(__ia64) || defined(__ia64__) \
 
244
  || defined(_M_IX86) || defined(_M_IA64) \
 
245
  || defined(_M_ALPHA) || defined(__amd64) \
 
246
  || defined(__amd64__) || defined(_M_AMD64) \
 
247
  || defined(__x86_64) || defined(__x86_64__) \
 
248
  || defined(_M_X64) || defined(__bfin__)
 
249
# undef WORDS_BIGENDIAN
 
250
 
 
251
#else
 
252
# error can not detect the endianness!
 
253
#endif
 
254
'''
 
255
 
 
256
def DoConfigure():
 
257
    if GetOption('clean'):
 
258
        return
 
259
 
 
260
    if GetOS() == 'Darwin':
 
261
        if not conf.CheckLibWithHeader('sqlite3', 'sqlite3.h', 'C'):
 
262
            Exit(1)
 
263
        if not conf.CheckLibWithHeader('iconv', 'iconv.h', 'C'):
 
264
            Exit(1)
 
265
    else:
 
266
        if not conf.CheckPKGConfig():
 
267
            Exit(1)
 
268
        if not conf.CheckPKG('sqlite3'):
 
269
            Exit(1)
 
270
 
 
271
    AddConfigItem('ENABLE_NLS', 1)
 
272
    AddConfigItem('GETTEXT_PACKAGE', '"sunpinyin2"')
 
273
    AddTestHeader('assert.h')
 
274
    AddTestFunction('bind_textdomain_codeset')
 
275
    AddTestFunction('dcgettext')
 
276
    AddTestHeader('dlfcn.h')
 
277
    AddTestFunction('exp2')
 
278
    AddTestHeader('fcntl.h')
 
279
    AddTestHeader('getopt.h')
 
280
    AddTestFunction('getopt_long')
 
281
    AddTestFunction('getpagesize')
 
282
    AddTestFunction('get_opt')
 
283
    AddTestHeader('iconv.h')
 
284
    AddTestHeader('inttypes.h')
 
285
    AddTestHeader('locale.h')
 
286
    AddTestHeader('libintl.h')
 
287
    AddTestHeader('limits.h')
 
288
    AddTestHeader('locale.h')
 
289
    AddTestFunction('log2')
 
290
    AddTestHeader('memory.h')
 
291
    AddTestFunction('memset')
 
292
    AddTestFunction('mmap')
 
293
    AddTestFunction('munmap')
 
294
    AddTestFunction('setlocale')
 
295
    AddTestFunction('strndup')
 
296
    AddTestHeader('sys/mman.h')
 
297
    AddTestHeader('sys/param.h')
 
298
    AddTestHeader('sys/stat.h')
 
299
    AddTestHeader('sys/types.h')
 
300
    AddTestHeader('unistd.h')
 
301
    AddTestHeader('wchar.h')
 
302
 
 
303
    # add essential package requirements
 
304
    AddConfigItem('PACKAGE', '"sunpinyin"')
 
305
    AddConfigItem('PACKAGE_NAME', '"sunpinyin"')
 
306
    AddConfigItem('PACKAGE_STRING', '"sunpinyin 2.0"')
 
307
    AddConfigItem('PACKAGE_TARNAME', '"sunpinyin"')
 
308
    AddConfigItem('PACKAGE_VERSION', '"2.0"')
 
309
    AddConfigItem('VRESION', '"2.0"')
 
310
 
 
311
    # append endianness checking defines
 
312
    AppendEndianCheck()
 
313
    
 
314
    # generate config.h
 
315
    f = file('config.h', 'w')
 
316
    f.write(config_h_content)
 
317
    f.close()
 
318
 
 
319
    # generate sunpinyin.pc
 
320
    f = file('sunpinyin-2.0.pc', 'w')
 
321
    content = (
 
322
        'prefix='+prefix,
 
323
        'exec_prefix=${prefix}',
 
324
        'libdir=${exec_prefix}/lib',
 
325
        'includedir=${exec_prefix}/include/sunpinyin-2.0',
 
326
        '',
 
327
        'Name: libsunpinyin',
 
328
        'Description: IME library based on Statistical Language Model',
 
329
        'Version: 2.0.1',
 
330
        'Requires: sqlite3',
 
331
        'Libs: -L${libdir} -lsunpinyin',
 
332
        'Cflags: ' + reduce(lambda a, b: a + ' ' + b,
 
333
                            map(lambda x: '-I${includedir}' + x[3:],
 
334
                                allinc()))
 
335
        )
 
336
    f.write(reduce(lambda a, b: a + '\n' + b, content))
 
337
    f.close()
 
338
    env = conf.Finish()
 
339
 
 
340
    if GetOS() != 'Darwin':
 
341
        env.ParseConfig('pkg-config sqlite3 --libs --cflags')
 
342
 
 
343
    LinkOSHeader()
 
344
 
 
345
DoConfigure()
 
346
 
 
347
#
 
348
#==============================compile==============================
 
349
#
 
350
env.Object(slmsource)
 
351
 
 
352
SConscript(['build/SConscript'], exports='env')
 
353
 
 
354
libname = 'libsunpinyin.so.%d.%d' % (abi_major, abi_minor)
 
355
libname_soname = 'libsunpinyin.so.%d' % abi_major
 
356
libname_link = 'libsunpinyin.so'
 
357
 
 
358
lib = env.SharedLibrary('sunpinyin-%d.%d' % (abi_major, abi_minor),
 
359
                        source=imesource)
 
360
 
 
361
if GetOption('clean'):
 
362
    os.environ['TAR'] = env['TAR']
 
363
    os.environ['MAKE'] = env['MAKE']
 
364
    os.system('$MAKE -C raw clean WGET="$WGET" TAR="$TAR"')
 
365
    os.system('$MAKE -C data clean WGET="$WGET" TAR="$TAR"')
 
366
 
 
367
def DoInstall():
 
368
    if not 'install' in COMMAND_LINE_TARGETS:
 
369
        return
 
370
 
 
371
    lib_target = None
 
372
    if GetOS() == 'Darwin':
 
373
        lib_target = env.Install(libdir, lib)
 
374
    else:
 
375
        lib_target_bin = env.InstallAs(libdir + '/' + libname, lib)
 
376
        install_path = os.path.dirname(str(lib_target_bin[0])) + '/'
 
377
        lib_target = [
 
378
            lib_target_bin,
 
379
            env.Command(install_path + libname_soname, lib_target_bin,
 
380
                        'cd %s && ln -sf %s %s' %
 
381
                        (install_path, libname, libname_soname)),
 
382
            env.Command(install_path + libname_link, lib_target_bin,
 
383
                        'cd %s && ln -sf %s %s' %
 
384
                        (install_path, libname, libname_link))
 
385
            ]
 
386
 
 
387
    lib_pkgconfig_target = env.Install(libdir+'/pkgconfig',
 
388
                                       ['sunpinyin-2.0.pc'])
 
389
    libdata_target = env.Install(libdatadir)
 
390
    header_targets = []
 
391
    for header in headers:
 
392
        header_targets.append(env.InstallAs(headersdir + header[3:], header))
 
393
    env.Alias('install-headers', header_targets)
 
394
    env.Alias('install-lib', lib_target + [lib_pkgconfig_target])
 
395
    env.Alias('install-libdata', libdata_target)
 
396
 
 
397
DoInstall()
 
398
env.Alias('install', ['install-lib', 'install-libdata', 'install-headers'])
 
399