epoger@google.com | fd03db0 | 2011-07-28 14:24:55 +0000 | [diff] [blame] | 1 | # Copyright 2011 Google Inc.
|
epoger@google.com | 877cfe3 | 2011-07-11 19:52:00 +0000 | [diff] [blame] | 2 | #
|
epoger@google.com | fd03db0 | 2011-07-28 14:24:55 +0000 | [diff] [blame] | 3 | # Use of this source code is governed by a BSD-style license that can be
|
| 4 | # found in the LICENSE file.
|
epoger@google.com | 877cfe3 | 2011-07-11 19:52:00 +0000 | [diff] [blame] | 5 |
|
| 6 | # "Makefile" replacement to build skia for Windows.
|
epoger@google.com | 9c875d3 | 2012-10-18 16:10:56 +0000 | [diff] [blame] | 7 | # More info at https://sites.google.com/site/skiadocs/
|
epoger@google.com | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 8 | #
|
| 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.com | 877cfe3 | 2011-07-11 19:52:00 +0000 | [diff] [blame] | 15 |
|
| 16 | import os
|
| 17 | import shutil
|
| 18 | import sys
|
| 19 |
|
epoger@google.com | 0fb2125 | 2011-07-13 21:30:14 +0000 | [diff] [blame] | 20 | BUILDTYPE = 'Debug'
|
| 21 |
|
epoger@google.com | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 22 | # special targets
|
epoger@google.com | 9c875d3 | 2012-10-18 16:10:56 +0000 | [diff] [blame] | 23 | TARGET_ALL = 'all'
|
| 24 | TARGET_CLEAN = 'clean'
|
| 25 | TARGET_DEFAULT = 'most'
|
| 26 | TARGET_GYP = 'gyp'
|
epoger@google.com | 877cfe3 | 2011-07-11 19:52:00 +0000 | [diff] [blame] | 27 |
|
| 28 | SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
|
borenet@google.com | a82c9eb | 2013-07-23 15:45:50 +0000 | [diff] [blame] | 29 | OUT_SUBDIR = os.environ.get('SKIA_OUT', 'out')
|
epoger@google.com | 877cfe3 | 2011-07-11 19:52:00 +0000 | [diff] [blame] | 30 | GYP_SUBDIR = 'gyp'
|
| 31 |
|
| 32 |
|
| 33 | # Simple functions that report what they are doing, and exit(1) on failure.
|
| 34 | def cd(path):
|
| 35 | print '> cd %s' % path
|
epoger@google.com | 0fb2125 | 2011-07-13 21:30:14 +0000 | [diff] [blame] | 36 | if not os.path.isdir(path):
|
| 37 | print 'directory %s does not exist' % path
|
epoger@google.com | 877cfe3 | 2011-07-11 19:52:00 +0000 | [diff] [blame] | 38 | sys.exit(1)
|
| 39 | os.chdir(path)
|
| 40 |
|
| 41 | def rmtree(path):
|
| 42 | print '> rmtree %s' % path
|
| 43 | shutil.rmtree(path, ignore_errors=True)
|
| 44 |
|
epoger@google.com | 0fb2125 | 2011-07-13 21:30:14 +0000 | [diff] [blame] | 45 | def mkdirs(path):
|
| 46 | print '> mkdirs %s' % path
|
| 47 | if not os.path.isdir(path):
|
| 48 | os.makedirs(path)
|
| 49 |
|
epoger@google.com | 877cfe3 | 2011-07-11 19:52:00 +0000 | [diff] [blame] | 50 | def runcommand(command):
|
| 51 | print '> %s' % command
|
| 52 | if os.system(command):
|
| 53 | sys.exit(1)
|
| 54 |
|
| 55 | def 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 |
|
| 63 | def 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 |
|
epoger@google.com | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 96 | def MakeWindows(targets):
|
epoger@google.com | 877cfe3 | 2011-07-11 19:52:00 +0000 | [diff] [blame] | 97 | """For Windows: build as appropriate for the command line arguments.
|
| 98 |
|
| 99 | parameters:
|
epoger@google.com | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 100 | targets: build targets as a list of strings
|
epoger@google.com | 877cfe3 | 2011-07-11 19:52:00 +0000 | [diff] [blame] | 101 | """
|
| 102 | CheckWindowsEnvironment()
|
epoger@google.com | 0fb2125 | 2011-07-13 21:30:14 +0000 | [diff] [blame] | 103 |
|
epoger@google.com | 877cfe3 | 2011-07-11 19:52:00 +0000 | [diff] [blame] | 104 | # Run gyp_skia to prepare Visual Studio projects.
|
| 105 | cd(SCRIPT_DIR)
|
| 106 | runcommand('python gyp_skia')
|
epoger@google.com | 0fb2125 | 2011-07-13 21:30:14 +0000 | [diff] [blame] | 107 |
|
| 108 | # Prepare final output dir into which we will copy all binaries.
|
| 109 | msbuild_working_dir = os.path.join(SCRIPT_DIR, OUT_SUBDIR, GYP_SUBDIR)
|
| 110 | msbuild_output_dir = os.path.join(msbuild_working_dir, BUILDTYPE)
|
| 111 | final_output_dir = os.path.join(SCRIPT_DIR, OUT_SUBDIR, BUILDTYPE)
|
| 112 | mkdirs(final_output_dir)
|
| 113 |
|
epoger@google.com | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 114 | for target in targets:
|
epoger@google.com | 52c5cbf | 2012-03-23 18:14:25 +0000 | [diff] [blame] | 115 | # We already built the gypfiles...
|
| 116 | if target == TARGET_GYP:
|
| 117 | continue
|
| 118 |
|
epoger@google.com | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 119 | cd(msbuild_working_dir)
|
| 120 | runcommand(
|
| 121 | ('msbuild /nologo /property:Configuration=%s'
|
| 122 | ' /target:%s /verbosity:minimal %s.sln') % (
|
| 123 | BUILDTYPE, target, target))
|
| 124 | runcommand('xcopy /y %s\* %s' % (
|
| 125 | msbuild_output_dir, final_output_dir))
|
epoger@google.com | 877cfe3 | 2011-07-11 19:52:00 +0000 | [diff] [blame] | 126 |
|
epoger@google.com | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 127 |
|
| 128 | def Make(args):
|
| 129 | """Main function.
|
| 130 |
|
| 131 | parameters:
|
| 132 | args: command line arguments as a list of strings
|
| 133 | """
|
| 134 | # handle any variable-setting parameters or special targets
|
| 135 | global BUILDTYPE
|
epoger@google.com | 9c875d3 | 2012-10-18 16:10:56 +0000 | [diff] [blame] | 136 |
|
| 137 | # if no targets were specified at all, make default target
|
| 138 | if not args:
|
| 139 | args = [TARGET_DEFAULT]
|
| 140 |
|
epoger@google.com | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 141 | targets = []
|
| 142 | for arg in args:
|
epoger@google.com | 6714ea4 | 2012-10-25 16:32:07 +0000 | [diff] [blame] | 143 | # If user requests "make all", chain to our explicitly-declared "everything"
|
| 144 | # target. See https://code.google.com/p/skia/issues/detail?id=932 ("gyp
|
| 145 | # automatically creates "all" target on some build flavors but not others")
|
epoger@google.com | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 146 | if arg == TARGET_ALL:
|
epoger@google.com | 6714ea4 | 2012-10-25 16:32:07 +0000 | [diff] [blame] | 147 | targets.append('everything')
|
epoger@google.com | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 148 | elif arg == TARGET_CLEAN:
|
| 149 | MakeClean()
|
| 150 | elif arg.startswith('BUILDTYPE='):
|
| 151 | BUILDTYPE = arg[10:]
|
| 152 | elif arg.startswith('GYP_DEFINES='):
|
| 153 | os.environ['GYP_DEFINES'] = arg[12:]
|
| 154 | else:
|
| 155 | targets.append(arg)
|
| 156 |
|
| 157 | # if there are no remaining targets, we're done
|
| 158 | if not targets:
|
| 159 | sys.exit(0)
|
| 160 |
|
| 161 | # dispatch to appropriate Make<Platform>() variant.
|
| 162 | if os.name == 'nt':
|
| 163 | MakeWindows(targets)
|
| 164 | sys.exit(0)
|
| 165 | elif os.name == 'posix':
|
| 166 | if sys.platform == 'darwin':
|
| 167 | print 'Mac developers should not run this script; see ' \
|
epoger@google.com | 9c875d3 | 2012-10-18 16:10:56 +0000 | [diff] [blame] | 168 | 'https://sites.google.com/site/skiadocs/user-documentation/quick-start-guides/mac'
|
epoger@google.com | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 169 | sys.exit(1)
|
| 170 | elif sys.platform == 'cygwin':
|
epoger@google.com | 9c875d3 | 2012-10-18 16:10:56 +0000 | [diff] [blame] | 171 | print 'Windows development on Cygwin is not currently supported; see ' \
|
| 172 | 'https://sites.google.com/site/skiadocs/user-documentation/quick-start-guides/windows'
|
epoger@google.com | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 173 | sys.exit(1)
|
| 174 | else:
|
| 175 | print 'Unix developers should not run this script; see ' \
|
epoger@google.com | 9c875d3 | 2012-10-18 16:10:56 +0000 | [diff] [blame] | 176 | 'https://sites.google.com/site/skiadocs/user-documentation/quick-start-guides/linux'
|
epoger@google.com | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 177 | sys.exit(1)
|
epoger@google.com | 877cfe3 | 2011-07-11 19:52:00 +0000 | [diff] [blame] | 178 | else:
|
epoger@google.com | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 179 | print 'unknown platform (os.name=%s, sys.platform=%s); see %s' % (
|
epoger@google.com | 9c875d3 | 2012-10-18 16:10:56 +0000 | [diff] [blame] | 180 | os.name, sys.platform, 'https://sites.google.com/site/skiadocs/')
|
epoger@google.com | 877cfe3 | 2011-07-11 19:52:00 +0000 | [diff] [blame] | 181 | sys.exit(1)
|
epoger@google.com | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 182 | sys.exit(0)
|
| 183 |
|
| 184 |
|
| 185 | # main()
|
| 186 | Make(sys.argv[1:])
|
| 187 |
|
epoger@google.com | 877cfe3 | 2011-07-11 19:52:00 +0000 | [diff] [blame] | 188 |
|