2014-02-06 16:13:00 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
# Copyright 2014 Google Inc.
|
|
|
|
#
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
|
|
|
"""
|
|
|
|
Functions for creating an Android.mk from already created dictionaries.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
def write_group(f, name, items, append):
|
2014-04-28 16:00:30 +00:00
|
|
|
"""Helper function to list all names passed to a variable.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
f: File open for writing (Android.mk)
|
|
|
|
name: Name of the makefile variable (e.g. LOCAL_CFLAGS)
|
|
|
|
items: list of strings to be passed to the variable.
|
|
|
|
append: Whether to append to the variable or overwrite it.
|
2014-02-06 16:13:00 +00:00
|
|
|
"""
|
|
|
|
if not items:
|
|
|
|
return
|
|
|
|
|
|
|
|
# Copy the list so we can prepend it with its name.
|
|
|
|
items_to_write = list(items)
|
|
|
|
|
|
|
|
if append:
|
|
|
|
items_to_write.insert(0, '%s +=' % name)
|
|
|
|
else:
|
|
|
|
items_to_write.insert(0, '%s :=' % name)
|
|
|
|
|
|
|
|
f.write(' \\\n\t'.join(items_to_write))
|
|
|
|
|
|
|
|
f.write('\n\n')
|
|
|
|
|
|
|
|
|
2014-02-28 17:24:32 +00:00
|
|
|
def write_local_vars(f, var_dict, append, name):
|
2014-04-28 16:00:30 +00:00
|
|
|
"""Helper function to write all the members of var_dict to the makefile.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
f: File open for writing (Android.mk)
|
|
|
|
var_dict: VarsDict holding the unique values for one configuration.
|
|
|
|
append: Whether to append to each makefile variable or overwrite it.
|
|
|
|
name: If not None, a string to be appended to each key.
|
2014-02-06 16:13:00 +00:00
|
|
|
"""
|
|
|
|
for key in var_dict.keys():
|
2014-03-28 15:59:04 +00:00
|
|
|
_key = key
|
|
|
|
_items = var_dict[key]
|
2014-02-06 16:13:00 +00:00
|
|
|
if key == 'LOCAL_CFLAGS':
|
|
|
|
# Always append LOCAL_CFLAGS. This allows us to define some early on in
|
|
|
|
# the makefile and not overwrite them.
|
|
|
|
_append = True
|
2014-03-28 15:59:04 +00:00
|
|
|
elif key == 'DEFINES':
|
|
|
|
# For DEFINES, we want to append to LOCAL_CFLAGS.
|
|
|
|
_append = True
|
|
|
|
_key = 'LOCAL_CFLAGS'
|
|
|
|
_items_with_D = []
|
|
|
|
for define in _items:
|
|
|
|
_items_with_D.append('-D' + define)
|
|
|
|
_items = _items_with_D
|
2014-02-06 16:13:00 +00:00
|
|
|
elif key == 'KNOWN_TARGETS':
|
|
|
|
# KNOWN_TARGETS are not needed in the final make file.
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
_append = append
|
2014-02-28 17:24:32 +00:00
|
|
|
if name:
|
|
|
|
_key += '_' + name
|
2014-03-28 15:59:04 +00:00
|
|
|
write_group(f, _key, _items, _append)
|
2014-02-06 16:13:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
AUTOGEN_WARNING = (
|
|
|
|
"""
|
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# THIS FILE IS AUTOGENERATED BY GYP_TO_ANDROID.PY. DO NOT EDIT.
|
|
|
|
#
|
2015-02-12 16:20:40 +00:00
|
|
|
# For bugs, please contact scroggo@google.com or djsollen@google.com
|
|
|
|
#
|
2014-02-06 16:13:00 +00:00
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
|
|
|
|
DEBUGGING_HELP = (
|
|
|
|
"""
|
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# PROBLEMS WITH SKIA DEBUGGING?? READ THIS...
|
|
|
|
#
|
|
|
|
# The debug build results in changes to the Skia headers. This means that those
|
|
|
|
# using libskia must also be built with the debug version of the Skia headers.
|
|
|
|
# There are a few scenarios where this comes into play:
|
|
|
|
#
|
|
|
|
# (1) You're building debug code that depends on libskia.
|
|
|
|
# (a) If libskia is built in release, then define SK_RELEASE when building
|
|
|
|
# your sources.
|
|
|
|
# (b) If libskia is built with debugging (see step 2), then no changes are
|
|
|
|
# needed since your sources and libskia have been built with SK_DEBUG.
|
|
|
|
# (2) You're building libskia in debug mode.
|
|
|
|
# (a) RECOMMENDED: You can build the entire system in debug mode. Do this by
|
2014-06-02 14:19:13 +00:00
|
|
|
# updating your build/core/config.mk to include -DSK_DEBUG on the line
|
|
|
|
# that defines COMMON_GLOBAL_CFLAGS
|
2014-02-06 16:13:00 +00:00
|
|
|
# (b) You can update all the users of libskia to define SK_DEBUG when they are
|
|
|
|
# building their sources.
|
|
|
|
#
|
|
|
|
# NOTE: If neither SK_DEBUG or SK_RELEASE are defined then Skia checks NDEBUG to
|
|
|
|
# determine which build type to use.
|
|
|
|
###############################################################################
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
|
2014-03-24 18:26:36 +00:00
|
|
|
SKIA_TOOLS = (
|
|
|
|
"""
|
|
|
|
#############################################################
|
2016-12-09 14:35:50 +00:00
|
|
|
# Build the skia tools (except in the PDK build)
|
2014-03-24 18:26:36 +00:00
|
|
|
#
|
2016-12-09 14:35:50 +00:00
|
|
|
ifneq ($(TARGET_BUILD_PDK),true)
|
2014-03-24 18:26:36 +00:00
|
|
|
|
|
|
|
# benchmark (timings)
|
2014-08-21 20:12:34 +00:00
|
|
|
include $(BASE_PATH)/bench/Android.mk
|
2014-03-24 18:26:36 +00:00
|
|
|
|
2014-05-16 18:11:51 +00:00
|
|
|
# diamond-master (one test to rule them all)
|
|
|
|
include $(BASE_PATH)/dm/Android.mk
|
2016-12-09 14:35:50 +00:00
|
|
|
|
|
|
|
endif # disable for PDK
|
2014-03-24 18:26:36 +00:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
|
2016-02-12 16:44:39 +00:00
|
|
|
STATIC_HEADER = (
|
|
|
|
"""
|
|
|
|
###############################################################################
|
|
|
|
# STATIC LIBRARY
|
|
|
|
#
|
|
|
|
# This target is only to be used internally for only one of two purposes...
|
|
|
|
# (1) statically linking into testing frameworks
|
|
|
|
# (2) as an inclusion target for the libskia.so shared library
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
|
|
|
|
SHARED_HEADER = (
|
|
|
|
"""
|
|
|
|
###############################################################################
|
|
|
|
# SHARED LIBRARY
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
|
|
|
|
STATIC_DEPS_INFO = (
|
|
|
|
"""
|
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# This file contains the shared and static dependencies needed by any target
|
|
|
|
# that attempts to statically link Skia (i.e. libskia_static build target).
|
|
|
|
#
|
|
|
|
# This is a workaround for the fact that the build system does not add these
|
|
|
|
# transitive dependencies when it attempts to link libskia_static into another
|
|
|
|
# library.
|
|
|
|
#
|
|
|
|
###############################################################################
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
|
|
|
|
CLEAR_VARS = ("""include $(CLEAR_VARS)\n""")
|
|
|
|
LOCAL_PATH = ("""LOCAL_PATH:= $(call my-dir)\n""")
|
2014-03-24 18:26:36 +00:00
|
|
|
|
2014-02-28 17:24:32 +00:00
|
|
|
class VarsDictData(object):
|
2014-04-28 16:00:30 +00:00
|
|
|
"""Helper class to keep a VarsDict along with a name and optional condition.
|
2014-02-28 17:24:32 +00:00
|
|
|
"""
|
|
|
|
def __init__(self, vars_dict, name, condition=None):
|
2014-04-28 16:00:30 +00:00
|
|
|
"""Create a new VarsDictData.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
vars_dict: A VarsDict. Can be accessed via self.vars_dict.
|
|
|
|
name: Name associated with the VarsDict. Can be accessed via
|
|
|
|
self.name.
|
|
|
|
condition: Optional string representing a condition. If not None,
|
|
|
|
used to create a conditional inside the makefile.
|
2014-02-28 17:24:32 +00:00
|
|
|
"""
|
|
|
|
self.vars_dict = vars_dict
|
|
|
|
self.condition = condition
|
|
|
|
self.name = name
|
|
|
|
|
2016-02-12 16:44:39 +00:00
|
|
|
def write_static_deps_mk(target_dir, common, deviations_from_common):
|
|
|
|
"""Given all the variables, write the final make file.
|
2014-04-28 16:00:30 +00:00
|
|
|
|
2014-07-17 13:58:28 +00:00
|
|
|
Args:
|
2016-02-12 16:44:39 +00:00
|
|
|
target_dir: The full path to the directory to write skia_static_includes.mk,
|
|
|
|
or None to use the current working directory.
|
|
|
|
common: VarsDict holding variables definitions common to all
|
|
|
|
configurations.
|
|
|
|
deviations_from_common: List of VarsDictData, one for each possible
|
|
|
|
configuration. VarsDictData.name will be appended to each key before
|
|
|
|
writing it to the makefile. VarsDictData.condition, if not None, will be
|
|
|
|
written to the makefile as a condition to determine whether to include
|
|
|
|
VarsDictData.vars_dict.
|
2014-07-17 13:58:28 +00:00
|
|
|
"""
|
2016-02-12 16:44:39 +00:00
|
|
|
target_file = 'skia_static_deps.mk'
|
|
|
|
if target_dir:
|
|
|
|
target_file = os.path.join(target_dir, target_file)
|
|
|
|
with open(target_file, 'w') as f:
|
|
|
|
f.write(AUTOGEN_WARNING)
|
|
|
|
f.write(STATIC_DEPS_INFO)
|
2014-04-28 16:00:30 +00:00
|
|
|
|
2016-02-12 16:44:39 +00:00
|
|
|
for data in deviations_from_common:
|
|
|
|
var_dict_shared = data.vars_dict['LOCAL_SHARED_LIBRARIES']
|
|
|
|
var_dict_static = data.vars_dict['LOCAL_STATIC_LIBRARIES']
|
|
|
|
if data.condition and (var_dict_shared or var_dict_static):
|
|
|
|
f.write('ifeq ($(%s), true)\n' % data.condition)
|
|
|
|
write_group(f, 'LOCAL_SHARED_LIBRARIES', var_dict_shared, True)
|
|
|
|
write_group(f, 'LOCAL_STATIC_LIBRARIES', var_dict_static, True)
|
|
|
|
if data.condition and (var_dict_shared or var_dict_static):
|
|
|
|
f.write('endif\n\n')
|
|
|
|
|
|
|
|
write_group(f, 'LOCAL_SHARED_LIBRARIES', common['LOCAL_SHARED_LIBRARIES'],
|
|
|
|
True)
|
|
|
|
write_group(f, 'LOCAL_STATIC_LIBRARIES', common['LOCAL_STATIC_LIBRARIES'],
|
|
|
|
True)
|
2014-04-28 16:00:30 +00:00
|
|
|
|
|
|
|
|
2014-02-28 17:24:32 +00:00
|
|
|
def write_android_mk(target_dir, common, deviations_from_common):
|
2014-04-28 16:00:30 +00:00
|
|
|
"""Given all the variables, write the final make file.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
target_dir: The full path to the directory to write Android.mk, or None
|
|
|
|
to use the current working directory.
|
|
|
|
common: VarsDict holding variables definitions common to all
|
|
|
|
configurations.
|
|
|
|
deviations_from_common: List of VarsDictData, one for each possible
|
|
|
|
configuration. VarsDictData.name will be appended to each key before
|
|
|
|
writing it to the makefile. VarsDictData.condition, if not None, will be
|
|
|
|
written to the makefile as a condition to determine whether to include
|
|
|
|
VarsDictData.vars_dict.
|
2014-02-06 16:13:00 +00:00
|
|
|
"""
|
|
|
|
target_file = 'Android.mk'
|
|
|
|
if target_dir:
|
|
|
|
target_file = os.path.join(target_dir, target_file)
|
|
|
|
with open(target_file, 'w') as f:
|
|
|
|
f.write(AUTOGEN_WARNING)
|
|
|
|
f.write('BASE_PATH := $(call my-dir)\n')
|
2016-02-12 16:44:39 +00:00
|
|
|
f.write(LOCAL_PATH)
|
2014-02-06 16:13:00 +00:00
|
|
|
|
|
|
|
f.write(DEBUGGING_HELP)
|
|
|
|
|
2016-02-12 16:44:39 +00:00
|
|
|
f.write(STATIC_HEADER)
|
|
|
|
f.write(CLEAR_VARS)
|
2014-08-21 14:38:31 +00:00
|
|
|
|
|
|
|
# need flags to enable feedback driven optimization (FDO) when requested
|
|
|
|
# by the build system.
|
2014-07-29 19:38:25 +00:00
|
|
|
f.write('LOCAL_FDO_SUPPORT := true\n')
|
2014-08-21 20:02:27 +00:00
|
|
|
f.write('ifneq ($(strip $(TARGET_FDO_CFLAGS)),)\n')
|
2014-08-21 14:38:31 +00:00
|
|
|
f.write('\t# This should be the last -Oxxx specified in LOCAL_CFLAGS\n')
|
|
|
|
f.write('\tLOCAL_CFLAGS += -O2\n')
|
|
|
|
f.write('endif\n\n')
|
|
|
|
|
2014-02-06 16:13:00 +00:00
|
|
|
f.write('LOCAL_ARM_MODE := thumb\n')
|
|
|
|
|
|
|
|
f.write('# used for testing\n')
|
|
|
|
f.write('#LOCAL_CFLAGS += -g -O0\n\n')
|
|
|
|
|
2016-02-12 16:44:39 +00:00
|
|
|
# update the provided LOCAL_MODULE with a _static suffix
|
|
|
|
local_module = common['LOCAL_MODULE'][0]
|
|
|
|
static_local_module = local_module + '_static'
|
|
|
|
common['LOCAL_MODULE'].reset()
|
|
|
|
common['LOCAL_MODULE'].add(static_local_module)
|
2014-02-06 16:13:00 +00:00
|
|
|
|
2014-02-28 17:24:32 +00:00
|
|
|
write_local_vars(f, common, False, None)
|
2014-02-06 16:13:00 +00:00
|
|
|
|
2014-02-28 17:24:32 +00:00
|
|
|
for data in deviations_from_common:
|
2016-09-27 14:37:20 +00:00
|
|
|
if data.name == 'mips':
|
|
|
|
if data.condition =='mips32r2dspr2-fp' :
|
|
|
|
f.write('ifeq ($(TARGET_ARCH_VARIANT), %s)\n' % (data.condition))
|
|
|
|
write_local_vars(f, data.vars_dict, True, data.name)
|
|
|
|
elif data.condition =='mips32r2dsp-fp' :
|
|
|
|
f.write('else ifeq ($(TARGET_ARCH_VARIANT), %s)\n' % (data.condition))
|
|
|
|
write_local_vars(f, data.vars_dict, True, data.name)
|
|
|
|
else :
|
|
|
|
f.write('else\n')
|
|
|
|
write_local_vars(f, data.vars_dict, True, data.name)
|
|
|
|
f.write('endif\n\n')
|
|
|
|
else :
|
|
|
|
if data.condition:
|
|
|
|
f.write('ifeq ($(%s), true)\n' % data.condition)
|
|
|
|
write_local_vars(f, data.vars_dict, True, data.name)
|
|
|
|
if data.condition:
|
|
|
|
f.write('endif\n\n')
|
2014-02-06 16:13:00 +00:00
|
|
|
|
2016-02-12 16:44:39 +00:00
|
|
|
f.write('LOCAL_MODULE_CLASS := STATIC_LIBRARIES\n')
|
|
|
|
f.write('include $(BUILD_STATIC_LIBRARY)\n\n')
|
|
|
|
|
|
|
|
f.write(SHARED_HEADER)
|
|
|
|
f.write(CLEAR_VARS)
|
|
|
|
f.write('LOCAL_MODULE_CLASS := SHARED_LIBRARIES\n')
|
|
|
|
f.write('LOCAL_MODULE := %s\n' % local_module)
|
|
|
|
f.write('LOCAL_WHOLE_STATIC_LIBRARIES := %s\n' % static_local_module)
|
|
|
|
write_group(f, 'LOCAL_EXPORT_C_INCLUDE_DIRS',
|
|
|
|
common['LOCAL_EXPORT_C_INCLUDE_DIRS'], False)
|
|
|
|
f.write('include $(BASE_PATH)/skia_static_deps.mk\n')
|
2014-02-06 16:13:00 +00:00
|
|
|
f.write('include $(BUILD_SHARED_LIBRARY)\n')
|
2016-02-12 16:44:39 +00:00
|
|
|
|
2014-03-24 18:26:36 +00:00
|
|
|
f.write(SKIA_TOOLS)
|
2014-02-06 16:13:00 +00:00
|
|
|
|