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.
|
Thiago Farina | 4c93a12 | 2015-02-03 13:12:54 -0200 | [diff] [blame] | 7 | # More info at https://skia.org.
|
epoger@google.com | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 8 | #
|
| 9 | # Some usage examples:
|
| 10 | # make clean
|
Thiago Farina | e6402ca | 2014-10-13 17:51:57 -0300 | [diff] [blame] | 11 | # make dm
|
epoger@google.com | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 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 |
|
| 45 | def runcommand(command):
|
| 46 | print '> %s' % command
|
| 47 | if os.system(command):
|
| 48 | sys.exit(1)
|
| 49 |
|
| 50 | def MakeClean():
|
| 51 | """Cross-platform "make clean" operation."""
|
| 52 | cd(SCRIPT_DIR)
|
| 53 | rmtree(OUT_SUBDIR)
|
epoger@google.com | 877cfe3 | 2011-07-11 19:52:00 +0000 | [diff] [blame] | 54 |
|
| 55 |
|
| 56 | def CheckWindowsEnvironment():
|
| 57 | """For Windows: check environment variables needed for command-line build.
|
| 58 |
|
| 59 | If those environment variables are missing, try to set them.
|
| 60 | If environment variables can be set up, this function returns; otherwise,
|
| 61 | it displays an error message and exits.
|
| 62 | """
|
| 63 | # If we already have the proper environment variables, nothing to do here.
|
Eric Boren | 030854e | 2015-03-03 13:15:38 -0500 | [diff] [blame] | 64 | if os.environ.get('DevEnvDir'):
|
| 65 | return
|
epoger@google.com | 877cfe3 | 2011-07-11 19:52:00 +0000 | [diff] [blame] | 66 |
|
| 67 | print ('\nCould not find Visual Studio environment variables.'
|
| 68 | '\nPerhaps you have not yet run vcvars32.bat as described at'
|
| 69 | '\nhttp://msdn.microsoft.com/en-us/library/f2ccy3wt.aspx ?')
|
| 70 | found_path = None
|
| 71 | try:
|
| 72 | possible_path = os.path.abspath(os.path.join(
|
| 73 | os.environ['VS100COMNTOOLS'], os.path.pardir, os.path.pardir,
|
| 74 | 'VC', 'bin', 'vcvars32.bat'))
|
| 75 | if os.path.exists(possible_path):
|
| 76 | found_path = possible_path
|
| 77 | except KeyError:
|
| 78 | pass
|
| 79 | if found_path:
|
| 80 | print '\nIt looks like you can run that script at:\n%s' % found_path
|
| 81 | else:
|
| 82 | print '\nUnable to find vcvars32.bat on your system.'
|
| 83 | sys.exit(1)
|
| 84 |
|
| 85 |
|
epoger@google.com | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 86 | def MakeWindows(targets):
|
epoger@google.com | 877cfe3 | 2011-07-11 19:52:00 +0000 | [diff] [blame] | 87 | """For Windows: build as appropriate for the command line arguments.
|
| 88 |
|
| 89 | parameters:
|
epoger@google.com | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 90 | targets: build targets as a list of strings
|
epoger@google.com | 877cfe3 | 2011-07-11 19:52:00 +0000 | [diff] [blame] | 91 | """
|
Eric Boren | 9118413 | 2014-06-16 10:02:42 -0400 | [diff] [blame] | 92 | if os.environ.get('CHROME_HEADLESS', '0') != '1':
|
| 93 | # TODO(epoger): I'm not sure if this is needed for ninja builds.
|
| 94 | CheckWindowsEnvironment()
|
epoger@google.com | 0fb2125 | 2011-07-13 21:30:14 +0000 | [diff] [blame] | 95 |
|
epoger@google.com | 877cfe3 | 2011-07-11 19:52:00 +0000 | [diff] [blame] | 96 | # Run gyp_skia to prepare Visual Studio projects.
|
| 97 | cd(SCRIPT_DIR)
|
Eric Boren | 030854e | 2015-03-03 13:15:38 -0500 | [diff] [blame] | 98 | runcommand('python gyp_skia --no-parallel -G config=%s' % BUILDTYPE)
|
epoger@google.com | 0fb2125 | 2011-07-13 21:30:14 +0000 | [diff] [blame] | 99 |
|
epoger@google.com | 58d69d8 | 2014-04-01 07:02:41 +0000 | [diff] [blame] | 100 | # We already built the gypfiles...
|
| 101 | while TARGET_GYP in targets:
|
| 102 | targets.remove(TARGET_GYP)
|
epoger@google.com | 0fb2125 | 2011-07-13 21:30:14 +0000 | [diff] [blame] | 103 |
|
epoger@google.com | 58d69d8 | 2014-04-01 07:02:41 +0000 | [diff] [blame] | 104 | # And call ninja to do the work!
|
| 105 | if targets:
|
| 106 | runcommand('ninja -C %s %s' % (
|
| 107 | os.path.join(OUT_SUBDIR, BUILDTYPE), ' '.join(targets)))
|
epoger@google.com | 877cfe3 | 2011-07-11 19:52:00 +0000 | [diff] [blame] | 108 |
|
epoger@google.com | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 109 |
|
| 110 | def Make(args):
|
| 111 | """Main function.
|
| 112 |
|
| 113 | parameters:
|
| 114 | args: command line arguments as a list of strings
|
| 115 | """
|
| 116 | # handle any variable-setting parameters or special targets
|
| 117 | global BUILDTYPE
|
epoger@google.com | 9c875d3 | 2012-10-18 16:10:56 +0000 | [diff] [blame] | 118 |
|
| 119 | # if no targets were specified at all, make default target
|
| 120 | if not args:
|
| 121 | args = [TARGET_DEFAULT]
|
| 122 |
|
epoger@google.com | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 123 | targets = []
|
| 124 | for arg in args:
|
Eric Boren | 030854e | 2015-03-03 13:15:38 -0500 | [diff] [blame] | 125 | # If user requests "make all", chain to our explicitly-declared
|
| 126 | # "everything" target. See
|
| 127 | # https://code.google.com/p/skia/issues/detail?id=932 ("gyp
|
| 128 | # automatically creates "all" target on some build flavors but not
|
| 129 | # others")
|
epoger@google.com | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 130 | if arg == TARGET_ALL:
|
epoger@google.com | 6714ea4 | 2012-10-25 16:32:07 +0000 | [diff] [blame] | 131 | targets.append('everything')
|
epoger@google.com | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 132 | elif arg == TARGET_CLEAN:
|
| 133 | MakeClean()
|
| 134 | elif arg.startswith('BUILDTYPE='):
|
| 135 | BUILDTYPE = arg[10:]
|
| 136 | elif arg.startswith('GYP_DEFINES='):
|
| 137 | os.environ['GYP_DEFINES'] = arg[12:]
|
| 138 | else:
|
| 139 | targets.append(arg)
|
| 140 |
|
| 141 | # if there are no remaining targets, we're done
|
| 142 | if not targets:
|
| 143 | sys.exit(0)
|
| 144 |
|
| 145 | # dispatch to appropriate Make<Platform>() variant.
|
| 146 | if os.name == 'nt':
|
| 147 | MakeWindows(targets)
|
| 148 | sys.exit(0)
|
| 149 | elif os.name == 'posix':
|
| 150 | if sys.platform == 'darwin':
|
Eric Boren | 030854e | 2015-03-03 13:15:38 -0500 | [diff] [blame] | 151 | print ('Mac developers should not run this script; see '
|
| 152 | 'https://skia.org/user/quick/macos')
|
epoger@google.com | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 153 | sys.exit(1)
|
| 154 | elif sys.platform == 'cygwin':
|
Eric Boren | 030854e | 2015-03-03 13:15:38 -0500 | [diff] [blame] | 155 | print ('Windows development on Cygwin is not currently supported; '
|
| 156 | 'see https://skia.org/user/quick/windows')
|
epoger@google.com | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 157 | sys.exit(1)
|
| 158 | else:
|
Eric Boren | 030854e | 2015-03-03 13:15:38 -0500 | [diff] [blame] | 159 | print ('Unix developers should not run this script; see '
|
| 160 | 'https://skia.org/user/quick/linux')
|
epoger@google.com | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 161 | sys.exit(1)
|
epoger@google.com | 877cfe3 | 2011-07-11 19:52:00 +0000 | [diff] [blame] | 162 | else:
|
epoger@google.com | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 163 | print 'unknown platform (os.name=%s, sys.platform=%s); see %s' % (
|
Thiago Farina | 4c93a12 | 2015-02-03 13:12:54 -0200 | [diff] [blame] | 164 | os.name, sys.platform, 'https://skia.org/user/quick')
|
epoger@google.com | 877cfe3 | 2011-07-11 19:52:00 +0000 | [diff] [blame] | 165 | sys.exit(1)
|
epoger@google.com | 7815e73 | 2011-07-15 13:23:22 +0000 | [diff] [blame] | 166 | sys.exit(0)
|
| 167 |
|
| 168 |
|
| 169 | # main()
|
| 170 | Make(sys.argv[1:])
|
| 171 |
|
epoger@google.com | 877cfe3 | 2011-07-11 19:52:00 +0000 | [diff] [blame] | 172 |
|