blob: a4081a205bc6758e54f5e8972c107a312d0e52c4 [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.
7# More info at http://code.google.com/p/skia/wiki/DocRoot
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
23TARGET_ALL = 'all'
epoger@google.com877cfe32011-07-11 19:52:00 +000024TARGET_CLEAN = 'clean'
epoger@google.com7815e732011-07-15 13:23:22 +000025LIST_OF_ALL_TARGETS = ['SampleApp', 'bench', 'gm', 'tests', 'tools']
epoger@google.com877cfe32011-07-11 19:52:00 +000026
27SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
28OUT_SUBDIR = 'out'
29GYP_SUBDIR = 'gyp'
30
31
32# Simple functions that report what they are doing, and exit(1) on failure.
33def cd(path):
34 print '> cd %s' % path
epoger@google.com0fb21252011-07-13 21:30:14 +000035 if not os.path.isdir(path):
36 print 'directory %s does not exist' % path
epoger@google.com877cfe32011-07-11 19:52:00 +000037 sys.exit(1)
38 os.chdir(path)
39
40def rmtree(path):
41 print '> rmtree %s' % path
42 shutil.rmtree(path, ignore_errors=True)
43
epoger@google.com0fb21252011-07-13 21:30:14 +000044def mkdirs(path):
45 print '> mkdirs %s' % path
46 if not os.path.isdir(path):
47 os.makedirs(path)
48
epoger@google.com877cfe32011-07-11 19:52:00 +000049def runcommand(command):
50 print '> %s' % command
51 if os.system(command):
52 sys.exit(1)
53
54def MakeClean():
55 """Cross-platform "make clean" operation."""
56 cd(SCRIPT_DIR)
57 rmtree(OUT_SUBDIR)
58 # clean up the directory that XCode (on Mac) creates
59 rmtree('xcodebuild')
60
61
62def CheckWindowsEnvironment():
63 """For Windows: check environment variables needed for command-line build.
64
65 If those environment variables are missing, try to set them.
66 If environment variables can be set up, this function returns; otherwise,
67 it displays an error message and exits.
68 """
69 # If we already have the proper environment variables, nothing to do here.
70 try:
71 env_DevEnvDir = os.environ['DevEnvDir']
72 return # found it, so we are done
73 except KeyError:
74 pass # go on and run the rest of this function
75
76 print ('\nCould not find Visual Studio environment variables.'
77 '\nPerhaps you have not yet run vcvars32.bat as described at'
78 '\nhttp://msdn.microsoft.com/en-us/library/f2ccy3wt.aspx ?')
79 found_path = None
80 try:
81 possible_path = os.path.abspath(os.path.join(
82 os.environ['VS100COMNTOOLS'], os.path.pardir, os.path.pardir,
83 'VC', 'bin', 'vcvars32.bat'))
84 if os.path.exists(possible_path):
85 found_path = possible_path
86 except KeyError:
87 pass
88 if found_path:
89 print '\nIt looks like you can run that script at:\n%s' % found_path
90 else:
91 print '\nUnable to find vcvars32.bat on your system.'
92 sys.exit(1)
93
94
epoger@google.com7815e732011-07-15 13:23:22 +000095def MakeWindows(targets):
epoger@google.com877cfe32011-07-11 19:52:00 +000096 """For Windows: build as appropriate for the command line arguments.
97
98 parameters:
epoger@google.com7815e732011-07-15 13:23:22 +000099 targets: build targets as a list of strings
epoger@google.com877cfe32011-07-11 19:52:00 +0000100 """
101 CheckWindowsEnvironment()
epoger@google.com0fb21252011-07-13 21:30:14 +0000102
epoger@google.com877cfe32011-07-11 19:52:00 +0000103 # Run gyp_skia to prepare Visual Studio projects.
104 cd(SCRIPT_DIR)
105 runcommand('python gyp_skia')
epoger@google.com0fb21252011-07-13 21:30:14 +0000106
107 # Prepare final output dir into which we will copy all binaries.
108 msbuild_working_dir = os.path.join(SCRIPT_DIR, OUT_SUBDIR, GYP_SUBDIR)
109 msbuild_output_dir = os.path.join(msbuild_working_dir, BUILDTYPE)
110 final_output_dir = os.path.join(SCRIPT_DIR, OUT_SUBDIR, BUILDTYPE)
111 mkdirs(final_output_dir)
112
epoger@google.com7815e732011-07-15 13:23:22 +0000113 for target in targets:
114 cd(msbuild_working_dir)
115 runcommand(
116 ('msbuild /nologo /property:Configuration=%s'
117 ' /target:%s /verbosity:minimal %s.sln') % (
118 BUILDTYPE, target, target))
119 runcommand('xcopy /y %s\* %s' % (
120 msbuild_output_dir, final_output_dir))
epoger@google.com877cfe32011-07-11 19:52:00 +0000121
epoger@google.com7815e732011-07-15 13:23:22 +0000122
123def Make(args):
124 """Main function.
125
126 parameters:
127 args: command line arguments as a list of strings
128 """
129 # handle any variable-setting parameters or special targets
130 global BUILDTYPE
131 targets = []
132 for arg in args:
133 if arg == TARGET_ALL:
134 targets.extend(LIST_OF_ALL_TARGETS)
135 elif arg == TARGET_CLEAN:
136 MakeClean()
137 elif arg.startswith('BUILDTYPE='):
138 BUILDTYPE = arg[10:]
139 elif arg.startswith('GYP_DEFINES='):
140 os.environ['GYP_DEFINES'] = arg[12:]
141 else:
142 targets.append(arg)
143
144 # if there are no remaining targets, we're done
145 if not targets:
146 sys.exit(0)
147
148 # dispatch to appropriate Make<Platform>() variant.
149 if os.name == 'nt':
150 MakeWindows(targets)
151 sys.exit(0)
152 elif os.name == 'posix':
153 if sys.platform == 'darwin':
154 print 'Mac developers should not run this script; see ' \
155 'http://code.google.com/p/skia/wiki/GettingStartedOnMac'
156 sys.exit(1)
157 elif sys.platform == 'cygwin':
158 print 'Windows development on Cygwin is not currently supported; ' \
159 'see http://code.google.com/p/skia/wiki/GettingStartedOnWindows'
160 sys.exit(1)
161 else:
162 print 'Unix developers should not run this script; see ' \
163 'http://code.google.com/p/skia/wiki/GettingStartedOnLinux'
164 sys.exit(1)
epoger@google.com877cfe32011-07-11 19:52:00 +0000165 else:
epoger@google.com7815e732011-07-15 13:23:22 +0000166 print 'unknown platform (os.name=%s, sys.platform=%s); see %s' % (
167 os.name, sys.platform, 'http://code.google.com/p/skia/wiki/DocRoot')
epoger@google.com877cfe32011-07-11 19:52:00 +0000168 sys.exit(1)
epoger@google.com7815e732011-07-15 13:23:22 +0000169 sys.exit(0)
170
171
172# main()
173Make(sys.argv[1:])
174
epoger@google.com877cfe32011-07-11 19:52:00 +0000175