blob: 03421fe95b2dd1a771158443a1202a525a006669 [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.com7815e732011-07-15 13:23:22 +000027LIST_OF_ALL_TARGETS = ['SampleApp', 'bench', 'gm', 'tests', 'tools']
epoger@google.com877cfe32011-07-11 19:52:00 +000028
29SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
30OUT_SUBDIR = 'out'
31GYP_SUBDIR = 'gyp'
32
33
34# Simple functions that report what they are doing, and exit(1) on failure.
35def cd(path):
36 print '> cd %s' % path
epoger@google.com0fb21252011-07-13 21:30:14 +000037 if not os.path.isdir(path):
38 print 'directory %s does not exist' % path
epoger@google.com877cfe32011-07-11 19:52:00 +000039 sys.exit(1)
40 os.chdir(path)
41
42def rmtree(path):
43 print '> rmtree %s' % path
44 shutil.rmtree(path, ignore_errors=True)
45
epoger@google.com0fb21252011-07-13 21:30:14 +000046def mkdirs(path):
47 print '> mkdirs %s' % path
48 if not os.path.isdir(path):
49 os.makedirs(path)
50
epoger@google.com877cfe32011-07-11 19:52:00 +000051def runcommand(command):
52 print '> %s' % command
53 if os.system(command):
54 sys.exit(1)
55
56def MakeClean():
57 """Cross-platform "make clean" operation."""
58 cd(SCRIPT_DIR)
59 rmtree(OUT_SUBDIR)
60 # clean up the directory that XCode (on Mac) creates
61 rmtree('xcodebuild')
62
63
64def CheckWindowsEnvironment():
65 """For Windows: check environment variables needed for command-line build.
66
67 If those environment variables are missing, try to set them.
68 If environment variables can be set up, this function returns; otherwise,
69 it displays an error message and exits.
70 """
71 # If we already have the proper environment variables, nothing to do here.
72 try:
73 env_DevEnvDir = os.environ['DevEnvDir']
74 return # found it, so we are done
75 except KeyError:
76 pass # go on and run the rest of this function
77
78 print ('\nCould not find Visual Studio environment variables.'
79 '\nPerhaps you have not yet run vcvars32.bat as described at'
80 '\nhttp://msdn.microsoft.com/en-us/library/f2ccy3wt.aspx ?')
81 found_path = None
82 try:
83 possible_path = os.path.abspath(os.path.join(
84 os.environ['VS100COMNTOOLS'], os.path.pardir, os.path.pardir,
85 'VC', 'bin', 'vcvars32.bat'))
86 if os.path.exists(possible_path):
87 found_path = possible_path
88 except KeyError:
89 pass
90 if found_path:
91 print '\nIt looks like you can run that script at:\n%s' % found_path
92 else:
93 print '\nUnable to find vcvars32.bat on your system.'
94 sys.exit(1)
95
96
epoger@google.com7815e732011-07-15 13:23:22 +000097def MakeWindows(targets):
epoger@google.com877cfe32011-07-11 19:52:00 +000098 """For Windows: build as appropriate for the command line arguments.
99
100 parameters:
epoger@google.com7815e732011-07-15 13:23:22 +0000101 targets: build targets as a list of strings
epoger@google.com877cfe32011-07-11 19:52:00 +0000102 """
103 CheckWindowsEnvironment()
epoger@google.com0fb21252011-07-13 21:30:14 +0000104
epoger@google.com877cfe32011-07-11 19:52:00 +0000105 # Run gyp_skia to prepare Visual Studio projects.
106 cd(SCRIPT_DIR)
107 runcommand('python gyp_skia')
epoger@google.com0fb21252011-07-13 21:30:14 +0000108
109 # Prepare final output dir into which we will copy all binaries.
110 msbuild_working_dir = os.path.join(SCRIPT_DIR, OUT_SUBDIR, GYP_SUBDIR)
111 msbuild_output_dir = os.path.join(msbuild_working_dir, BUILDTYPE)
112 final_output_dir = os.path.join(SCRIPT_DIR, OUT_SUBDIR, BUILDTYPE)
113 mkdirs(final_output_dir)
114
epoger@google.com7815e732011-07-15 13:23:22 +0000115 for target in targets:
epoger@google.com52c5cbf2012-03-23 18:14:25 +0000116 # We already built the gypfiles...
117 if target == TARGET_GYP:
118 continue
119
epoger@google.com7815e732011-07-15 13:23:22 +0000120 cd(msbuild_working_dir)
121 runcommand(
122 ('msbuild /nologo /property:Configuration=%s'
123 ' /target:%s /verbosity:minimal %s.sln') % (
124 BUILDTYPE, target, target))
125 runcommand('xcopy /y %s\* %s' % (
126 msbuild_output_dir, final_output_dir))
epoger@google.com877cfe32011-07-11 19:52:00 +0000127
epoger@google.com7815e732011-07-15 13:23:22 +0000128
129def Make(args):
130 """Main function.
131
132 parameters:
133 args: command line arguments as a list of strings
134 """
135 # handle any variable-setting parameters or special targets
136 global BUILDTYPE
epoger@google.com9c875d32012-10-18 16:10:56 +0000137
138 # if no targets were specified at all, make default target
139 if not args:
140 args = [TARGET_DEFAULT]
141
epoger@google.com7815e732011-07-15 13:23:22 +0000142 targets = []
143 for arg in args:
144 if arg == TARGET_ALL:
145 targets.extend(LIST_OF_ALL_TARGETS)
146 elif arg == TARGET_CLEAN:
147 MakeClean()
148 elif arg.startswith('BUILDTYPE='):
149 BUILDTYPE = arg[10:]
150 elif arg.startswith('GYP_DEFINES='):
151 os.environ['GYP_DEFINES'] = arg[12:]
152 else:
153 targets.append(arg)
154
155 # if there are no remaining targets, we're done
156 if not targets:
157 sys.exit(0)
158
159 # dispatch to appropriate Make<Platform>() variant.
160 if os.name == 'nt':
161 MakeWindows(targets)
162 sys.exit(0)
163 elif os.name == 'posix':
164 if sys.platform == 'darwin':
165 print 'Mac developers should not run this script; see ' \
epoger@google.com9c875d32012-10-18 16:10:56 +0000166 'https://sites.google.com/site/skiadocs/user-documentation/quick-start-guides/mac'
epoger@google.com7815e732011-07-15 13:23:22 +0000167 sys.exit(1)
168 elif sys.platform == 'cygwin':
epoger@google.com9c875d32012-10-18 16:10:56 +0000169 print 'Windows development on Cygwin is not currently supported; see ' \
170 'https://sites.google.com/site/skiadocs/user-documentation/quick-start-guides/windows'
epoger@google.com7815e732011-07-15 13:23:22 +0000171 sys.exit(1)
172 else:
173 print 'Unix developers should not run this script; see ' \
epoger@google.com9c875d32012-10-18 16:10:56 +0000174 'https://sites.google.com/site/skiadocs/user-documentation/quick-start-guides/linux'
epoger@google.com7815e732011-07-15 13:23:22 +0000175 sys.exit(1)
epoger@google.com877cfe32011-07-11 19:52:00 +0000176 else:
epoger@google.com7815e732011-07-15 13:23:22 +0000177 print 'unknown platform (os.name=%s, sys.platform=%s); see %s' % (
epoger@google.com9c875d32012-10-18 16:10:56 +0000178 os.name, sys.platform, 'https://sites.google.com/site/skiadocs/')
epoger@google.com877cfe32011-07-11 19:52:00 +0000179 sys.exit(1)
epoger@google.com7815e732011-07-15 13:23:22 +0000180 sys.exit(0)
181
182
183# main()
184Make(sys.argv[1:])
185
epoger@google.com877cfe32011-07-11 19:52:00 +0000186