blob: 414cc9f5bb4fbf817fcfbc8c113258e9e6b4ddb0 [file] [log] [blame]
epoger@google.comfd03db02011-07-28 14:24:55 +00001# Copyright 2011 Google Inc.
epoger@google.com877cfe32011-07-11 19:52:00 +00002#
epoger@google.comfd03db02011-07-28 14:24:55 +00003# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
epoger@google.com877cfe32011-07-11 19:52:00 +00005
6# "Makefile" replacement to build skia for Windows.
Thiago Farina4c93a122015-02-03 13:12:54 -02007# More info at https://skia.org.
epoger@google.com7815e732011-07-15 13:23:22 +00008#
9# Some usage examples:
10# make clean
Thiago Farinae6402ca2014-10-13 17:51:57 -030011# make dm
epoger@google.com7815e732011-07-15 13:23:22 +000012# make bench BUILDTYPE=Release
13# make gm GYP_DEFINES=skia_scalar=fixed BUILDTYPE=Release
14# make all
epoger@google.com877cfe32011-07-11 19:52:00 +000015
16import os
17import shutil
18import sys
19
epoger@google.com0fb21252011-07-13 21:30:14 +000020BUILDTYPE = 'Debug'
21
epoger@google.com7815e732011-07-15 13:23:22 +000022# special targets
epoger@google.com9c875d32012-10-18 16:10:56 +000023TARGET_ALL = 'all'
24TARGET_CLEAN = 'clean'
25TARGET_DEFAULT = 'most'
26TARGET_GYP = 'gyp'
epoger@google.com877cfe32011-07-11 19:52:00 +000027
28SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
borenet@google.coma82c9eb2013-07-23 15:45:50 +000029OUT_SUBDIR = os.environ.get('SKIA_OUT', 'out')
epoger@google.com877cfe32011-07-11 19:52:00 +000030GYP_SUBDIR = 'gyp'
31
32
33# Simple functions that report what they are doing, and exit(1) on failure.
34def cd(path):
35 print '> cd %s' % path
epoger@google.com0fb21252011-07-13 21:30:14 +000036 if not os.path.isdir(path):
37 print 'directory %s does not exist' % path
epoger@google.com877cfe32011-07-11 19:52:00 +000038 sys.exit(1)
39 os.chdir(path)
40
41def rmtree(path):
42 print '> rmtree %s' % path
43 shutil.rmtree(path, ignore_errors=True)
44
45def runcommand(command):
46 print '> %s' % command
47 if os.system(command):
48 sys.exit(1)
49
50def MakeClean():
51 """Cross-platform "make clean" operation."""
52 cd(SCRIPT_DIR)
53 rmtree(OUT_SUBDIR)
epoger@google.com877cfe32011-07-11 19:52:00 +000054
55
56def 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.
64 try:
65 env_DevEnvDir = os.environ['DevEnvDir']
66 return # found it, so we are done
67 except KeyError:
68 pass # go on and run the rest of this function
69
70 print ('\nCould not find Visual Studio environment variables.'
71 '\nPerhaps you have not yet run vcvars32.bat as described at'
72 '\nhttp://msdn.microsoft.com/en-us/library/f2ccy3wt.aspx ?')
73 found_path = None
74 try:
75 possible_path = os.path.abspath(os.path.join(
76 os.environ['VS100COMNTOOLS'], os.path.pardir, os.path.pardir,
77 'VC', 'bin', 'vcvars32.bat'))
78 if os.path.exists(possible_path):
79 found_path = possible_path
80 except KeyError:
81 pass
82 if found_path:
83 print '\nIt looks like you can run that script at:\n%s' % found_path
84 else:
85 print '\nUnable to find vcvars32.bat on your system.'
86 sys.exit(1)
87
88
epoger@google.com7815e732011-07-15 13:23:22 +000089def MakeWindows(targets):
epoger@google.com877cfe32011-07-11 19:52:00 +000090 """For Windows: build as appropriate for the command line arguments.
91
92 parameters:
epoger@google.com7815e732011-07-15 13:23:22 +000093 targets: build targets as a list of strings
epoger@google.com877cfe32011-07-11 19:52:00 +000094 """
Eric Boren91184132014-06-16 10:02:42 -040095 if os.environ.get('CHROME_HEADLESS', '0') != '1':
96 # TODO(epoger): I'm not sure if this is needed for ninja builds.
97 CheckWindowsEnvironment()
epoger@google.com0fb21252011-07-13 21:30:14 +000098
epoger@google.com877cfe32011-07-11 19:52:00 +000099 # Run gyp_skia to prepare Visual Studio projects.
100 cd(SCRIPT_DIR)
101 runcommand('python gyp_skia')
epoger@google.com0fb21252011-07-13 21:30:14 +0000102
epoger@google.com58d69d82014-04-01 07:02:41 +0000103 # We already built the gypfiles...
104 while TARGET_GYP in targets:
105 targets.remove(TARGET_GYP)
epoger@google.com0fb21252011-07-13 21:30:14 +0000106
epoger@google.com58d69d82014-04-01 07:02:41 +0000107 # And call ninja to do the work!
108 if targets:
109 runcommand('ninja -C %s %s' % (
110 os.path.join(OUT_SUBDIR, BUILDTYPE), ' '.join(targets)))
epoger@google.com877cfe32011-07-11 19:52:00 +0000111
epoger@google.com7815e732011-07-15 13:23:22 +0000112
113def Make(args):
114 """Main function.
115
116 parameters:
117 args: command line arguments as a list of strings
118 """
119 # handle any variable-setting parameters or special targets
120 global BUILDTYPE
epoger@google.com9c875d32012-10-18 16:10:56 +0000121
122 # if no targets were specified at all, make default target
123 if not args:
124 args = [TARGET_DEFAULT]
125
epoger@google.com7815e732011-07-15 13:23:22 +0000126 targets = []
127 for arg in args:
epoger@google.com6714ea42012-10-25 16:32:07 +0000128 # If user requests "make all", chain to our explicitly-declared "everything"
129 # target. See https://code.google.com/p/skia/issues/detail?id=932 ("gyp
130 # automatically creates "all" target on some build flavors but not others")
epoger@google.com7815e732011-07-15 13:23:22 +0000131 if arg == TARGET_ALL:
epoger@google.com6714ea42012-10-25 16:32:07 +0000132 targets.append('everything')
epoger@google.com7815e732011-07-15 13:23:22 +0000133 elif arg == TARGET_CLEAN:
134 MakeClean()
135 elif arg.startswith('BUILDTYPE='):
136 BUILDTYPE = arg[10:]
137 elif arg.startswith('GYP_DEFINES='):
138 os.environ['GYP_DEFINES'] = arg[12:]
139 else:
140 targets.append(arg)
141
142 # if there are no remaining targets, we're done
143 if not targets:
144 sys.exit(0)
145
146 # dispatch to appropriate Make<Platform>() variant.
147 if os.name == 'nt':
148 MakeWindows(targets)
149 sys.exit(0)
150 elif os.name == 'posix':
151 if sys.platform == 'darwin':
152 print 'Mac developers should not run this script; see ' \
Thiago Farina4c93a122015-02-03 13:12:54 -0200153 'https://skia.org/user/quick/macos'
epoger@google.com7815e732011-07-15 13:23:22 +0000154 sys.exit(1)
155 elif sys.platform == 'cygwin':
epoger@google.com9c875d32012-10-18 16:10:56 +0000156 print 'Windows development on Cygwin is not currently supported; see ' \
Thiago Farina4c93a122015-02-03 13:12:54 -0200157 'https://skia.org/user/quick/windows'
epoger@google.com7815e732011-07-15 13:23:22 +0000158 sys.exit(1)
159 else:
160 print 'Unix developers should not run this script; see ' \
Thiago Farina4c93a122015-02-03 13:12:54 -0200161 'https://skia.org/user/quick/linux'
epoger@google.com7815e732011-07-15 13:23:22 +0000162 sys.exit(1)
epoger@google.com877cfe32011-07-11 19:52:00 +0000163 else:
epoger@google.com7815e732011-07-15 13:23:22 +0000164 print 'unknown platform (os.name=%s, sys.platform=%s); see %s' % (
Thiago Farina4c93a122015-02-03 13:12:54 -0200165 os.name, sys.platform, 'https://skia.org/user/quick')
epoger@google.com877cfe32011-07-11 19:52:00 +0000166 sys.exit(1)
epoger@google.com7815e732011-07-15 13:23:22 +0000167 sys.exit(0)
168
169
170# main()
171Make(sys.argv[1:])
172
epoger@google.com877cfe32011-07-11 19:52:00 +0000173