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