blob: f6f9f11e25cfc195ab8b11223a21d439f2be8873 [file] [log] [blame]
epoger@google.comfd03db02011-07-28 14:24:55 +00001# Copyright 2011 Google Inc.
epoger@google.com877cfe32011-07-11 19:52:00 +00002#
epoger@google.comfd03db02011-07-28 14:24:55 +00003# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
epoger@google.com877cfe32011-07-11 19:52:00 +00005
6# "Makefile" replacement to build skia for Windows.
epoger@google.com9c875d32012-10-18 16:10:56 +00007# More info at https://sites.google.com/site/skiadocs/
epoger@google.com7815e732011-07-15 13:23:22 +00008#
9# Some usage examples:
10# make clean
11# make tests
12# make bench BUILDTYPE=Release
13# make gm GYP_DEFINES=skia_scalar=fixed BUILDTYPE=Release
14# make all
epoger@google.com877cfe32011-07-11 19:52:00 +000015
16import os
17import shutil
18import sys
19
epoger@google.com0fb21252011-07-13 21:30:14 +000020BUILDTYPE = 'Debug'
21
epoger@google.com7815e732011-07-15 13:23:22 +000022# special targets
epoger@google.com9c875d32012-10-18 16:10:56 +000023TARGET_ALL = 'all'
24TARGET_CLEAN = 'clean'
25TARGET_DEFAULT = 'most'
26TARGET_GYP = 'gyp'
epoger@google.com877cfe32011-07-11 19:52:00 +000027
28SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
borenet@google.coma82c9eb2013-07-23 15:45:50 +000029OUT_SUBDIR = os.environ.get('SKIA_OUT', 'out')
epoger@google.com877cfe32011-07-11 19:52:00 +000030GYP_SUBDIR = 'gyp'
31
32
33# Simple functions that report what they are doing, and exit(1) on failure.
34def cd(path):
35 print '> cd %s' % path
epoger@google.com0fb21252011-07-13 21:30:14 +000036 if not os.path.isdir(path):
37 print 'directory %s does not exist' % path
epoger@google.com877cfe32011-07-11 19:52:00 +000038 sys.exit(1)
39 os.chdir(path)
40
41def rmtree(path):
42 print '> rmtree %s' % path
43 shutil.rmtree(path, ignore_errors=True)
44
45def runcommand(command):
46 print '> %s' % command
47 if os.system(command):
48 sys.exit(1)
49
50def MakeClean():
51 """Cross-platform "make clean" operation."""
52 cd(SCRIPT_DIR)
53 rmtree(OUT_SUBDIR)
54 # clean up the directory that XCode (on Mac) creates
55 rmtree('xcodebuild')
56
57
58def CheckWindowsEnvironment():
59 """For Windows: check environment variables needed for command-line build.
60
61 If those environment variables are missing, try to set them.
62 If environment variables can be set up, this function returns; otherwise,
63 it displays an error message and exits.
64 """
65 # If we already have the proper environment variables, nothing to do here.
66 try:
67 env_DevEnvDir = os.environ['DevEnvDir']
68 return # found it, so we are done
69 except KeyError:
70 pass # go on and run the rest of this function
71
72 print ('\nCould not find Visual Studio environment variables.'
73 '\nPerhaps you have not yet run vcvars32.bat as described at'
74 '\nhttp://msdn.microsoft.com/en-us/library/f2ccy3wt.aspx ?')
75 found_path = None
76 try:
77 possible_path = os.path.abspath(os.path.join(
78 os.environ['VS100COMNTOOLS'], os.path.pardir, os.path.pardir,
79 'VC', 'bin', 'vcvars32.bat'))
80 if os.path.exists(possible_path):
81 found_path = possible_path
82 except KeyError:
83 pass
84 if found_path:
85 print '\nIt looks like you can run that script at:\n%s' % found_path
86 else:
87 print '\nUnable to find vcvars32.bat on your system.'
88 sys.exit(1)
89
90
epoger@google.com7815e732011-07-15 13:23:22 +000091def MakeWindows(targets):
epoger@google.com877cfe32011-07-11 19:52:00 +000092 """For Windows: build as appropriate for the command line arguments.
93
94 parameters:
epoger@google.com7815e732011-07-15 13:23:22 +000095 targets: build targets as a list of strings
epoger@google.com877cfe32011-07-11 19:52:00 +000096 """
epoger@google.com58d69d82014-04-01 07:02:41 +000097 # TODO(epoger): I'm not sure if this is needed for ninja builds.
epoger@google.com877cfe32011-07-11 19:52:00 +000098 CheckWindowsEnvironment()
epoger@google.com0fb21252011-07-13 21:30:14 +000099
epoger@google.com877cfe32011-07-11 19:52:00 +0000100 # Run gyp_skia to prepare Visual Studio projects.
101 cd(SCRIPT_DIR)
102 runcommand('python gyp_skia')
epoger@google.com0fb21252011-07-13 21:30:14 +0000103
epoger@google.com58d69d82014-04-01 07:02:41 +0000104 # We already built the gypfiles...
105 while TARGET_GYP in targets:
106 targets.remove(TARGET_GYP)
epoger@google.com0fb21252011-07-13 21:30:14 +0000107
epoger@google.com58d69d82014-04-01 07:02:41 +0000108 # And call ninja to do the work!
109 if targets:
110 runcommand('ninja -C %s %s' % (
111 os.path.join(OUT_SUBDIR, BUILDTYPE), ' '.join(targets)))
epoger@google.com877cfe32011-07-11 19:52:00 +0000112
epoger@google.com7815e732011-07-15 13:23:22 +0000113
114def Make(args):
115 """Main function.
116
117 parameters:
118 args: command line arguments as a list of strings
119 """
120 # handle any variable-setting parameters or special targets
121 global BUILDTYPE
epoger@google.com9c875d32012-10-18 16:10:56 +0000122
123 # if no targets were specified at all, make default target
124 if not args:
125 args = [TARGET_DEFAULT]
126
epoger@google.com7815e732011-07-15 13:23:22 +0000127 targets = []
128 for arg in args:
epoger@google.com6714ea42012-10-25 16:32:07 +0000129 # If user requests "make all", chain to our explicitly-declared "everything"
130 # target. See https://code.google.com/p/skia/issues/detail?id=932 ("gyp
131 # automatically creates "all" target on some build flavors but not others")
epoger@google.com7815e732011-07-15 13:23:22 +0000132 if arg == TARGET_ALL:
epoger@google.com6714ea42012-10-25 16:32:07 +0000133 targets.append('everything')
epoger@google.com7815e732011-07-15 13:23:22 +0000134 elif arg == TARGET_CLEAN:
135 MakeClean()
136 elif arg.startswith('BUILDTYPE='):
137 BUILDTYPE = arg[10:]
138 elif arg.startswith('GYP_DEFINES='):
139 os.environ['GYP_DEFINES'] = arg[12:]
140 else:
141 targets.append(arg)
142
143 # if there are no remaining targets, we're done
144 if not targets:
145 sys.exit(0)
146
147 # dispatch to appropriate Make<Platform>() variant.
148 if os.name == 'nt':
149 MakeWindows(targets)
150 sys.exit(0)
151 elif os.name == 'posix':
152 if sys.platform == 'darwin':
153 print 'Mac developers should not run this script; see ' \
epoger@google.com9c875d32012-10-18 16:10:56 +0000154 'https://sites.google.com/site/skiadocs/user-documentation/quick-start-guides/mac'
epoger@google.com7815e732011-07-15 13:23:22 +0000155 sys.exit(1)
156 elif sys.platform == 'cygwin':
epoger@google.com9c875d32012-10-18 16:10:56 +0000157 print 'Windows development on Cygwin is not currently supported; see ' \
158 'https://sites.google.com/site/skiadocs/user-documentation/quick-start-guides/windows'
epoger@google.com7815e732011-07-15 13:23:22 +0000159 sys.exit(1)
160 else:
161 print 'Unix developers should not run this script; see ' \
epoger@google.com9c875d32012-10-18 16:10:56 +0000162 'https://sites.google.com/site/skiadocs/user-documentation/quick-start-guides/linux'
epoger@google.com7815e732011-07-15 13:23:22 +0000163 sys.exit(1)
epoger@google.com877cfe32011-07-11 19:52:00 +0000164 else:
epoger@google.com7815e732011-07-15 13:23:22 +0000165 print 'unknown platform (os.name=%s, sys.platform=%s); see %s' % (
epoger@google.com9c875d32012-10-18 16:10:56 +0000166 os.name, sys.platform, 'https://sites.google.com/site/skiadocs/')
epoger@google.com877cfe32011-07-11 19:52:00 +0000167 sys.exit(1)
epoger@google.com7815e732011-07-15 13:23:22 +0000168 sys.exit(0)
169
170
171# main()
172Make(sys.argv[1:])
173
epoger@google.com877cfe32011-07-11 19:52:00 +0000174