Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / make.py
1 # Copyright 2011 Google Inc.\r
2 #\r
3 # Use of this source code is governed by a BSD-style license that can be\r
4 # found in the LICENSE file.\r
5 \r
6 # "Makefile" replacement to build skia for Windows.\r
7 # More info at https://sites.google.com/site/skiadocs/\r
8 #\r
9 # Some usage examples:\r
10 #   make clean\r
11 #   make dm\r
12 #   make bench BUILDTYPE=Release\r
13 #   make gm GYP_DEFINES=skia_scalar=fixed BUILDTYPE=Release\r
14 #   make all\r
15 \r
16 import os\r
17 import shutil\r
18 import sys\r
19 \r
20 BUILDTYPE = 'Debug'\r
21 \r
22 # special targets\r
23 TARGET_ALL     = 'all'\r
24 TARGET_CLEAN   = 'clean'\r
25 TARGET_DEFAULT = 'most'\r
26 TARGET_GYP     = 'gyp'\r
27 \r
28 SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))\r
29 OUT_SUBDIR = os.environ.get('SKIA_OUT', 'out')\r
30 GYP_SUBDIR = 'gyp'\r
31 \r
32 \r
33 # Simple functions that report what they are doing, and exit(1) on failure.\r
34 def cd(path):\r
35     print '> cd %s' % path\r
36     if not os.path.isdir(path):\r
37         print 'directory %s does not exist' % path\r
38         sys.exit(1)\r
39     os.chdir(path)\r
40 \r
41 def rmtree(path):\r
42     print '> rmtree %s' % path\r
43     shutil.rmtree(path, ignore_errors=True)\r
44 \r
45 def runcommand(command):\r
46     print '> %s' % command\r
47     if os.system(command):\r
48         sys.exit(1)\r
49 \r
50 def MakeClean():\r
51     """Cross-platform "make clean" operation."""\r
52     cd(SCRIPT_DIR)\r
53     rmtree(OUT_SUBDIR)\r
54 \r
55 \r
56 def CheckWindowsEnvironment():\r
57     """For Windows: check environment variables needed for command-line build.\r
58 \r
59     If those environment variables are missing, try to set them.\r
60     If environment variables can be set up, this function returns; otherwise,\r
61     it displays an error message and exits.\r
62     """\r
63     # If we already have the proper environment variables, nothing to do here.\r
64     try:\r
65         env_DevEnvDir = os.environ['DevEnvDir']\r
66         return  # found it, so we are done\r
67     except KeyError:\r
68         pass # go on and run the rest of this function\r
69 \r
70     print ('\nCould not find Visual Studio environment variables.'\r
71            '\nPerhaps you have not yet run vcvars32.bat as described at'\r
72            '\nhttp://msdn.microsoft.com/en-us/library/f2ccy3wt.aspx ?')\r
73     found_path = None\r
74     try:\r
75         possible_path = os.path.abspath(os.path.join(\r
76             os.environ['VS100COMNTOOLS'], os.path.pardir, os.path.pardir,\r
77             'VC', 'bin', 'vcvars32.bat'))\r
78         if os.path.exists(possible_path):\r
79             found_path = possible_path\r
80     except KeyError:\r
81         pass\r
82     if found_path:\r
83         print '\nIt looks like you can run that script at:\n%s' % found_path\r
84     else:\r
85         print '\nUnable to find vcvars32.bat on your system.'\r
86     sys.exit(1)\r
87 \r
88 \r
89 def MakeWindows(targets):\r
90     """For Windows: build as appropriate for the command line arguments.\r
91 \r
92     parameters:\r
93         targets: build targets as a list of strings\r
94     """\r
95     if os.environ.get('CHROME_HEADLESS', '0') != '1':\r
96         # TODO(epoger): I'm not sure if this is needed for ninja builds.\r
97         CheckWindowsEnvironment()\r
98 \r
99     # Run gyp_skia to prepare Visual Studio projects.\r
100     cd(SCRIPT_DIR)\r
101     runcommand('python gyp_skia')\r
102 \r
103     # We already built the gypfiles...\r
104     while TARGET_GYP in targets:\r
105         targets.remove(TARGET_GYP)\r
106 \r
107     # And call ninja to do the work!\r
108     if targets:\r
109         runcommand('ninja -C %s %s' % (\r
110             os.path.join(OUT_SUBDIR, BUILDTYPE), ' '.join(targets)))\r
111 \r
112 \r
113 def Make(args):\r
114     """Main function.\r
115 \r
116     parameters:\r
117         args: command line arguments as a list of strings\r
118     """\r
119     # handle any variable-setting parameters or special targets\r
120     global BUILDTYPE\r
121 \r
122     # if no targets were specified at all, make default target\r
123     if not args:\r
124         args = [TARGET_DEFAULT]\r
125 \r
126     targets = []\r
127     for arg in args:\r
128         # If user requests "make all", chain to our explicitly-declared "everything"\r
129         # target. See https://code.google.com/p/skia/issues/detail?id=932 ("gyp\r
130         # automatically creates "all" target on some build flavors but not others")\r
131         if arg == TARGET_ALL:\r
132             targets.append('everything')\r
133         elif arg == TARGET_CLEAN:\r
134             MakeClean()\r
135         elif arg.startswith('BUILDTYPE='):\r
136             BUILDTYPE = arg[10:]\r
137         elif arg.startswith('GYP_DEFINES='):\r
138             os.environ['GYP_DEFINES'] = arg[12:]\r
139         else:\r
140             targets.append(arg)\r
141 \r
142     # if there are no remaining targets, we're done\r
143     if not targets:\r
144         sys.exit(0)\r
145 \r
146     # dispatch to appropriate Make<Platform>() variant.\r
147     if os.name == 'nt':\r
148         MakeWindows(targets)\r
149         sys.exit(0)\r
150     elif os.name == 'posix':\r
151         if sys.platform == 'darwin':\r
152             print 'Mac developers should not run this script; see ' \\r
153                 'https://sites.google.com/site/skiadocs/user-documentation/quick-start-guides/mac'\r
154             sys.exit(1)\r
155         elif sys.platform == 'cygwin':\r
156             print 'Windows development on Cygwin is not currently supported; see ' \\r
157                 'https://sites.google.com/site/skiadocs/user-documentation/quick-start-guides/windows'\r
158             sys.exit(1)\r
159         else:\r
160             print 'Unix developers should not run this script; see ' \\r
161                 'https://sites.google.com/site/skiadocs/user-documentation/quick-start-guides/linux'\r
162             sys.exit(1)\r
163     else:\r
164         print 'unknown platform (os.name=%s, sys.platform=%s); see %s' % (\r
165             os.name, sys.platform, 'https://sites.google.com/site/skiadocs/')\r
166         sys.exit(1)\r
167     sys.exit(0)\r
168 \r
169 \r
170 # main()\r
171 Make(sys.argv[1:])\r
172 \r
173     \r