~ubuntu-branches/ubuntu/wily/bombono-dvd/wily

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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
#!/usr/bin/env python

#
# Make configuration like autoconf
#

import sys
from BuildVars import *

Import('user_options_dict')

ConfigDict = {}
user_options_dict['CONFIGURATION'] = ConfigDict

############################################

def GetYesNo(bool_type):
    if bool_type:
        return 'yes'
    return 'no'

compiler_text = """
int main()
{
#ifndef %s
    choke me
#endif
    return 0;
}
"""

def CheckCompiler(context, c_name, cdef_name):
    context.Message( 'Checking whether we are using the %s compiler ... ' % c_name ) 

    ret = context.TryCompile(compiler_text % cdef_name, '.c')
    context.Result( GetYesNo(ret) )
    return ret

def CheckGNUCompiler(context):
    return CheckCompiler(context, 'GNU C', '__GNUC__')

def CheckClangCompiler(context):
    return CheckCompiler(context, 'Clang', '__clang__')

# copy-n-paste from linuxdcpp project :)
def CheckPKGConfig(context):
	context.Message('Checking for pkg-config ... ')
	ret = context.TryAction('pkg-config --version')[0]
	context.Result( GetYesNo(ret) )
	return ret

def CheckTimeval(context):
    context.Message( 'Checking for struct timeval ... ' )
    ret = context.TryLink("""
#include <sys/time.h>
#include <time.h>

int main ()
{
    if( (struct timeval *)0 )
        return 0;
    if( sizeof(struct timeval) )
        return 0;
    return 0;
}
""", '.c')
    context.Result( GetYesNo(ret) )
    return ret

altivec_text = """
%s
int main ()
{
    typedef vector int t;
    vec_ld(0, (unsigned char *)0);
    return 0;
}
"""

def CheckAltivec(context, is_altivec):
    ret, is_altivec.value = 0, 0

    context.Message( 'Checking for AltiVec support ... ' )
    origCCFLAGS = context.env['CCFLAGS']
    for try_cflags in ['-mpim-altivec', '-faltivec', '-maltivec', '-fvec']:
        context.env.Replace(CCFLAGS = origCCFLAGS+[try_cflags])
        if context.TryLink(altivec_text % '', '.c'):
            ret = 1
            break
        if context.TryLink(altivec_text % 'include <altivec.h>', '.c'):
            is_altivec.value = 1
            ret = 1
            break

    context.Result( GetYesNo(ret) )
    context.env.Replace(CCFLAGS = origCCFLAGS)
    return ret

align_text = """
int main ()
{
    static struct s 
    {
        char a;
        char b __attribute__ ((aligned(%s)));
    } S = {0, 0};
    switch (1) 
    {
    case 0:
    case (int)(&((struct s *)0)->b) == %s:
        return 0;
    }
    return (long)&S;
}
"""

def CheckMaxAligning(context):
    context.Message( 'Checking maximum supported data alignment ... ' )
    origCCFLAGS = context.env['CCFLAGS']

    if IsGccLike():
        context.env.Append(CCFLAGS = ['-Werror'])
    max_align = 0
    for try_align in [2, 4, 8, 16, 32, 64]:
        if context.TryLink(align_text % (try_align, try_align), '.c'):
            max_align = try_align

    ret = (max_align != 0)
    if ret:
        context.Result( str(max_align) )
    else:
        context.Result( GetYesNo(ret) )
    context.env.Replace(CCFLAGS = origCCFLAGS)
    return max_align

builtin_expext_text = """
int foo (int a)
{
    a = __builtin_expect (a, 10);
    return a == 10 ? 0 : 1;
}
"""

def GetFlags(opt_name, env):
    return env.get(opt_name, [])

def CheckBuiltinExpect(context):
    context.Message( 'Checking whether compiler understands __builtin_expect ... ' )
    if IsGccLike():
        origLINKFLAGS, origLIBS = GetFlags('LINKFLAGS', context.env), GetFlags('LIBS', context.env)
    
        context.env.Append(LINKFLAGS = ['-nostdlib', '-nostartfiles'], LIBS = ['gcc'])
        ret = context.TryLink(builtin_expext_text, '.c')
    
        context.env.Replace(LINKFLAGS = origLINKFLAGS, LIBS = origLIBS)
    else:
        ret = 0

    context.Result( GetYesNo(ret) )
    return ret

sigtype_text = """
#include <signal.h>
#ifdef signal
# undef signal
#endif

void (*signal ()) ();
int main ()
{
    int i;
    return 0;
}
"""

def CheckSignalRetType(context):
    context.Message( 'Checking return type of signal handlers ... ' )

    type = "void"
    if context.TryLink(sigtype_text, '.c'):
        context.Result( "void" )
    else:
        context.Result( "int (assumed)" )
        type = "int"
    return type

inline_text = """
%s int foo() { return 0; }
"""
def CheckCInline(context):
    context.Message( 'Checking for inline ... ' )

    inline_word = ''
    for word in ['inline', '__inline__', '__inline']:
        if context.TryCompile(inline_text % word, '.c'):
            inline_word = word
            break
    context.Result( GetYesNo(inline_word != '') + " ('" + inline_word + "')" )
    return inline_word

restrict_text = """
int foo() 
{
    char * %s p;
    return 0; 
}
"""
def CheckRestrictWord(context):
    context.Message( 'Checking for restrict ... ' )

    restrict_word = '' # empty
    for word in ['restrict', '__restrict__', '__restrict']:
        if context.TryCompile(restrict_text % word, '.c'):
            restrict_word = word
            break

    context.Result( GetYesNo(restrict_word != '') + " ('" + restrict_word + "')")
    return word

def AddCfgVariable(key, **cfg_var):
    assert not(key in ConfigDict.keys())
    ConfigDict[key] = cfg_var

def AddCfgName(name, is_on, **opt):
    key = name.upper()
    key = key.replace(':', '_')
    key = key.replace('.', '_')
    key = key.replace('/', '_')
    key = key.replace(' ', '_')
    key = 'HAVE_' + key

    cfg_var = { 'is_on' : is_on, 'val' : str(1) }
    cfg_var.update(opt)

    AddCfgVariable(key, **cfg_var)

def CfgCheckCHeader(conf, header_name):
    ret = conf.CheckCHeader(header_name)

    AddCfgName(header_name, ret, ccomment = header_name)

############################################

env = Environment(ENV = os.environ)

conf_dir = user_options_dict['ConfigDir']
log_file = conf_dir + "/config.log"
conf = Configure(
        env,
        custom_tests = 
        {
            'CheckGNUCompiler'  : CheckGNUCompiler,
            'CheckClangCompiler': CheckClangCompiler,
            'CheckPKGConfig'    : CheckPKGConfig,
            'CheckTimeval'      : CheckTimeval, 
            'CheckAltivec'      : CheckAltivec,
            'CheckMaxAligning'  : CheckMaxAligning,
            'CheckBuiltinExpect': CheckBuiltinExpect,
            'CheckSignalRetType': CheckSignalRetType,
            'CheckCInline'      : CheckCInline,
            'CheckRestrictWord' : CheckRestrictWord,
        },
        conf_dir = conf_dir, 
        log_file = log_file)

# :TODO: change compiler to BuildVars.Cc and so on
conf.env.Replace(CC = Cc)
conf.env.Append(**user_options_dict['DVDREAD_DICT'])

#
# 0 Tools checks
# 

# is gcc?
user_options_dict["IS_GCC"]   = conf.CheckGNUCompiler()
user_options_dict["IS_CLANG"] = conf.CheckClangCompiler()
# pkg-config
if not conf.CheckPKGConfig():
    ErrorAndExit("'pkg-config' utility is not found.")

# now we know the compiler, set all that config options
user_options_dict['AdjustConfigOptions'](conf.env)

#
# 1 architecture options
#
arch_dict = { 
             'ARCH_X86'   : 0, 
             'ARCH_PPC'   : 0, 
             'ARCH_SPARC' : 0, 
             'ARCH_ALPHA' : 0, 
            }
set_altivec = 0
if IsGccLike():
    if IsX86Arch():
        arch_dict['ARCH_X86'] = 1
    elif IsPPCArch():
        class is_altivec:
            pass
        is_av = is_altivec()
        arch_dict['ARCH_PPC'] = conf.CheckAltivec(is_altivec = is_av)
        set_altivec = is_av.value
    elif IsSparcArch():
        arch_dict['ARCH_SPARC'] = 1
    elif IsAlphaArch():
        arch_dict['ARCH_ALPHA'] = 1

def SetArch(name, is_on):
    str = name[5:].lower() + ' architecture'
    cfg_var = { 'is_on' : is_on, 'val' : None, 'comment' : str }
    AddCfgVariable(name, **cfg_var)

for name in arch_dict.keys():
    SetArch(name, arch_dict[name])
AddCfgName('altivec.h', set_altivec, ccomment = 'altivec.h')

#
# 2 header existance
#

def CfgCheckCHeaderList(conf, hdr_list):
    for hdr in hdr_list:
        CfgCheckCHeader(conf, hdr)

CfgCheckCHeaderList(conf, ['sys/types.h', 'sys/stat.h', 'stdlib.h', 'string.h', 
    'memory.h', 'strings.h', 'inttypes.h', 'stdint.h', 'unistd.h'])

CfgCheckCHeader(conf, 'dlfcn.h')

CfgCheckCHeaderList(conf, ['sys/timeb.h', 'sys/time.h', 'time.h', 'io.h'])

#
# 3 functions and structs
#

AddCfgName('struct timeval', conf.CheckTimeval(), ocomment = "type `struct timeval'")

AddCfgName('ftime', conf.CheckFunc('ftime'), ocomment = "`ftime' function")

AddCfgName('gettimeofday',  conf.CheckFunc('gettimeofday'), ocomment = "`gettimeofday' function")

#
# 4 misc
#

align = conf.CheckMaxAligning()
AddCfgVariable('ATTRIBUTE_ALIGNED_MAX', is_on = (align != 0), val = align, 
    comment = "maximum supported data alignment" )

AddCfgVariable('HAVE_BUILTIN_EXPECT', is_on = conf.CheckBuiltinExpect(),
    ocomment = "`__builtin_expect' function")

AddCfgVariable('RETSIGTYPE', is_on = 1, val = conf.CheckSignalRetType(), 
    comment = "Define as the return type of signal handlers (`int' or `void').")

AddCfgVariable('WORDS_BIGENDIAN', is_on = (sys.byteorder == 'big'), val = 1, comment = 
"""Define to 1 if your processor stores words with the most significant byte
   first (like Motorola and SPARC, unlike Intel and VAX).""")

inline_word = conf.CheckCInline()
if inline_word == 'inline':
    inline_def = '#undef'
else:
    inline_def = '#define inline'
inline_text = """#ifndef __cplusplus
%s %s
#endif""" % (inline_def, inline_word)
AddCfgVariable('inline', text = inline_text, comment = 
"""Define to `__inline__' or `__inline' if that's what the C compiler
   calls it, or to nothing if 'inline' is not supported under any name.""")

AddCfgVariable('restrict', is_on = 1, val = conf.CheckRestrictWord(), comment = 
"""Define as `__restrict' if that's what the C compiler calls it, or to
   nothing if it is not supported.""")

if not conf.CheckLib("dvdread", "DVDOpenFile"):
    ErrorAndExit("Can't find library libdvdread!")

#
# 5 File checks
#

#/* Number of bits in a file offset, on hosts where this is settable. */
#define _FILE_OFFSET_BITS 64

#/* Define for large files, on AIX-style hosts. */
#/* #undef _LARGE_FILES */

conf.Finish()

########################################################
# Other checks

#
# Our purpose is not to describe all the checks that classical 'autoconf' tool
# has; so we assume the following requirements:
#  - C compiler fully meet the standard C90, probably with some 'extensions'
#  - C++ compiler fully meet the standard C++98, probably with some 'extensions'
#

# So, we assume (and dont check those) that:
#  - we have ANSI C header like stdlib.h, stdarg.h, ... (STDC_HEADERS)
#  - we have `const', `unsigned', `size_t', `volatile'
#  - we can calc sizes of types by sizeof (SIZEOF_CHAR, SIZEOF_VOIDP, ...)