1 # Copyright 2011 Google Inc.
\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
6 # "Makefile" replacement to build skia for Windows.
\r
7 # More info at https://sites.google.com/site/skiadocs/
\r
9 # Some usage examples:
\r
12 # make bench BUILDTYPE=Release
\r
13 # make gm GYP_DEFINES=skia_scalar=fixed BUILDTYPE=Release
\r
24 TARGET_CLEAN = 'clean'
\r
25 TARGET_DEFAULT = 'most'
\r
28 SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
\r
29 OUT_SUBDIR = os.environ.get('SKIA_OUT', 'out')
\r
33 # Simple functions that report what they are doing, and exit(1) on failure.
\r
35 print '> cd %s' % path
\r
36 if not os.path.isdir(path):
\r
37 print 'directory %s does not exist' % path
\r
42 print '> rmtree %s' % path
\r
43 shutil.rmtree(path, ignore_errors=True)
\r
45 def runcommand(command):
\r
46 print '> %s' % command
\r
47 if os.system(command):
\r
51 """Cross-platform "make clean" operation."""
\r
56 def CheckWindowsEnvironment():
\r
57 """For Windows: check environment variables needed for command-line build.
\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
63 # If we already have the proper environment variables, nothing to do here.
\r
65 env_DevEnvDir = os.environ['DevEnvDir']
\r
66 return # found it, so we are done
\r
68 pass # go on and run the rest of this function
\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
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
83 print '\nIt looks like you can run that script at:\n%s' % found_path
\r
85 print '\nUnable to find vcvars32.bat on your system.'
\r
89 def MakeWindows(targets):
\r
90 """For Windows: build as appropriate for the command line arguments.
\r
93 targets: build targets as a list of strings
\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
99 # Run gyp_skia to prepare Visual Studio projects.
\r
101 runcommand('python gyp_skia')
\r
103 # We already built the gypfiles...
\r
104 while TARGET_GYP in targets:
\r
105 targets.remove(TARGET_GYP)
\r
107 # And call ninja to do the work!
\r
109 runcommand('ninja -C %s %s' % (
\r
110 os.path.join(OUT_SUBDIR, BUILDTYPE), ' '.join(targets)))
\r
117 args: command line arguments as a list of strings
\r
119 # handle any variable-setting parameters or special targets
\r
122 # if no targets were specified at all, make default target
\r
124 args = [TARGET_DEFAULT]
\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
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
140 targets.append(arg)
\r
142 # if there are no remaining targets, we're done
\r
146 # dispatch to appropriate Make<Platform>() variant.
\r
147 if os.name == 'nt':
\r
148 MakeWindows(targets)
\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
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
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
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