forked from mongodb/mongo-snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jslib-sconstruct
163 lines (127 loc) · 4.16 KB
/
jslib-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
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
# -*- mode: python; -*-
# scons file to build spidermonkey
# experimental
#
import os
import subprocess
AddOption( "--64",
dest="force64",
type="string",
nargs=0,
action="store",
help="whether to force 64 bit" )
coreFiles = [ "jsapi.c" ,
"jsarena.c" ,
"jsarray.c" ,
"jsatom.c" ,
"jsbool.c" ,
"jscntxt.c" ,
"jsdate.c" ,
"jsdbgapi.c" ,
"jsdhash.c" ,
"jsdtoa.c" ,
"jsemit.c" ,
"jsexn.c" ,
"jsfun.c" ,
"jsgc.c" ,
"jshash.c" ,
"jsiter.c" ,
"jsinterp.c" ,
"jslock.c" ,
"jslog2.c" ,
"jslong.c" ,
"jsmath.c" ,
"jsnum.c" ,
"jsobj.c" ,
"jsopcode.c" ,
"jsparse.c" ,
"jsprf.c" ,
"jsregexp.c" ,
"jsscan.c" ,
"jsscope.c" ,
"jsscript.c" ,
"jsstr.c" ,
"jsutil.c" ,
"jsxdrapi.c" ,
"jsxml.c" ,
"prmjtime.c" ]
force64 = GetOption( "force64" ) is not None
msarch = None
if force64:
msarch = "amd64"
env = Environment( MSVS_ARCH=msarch )
nix = False
def findVersion( root , choices ):
if not isinstance(root, list):
root = [root]
for r in root:
for c in choices:
if ( os.path.exists( r + c ) ):
return r + c
raise RuntimeError("can't find a version of [" + repr(root) + "] choices: " + repr(choices))
if "win32" == os.sys.platform:
for pathdir in env['ENV']['PATH'].split(os.pathsep):
if os.path.exists(os.path.join(pathdir, 'cl.exe')):
print( "found visual studio at " + pathdir )
break
else:
#use current environment
print "using current environment (PATH etc.) settings"
#print os.environ
env['ENV'] = dict(os.environ)
if force64:
env.Append( CPPDEFINES=["_AMD64_=1"] )
else:
env.Append( CPPDEFINES=["_X86_=1"] )
env.Append( CPPFLAGS= " /nologo /MT /W3 /Gm /EHsc /Zi /Od /Fp " )
env.Append( CPPDEFINES=[ "_WINDOWS" , "WIN32" , "XP_WIN" ] )
winSDKHome = findVersion( [ "C:/Program Files/Microsoft SDKs/Windows/", "C:/Program Files (x86)/Microsoft SDKs/Windows/" ] ,
[ "v6.0" , "v6.0a" , "v6.1", "v7.0A" ] )
env.Append( CPPPATH=[ winSDKHome + "/Include" ] )
if force64:
env.Append( LIBPATH=[ winSDKHome + "/Lib/x64" ] )
else:
env.Append( LIBPATH=[ winSDKHome + "/Lib" ] )
elif "darwin" == os.sys.platform:
nix = True
elif "sunos5" == os.sys.platform:
nix = True
env.Append( CPPDEFINES=["SVR4" , "SYSV" , "SOLARIS" , "HAVE_LOCALTIMER_" ] )
if force64:
env.Append( CPPDEFINES=[ "HAVE_VA_LIST_AS_ARRAY" ] )
if os.uname()[1].count( "joyent" ) >= 1:
print( "JOYENT" )
env["CC"] = "/opt/gcc/gcc44/bin/gcc"
env["CXX"] = "/opt/gcc/gcc44/bin/g++"
elif "freebsd7" == os.sys.platform:
nix = True
elif "linux2" == os.sys.platform:
nix = True
else:
print( "unknown platform: " + os.sys.platform )
Exit(-1)
if nix:
env.Append( CPPDEFINES=[ "XP_UNIX" ] )
if force64:
env.Append( CPPFLAGS=" -m64 " )
env.Append( LINKFLAGS=" -m64 " )
env.Append( CPPDEFINES=[ "JSFILE" , "EXPORT_JS_API" , "JS_C_STRINGS_ARE_UTF8" ] )
env.StaticLibrary( "js" , coreFiles )
jskwgen = str( env.Program( "jskwgen" , [ "jskwgen.c" ] )[0] )
jscpucfg = str( env.Program( "jscpucfg" , [ "jscpucfg.c" ] )[0] )
def buildAutoFile( target , source , env ):
outFile = str( target[0] )
cmd = str( source[0] )
if nix:
cmd = "./" + cmd
output = subprocess.Popen( [ cmd ], stdout=subprocess.PIPE).communicate()[0]
output = output.replace( '\r' , '\n' )
out = open( outFile , 'w' )
out.write( output )
return None
autoBuilder = Builder(
action = buildAutoFile ,
suffix = '.h')
env.Append( BUILDERS={ 'Auto' : autoBuilder } )
env.Auto( "jsautokw.h" , [ jskwgen ] )
env.Auto( "jsautocfg.h" , [ jscpucfg ] )