OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 # Copyright 2014 Google Inc. | 3 # Copyright 2014 Google Inc. |
4 # | 4 # |
5 # Use of this source code is governed by a BSD-style license that can be | 5 # Use of this source code is governed by a BSD-style license that can be |
6 # found in the LICENSE file. | 6 # found in the LICENSE file. |
7 | 7 |
8 """ | 8 """ |
9 Functions for creating an Android.mk from already created dictionaries. | 9 Functions for creating an Android.mk from already created dictionaries. |
10 """ | 10 """ |
11 | 11 |
12 import os | 12 import os |
13 | 13 |
14 def write_group(f, name, items, append): | 14 def write_group(f, name, items, append): |
15 """ | 15 """Helper function to list all names passed to a variable. |
16 Helper function to list all names passed to a variable. | 16 |
17 @param f File open for writing (Android.mk) | 17 Args: |
18 @param name Name of the makefile variable (e.g. LOCAL_CFLAGS) | 18 f: File open for writing (Android.mk) |
19 @param items list of strings to be passed to the variable. | 19 name: Name of the makefile variable (e.g. LOCAL_CFLAGS) |
20 @param append Whether to append to the variable or overwrite it. | 20 items: list of strings to be passed to the variable. |
| 21 append: Whether to append to the variable or overwrite it. |
21 """ | 22 """ |
22 if not items: | 23 if not items: |
23 return | 24 return |
24 | 25 |
25 # Copy the list so we can prepend it with its name. | 26 # Copy the list so we can prepend it with its name. |
26 items_to_write = list(items) | 27 items_to_write = list(items) |
27 | 28 |
28 if append: | 29 if append: |
29 items_to_write.insert(0, '%s +=' % name) | 30 items_to_write.insert(0, '%s +=' % name) |
30 else: | 31 else: |
31 items_to_write.insert(0, '%s :=' % name) | 32 items_to_write.insert(0, '%s :=' % name) |
32 | 33 |
33 f.write(' \\\n\t'.join(items_to_write)) | 34 f.write(' \\\n\t'.join(items_to_write)) |
34 | 35 |
35 f.write('\n\n') | 36 f.write('\n\n') |
36 | 37 |
37 | 38 |
38 def write_local_vars(f, var_dict, append, name): | 39 def write_local_vars(f, var_dict, append, name): |
39 """ | 40 """Helper function to write all the members of var_dict to the makefile. |
40 Helper function to write all the members of var_dict to the makefile. | 41 |
41 @param f File open for writing (Android.mk) | 42 Args: |
42 @param var_dict VarsDict holding the unique values for one configuration. | 43 f: File open for writing (Android.mk) |
43 @param append Whether to append to each makefile variable or overwrite it. | 44 var_dict: VarsDict holding the unique values for one configuration. |
44 @param name If not None, a string to be appended to each key. | 45 append: Whether to append to each makefile variable or overwrite it. |
| 46 name: If not None, a string to be appended to each key. |
45 """ | 47 """ |
46 for key in var_dict.keys(): | 48 for key in var_dict.keys(): |
47 _key = key | 49 _key = key |
48 _items = var_dict[key] | 50 _items = var_dict[key] |
49 if key == 'LOCAL_CFLAGS': | 51 if key == 'LOCAL_CFLAGS': |
50 # Always append LOCAL_CFLAGS. This allows us to define some early on in | 52 # Always append LOCAL_CFLAGS. This allows us to define some early on in |
51 # the makefile and not overwrite them. | 53 # the makefile and not overwrite them. |
52 _append = True | 54 _append = True |
53 elif key == 'DEFINES': | 55 elif key == 'DEFINES': |
54 # For DEFINES, we want to append to LOCAL_CFLAGS. | 56 # For DEFINES, we want to append to LOCAL_CFLAGS. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 # Build the skia tools | 116 # Build the skia tools |
115 # | 117 # |
116 | 118 |
117 # benchmark (timings) | 119 # benchmark (timings) |
118 #include $(BASE_PATH)/bench/Android.mk | 120 #include $(BASE_PATH)/bench/Android.mk |
119 | 121 |
120 # golden-master (fidelity / regression test) | 122 # golden-master (fidelity / regression test) |
121 #include $(BASE_PATH)/gm/Android.mk | 123 #include $(BASE_PATH)/gm/Android.mk |
122 | 124 |
123 # unit-tests | 125 # unit-tests |
124 #include $(BASE_PATH)/tests/Android.mk | 126 include $(BASE_PATH)/tests/Android.mk |
125 | |
126 # pathOps unit-tests | |
127 # TODO include those sources! | |
128 """ | 127 """ |
129 ) | 128 ) |
130 | 129 |
131 | 130 |
132 class VarsDictData(object): | 131 class VarsDictData(object): |
133 """ | 132 """Helper class to keep a VarsDict along with a name and optional condition. |
134 Helper class for keeping a VarsDict along with a name and an optional | |
135 condition. | |
136 """ | 133 """ |
137 def __init__(self, vars_dict, name, condition=None): | 134 def __init__(self, vars_dict, name, condition=None): |
138 """ | 135 """Create a new VarsDictData. |
139 Create a new VarsDictData. | 136 |
140 @param vars_dict A VarsDict. Can be accessed via self.vars_dict. | 137 Args: |
141 @param name Name associated with the VarsDict. Can be accessed via | 138 vars_dict: A VarsDict. Can be accessed via self.vars_dict. |
142 self.name. | 139 name: Name associated with the VarsDict. Can be accessed via |
143 @param condition Optional string representing a condition. If not None, | 140 self.name. |
144 used to create a conditional inside the makefile. | 141 condition: Optional string representing a condition. If not None, |
| 142 used to create a conditional inside the makefile. |
145 """ | 143 """ |
146 self.vars_dict = vars_dict | 144 self.vars_dict = vars_dict |
147 self.condition = condition | 145 self.condition = condition |
148 self.name = name | 146 self.name = name |
149 | 147 |
| 148 def write_local_path(f): |
| 149 """Add the LOCAL_PATH line to the makefile. |
| 150 |
| 151 Args: |
| 152 f: File open for writing. |
| 153 """ |
| 154 f.write('LOCAL_PATH:= $(call my-dir)\n') |
| 155 |
| 156 def write_clear_vars(f): |
| 157 """Add the CLEAR_VARS line to the makefile. |
| 158 |
| 159 Args: |
| 160 f: File open for writing. |
| 161 """ |
| 162 f.write('include $(CLEAR_VARS)\n') |
| 163 |
| 164 def write_include_stlport(f): |
| 165 """Add a line to include stlport. |
| 166 |
| 167 Args: |
| 168 f: File open for writing. |
| 169 """ |
| 170 f.write('include external/stlport/libstlport.mk\n') |
| 171 |
150 def write_android_mk(target_dir, common, deviations_from_common): | 172 def write_android_mk(target_dir, common, deviations_from_common): |
151 """ | 173 """Given all the variables, write the final make file. |
152 Given all the variables, write the final make file. | 174 |
153 @param target_dir The full path to the directory to write Android.mk, or None | 175 Args: |
154 to use the current working directory. | 176 target_dir: The full path to the directory to write Android.mk, or None |
155 @param common VarsDict holding variables definitions common to all | 177 to use the current working directory. |
156 configurations. | 178 common: VarsDict holding variables definitions common to all |
157 @param deviations_from_common List of VarsDictData, one for each possible | 179 configurations. |
158 configuration. VarsDictData.name will be | 180 deviations_from_common: List of VarsDictData, one for each possible |
159 appended to each key before writing it to the | 181 configuration. VarsDictData.name will be appended to each key before |
160 makefile. VarsDictData.condition, if not None, | 182 writing it to the makefile. VarsDictData.condition, if not None, will be |
161 will be written to the makefile as a condition | 183 written to the makefile as a condition to determine whether to include |
162 to determine whether to include | 184 VarsDictData.vars_dict. |
163 VarsDictData.vars_dict. | |
164 """ | 185 """ |
165 target_file = 'Android.mk' | 186 target_file = 'Android.mk' |
166 if target_dir: | 187 if target_dir: |
167 target_file = os.path.join(target_dir, target_file) | 188 target_file = os.path.join(target_dir, target_file) |
168 with open(target_file, 'w') as f: | 189 with open(target_file, 'w') as f: |
169 f.write(AUTOGEN_WARNING) | 190 f.write(AUTOGEN_WARNING) |
170 f.write('BASE_PATH := $(call my-dir)\n') | 191 f.write('BASE_PATH := $(call my-dir)\n') |
171 f.write('LOCAL_PATH:= $(call my-dir)\n') | 192 write_local_path(f) |
172 | 193 |
173 f.write(DEBUGGING_HELP) | 194 f.write(DEBUGGING_HELP) |
174 | 195 |
175 f.write('include $(CLEAR_VARS)\n') | 196 write_clear_vars(f) |
176 | |
177 f.write('LOCAL_ARM_MODE := thumb\n') | 197 f.write('LOCAL_ARM_MODE := thumb\n') |
178 | 198 |
179 # need a flag to tell the C side when we're on devices with large memory | 199 # need a flag to tell the C side when we're on devices with large memory |
180 # budgets (i.e. larger than the low-end devices that initially shipped) | 200 # budgets (i.e. larger than the low-end devices that initially shipped) |
181 # On arm, only define the flag if it has VFP. For all other architectures, | 201 # On arm, only define the flag if it has VFP. For all other architectures, |
182 # always define the flag. | 202 # always define the flag. |
183 f.write('ifeq ($(TARGET_ARCH),arm)\n') | 203 f.write('ifeq ($(TARGET_ARCH),arm)\n') |
184 f.write('\tifeq ($(ARCH_ARM_HAVE_VFP),true)\n') | 204 f.write('\tifeq ($(ARCH_ARM_HAVE_VFP),true)\n') |
185 f.write('\t\tLOCAL_CFLAGS += -DANDROID_LARGE_MEMORY_DEVICE\n') | 205 f.write('\t\tLOCAL_CFLAGS += -DANDROID_LARGE_MEMORY_DEVICE\n') |
186 f.write('\tendif\n') | 206 f.write('\tendif\n') |
(...skipping 10 matching lines...) Expand all Loading... |
197 | 217 |
198 write_local_vars(f, common, False, None) | 218 write_local_vars(f, common, False, None) |
199 | 219 |
200 for data in deviations_from_common: | 220 for data in deviations_from_common: |
201 if data.condition: | 221 if data.condition: |
202 f.write('ifeq ($(%s), true)\n' % data.condition) | 222 f.write('ifeq ($(%s), true)\n' % data.condition) |
203 write_local_vars(f, data.vars_dict, True, data.name) | 223 write_local_vars(f, data.vars_dict, True, data.name) |
204 if data.condition: | 224 if data.condition: |
205 f.write('endif\n\n') | 225 f.write('endif\n\n') |
206 | 226 |
207 f.write('include external/stlport/libstlport.mk\n') | 227 write_include_stlport(f) |
208 f.write('LOCAL_MODULE:= libskia\n') | |
209 f.write('include $(BUILD_SHARED_LIBRARY)\n') | 228 f.write('include $(BUILD_SHARED_LIBRARY)\n') |
210 f.write(SKIA_TOOLS) | 229 f.write(SKIA_TOOLS) |
211 | 230 |
OLD | NEW |