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 | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 27 | LIST_OF_ALL_TARGETS = ['SampleApp', 'bench', 'gm', 'tests', 'tools']
|
epoger@google.com | 877cfe3 | 2011-07-11 19:52:00 +0000 | [diff] [blame] | 28 |
|
| 29 | SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
|
| 30 | OUT_SUBDIR = 'out'
|
| 31 | GYP_SUBDIR = 'gyp'
|
| 32 |
|
| 33 |
|
| 34 | # Simple functions that report what they are doing, and exit(1) on failure.
|
| 35 | def cd(path):
|
| 36 | print '> cd %s' % path
|
epoger@google.com | 0fb2125 | 2011-07-13 21:30:14 +0000 | [diff] [blame] | 37 | if not os.path.isdir(path):
|
| 38 | print 'directory %s does not exist' % path
|
epoger@google.com | 877cfe3 | 2011-07-11 19:52:00 +0000 | [diff] [blame] | 39 | sys.exit(1)
|
| 40 | os.chdir(path)
|
| 41 |
|
| 42 | def rmtree(path):
|
| 43 | print '> rmtree %s' % path
|
| 44 | shutil.rmtree(path, ignore_errors=True)
|
| 45 |
|
epoger@google.com | 0fb2125 | 2011-07-13 21:30:14 +0000 | [diff] [blame] | 46 | def mkdirs(path):
|
| 47 | print '> mkdirs %s' % path
|
| 48 | if not os.path.isdir(path):
|
| 49 | os.makedirs(path)
|
| 50 |
|
epoger@google.com | 877cfe3 | 2011-07-11 19:52:00 +0000 | [diff] [blame] | 51 | def runcommand(command):
|
| 52 | print '> %s' % command
|
| 53 | if os.system(command):
|
| 54 | sys.exit(1)
|
| 55 |
|
| 56 | def MakeClean():
|
| 57 | """Cross-platform "make clean" operation."""
|
| 58 | cd(SCRIPT_DIR)
|
| 59 | rmtree(OUT_SUBDIR)
|
| 60 | # clean up the directory that XCode (on Mac) creates
|
| 61 | rmtree('xcodebuild')
|
| 62 |
|
| 63 |
|
| 64 | def CheckWindowsEnvironment():
|
| 65 | """For Windows: check environment variables needed for command-line build.
|
| 66 |
|
| 67 | If those environment variables are missing, try to set them.
|
| 68 | If environment variables can be set up, this function returns; otherwise,
|
| 69 | it displays an error message and exits.
|
| 70 | """
|
| 71 | # If we already have the proper environment variables, nothing to do here.
|
| 72 | try:
|
| 73 | env_DevEnvDir = os.environ['DevEnvDir']
|
| 74 | return # found it, so we are done
|
| 75 | except KeyError:
|
| 76 | pass # go on and run the rest of this function
|
| 77 |
|
| 78 | print ('\nCould not find Visual Studio environment variables.'
|
| 79 | '\nPerhaps you have not yet run vcvars32.bat as described at'
|
| 80 | '\nhttp://msdn.microsoft.com/en-us/library/f2ccy3wt.aspx ?')
|
| 81 | found_path = None
|
| 82 | try:
|
| 83 | possible_path = os.path.abspath(os.path.join(
|
| 84 | os.environ['VS100COMNTOOLS'], os.path.pardir, os.path.pardir,
|
| 85 | 'VC', 'bin', 'vcvars32.bat'))
|
| 86 | if os.path.exists(possible_path):
|
| 87 | found_path = possible_path
|
| 88 | except KeyError:
|
| 89 | pass
|
| 90 | if found_path:
|
| 91 | print '\nIt looks like you can run that script at:\n%s' % found_path
|
| 92 | else:
|
| 93 | print '\nUnable to find vcvars32.bat on your system.'
|
| 94 | sys.exit(1)
|
| 95 |
|
| 96 |
|
epoger@google.com | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 97 | def MakeWindows(targets):
|
epoger@google.com | 877cfe3 | 2011-07-11 19:52:00 +0000 | [diff] [blame] | 98 | """For Windows: build as appropriate for the command line arguments.
|
| 99 |
|
| 100 | parameters:
|
epoger@google.com | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 101 | targets: build targets as a list of strings
|
epoger@google.com | 877cfe3 | 2011-07-11 19:52:00 +0000 | [diff] [blame] | 102 | """
|
| 103 | CheckWindowsEnvironment()
|
epoger@google.com | 0fb2125 | 2011-07-13 21:30:14 +0000 | [diff] [blame] | 104 |
|
epoger@google.com | 877cfe3 | 2011-07-11 19:52:00 +0000 | [diff] [blame] | 105 | # Run gyp_skia to prepare Visual Studio projects.
|
| 106 | cd(SCRIPT_DIR)
|
| 107 | runcommand('python gyp_skia')
|
epoger@google.com | 0fb2125 | 2011-07-13 21:30:14 +0000 | [diff] [blame] | 108 |
|
| 109 | # Prepare final output dir into which we will copy all binaries.
|
| 110 | msbuild_working_dir = os.path.join(SCRIPT_DIR, OUT_SUBDIR, GYP_SUBDIR)
|
| 111 | msbuild_output_dir = os.path.join(msbuild_working_dir, BUILDTYPE)
|
| 112 | final_output_dir = os.path.join(SCRIPT_DIR, OUT_SUBDIR, BUILDTYPE)
|
| 113 | mkdirs(final_output_dir)
|
| 114 |
|
epoger@google.com | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 115 | for target in targets:
|
epoger@google.com | 52c5cbf | 2012-03-23 18:14:25 +0000 | [diff] [blame] | 116 | # We already built the gypfiles...
|
| 117 | if target == TARGET_GYP:
|
| 118 | continue
|
| 119 |
|
epoger@google.com | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 120 | cd(msbuild_working_dir)
|
| 121 | runcommand(
|
| 122 | ('msbuild /nologo /property:Configuration=%s'
|
| 123 | ' /target:%s /verbosity:minimal %s.sln') % (
|
| 124 | BUILDTYPE, target, target))
|
| 125 | runcommand('xcopy /y %s\* %s' % (
|
| 126 | msbuild_output_dir, final_output_dir))
|
epoger@google.com | 877cfe3 | 2011-07-11 19:52:00 +0000 | [diff] [blame] | 127 |
|
epoger@google.com | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 128 |
|
| 129 | def Make(args):
|
| 130 | """Main function.
|
| 131 |
|
| 132 | parameters:
|
| 133 | args: command line arguments as a list of strings
|
| 134 | """
|
| 135 | # handle any variable-setting parameters or special targets
|
| 136 | global BUILDTYPE
|
epoger@google.com | 9c875d3 | 2012-10-18 16:10:56 +0000 | [diff] [blame] | 137 |
|
| 138 | # if no targets were specified at all, make default target
|
| 139 | if not args:
|
| 140 | args = [TARGET_DEFAULT]
|
| 141 |
|
epoger@google.com | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 142 | targets = []
|
| 143 | for arg in args:
|
| 144 | if arg == TARGET_ALL:
|
| 145 | targets.extend(LIST_OF_ALL_TARGETS)
|
| 146 | elif arg == TARGET_CLEAN:
|
| 147 | MakeClean()
|
| 148 | elif arg.startswith('BUILDTYPE='):
|
| 149 | BUILDTYPE = arg[10:]
|
| 150 | elif arg.startswith('GYP_DEFINES='):
|
| 151 | os.environ['GYP_DEFINES'] = arg[12:]
|
| 152 | else:
|
| 153 | targets.append(arg)
|
| 154 |
|
| 155 | # if there are no remaining targets, we're done
|
| 156 | if not targets:
|
| 157 | sys.exit(0)
|
| 158 |
|
| 159 | # dispatch to appropriate Make<Platform>() variant.
|
| 160 | if os.name == 'nt':
|
| 161 | MakeWindows(targets)
|
| 162 | sys.exit(0)
|
| 163 | elif os.name == 'posix':
|
| 164 | if sys.platform == 'darwin':
|
| 165 | print 'Mac developers should not run this script; see ' \
|
epoger@google.com | 9c875d3 | 2012-10-18 16:10:56 +0000 | [diff] [blame] | 166 | '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] | 167 | sys.exit(1)
|
| 168 | elif sys.platform == 'cygwin':
|
epoger@google.com | 9c875d3 | 2012-10-18 16:10:56 +0000 | [diff] [blame] | 169 | print 'Windows development on Cygwin is not currently supported; see ' \
|
| 170 | '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] | 171 | sys.exit(1)
|
| 172 | else:
|
| 173 | print 'Unix developers should not run this script; see ' \
|
epoger@google.com | 9c875d3 | 2012-10-18 16:10:56 +0000 | [diff] [blame] | 174 | '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] | 175 | sys.exit(1)
|
epoger@google.com | 877cfe3 | 2011-07-11 19:52:00 +0000 | [diff] [blame] | 176 | else:
|
epoger@google.com | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 177 | print 'unknown platform (os.name=%s, sys.platform=%s); see %s' % (
|
epoger@google.com | 9c875d3 | 2012-10-18 16:10:56 +0000 | [diff] [blame] | 178 | os.name, sys.platform, 'https://sites.google.com/site/skiadocs/')
|
epoger@google.com | 877cfe3 | 2011-07-11 19:52:00 +0000 | [diff] [blame] | 179 | sys.exit(1)
|
epoger@google.com | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 180 | sys.exit(0)
|
| 181 |
|
| 182 |
|
| 183 | # main()
|
| 184 | Make(sys.argv[1:])
|
| 185 |
|
epoger@google.com | 877cfe3 | 2011-07-11 19:52:00 +0000 | [diff] [blame] | 186 |
|