fix compile errors
[platform/upstream/libSkiaSharp.git] / 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://skia.org.\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_gpu=0' 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 = os.environ.get('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     if os.environ.get('DevEnvDir'):\r
65       return\r
66 \r
67     print ('\nCould not find Visual Studio environment variables.'\r
68            '\nPerhaps you have not yet run vcvars32.bat as described at'\r
69            '\nhttp://msdn.microsoft.com/en-us/library/f2ccy3wt.aspx ?')\r
70     found_path = None\r
71     try:\r
72         possible_path = os.path.abspath(os.path.join(\r
73             os.environ['VS100COMNTOOLS'], os.path.pardir, os.path.pardir,\r
74             'VC', 'bin', 'vcvars32.bat'))\r
75         if os.path.exists(possible_path):\r
76             found_path = possible_path\r
77     except KeyError:\r
78         pass\r
79     if found_path:\r
80         print '\nIt looks like you can run that script at:\n%s' % found_path\r
81     else:\r
82         print '\nUnable to find vcvars32.bat on your system.'\r
83     sys.exit(1)\r
84 \r
85 \r
86 def MakeWindows(targets):\r
87     """For Windows: build as appropriate for the command line arguments.\r
88 \r
89     parameters:\r
90         targets: build targets as a list of strings\r
91     """\r
92     if os.environ.get('CHROME_HEADLESS', '0') != '1':\r
93         # TODO(epoger): I'm not sure if this is needed for ninja builds.\r
94         CheckWindowsEnvironment()\r
95 \r
96     # Run gyp_skia to prepare Visual Studio projects.\r
97     cd(SCRIPT_DIR)\r
98     runcommand('python gyp_skia --no-parallel -G config=%s' % BUILDTYPE)\r
99 \r
100     # We already built the gypfiles...\r
101     while TARGET_GYP in targets:\r
102         targets.remove(TARGET_GYP)\r
103 \r
104     # And call ninja to do the work!\r
105     if targets:\r
106         runcommand('ninja -C %s %s' % (\r
107             os.path.join(OUT_SUBDIR, BUILDTYPE), ' '.join(targets)))\r
108 \r
109 \r
110 def Make(args):\r
111     """Main function.\r
112 \r
113     parameters:\r
114         args: command line arguments as a list of strings\r
115     """\r
116     # handle any variable-setting parameters or special targets\r
117     global BUILDTYPE\r
118 \r
119     # if no targets were specified at all, make default target\r
120     if not args:\r
121         args = [TARGET_DEFAULT]\r
122 \r
123     targets = []\r
124     for arg in args:\r
125         # If user requests "make all", chain to our explicitly-declared\r
126         # "everything" target. See\r
127         # https://code.google.com/p/skia/issues/detail?id=932 ("gyp\r
128         # automatically creates "all" target on some build flavors but not\r
129         # others")\r
130         if arg == TARGET_ALL:\r
131             targets.append('everything')\r
132         elif arg == TARGET_CLEAN:\r
133             MakeClean()\r
134         elif arg.startswith('BUILDTYPE='):\r
135             BUILDTYPE = arg[10:]\r
136         elif arg.startswith('GYP_DEFINES='):\r
137             os.environ['GYP_DEFINES'] = arg[12:]\r
138         else:\r
139             targets.append(arg)\r
140 \r
141     # if there are no remaining targets, we're done\r
142     if not targets:\r
143         sys.exit(0)\r
144 \r
145     # dispatch to appropriate Make<Platform>() variant.\r
146     if os.name == 'nt':\r
147         MakeWindows(targets)\r
148         sys.exit(0)\r
149     elif os.name == 'posix':\r
150         if sys.platform == 'darwin':\r
151             print ('Mac developers should not run this script; see '\r
152                    'https://skia.org/user/quick/macos')\r
153             sys.exit(1)\r
154         elif sys.platform == 'cygwin':\r
155             print ('Windows development on Cygwin is not currently supported; '\r
156                    'see https://skia.org/user/quick/windows')\r
157             sys.exit(1)\r
158         else:\r
159             print ('Unix developers should not run this script; see '\r
160                    'https://skia.org/user/quick/linux')\r
161             sys.exit(1)\r
162     else:\r
163         print 'unknown platform (os.name=%s, sys.platform=%s); see %s' % (\r
164             os.name, sys.platform, 'https://skia.org/user/quick')\r
165         sys.exit(1)\r
166     sys.exit(0)\r
167 \r
168 \r
169 # main()\r
170 Make(sys.argv[1:])\r
171 \r
172     \r