2011-07-28 14:24:55 +00:00
|
|
|
# Copyright 2011 Google Inc.
|
2011-07-11 19:52:00 +00:00
|
|
|
#
|
2011-07-28 14:24:55 +00:00
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
2011-07-11 19:52:00 +00:00
|
|
|
|
|
|
|
# "Makefile" replacement to build skia for Windows.
|
2012-10-18 16:10:56 +00:00
|
|
|
# More info at https://sites.google.com/site/skiadocs/
|
2011-07-15 13:23:22 +00:00
|
|
|
#
|
|
|
|
# Some usage examples:
|
|
|
|
# make clean
|
|
|
|
# make tests
|
|
|
|
# make bench BUILDTYPE=Release
|
|
|
|
# make gm GYP_DEFINES=skia_scalar=fixed BUILDTYPE=Release
|
|
|
|
# make all
|
2011-07-11 19:52:00 +00:00
|
|
|
|
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import sys
|
|
|
|
|
2011-07-13 21:30:14 +00:00
|
|
|
BUILDTYPE = 'Debug'
|
|
|
|
|
2011-07-15 13:23:22 +00:00
|
|
|
# special targets
|
2012-10-18 16:10:56 +00:00
|
|
|
TARGET_ALL = 'all'
|
|
|
|
TARGET_CLEAN = 'clean'
|
|
|
|
TARGET_DEFAULT = 'most'
|
|
|
|
TARGET_GYP = 'gyp'
|
2011-07-11 19:52:00 +00:00
|
|
|
|
|
|
|
SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
|
|
|
|
OUT_SUBDIR = 'out'
|
|
|
|
GYP_SUBDIR = 'gyp'
|
|
|
|
|
|
|
|
|
|
|
|
# Simple functions that report what they are doing, and exit(1) on failure.
|
|
|
|
def cd(path):
|
|
|
|
print '> cd %s' % path
|
2011-07-13 21:30:14 +00:00
|
|
|
if not os.path.isdir(path):
|
|
|
|
print 'directory %s does not exist' % path
|
2011-07-11 19:52:00 +00:00
|
|
|
sys.exit(1)
|
|
|
|
os.chdir(path)
|
|
|
|
|
|
|
|
def rmtree(path):
|
|
|
|
print '> rmtree %s' % path
|
|
|
|
shutil.rmtree(path, ignore_errors=True)
|
|
|
|
|
2011-07-13 21:30:14 +00:00
|
|
|
def mkdirs(path):
|
|
|
|
print '> mkdirs %s' % path
|
|
|
|
if not os.path.isdir(path):
|
|
|
|
os.makedirs(path)
|
|
|
|
|
2011-07-11 19:52:00 +00:00
|
|
|
def runcommand(command):
|
|
|
|
print '> %s' % command
|
|
|
|
if os.system(command):
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
def MakeClean():
|
|
|
|
"""Cross-platform "make clean" operation."""
|
|
|
|
cd(SCRIPT_DIR)
|
|
|
|
rmtree(OUT_SUBDIR)
|
|
|
|
# clean up the directory that XCode (on Mac) creates
|
|
|
|
rmtree('xcodebuild')
|
|
|
|
|
|
|
|
|
|
|
|
def CheckWindowsEnvironment():
|
|
|
|
"""For Windows: check environment variables needed for command-line build.
|
|
|
|
|
|
|
|
If those environment variables are missing, try to set them.
|
|
|
|
If environment variables can be set up, this function returns; otherwise,
|
|
|
|
it displays an error message and exits.
|
|
|
|
"""
|
|
|
|
# If we already have the proper environment variables, nothing to do here.
|
|
|
|
try:
|
|
|
|
env_DevEnvDir = os.environ['DevEnvDir']
|
|
|
|
return # found it, so we are done
|
|
|
|
except KeyError:
|
|
|
|
pass # go on and run the rest of this function
|
|
|
|
|
|
|
|
print ('\nCould not find Visual Studio environment variables.'
|
|
|
|
'\nPerhaps you have not yet run vcvars32.bat as described at'
|
|
|
|
'\nhttp://msdn.microsoft.com/en-us/library/f2ccy3wt.aspx ?')
|
|
|
|
found_path = None
|
|
|
|
try:
|
|
|
|
possible_path = os.path.abspath(os.path.join(
|
|
|
|
os.environ['VS100COMNTOOLS'], os.path.pardir, os.path.pardir,
|
|
|
|
'VC', 'bin', 'vcvars32.bat'))
|
|
|
|
if os.path.exists(possible_path):
|
|
|
|
found_path = possible_path
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
if found_path:
|
|
|
|
print '\nIt looks like you can run that script at:\n%s' % found_path
|
|
|
|
else:
|
|
|
|
print '\nUnable to find vcvars32.bat on your system.'
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
2011-07-15 13:23:22 +00:00
|
|
|
def MakeWindows(targets):
|
2011-07-11 19:52:00 +00:00
|
|
|
"""For Windows: build as appropriate for the command line arguments.
|
|
|
|
|
|
|
|
parameters:
|
2011-07-15 13:23:22 +00:00
|
|
|
targets: build targets as a list of strings
|
2011-07-11 19:52:00 +00:00
|
|
|
"""
|
|
|
|
CheckWindowsEnvironment()
|
2011-07-13 21:30:14 +00:00
|
|
|
|
2011-07-11 19:52:00 +00:00
|
|
|
# Run gyp_skia to prepare Visual Studio projects.
|
|
|
|
cd(SCRIPT_DIR)
|
|
|
|
runcommand('python gyp_skia')
|
2011-07-13 21:30:14 +00:00
|
|
|
|
|
|
|
# Prepare final output dir into which we will copy all binaries.
|
|
|
|
msbuild_working_dir = os.path.join(SCRIPT_DIR, OUT_SUBDIR, GYP_SUBDIR)
|
|
|
|
msbuild_output_dir = os.path.join(msbuild_working_dir, BUILDTYPE)
|
|
|
|
final_output_dir = os.path.join(SCRIPT_DIR, OUT_SUBDIR, BUILDTYPE)
|
|
|
|
mkdirs(final_output_dir)
|
|
|
|
|
2011-07-15 13:23:22 +00:00
|
|
|
for target in targets:
|
2012-03-23 18:14:25 +00:00
|
|
|
# We already built the gypfiles...
|
|
|
|
if target == TARGET_GYP:
|
|
|
|
continue
|
|
|
|
|
2011-07-15 13:23:22 +00:00
|
|
|
cd(msbuild_working_dir)
|
|
|
|
runcommand(
|
|
|
|
('msbuild /nologo /property:Configuration=%s'
|
|
|
|
' /target:%s /verbosity:minimal %s.sln') % (
|
|
|
|
BUILDTYPE, target, target))
|
|
|
|
runcommand('xcopy /y %s\* %s' % (
|
|
|
|
msbuild_output_dir, final_output_dir))
|
|
|
|
|
|
|
|
|
|
|
|
def Make(args):
|
|
|
|
"""Main function.
|
|
|
|
|
|
|
|
parameters:
|
|
|
|
args: command line arguments as a list of strings
|
|
|
|
"""
|
|
|
|
# handle any variable-setting parameters or special targets
|
|
|
|
global BUILDTYPE
|
2012-10-18 16:10:56 +00:00
|
|
|
|
|
|
|
# if no targets were specified at all, make default target
|
|
|
|
if not args:
|
|
|
|
args = [TARGET_DEFAULT]
|
|
|
|
|
2011-07-15 13:23:22 +00:00
|
|
|
targets = []
|
|
|
|
for arg in args:
|
2012-10-25 16:32:07 +00:00
|
|
|
# If user requests "make all", chain to our explicitly-declared "everything"
|
|
|
|
# target. See https://code.google.com/p/skia/issues/detail?id=932 ("gyp
|
|
|
|
# automatically creates "all" target on some build flavors but not others")
|
2011-07-15 13:23:22 +00:00
|
|
|
if arg == TARGET_ALL:
|
2012-10-25 16:32:07 +00:00
|
|
|
targets.append('everything')
|
2011-07-15 13:23:22 +00:00
|
|
|
elif arg == TARGET_CLEAN:
|
2011-07-11 19:52:00 +00:00
|
|
|
MakeClean()
|
2011-07-15 13:23:22 +00:00
|
|
|
elif arg.startswith('BUILDTYPE='):
|
|
|
|
BUILDTYPE = arg[10:]
|
|
|
|
elif arg.startswith('GYP_DEFINES='):
|
|
|
|
os.environ['GYP_DEFINES'] = arg[12:]
|
2011-07-11 19:52:00 +00:00
|
|
|
else:
|
2011-07-15 13:23:22 +00:00
|
|
|
targets.append(arg)
|
|
|
|
|
|
|
|
# if there are no remaining targets, we're done
|
|
|
|
if not targets:
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
# dispatch to appropriate Make<Platform>() variant.
|
|
|
|
if os.name == 'nt':
|
|
|
|
MakeWindows(targets)
|
|
|
|
sys.exit(0)
|
|
|
|
elif os.name == 'posix':
|
|
|
|
if sys.platform == 'darwin':
|
|
|
|
print 'Mac developers should not run this script; see ' \
|
2012-10-18 16:10:56 +00:00
|
|
|
'https://sites.google.com/site/skiadocs/user-documentation/quick-start-guides/mac'
|
2011-07-15 13:23:22 +00:00
|
|
|
sys.exit(1)
|
|
|
|
elif sys.platform == 'cygwin':
|
2012-10-18 16:10:56 +00:00
|
|
|
print 'Windows development on Cygwin is not currently supported; see ' \
|
|
|
|
'https://sites.google.com/site/skiadocs/user-documentation/quick-start-guides/windows'
|
2011-07-15 13:23:22 +00:00
|
|
|
sys.exit(1)
|
|
|
|
else:
|
|
|
|
print 'Unix developers should not run this script; see ' \
|
2012-10-18 16:10:56 +00:00
|
|
|
'https://sites.google.com/site/skiadocs/user-documentation/quick-start-guides/linux'
|
2011-07-15 13:23:22 +00:00
|
|
|
sys.exit(1)
|
2011-07-11 19:52:00 +00:00
|
|
|
else:
|
2011-07-15 13:23:22 +00:00
|
|
|
print 'unknown platform (os.name=%s, sys.platform=%s); see %s' % (
|
2012-10-18 16:10:56 +00:00
|
|
|
os.name, sys.platform, 'https://sites.google.com/site/skiadocs/')
|
2011-07-11 19:52:00 +00:00
|
|
|
sys.exit(1)
|
2011-07-15 13:23:22 +00:00
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
|
|
|
|
# main()
|
|
|
|
Make(sys.argv[1:])
|
|
|
|
|
2011-07-11 19:52:00 +00:00
|
|
|
|