-
Notifications
You must be signed in to change notification settings - Fork 12
/
SConstruct
113 lines (94 loc) · 4.11 KB
/
SConstruct
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
import os
# Set clang options by env
env = Environment(CC = "clang", CFLAGS = "-Wall -Werror")
# Output colors
env['ENV']['TERM'] = os.environ['TERM']
# Symlink builder
# http://stackoverflow.com/a/6415507/469463
env.Append(BUILDERS = {
"Symlink" : Builder(action = "ln -s ${SOURCE.file} ${TARGET.file}", chdir = True),
'Download': Builder(action = "wget --continue ${URL} -O ${TARGET}", chdir = True),
'Unpack' : Builder(action = "tar -${FLAGS} ${SOURCE.file}", chdir = True, target_factory = env.fs.Dir)
})
# Install options
name = 'libnss_resolver'
version = os.popen("git describe --abbrev=0 --tags").read()
version = version.strip().replace("v", "")
lib_name = '%s.so.%s' % (name, version)
# Build folder
build_dir = os.environ.get('BUILD_FOLDER', "./build")
env['ENV']['BUILD_FOLDER'] = build_dir
# cdefines
DEBUG=""
cppdefines = []
for key, value in ARGLIST:
if key == 'define':
cppdefines.append(value)
if (value == "DEBUG"):
DEBUG="-g"
env.Append(CPPDEFINES = cppdefines)
# dependencie cmocka
cmocka_version = "1.0.1"
cmocka_url = "git.cryptomilk.org/projects/cmocka.git/snapshot/cmocka-%s.tar.xz" % cmocka_version
cmocka_file = "%s/cmocka-%s.tar.xz" % (build_dir, cmocka_version)
cmocka_folder = "%s/cmocka-%s" % (build_dir, cmocka_version)
cmocka_script = """
cd $SOURCE; mkdir -p ./build;
cd $SOURCE/build; cmake ../;
cd $SOURCE/build; make install;
"""
cmocka_file = env.Download(cmocka_file, None, URL = cmocka_url)
cmocka_folder = env.Unpack(cmocka_folder, cmocka_file, FLAGS = "xJf")
cmocka = env.Command("/usr/local/lib/libcmocka.so", cmocka_folder, Action(cmocka_script));
# Dependencie cares
cares_version = "1_11_0-rc1"
cares_url = "https://github.com/azukiapp/c-ares/releases/download/%s/c-ares-%s.tar.gz" % (cares_version, cares_version)
cares_file = "%s/c-ares-%s.tar.gz" % (build_dir, cares_version)
cares_folder = "%s/c-ares-%s" % (build_dir, cares_version)
cares_script = """
cd $SOURCE; if [ ! -f Makefile ]; then ./configure --disable-shared --enable-static --enable-symbol-hiding; fi
cd $SOURCE; make;
cp $SOURCE/.libs/libcares.a $TARGET;
"""
env.Download(cares_file, None, URL = cares_url, chdir=False)
env.Unpack(cares_folder, cares_file, FLAGS = "zxf")
cares = env.Command("%s/libcares.a" % build_dir, cares_folder, Action(cares_script));
# Library
so = env.SharedLibrary("%s/libnss_resolver" % build_dir, Glob("src/*c"),
LIBS = [cares],
CFLAGS = ("%s -I%s" % (DEBUG, cares_folder)),
LINKFLAGS = "-Wl,--no-as-needed -lrt",
)
install_dirs = {
'pack' : ARGUMENTS.get('pack_prefix', '%s/libnss/usr/lib' % build_dir),
'local': ARGUMENTS.get('prefix', '/usr/lib'),
'azk' : '/azk/lib'
}
for k,v in install_dirs.items():
directory = os.path.normpath(v);
build = env.InstallAs('%s/%s.so.2' % (directory, name), so)
globals()['so_' + k] = build
# Test
env['ENV']['TEST_DNS_PORT'] = os.environ.get('DNS_DNS_PORT', None)
env['ENV']['TEST_DNS_HOST'] = os.environ.get('DNS_DNS_HOST', None)
env['ENV']['TEST_DNS_IP'] = os.environ.get('DNS_IP', None)
env['ENV']['TEST_DOMAIN'] = os.environ.get('DNS_DOMAIN', None)
env['ENV']['TEST_FIXTURES'] = os.getcwd() + '/test/fixtures/'
env['ENV']['VALGRIND_OPTS'] = ARGUMENTS.get('valgrind', '')
env['ENV']['LD_LIBRARY_PATH'] = '/usr/local/lib'
test_bin = "%s/test" % build_dir
test_app = env.Program(test_bin, so_local + cmocka + ["src/resolver.c", "src/files.c", Glob("test/*.c")],
LIBS = [cmocka, cares],
CFLAGS = ("%s -I/usr/local/include -I%s -I%s/include" % (DEBUG, cares_folder, cmocka_folder[0])),
LINKFLAGS = "-Wl,--no-as-needed -lrt -lcmocka")
test_run = env.Alias("run-test", cares + cmocka + test_app,
Action("echo '\x1b[2J\x1b[0;0f'; valgrind --suppressions=./valgrind.supp ${VALGRIND_OPTS} %s" % test_bin)
)
AlwaysBuild(test_run)
# Alias
env.Alias('cares' , cares)
env.Alias('cmocka' , cmocka)
env.Alias('test' , cares + cmocka + test_app)
env.Alias('pack' , cares + so_pack)
env.Alias('install', cares + ['/azk/lib'])
env.Alias('local-install', cares + [install_dirs['local']])