forked from libxmljs/libxmljs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSConstruct
More file actions
120 lines (99 loc) · 3.15 KB
/
SConstruct
File metadata and controls
120 lines (99 loc) · 3.15 KB
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
import sys
import os
import re
import subprocess
from os.path import join, dirname, abspath
from types import DictType, StringTypes
root_dir = dirname(File('SConstruct').rfile().abspath)
# prefer these tools to anything living in the system already.
sys.path.insert(0, join(root_dir, 'tools'))
import js2c
if ARGUMENTS.get('debug', 0):
node_exe ='node_g'
else:
node_exe ='node'
def shellOut(target):
return subprocess.Popen(target, stdout=subprocess.PIPE).communicate()[0].strip()
def CheckForNodeJS(context):
context.Message('Checking for node.js ...')
result = shellOut(['which', node_exe]) != ''
context.Result(result)
return result
def CheckVersion(a,b):
from pkg_resources import parse_version as V
return V(a) >= V(b)
def GetLibXml2cflags():
minxml2version = '2.7.1'
if CheckVersion(shellOut(['xml2-config', '--version']), minxml2version):
return shellOut(['xml2-config', '--cflags'])
elif os.path.isfile('/opt/local/bin/xml2-config') and CheckVersion(shellOut(['/opt/local/bin/xml2-config', '--version']), minxml2versio$
return shellOut(['/opt/local/bin/xml2-config', '--cflags'])
else:
print 'Your version of libxml2 is too old, exiting.'
Exit(1);
using_node_js = (('libxmljs.node' in COMMAND_LINE_TARGETS) or ('test' in COMMAND_LINE_TARGETS))
libs = ['xml2']
libpath = [
'/opt/local/lib',
'/usr/local/lib',
'/usr/lib'
]
#cflags = ' '.join([
# '-I/opt/local/include',
# '-I/opt/local/include/libxml2',
# '-I/usr/local/include',
# '-I/usr/include',
# '-I/usr/include/libxml2',
#])
cflags = GetLibXml2cflags()
if using_node_js:
node_flags = shellOut([node_exe, '--vars'])
node_flags = re.search(r'^NODE_CFLAGS:\s*(.*)$', node_flags, re.MULTILINE)
if node_flags:
cflags += ' ' + node_flags.group(1)
testBuilder = Builder(action = 'node spec/tacular.js')
env = Environment(BUILDERS = {'Test' : testBuilder})
env.Append(
LIBPATH = libpath,
CCFLAGS = cflags
)
# explicitly link against node under cygwin
if env['PLATFORM'] == 'cygwin':
libs += ['node']
if not env.GetOption('clean'):
conf = Configure(env, custom_tests = {'CheckForNodeJS' : CheckForNodeJS})
print conf.CheckForNodeJS()
if not conf.CheckLib('xml2', header = '#include <libxml/parser.h>', language = 'c++'):
print 'Did not find libxml2, exiting!'
Exit(1)
if not using_node_js and not conf.CheckLib('v8', header = '#include <v8.h>', language = 'c++'):
print 'Did not find libv8, exiting!'
Exit(1)
if using_node_js and not conf.CheckForNodeJS():
print 'Did not find node.js exiting!'
Exit(1)
env = conf.Finish()
# Build native js
js2c.JS2C(Glob('src/*.js'), ['src/natives.h'])
cc_sources = Glob('src/*.cc')
# Build libxmljs binary
libxmljs = env.Program(
target = 'libxmljs',
source = cc_sources,
CCFLAGS = cflags,
LIBS = libs,
LIBPATH = libpath
)
# Build libxmljs node plugin
if env['PLATFORM'] == 'darwin':
env.Append(LDMODULEFLAGS = ['-bundle_loader', shellOut(['which', 'node'])])
node = env.LoadableModule(
target = 'libxmljs.node',
source = cc_sources,
CCFLAGS = cflags,
LIBS = libs,
LIBPATH = libpath
)
# Run tests
tests = env.Test('test', 'libxmljs.node')
env.Default(libxmljs)