blob: b1deaab933ba0c508dc3e3121e87d9832edb34cc [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
22# TODO(epoger): add special 'all' target
23TARGET_CLEAN = 'clean'
24
25SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
26OUT_SUBDIR = 'out'
27GYP_SUBDIR = 'gyp'
28
29
30# Simple functions that report what they are doing, and exit(1) on failure.
31def cd(path):
32 print '> cd %s' % path
33 if not os.path.exists(path):
34 print 'path %s does not exist' % path
35 sys.exit(1)
36 os.chdir(path)
37
38def rmtree(path):
39 print '> rmtree %s' % path
40 shutil.rmtree(path, ignore_errors=True)
41
42def runcommand(command):
43 print '> %s' % command
44 if os.system(command):
45 sys.exit(1)
46
47def MakeClean():
48 """Cross-platform "make clean" operation."""
49 cd(SCRIPT_DIR)
50 rmtree(OUT_SUBDIR)
51 # clean up the directory that XCode (on Mac) creates
52 rmtree('xcodebuild')
53
54
55def CheckWindowsEnvironment():
56 """For Windows: check environment variables needed for command-line build.
57
58 If those environment variables are missing, try to set them.
59 If environment variables can be set up, this function returns; otherwise,
60 it displays an error message and exits.
61 """
62 # If we already have the proper environment variables, nothing to do here.
63 try:
64 env_DevEnvDir = os.environ['DevEnvDir']
65 return # found it, so we are done
66 except KeyError:
67 pass # go on and run the rest of this function
68
69 print ('\nCould not find Visual Studio environment variables.'
70 '\nPerhaps you have not yet run vcvars32.bat as described at'
71 '\nhttp://msdn.microsoft.com/en-us/library/f2ccy3wt.aspx ?')
72 found_path = None
73 try:
74 possible_path = os.path.abspath(os.path.join(
75 os.environ['VS100COMNTOOLS'], os.path.pardir, os.path.pardir,
76 'VC', 'bin', 'vcvars32.bat'))
77 if os.path.exists(possible_path):
78 found_path = possible_path
79 except KeyError:
80 pass
81 if found_path:
82 print '\nIt looks like you can run that script at:\n%s' % found_path
83 else:
84 print '\nUnable to find vcvars32.bat on your system.'
85 sys.exit(1)
86
87
88def MakeWindows(args):
89 """For Windows: build as appropriate for the command line arguments.
90
91 parameters:
92 args: command line arguments as a list of strings
93 """
94 CheckWindowsEnvironment()
95 # TODO(epoger): what about parameters? (fixed vs float, debug vs release)
96 # TODO(epoger): what about "make" flags (like -j) that Windows doesn't support?
97
98 # Run gyp_skia to prepare Visual Studio projects.
99 cd(SCRIPT_DIR)
100 runcommand('python gyp_skia')
101
102 for target in args:
103 # Check for special-case targets
104 if target == TARGET_CLEAN:
105 MakeClean()
106 else:
107 cd(os.path.join(SCRIPT_DIR, OUT_SUBDIR, GYP_SUBDIR))
108 runcommand('msbuild /target:%s %s.sln' % (target, target))
109
110
111# main:
112# dispatch to appropriate Make<Platform>() variant.
113if os.name == 'nt':
114 MakeWindows(sys.argv[1:])
115 sys.exit(0)
116elif os.name == 'posix':
117 if sys.platform == 'darwin':
118 print 'Mac developers should not run this script; see ' \
119 'http://code.google.com/p/skia/wiki/GettingStartedOnMac'
120 sys.exit(1)
121 else:
122 print 'Unix developers should not run this script; see ' \
123 'http://code.google.com/p/skia/wiki/GettingStartedOnLinux'
124 sys.exit(1)
125else:
126 print 'unknown platform (os.name=%s, sys.platform=%s); see %s' % (
127 os.name, sys.platform, 'http://code.google.com/p/skia/wiki/DocRoot')
128 sys.exit(1)
129sys.exit(0)
130
131