-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_posixlibs.py
176 lines (152 loc) · 4 KB
/
find_posixlibs.py
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
# -*- python -*-
# stdlib imports ---
import os
import os.path as osp
# waf imports ---
import waflib.Utils
import waflib.Logs as msg
from waflib.Configure import conf
#
_heptooldir = osp.dirname(osp.abspath(__file__))
def options(ctx):
ctx.load('hwaf-base', tooldir=_heptooldir)
ctx.load('find_gdb', tooldir=_heptooldir)
return
def configure(ctx):
ctx.load('hwaf-base', tooldir=_heptooldir)
ctx.load('find_gdb', tooldir=_heptooldir)
return
@conf
def find_posixlibs(ctx, **kwargs):
ctx.load('hwaf-base', tooldir=_heptooldir)
if not ctx.env.HWAF_FOUND_C_COMPILER:
ctx.fatal('load a C compiler first')
pass
if not ctx.env.HWAF_FOUND_CXX_COMPILER:
ctx.fatal('load a C++ compiler first')
pass
if not ctx.env.HWAF_FOUND_GDB:
# gdb might have installed interesting libs (iberty, bfd)
ctx.find_gdb(mandatory=False)
pass
# find libm
ctx.check_with(
ctx.check,
"m",
features='c cprogram',
lib='m',
uselib_store='m',
**kwargs
)
# find dl
ctx.check_with(
ctx.check,
"dl",
features='c cprogram',
lib='dl',
uselib_store='dl',
**kwargs
)
# find pthread
ctx.check_with(
ctx.check,
"pthread",
features='c cprogram',
lib='pthread',
uselib_store='pthread',
**kwargs
)
# find libz
ctx.check_with(
ctx.check,
"zlib",
features='c cprogram',
header_name="zlib.h",
lib='z',
uselib_store='z',
**kwargs
)
extra_paths = waflib.Utils.to_list(kwargs.get('extra_paths',[]))
if ctx.env.GDB_HOME:
gdb = ctx.hwaf_subst_vars('${GDB_HOME}')
extra_paths.append(gdb)
pass
# find libiberty
iberty_mandatory = kwargs.get('iberty_mandatory', False)
if ctx.is_darwin():
iberty_mandatory = kwargs.get('iberty_mandatory', False)
pass
iberty_kwargs = dict(kwargs)
iberty_kwargs['mandatory'] = iberty_mandatory
iberty_kwargs['extra_paths'] = extra_paths
ctx.check_with(
ctx.check,
"iberty",
features='c cstlib',
header_name="libiberty.h",
stlib='iberty',
uselib_store='iberty',
**iberty_kwargs
)
if ctx.env.LIBPATH_iberty and 0:
ctx.env.STLIBPATH_iberty = ctx.env.LIBPATH_iberty
ctx.env.STLIB_iberty = ctx.env.LIB_iberty
ctx.env.LIB_iberty = []
ctx.env.LIBPATH_iberty = []
pass
# find bfd
bfd_mandatory = kwargs.get('bfd_mandatory', True)
if ctx.is_darwin():
bfd_mandatory = kwargs.get('bfd_mandatory', False)
pass
bfd_kwargs = dict(kwargs)
bfd_kwargs['mandatory'] = bfd_mandatory
bfd_kwargs['extra_paths'] = extra_paths
ctx.check_with(
ctx.check,
"bfd",
features='c cstlib',
defines=['PACKAGE="package-name"','PACKAGE_VERSION="package-version"',],
header_name="bfd.h",
stlib='bfd',
uselib_store='bfd',
use='dl iberty',
**bfd_kwargs
)
ctx.env.DEFINES_bfd = []
# find rt
if not ctx.is_darwin():
ctx.check_with(
ctx.check,
"rt",
features='c cprogram',
lib='rt',
uselib_store='rt',
**kwargs
)
pass
# test bfd
ctx.check_cc(
msg="Checking bfd_init",
okmsg="ok",
features='c cstlib',
fragment='''\
#ifndef PACKAGE
# define PACKAGE "package-name"
#endif
#ifndef PACKAGE_VERSION
# define PACKAGE_VERSION 1
#endif
#include "bfd.h"
int test_bfd_init() {
bfd_init();
bfd_error_type err = bfd_get_error();
return (int)err;
}
''',
use=['z', 'bfd', 'iberty', 'dl'],
mandatory= bfd_mandatory,
)
ctx.env.HWAF_FOUND_POSIXLIBS = 1
return
## EOF ##