1 # Copyright 2011 Google Inc.
\r
3 # Use of this source code is governed by a BSD-style license that can be
\r
4 # found in the LICENSE file.
\r
6 # "Makefile" replacement to build skia for Windows.
\r
7 # More info at http://code.google.com/p/skia/wiki/DocRoot
\r
9 # Some usage examples:
\r
12 # make bench BUILDTYPE=Release
\r
13 # make gm GYP_DEFINES=skia_scalar=fixed BUILDTYPE=Release
\r
24 TARGET_CLEAN = 'clean'
\r
26 LIST_OF_ALL_TARGETS = ['SampleApp', 'bench', 'gm', 'tests', 'tools']
\r
28 SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
\r
33 # Simple functions that report what they are doing, and exit(1) on failure.
\r
35 print '> cd %s' % path
\r
36 if not os.path.isdir(path):
\r
37 print 'directory %s does not exist' % path
\r
42 print '> rmtree %s' % path
\r
43 shutil.rmtree(path, ignore_errors=True)
\r
46 print '> mkdirs %s' % path
\r
47 if not os.path.isdir(path):
\r
50 def runcommand(command):
\r
51 print '> %s' % command
\r
52 if os.system(command):
\r
56 """Cross-platform "make clean" operation."""
\r
59 # clean up the directory that XCode (on Mac) creates
\r
60 rmtree('xcodebuild')
\r
63 def CheckWindowsEnvironment():
\r
64 """For Windows: check environment variables needed for command-line build.
\r
66 If those environment variables are missing, try to set them.
\r
67 If environment variables can be set up, this function returns; otherwise,
\r
68 it displays an error message and exits.
\r
70 # If we already have the proper environment variables, nothing to do here.
\r
72 env_DevEnvDir = os.environ['DevEnvDir']
\r
73 return # found it, so we are done
\r
75 pass # go on and run the rest of this function
\r
77 print ('\nCould not find Visual Studio environment variables.'
\r
78 '\nPerhaps you have not yet run vcvars32.bat as described at'
\r
79 '\nhttp://msdn.microsoft.com/en-us/library/f2ccy3wt.aspx ?')
\r
82 possible_path = os.path.abspath(os.path.join(
\r
83 os.environ['VS100COMNTOOLS'], os.path.pardir, os.path.pardir,
\r
84 'VC', 'bin', 'vcvars32.bat'))
\r
85 if os.path.exists(possible_path):
\r
86 found_path = possible_path
\r
90 print '\nIt looks like you can run that script at:\n%s' % found_path
\r
92 print '\nUnable to find vcvars32.bat on your system.'
\r
96 def MakeWindows(targets):
\r
97 """For Windows: build as appropriate for the command line arguments.
\r
100 targets: build targets as a list of strings
\r
102 CheckWindowsEnvironment()
\r
104 # Run gyp_skia to prepare Visual Studio projects.
\r
106 runcommand('python gyp_skia')
\r
108 # Prepare final output dir into which we will copy all binaries.
\r
109 msbuild_working_dir = os.path.join(SCRIPT_DIR, OUT_SUBDIR, GYP_SUBDIR)
\r
110 msbuild_output_dir = os.path.join(msbuild_working_dir, BUILDTYPE)
\r
111 final_output_dir = os.path.join(SCRIPT_DIR, OUT_SUBDIR, BUILDTYPE)
\r
112 mkdirs(final_output_dir)
\r
114 for target in targets:
\r
115 # We already built the gypfiles...
\r
116 if target == TARGET_GYP:
\r
119 cd(msbuild_working_dir)
\r
121 ('msbuild /nologo /property:Configuration=%s'
\r
122 ' /target:%s /verbosity:minimal %s.sln') % (
\r
123 BUILDTYPE, target, target))
\r
124 runcommand('xcopy /y %s\* %s' % (
\r
125 msbuild_output_dir, final_output_dir))
\r
132 args: command line arguments as a list of strings
\r
134 # handle any variable-setting parameters or special targets
\r
138 if arg == TARGET_ALL:
\r
139 targets.extend(LIST_OF_ALL_TARGETS)
\r
140 elif arg == TARGET_CLEAN:
\r
142 elif arg.startswith('BUILDTYPE='):
\r
143 BUILDTYPE = arg[10:]
\r
144 elif arg.startswith('GYP_DEFINES='):
\r
145 os.environ['GYP_DEFINES'] = arg[12:]
\r
147 targets.append(arg)
\r
149 # if there are no remaining targets, we're done
\r
153 # dispatch to appropriate Make<Platform>() variant.
\r
154 if os.name == 'nt':
\r
155 MakeWindows(targets)
\r
157 elif os.name == 'posix':
\r
158 if sys.platform == 'darwin':
\r
159 print 'Mac developers should not run this script; see ' \
\r
160 'http://code.google.com/p/skia/wiki/GettingStartedOnMac'
\r
162 elif sys.platform == 'cygwin':
\r
163 print 'Windows development on Cygwin is not currently supported; ' \
\r
164 'see http://code.google.com/p/skia/wiki/GettingStartedOnWindows'
\r
167 print 'Unix developers should not run this script; see ' \
\r
168 'http://code.google.com/p/skia/wiki/GettingStartedOnLinux'
\r
171 print 'unknown platform (os.name=%s, sys.platform=%s); see %s' % (
\r
172 os.name, sys.platform, 'http://code.google.com/p/skia/wiki/DocRoot')
\r