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