Upstream version 7.36.151.0
[platform/framework/web/crosswalk.git] / src / v8 / tools / mingw-generate-makefiles.sh
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
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