OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/python |
| 2 |
| 3 # Copyright 2014 Google Inc. |
| 4 # |
| 5 # Use of this source code is governed by a BSD-style license that can be |
| 6 # found in the LICENSE file. |
| 7 |
| 8 """ |
| 9 Functions for creating an Android.mk from already created dictionaries. |
| 10 """ |
| 11 |
| 12 import os |
| 13 import variables |
| 14 |
| 15 def write_group(f, name, items, append): |
| 16 """ |
| 17 Helper function to list all names passed to a variable. |
| 18 @param f File open for writing (Android.mk) |
| 19 @param name Name of the makefile variable (e.g. LOCAL_CFLAGS) |
| 20 @param items list of strings to be passed to the variable. |
| 21 @param append Whether to append to the variable or overwrite it. |
| 22 """ |
| 23 if not items: |
| 24 return |
| 25 |
| 26 # Copy the list so we can prepend it with its name. |
| 27 items_to_write = list(items) |
| 28 |
| 29 if append: |
| 30 items_to_write.insert(0, '%s +=' % name) |
| 31 else: |
| 32 items_to_write.insert(0, '%s :=' % name) |
| 33 |
| 34 f.write(' \\\n\t'.join(items_to_write)) |
| 35 |
| 36 f.write('\n\n') |
| 37 |
| 38 |
| 39 def write_local_vars(f, var_dict, append): |
| 40 """ |
| 41 Helper function to write all the members of var_dict to the makefile. |
| 42 @param f File open for writing (Android.mk) |
| 43 @param var_dict VarsDict holding the unique values for one configuration. |
| 44 @param append Whether to append to each makefile variable or overwrite it. |
| 45 """ |
| 46 for key in var_dict.keys(): |
| 47 if key == 'LOCAL_CFLAGS': |
| 48 # Always append LOCAL_CFLAGS. This allows us to define some early on in |
| 49 # the makefile and not overwrite them. |
| 50 _append = True |
| 51 elif key == 'KNOWN_TARGETS': |
| 52 # KNOWN_TARGETS are not needed in the final make file. |
| 53 continue |
| 54 else: |
| 55 _append = append |
| 56 write_group(f, key, var_dict[key], _append) |
| 57 |
| 58 |
| 59 AUTOGEN_WARNING = ( |
| 60 """ |
| 61 ############################################################################### |
| 62 # |
| 63 # THIS FILE IS AUTOGENERATED BY GYP_TO_ANDROID.PY. DO NOT EDIT. |
| 64 # |
| 65 ############################################################################### |
| 66 |
| 67 """ |
| 68 ) |
| 69 |
| 70 |
| 71 DEBUGGING_HELP = ( |
| 72 """ |
| 73 ############################################################################### |
| 74 # |
| 75 # PROBLEMS WITH SKIA DEBUGGING?? READ THIS... |
| 76 # |
| 77 # The debug build results in changes to the Skia headers. This means that those |
| 78 # using libskia must also be built with the debug version of the Skia headers. |
| 79 # There are a few scenarios where this comes into play: |
| 80 # |
| 81 # (1) You're building debug code that depends on libskia. |
| 82 # (a) If libskia is built in release, then define SK_RELEASE when building |
| 83 # your sources. |
| 84 # (b) If libskia is built with debugging (see step 2), then no changes are |
| 85 # needed since your sources and libskia have been built with SK_DEBUG. |
| 86 # (2) You're building libskia in debug mode. |
| 87 # (a) RECOMMENDED: You can build the entire system in debug mode. Do this by |
| 88 # updating your build/config.mk to include -DSK_DEBUG on the line that |
| 89 # defines COMMON_GLOBAL_CFLAGS |
| 90 # (b) You can update all the users of libskia to define SK_DEBUG when they are |
| 91 # building their sources. |
| 92 # |
| 93 # NOTE: If neither SK_DEBUG or SK_RELEASE are defined then Skia checks NDEBUG to |
| 94 # determine which build type to use. |
| 95 ############################################################################### |
| 96 |
| 97 """ |
| 98 ) |
| 99 |
| 100 |
| 101 def write_android_mk(target_dir, common, arm, armNeon, x86, default): |
| 102 """ |
| 103 Given all the variables, write the final make file. |
| 104 @param target_dir The full path to the directory to write Android.mk, or None |
| 105 to use the current working directory. |
| 106 @param common VarsDict holding variables definitions common to all |
| 107 configurations. |
| 108 @param arm VarsDict holding variable definitions unique to arm. Will be |
| 109 written to the makefile inside an 'ifeq ($(TARGET_ARCH), arm)' |
| 110 block. |
| 111 @param armNeon VarsDict holding variable definitions unique to arm with neon. |
| 112 Will be written inside an 'ifeq ($(ARCH_ARM_HAVE_NEON),true)' |
| 113 block nested inside an 'ifeq ($(TARGET_ARCH), arm)' block. |
| 114 @param x86 VarsDict holding variable definitions unique to x86. Will be |
| 115 written inside an 'ifeq ($(TARGET_ARCH),x86)' block. |
| 116 @param default VarsDict holding variable definitions for an architecture |
| 117 without custom optimizations. |
| 118 TODO: Add mips. |
| 119 """ |
| 120 target_file = 'Android.mk' |
| 121 if target_dir: |
| 122 target_file = os.path.join(target_dir, target_file) |
| 123 with open(target_file, 'w') as f: |
| 124 f.write(AUTOGEN_WARNING) |
| 125 f.write('BASE_PATH := $(call my-dir)\n') |
| 126 f.write('LOCAL_PATH:= $(call my-dir)\n') |
| 127 |
| 128 f.write(DEBUGGING_HELP) |
| 129 |
| 130 f.write('include $(CLEAR_VARS)\n') |
| 131 |
| 132 f.write('LOCAL_ARM_MODE := thumb\n') |
| 133 |
| 134 # need a flag to tell the C side when we're on devices with large memory |
| 135 # budgets (i.e. larger than the low-end devices that initially shipped) |
| 136 f.write('ifeq ($(ARCH_ARM_HAVE_VFP),true)\n') |
| 137 f.write('\tLOCAL_CFLAGS += -DANDROID_LARGE_MEMORY_DEVICE\n') |
| 138 f.write('endif\n\n') |
| 139 |
| 140 f.write('ifeq ($(TARGET_ARCH),x86)\n') |
| 141 f.write('\tLOCAL_CFLAGS += -DANDROID_LARGE_MEMORY_DEVICE\n') |
| 142 f.write('endif\n\n') |
| 143 |
| 144 f.write('# used for testing\n') |
| 145 f.write('#LOCAL_CFLAGS += -g -O0\n\n') |
| 146 |
| 147 f.write('ifeq ($(NO_FALLBACK_FONT),true)\n') |
| 148 f.write('\tLOCAL_CFLAGS += -DNO_FALLBACK_FONT\n') |
| 149 f.write('endif\n\n') |
| 150 |
| 151 write_local_vars(f, common, False) |
| 152 |
| 153 f.write('ifeq ($(TARGET_ARCH),arm)\n') |
| 154 f.write('ifeq ($(ARCH_ARM_HAVE_NEON),true)\n') |
| 155 write_local_vars(f, armNeon, True) |
| 156 f.write('endif\n\n') |
| 157 write_local_vars(f, arm, True) |
| 158 |
| 159 if variables.INCLUDE_X86_OPTS: |
| 160 f.write('else ifeq ($(TARGET_ARCH),x86)\n') |
| 161 write_local_vars(f, x86, True) |
| 162 |
| 163 f.write('else\n') |
| 164 write_local_vars(f, default, True) |
| 165 f.write('endif\n\n') |
| 166 |
| 167 f.write('include external/stlport/libstlport.mk\n') |
| 168 f.write('LOCAL_MODULE:= libskia\n') |
| 169 f.write('include $(BUILD_SHARED_LIBRARY)\n') |
| 170 |
| 171 |
| 172 |
OLD | NEW |