Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.

Commit 47b3ca9

Browse files
committed
Added support for windows platforms using mingw.
1 parent 8f8e205 commit 47b3ca9

4 files changed

Lines changed: 122 additions & 6 deletions

File tree

ext/libv8/builder.rb

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ def initialize
1616
@compiler = choose_compiler
1717
end
1818

19+
def make_target
20+
"#{libv8_arch}.#{profile}"
21+
end
22+
1923
def make_flags(*flags)
2024
profile = enable_config('debug') ? 'debug' : 'release'
2125

@@ -42,7 +46,7 @@ def make_flags(*flags)
4246
# with it on
4347
flags << 'werror=no'
4448

45-
"#{libv8_arch}.#{profile} #{flags.join ' '}"
49+
"#{make_target} #{flags.join ' '}"
4650
end
4751

4852
def build_libv8!
@@ -53,7 +57,17 @@ def build_libv8!
5357
setup_build_deps!
5458
patch! *patch_directories_for(@compiler)
5559
print_build_info
56-
puts `env CXX=#{@compiler} LINK=#{@compiler} #{make} #{make_flags}`
60+
61+
case RUBY_PLATFORM
62+
when /mingw/
63+
# use a script that will fix the paths in the generated Makefiles
64+
# don't use make_flags otherwise it will trigger a rebuild of the Makefiles
65+
`env CXX=#{@compiler} LINK=#{@compiler} bash #{PATCH_DIRECTORY}/mingw-generate-makefiles.sh`
66+
puts `env CXX=#{@compiler} LINK=#{@compiler} make #{make_target}`
67+
68+
else
69+
puts `env CXX=#{@compiler} LINK=#{@compiler} #{make} #{make_flags}`
70+
end
5771
end
5872
return $?.exitstatus
5973
end
@@ -96,8 +110,8 @@ def choose_compiler
96110
end
97111

98112
def python_version
99-
if system 'which python 2>&1 > /dev/null'
100-
`python -c 'import platform; print(platform.python_version())'`.chomp
113+
if `which python` =~ /python/
114+
`python -c "import platform; print(platform.python_version())"`.chomp
101115
else
102116
"not available"
103117
end

ext/libv8/checkout.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def checkout!
1515

1616
Dir.chdir(V8_Source) do
1717
`git fetch`
18-
`git checkout #{Libv8::VERSION.gsub(/\.\d+$/,'')} -f`
18+
`git checkout #{Libv8::VERSION.gsub(/\.\d+(\.rc\d+)?$/,'')} -f`
1919
`rm -f .applied_patches`
2020
end
2121

@@ -31,7 +31,8 @@ def checkout!
3131
# --git-dir is needed for older versions of git and git-svn
3232
`git --git-dir=../../.git/modules/vendor/gyp/ svn init #{GYP_SVN} -Ttrunk`
3333
`git config --replace-all svn-remote.svn.fetch trunk:refs/remotes/origin/master`
34-
`git checkout $(git --git-dir=../../.git/modules/vendor/gyp/ svn find-rev r#{rev} | tail -n 1) -f`
34+
svn_rev = `git --git-dir=../../.git/modules/vendor/gyp/ svn find-rev r#{rev} | tail -n 1`
35+
`git checkout #{svn_rev} -f`
3536
end
3637
end
3738

@@ -40,6 +41,9 @@ def git?(dir)
4041
end
4142

4243
def check_git_svn!
44+
# msysgit provides git svn
45+
return if RUBY_PLATFORM =~ /mingw/
46+
4347
unless system 'git help svn 2>&1 > /dev/null'
4448
fail "git-svn not installed!\nPlease install git-svn."
4549
end

ext/libv8/patcher.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def patch!(*additional_directories)
4747

4848
(available_patches - applied_patches).each do |patch|
4949
`patch -p1 -N < #{patch}`
50+
fail 'failed to apply patch' unless $?.success?
5051
f.puts patch
5152
end
5253
end
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/bin/sh
2+
# Copyright 2013 the V8 project authors. All rights reserved.
3+
# Redistribution and use in source and binary forms, with or without
4+
# modification, are permitted provided that the following conditions are
5+
# met:
6+
#
7+
# * Redistributions of source code must retain the above copyright
8+
# notice, this list of conditions and the following disclaimer.
9+
# * Redistributions in binary form must reproduce the above
10+
# copyright notice, this list of conditions and the following
11+
# disclaimer in the documentation and/or other materials provided
12+
# with the distribution.
13+
# * Neither the name of Google Inc. nor the names of its
14+
# contributors may be used to endorse or promote products derived
15+
# from this software without specific prior written permission.
16+
#
17+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
29+
# Monkey-patch GYP.
30+
cat > build/gyp/gyp.mingw << EOF
31+
#!/usr/bin/env python
32+
33+
# Copyright (c) 2009 Google Inc. All rights reserved.
34+
# Use of this source code is governed by a BSD-style license that can be
35+
# found in the LICENSE file.
36+
37+
import sys
38+
39+
# TODO(mark): sys.path manipulation is some temporary testing stuff.
40+
try:
41+
import gyp
42+
except ImportError, e:
43+
import os.path
44+
sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), 'pylib'))
45+
import gyp
46+
47+
def MonkeyBuildFileTargets(target_list, build_file):
48+
"""From a target_list, returns the subset from the specified build_file.
49+
"""
50+
build_file = build_file.replace('/', '\\\\')
51+
return [p for p in target_list if gyp.common.BuildFile(p) == build_file]
52+
gyp.common.BuildFileTargets = MonkeyBuildFileTargets
53+
54+
import gyp.generator.make
55+
import os
56+
def Monkey_ITIP(self):
57+
"""Returns the location of the final output for an installable target."""
58+
sep = os.path.sep
59+
# Xcode puts shared_library results into PRODUCT_DIR, and some gyp files
60+
# rely on this. Emulate this behavior for mac.
61+
if (self.type == 'shared_library' and
62+
(self.flavor != 'mac' or self.toolset != 'target')):
63+
# Install all shared libs into a common directory (per toolset) for
64+
# convenient access with LD_LIBRARY_PATH.
65+
return '\$(builddir)%slib.%s%s%s' % (sep, self.toolset, sep, self.alias)
66+
return '\$(builddir)' + sep + self.alias
67+
gyp.generator.make.MakefileWriter._InstallableTargetInstallPath = Monkey_ITIP
68+
69+
if __name__ == '__main__':
70+
sys.exit(gyp.main(sys.argv[1:]))
71+
EOF
72+
73+
# Delete old generated Makefiles.
74+
find out -name '*.mk' -or -name 'Makefile*' -exec rm {} \;
75+
76+
# Generate fresh Makefiles.
77+
mv build/gyp/gyp build/gyp/gyp.original
78+
mv build/gyp/gyp.mingw build/gyp/gyp
79+
make out/Makefile.ia32 out/Makefile.x64
80+
mv build/gyp/gyp build/gyp/gyp.mingw
81+
mv build/gyp/gyp.original build/gyp/gyp
82+
83+
# Patch generated Makefiles: replace most backslashes with forward slashes,
84+
# fix library names in linker flags.
85+
FILES=$(find out -name '*.mk' -or -name 'Makefile*')
86+
for F in $FILES ; do
87+
echo "Patching $F..."
88+
cp $F $F.orig
89+
cat $F.orig \
90+
| sed -e 's|\([)a-zA-Z0-9]\)\\\([a-zA-Z]\)|\1/\2|g' \
91+
-e 's|\([)a-zA-Z0-9]\)\\\\\([a-zA-Z]\)|\1/\2|g' \
92+
-e 's|'%s/n'|'%s\\\\n'|g' \
93+
-e 's|-lwinmm\.lib|-lwinmm|g' \
94+
-e 's|-lws2_32\.lib|-lws2_32|g' \
95+
> $F
96+
rm $F.orig
97+
done

0 commit comments

Comments
 (0)