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://skia.org.
\r
9 # Some usage examples:
\r
12 # make bench BUILDTYPE=Release
\r
13 # make gm GYP_DEFINES='skia_gpu=0' BUILDTYPE=Release
\r
20 BUILDTYPE = os.environ.get('BUILDTYPE', 'Debug')
\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
64 if os.environ.get('DevEnvDir'):
\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
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
80 print '\nIt looks like you can run that script at:\n%s' % found_path
\r
82 print '\nUnable to find vcvars32.bat on your system.'
\r
86 def MakeWindows(targets):
\r
87 """For Windows: build as appropriate for the command line arguments.
\r
90 targets: build targets as a list of strings
\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
96 # Run gyp_skia to prepare Visual Studio projects.
\r
98 runcommand('python gyp_skia --no-parallel -G config=%s' % BUILDTYPE)
\r
100 # We already built the gypfiles...
\r
101 while TARGET_GYP in targets:
\r
102 targets.remove(TARGET_GYP)
\r
104 # And call ninja to do the work!
\r
106 runcommand('ninja -C %s %s' % (
\r
107 os.path.join(OUT_SUBDIR, BUILDTYPE), ' '.join(targets)))
\r
114 args: command line arguments as a list of strings
\r
116 # handle any variable-setting parameters or special targets
\r
119 # if no targets were specified at all, make default target
\r
121 args = [TARGET_DEFAULT]
\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
130 if arg == TARGET_ALL:
\r
131 targets.append('everything')
\r
132 elif arg == TARGET_CLEAN:
\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
139 targets.append(arg)
\r
141 # if there are no remaining targets, we're done
\r
145 # dispatch to appropriate Make<Platform>() variant.
\r
146 if os.name == 'nt':
\r
147 MakeWindows(targets)
\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
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
159 print ('Unix developers should not run this script; see '
\r
160 'https://skia.org/user/quick/linux')
\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