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 import variables | |
14 | 13 |
15 def write_group(f, name, items, append): | 14 def write_group(f, name, items, append): |
16 """ | 15 """ |
17 Helper function to list all names passed to a variable. | 16 Helper function to list all names passed to a variable. |
18 @param f File open for writing (Android.mk) | 17 @param f File open for writing (Android.mk) |
19 @param name Name of the makefile variable (e.g. LOCAL_CFLAGS) | 18 @param name Name of the makefile variable (e.g. LOCAL_CFLAGS) |
20 @param items list of strings to be passed to the variable. | 19 @param items list of strings to be passed to the variable. |
21 @param append Whether to append to the variable or overwrite it. | 20 @param append Whether to append to the variable or overwrite it. |
22 """ | 21 """ |
23 if not items: | 22 if not items: |
24 return | 23 return |
25 | 24 |
26 # Copy the list so we can prepend it with its name. | 25 # Copy the list so we can prepend it with its name. |
27 items_to_write = list(items) | 26 items_to_write = list(items) |
28 | 27 |
29 if append: | 28 if append: |
30 items_to_write.insert(0, '%s +=' % name) | 29 items_to_write.insert(0, '%s +=' % name) |
31 else: | 30 else: |
32 items_to_write.insert(0, '%s :=' % name) | 31 items_to_write.insert(0, '%s :=' % name) |
33 | 32 |
34 f.write(' \\\n\t'.join(items_to_write)) | 33 f.write(' \\\n\t'.join(items_to_write)) |
35 | 34 |
36 f.write('\n\n') | 35 f.write('\n\n') |
37 | 36 |
38 | 37 |
39 def write_local_vars(f, var_dict, append): | 38 def write_local_vars(f, var_dict, append, name): |
40 """ | 39 """ |
41 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. |
42 @param f File open for writing (Android.mk) | 41 @param f File open for writing (Android.mk) |
43 @param var_dict VarsDict holding the unique values for one configuration. | 42 @param var_dict VarsDict holding the unique values for one configuration. |
44 @param append Whether to append to each makefile variable or overwrite it. | 43 @param append Whether to append to each makefile variable or overwrite it. |
44 @param name If not None, a string to be appended to each key. | |
45 """ | 45 """ |
46 for key in var_dict.keys(): | 46 for key in var_dict.keys(): |
47 if key == 'LOCAL_CFLAGS': | 47 if key == 'LOCAL_CFLAGS': |
48 # Always append LOCAL_CFLAGS. This allows us to define some early on in | 48 # Always append LOCAL_CFLAGS. This allows us to define some early on in |
49 # the makefile and not overwrite them. | 49 # the makefile and not overwrite them. |
50 _append = True | 50 _append = True |
51 elif key == 'KNOWN_TARGETS': | 51 elif key == 'KNOWN_TARGETS': |
52 # KNOWN_TARGETS are not needed in the final make file. | 52 # KNOWN_TARGETS are not needed in the final make file. |
53 continue | 53 continue |
54 else: | 54 else: |
55 _append = append | 55 _append = append |
56 write_group(f, key, var_dict[key], _append) | 56 _key = key |
57 if name: | |
58 _key += '_' + name | |
59 write_group(f, _key, var_dict[key], _append) | |
57 | 60 |
58 | 61 |
59 AUTOGEN_WARNING = ( | 62 AUTOGEN_WARNING = ( |
60 """ | 63 """ |
61 ############################################################################### | 64 ############################################################################### |
62 # | 65 # |
63 # THIS FILE IS AUTOGENERATED BY GYP_TO_ANDROID.PY. DO NOT EDIT. | 66 # THIS FILE IS AUTOGENERATED BY GYP_TO_ANDROID.PY. DO NOT EDIT. |
64 # | 67 # |
65 ############################################################################### | 68 ############################################################################### |
66 | 69 |
(...skipping 23 matching lines...) Expand all Loading... | |
90 # (b) You can update all the users of libskia to define SK_DEBUG when they are | 93 # (b) You can update all the users of libskia to define SK_DEBUG when they are |
91 # building their sources. | 94 # building their sources. |
92 # | 95 # |
93 # NOTE: If neither SK_DEBUG or SK_RELEASE are defined then Skia checks NDEBUG to | 96 # NOTE: If neither SK_DEBUG or SK_RELEASE are defined then Skia checks NDEBUG to |
94 # determine which build type to use. | 97 # determine which build type to use. |
95 ############################################################################### | 98 ############################################################################### |
96 | 99 |
97 """ | 100 """ |
98 ) | 101 ) |
99 | 102 |
103 class VarsDictData(object): | |
104 """ | |
105 Helper class for keeping a VarsDict along with a name and an optional | |
106 condition. | |
107 """ | |
108 def __init__(self, vars_dict, name, condition=None): | |
109 """ | |
110 Create a new VarsDictData. | |
111 @param vars_dict A VarsDict. Can be accessed via self.vars_dict. | |
112 @param name Name associated with the VarsDict. Can be accessed via | |
113 self.name. | |
114 @param condition Optional string representing a condition. If not None, | |
115 used to create a conditional inside the makefile. | |
116 """ | |
117 self.vars_dict = vars_dict | |
118 self.condition = condition | |
119 self.name = name | |
100 | 120 |
101 # TODO (scroggo): Currently write_android_mk has intimate knowledge about its | 121 def write_android_mk(target_dir, common, the_rest): |
102 # parameters: e.g. arm_neon keeps track of differences from arm, whereas the | |
103 # others keep track of differences from common. Consider reworking this. | |
104 def write_android_mk(target_dir, common, arm, arm_neon, x86, default): | |
105 """ | 122 """ |
106 Given all the variables, write the final make file. | 123 Given all the variables, write the final make file. |
107 @param target_dir The full path to the directory to write Android.mk, or None | 124 @param target_dir The full path to the directory to write Android.mk, or None |
108 to use the current working directory. | 125 to use the current working directory. |
109 @param common VarsDict holding variables definitions common to all | 126 @param common VarsDict holding variables definitions common to all |
110 configurations. | 127 configurations. |
111 @param arm VarsDict holding variable definitions unique to arm. Will be | 128 @param the_rest List of VarsDictData, one for each possible configuration. |
epoger
2014/02/28 15:56:43
Again, I think a name like deviations, deviations_
scroggo
2014/02/28 16:16:57
Done.
| |
112 written to the makefile inside an 'ifeq ($(TARGET_ARCH), arm)' | 129 VarsDictData.name will be appended to each key before writing |
113 block. | 130 it to the makefile. VarsDictData.condition, if not None, will |
114 @param arm_neon VarsDict holding variable definitions unique to arm with neon. | 131 be written to the makefile as a condition to determine |
epoger
2014/02/28 15:56:43
I don't think it's a big deal, but http://google-s
scroggo
2014/02/28 16:16:57
For now, I'd like to stick with the surrounding co
| |
115 Will be written inside an 'ifeq ($(ARCH_ARM_HAVE_NEON),true)' | 132 whether to include VarsDictData.vars_dict. |
116 block nested inside an 'ifeq ($(TARGET_ARCH), arm)' block. | |
117 @param x86 VarsDict holding variable definitions unique to x86. Will be | |
118 written inside an 'ifeq ($(TARGET_ARCH),x86)' block. | |
119 @param default VarsDict holding variable definitions for an architecture | |
120 without custom optimizations. | |
121 TODO: Add mips. | |
122 """ | 133 """ |
123 target_file = 'Android.mk' | 134 target_file = 'Android.mk' |
124 if target_dir: | 135 if target_dir: |
125 target_file = os.path.join(target_dir, target_file) | 136 target_file = os.path.join(target_dir, target_file) |
126 with open(target_file, 'w') as f: | 137 with open(target_file, 'w') as f: |
127 f.write(AUTOGEN_WARNING) | 138 f.write(AUTOGEN_WARNING) |
128 f.write('BASE_PATH := $(call my-dir)\n') | 139 f.write('BASE_PATH := $(call my-dir)\n') |
129 f.write('LOCAL_PATH:= $(call my-dir)\n') | 140 f.write('LOCAL_PATH:= $(call my-dir)\n') |
130 | 141 |
131 f.write(DEBUGGING_HELP) | 142 f.write(DEBUGGING_HELP) |
132 | 143 |
133 f.write('include $(CLEAR_VARS)\n') | 144 f.write('include $(CLEAR_VARS)\n') |
134 | 145 |
135 f.write('LOCAL_ARM_MODE := thumb\n') | 146 f.write('LOCAL_ARM_MODE := thumb\n') |
136 | 147 |
137 # need a flag to tell the C side when we're on devices with large memory | 148 # need a flag to tell the C side when we're on devices with large memory |
138 # budgets (i.e. larger than the low-end devices that initially shipped) | 149 # budgets (i.e. larger than the low-end devices that initially shipped) |
139 f.write('ifeq ($(ARCH_ARM_HAVE_VFP),true)\n') | 150 # On arm, only define the flag if it has VFP. For all other architectures, |
151 # always define the flag. | |
152 f.write('ifeq ($(TARGET_ARCH),arm)\n') | |
153 f.write('\tifeq ($(ARCH_ARM_HAVE_VFP),true)\n') | |
154 f.write('\t\tLOCAL_CFLAGS += -DANDROID_LARGE_MEMORY_DEVICE\n') | |
155 f.write('\tendif\n') | |
156 f.write('else\n') | |
140 f.write('\tLOCAL_CFLAGS += -DANDROID_LARGE_MEMORY_DEVICE\n') | 157 f.write('\tLOCAL_CFLAGS += -DANDROID_LARGE_MEMORY_DEVICE\n') |
141 f.write('endif\n\n') | 158 f.write('endif\n\n') |
142 | 159 |
143 f.write('ifeq ($(TARGET_ARCH),x86)\n') | |
144 f.write('\tLOCAL_CFLAGS += -DANDROID_LARGE_MEMORY_DEVICE\n') | |
145 f.write('endif\n\n') | |
146 | |
147 f.write('# used for testing\n') | 160 f.write('# used for testing\n') |
148 f.write('#LOCAL_CFLAGS += -g -O0\n\n') | 161 f.write('#LOCAL_CFLAGS += -g -O0\n\n') |
149 | 162 |
150 f.write('ifeq ($(NO_FALLBACK_FONT),true)\n') | 163 f.write('ifeq ($(NO_FALLBACK_FONT),true)\n') |
151 f.write('\tLOCAL_CFLAGS += -DNO_FALLBACK_FONT\n') | 164 f.write('\tLOCAL_CFLAGS += -DNO_FALLBACK_FONT\n') |
152 f.write('endif\n\n') | 165 f.write('endif\n\n') |
153 | 166 |
154 write_local_vars(f, common, False) | 167 write_local_vars(f, common, False, None) |
155 | 168 |
156 f.write('ifeq ($(TARGET_ARCH),arm)\n') | 169 for data in the_rest: |
157 f.write('ifeq ($(ARCH_ARM_HAVE_NEON),true)\n') | 170 if data.condition: |
epoger
2014/02/28 15:56:43
Please consider adding unittests at some point. T
scroggo
2014/02/28 16:16:57
Will do. Added a TODO.
| |
158 write_local_vars(f, arm_neon, True) | 171 f.write('ifeq ($(%s), true)\n' % data.condition) |
159 f.write('endif\n\n') | 172 write_local_vars(f, data.vars_dict, True, data.name) |
160 write_local_vars(f, arm, True) | 173 if data.condition: |
161 | 174 f.write('endif\n\n') |
162 if variables.INCLUDE_X86_OPTS: | |
163 f.write('else ifeq ($(TARGET_ARCH),x86)\n') | |
164 write_local_vars(f, x86, True) | |
165 | |
166 f.write('else\n') | |
167 write_local_vars(f, default, True) | |
168 f.write('endif\n\n') | |
169 | 175 |
170 f.write('include external/stlport/libstlport.mk\n') | 176 f.write('include external/stlport/libstlport.mk\n') |
171 f.write('LOCAL_MODULE:= libskia\n') | 177 f.write('LOCAL_MODULE:= libskia\n') |
172 f.write('include $(BUILD_SHARED_LIBRARY)\n') | 178 f.write('include $(BUILD_SHARED_LIBRARY)\n') |
173 | 179 |
174 | 180 |
175 | 181 |
OLD | NEW |