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