blob: 346dd6c92a72a8bd9ecde52edd2573e72bf8e38c [file] [log] [blame]
epoger@google.com877cfe32011-07-11 19:52:00 +00001# Copyright 2011 Google Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# "Makefile" replacement to build skia for Windows.
16# More info at http://code.google.com/p/skia/wiki/DocRoot
17
18import os
19import shutil
20import sys
21
epoger@google.com0fb21252011-07-13 21:30:14 +000022# TODO(epoger): allow caller to override BUILDTYPE
23BUILDTYPE = 'Debug'
24
epoger@google.com877cfe32011-07-11 19:52:00 +000025# TODO(epoger): add special 'all' target
26TARGET_CLEAN = 'clean'
27
28SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
29OUT_SUBDIR = 'out'
30GYP_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
epoger@google.com0fb21252011-07-13 21:30:14 +000045def mkdirs(path):
46 print '> mkdirs %s' % path
47 if not os.path.isdir(path):
48 os.makedirs(path)
49
epoger@google.com877cfe32011-07-11 19:52:00 +000050def runcommand(command):
51 print '> %s' % command
52 if os.system(command):
53 sys.exit(1)
54
55def MakeClean():
56 """Cross-platform "make clean" operation."""
57 cd(SCRIPT_DIR)
58 rmtree(OUT_SUBDIR)
59 # clean up the directory that XCode (on Mac) creates
60 rmtree('xcodebuild')
61
62
63def CheckWindowsEnvironment():
64 """For Windows: check environment variables needed for command-line build.
65
66 If those environment variables are missing, try to set them.
67 If environment variables can be set up, this function returns; otherwise,
68 it displays an error message and exits.
69 """
70 # If we already have the proper environment variables, nothing to do here.
71 try:
72 env_DevEnvDir = os.environ['DevEnvDir']
73 return # found it, so we are done
74 except KeyError:
75 pass # go on and run the rest of this function
76
77 print ('\nCould not find Visual Studio environment variables.'
78 '\nPerhaps you have not yet run vcvars32.bat as described at'
79 '\nhttp://msdn.microsoft.com/en-us/library/f2ccy3wt.aspx ?')
80 found_path = None
81 try:
82 possible_path = os.path.abspath(os.path.join(
83 os.environ['VS100COMNTOOLS'], os.path.pardir, os.path.pardir,
84 'VC', 'bin', 'vcvars32.bat'))
85 if os.path.exists(possible_path):
86 found_path = possible_path
87 except KeyError:
88 pass
89 if found_path:
90 print '\nIt looks like you can run that script at:\n%s' % found_path
91 else:
92 print '\nUnable to find vcvars32.bat on your system.'
93 sys.exit(1)
94
95
96def MakeWindows(args):
97 """For Windows: build as appropriate for the command line arguments.
98
99 parameters:
100 args: command line arguments as a list of strings
101 """
102 CheckWindowsEnvironment()
epoger@google.com0fb21252011-07-13 21:30:14 +0000103
104 # TODO(epoger): what about fixed vs float?
epoger@google.com877cfe32011-07-11 19:52:00 +0000105 # TODO(epoger): what about "make" flags (like -j) that Windows doesn't support?
106
107 # Run gyp_skia to prepare Visual Studio projects.
108 cd(SCRIPT_DIR)
109 runcommand('python gyp_skia')
epoger@google.com0fb21252011-07-13 21:30:14 +0000110
111 # Prepare final output dir into which we will copy all binaries.
112 msbuild_working_dir = os.path.join(SCRIPT_DIR, OUT_SUBDIR, GYP_SUBDIR)
113 msbuild_output_dir = os.path.join(msbuild_working_dir, BUILDTYPE)
114 final_output_dir = os.path.join(SCRIPT_DIR, OUT_SUBDIR, BUILDTYPE)
115 mkdirs(final_output_dir)
116
epoger@google.com877cfe32011-07-11 19:52:00 +0000117 for target in args:
118 # Check for special-case targets
119 if target == TARGET_CLEAN:
120 MakeClean()
121 else:
epoger@google.com0fb21252011-07-13 21:30:14 +0000122 cd(msbuild_working_dir)
123 runcommand(
124 ('msbuild /nologo /property:Configuration=%s'
125 ' /target:%s /verbosity:minimal %s.sln') % (
126 BUILDTYPE, target, target))
127 runcommand('xcopy /y %s\* %s' % (
128 msbuild_output_dir, final_output_dir))
epoger@google.com877cfe32011-07-11 19:52:00 +0000129
130# main:
131# dispatch to appropriate Make<Platform>() variant.
132if os.name == 'nt':
133 MakeWindows(sys.argv[1:])
134 sys.exit(0)
135elif os.name == 'posix':
136 if sys.platform == 'darwin':
137 print 'Mac developers should not run this script; see ' \
138 'http://code.google.com/p/skia/wiki/GettingStartedOnMac'
139 sys.exit(1)
epoger@google.com0fb21252011-07-13 21:30:14 +0000140 elif sys.platform == 'cygwin':
141 print 'Windows development on Cygwin is not currently supported; see ' \
142 'http://code.google.com/p/skia/wiki/GettingStartedOnWindows'
143 sys.exit(1)
epoger@google.com877cfe32011-07-11 19:52:00 +0000144 else:
145 print 'Unix developers should not run this script; see ' \
146 'http://code.google.com/p/skia/wiki/GettingStartedOnLinux'
147 sys.exit(1)
148else:
149 print 'unknown platform (os.name=%s, sys.platform=%s); see %s' % (
150 os.name, sys.platform, 'http://code.google.com/p/skia/wiki/DocRoot')
151 sys.exit(1)
152sys.exit(0)
153
154