change the prototype of the function a_version_tostr
[liba.git] / SConstruct
blob1a13a7a06716ba684a391b6ab6d314a4051cd288
1 import os
2 AddOption('--float', choices=('4', '8', '16'), default=8, metavar='4,8,16', help='floating-point number bytes')
3 AddOption('--tools', default='', help='append the default tool list')
4 vars = Variables()
5 vars.Add('CC', help='The C compiler')
6 vars.Add('CFLAGS', help='The C compiler flags')
7 vars.Add('LINKFLAGS', help='The linker flags')
8 env = Environment(
9 ENV=os.environ.copy(),
10 tools=['default'] + GetOption('tools').split(','),
11 variables=vars,
13 env.Append(CPPPATH=('include'))
14 env.Append(CPPDEFINES=('A_EXPORTS'))
15 env.Append(CPPDEFINES=('A_HAVA_H', '"a.scons.h"'))
16 def Undefine(conf):
17 if '\n' not in conf.config_h_text:
18 return
19 conf.config_h_text = conf.config_h_text.replace(
20 conf.config_h_text.splitlines()[-1] + '\n', ''
22 conf = env.Configure(config_h='include/a/a.scons.h')
23 A_SIZE_POINTER = conf.CheckTypeSize('void *')
24 Undefine(conf)
25 conf.Define('A_SIZE_POINTER', A_SIZE_POINTER)
26 res = conf.TryRun('''#include <stdio.h>
27 int main()
29 int const x = 1;
30 printf("%s", *(char *)&x ? "1234" : "4321");
31 return 0;
33 ''', '.c')
34 if res[0]:
35 conf.Define('A_BYTE_ORDER', res[1], 'The byte order of compiler target architecture.')
36 A_SIZE_FLOAT = int(env.GetOption('float'))
37 conf.Define('A_SIZE_FLOAT', A_SIZE_FLOAT, "The size of `a_float', as computed by sizeof.")
38 conf.CheckLib('m')
39 Undefine(conf)
40 for func in (
41 'expm1', 'log1p', 'hypot', 'atan2',
42 'csqrt', 'cpow', 'cexp', 'clog',
43 'csin', 'ccos', 'ctan',
44 'csinh', 'ccosh', 'ctanh',
45 'casin', 'cacos', 'catan',
46 'casinh', 'cacosh', 'catanh'
48 name = 'A_HAVE_' + func.upper()
49 if A_SIZE_FLOAT == 0x10:
50 func += 'l'
51 if A_SIZE_FLOAT == 0x04:
52 func += 'f'
53 ok = conf.CheckFunc(func)
54 Undefine(conf)
55 if ok:
56 conf.Define(name, '1')
57 env = conf.Finish()
58 a = env.SharedObject(env.Glob('src/*.c') + env.Glob('src/*/*.c'))
59 if env['PLATFORM'] == 'win32':
60 liba = env.SharedLibrary('liba', a)
61 else:
62 liba = env.SharedLibrary('a', a)
63 alib = env.StaticLibrary('a', a)
64 env.Install()
65 if env.GetOption('install_sandbox'):
66 include = env.Install('include', source='include/a')
67 def install_fixup(source, target, env):
68 source = source[0].get_relpath() + '/a.h'
69 target = target[0].get_relpath() + '/a.h'
70 with open(source, "r") as f:
71 text = f.read()
72 cur = "#if defined(A_HAVE_H)"
73 new = '#include "a.scons.h"\n' + cur
74 text = text.replace(cur, new)
75 with open(target, "wb") as f:
76 f.write(text.encode())
77 env.AddPostAction(include, install_fixup)
78 env.Install('lib', source=[alib, liba])