Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 04b1e8c8 authored by Christopher Ferris's avatar Christopher Ferris
Browse files

Refactor makefile.

With this change allow the creation of host backtrace libraries using
libunwind.

Change-Id: Ie48bb36cf0d2eccf94cb8ff516d829d8032f11f2
parent 51c4d4c4
Loading
Loading
Loading
Loading
+73 −0
Original line number Diff line number Diff line
#
# Copyright (C) 2014 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

include $(CLEAR_VARS)

LOCAL_MODULE := $(module)
LOCAL_MODULE_TAGS := $(module_tag)

LOCAL_ADDITIONAL_DEPENDENCIES := \
    $(LOCAL_PATH)/Android.mk \
    $(LOCAL_PATH)/Android.build.mk \

LOCAL_CFLAGS := \
    $(common_cflags) \
    $($(module)_cflags) \
    $($(module)_cflags_$(build_type)) \

LOCAL_CONLYFLAGS += \
    $(common_conlyflags) \
    $($(module)_conlyflags) \
    $($(module)_conlyflags_$(build_type)) \

LOCAL_CPPFLAGS += \
    $(common_cppflags) \
    $($(module)_cppflags) \
    $($(module)_cppflags_$(build_type)) \

LOCAL_C_INCLUDES := \
    $(common_c_includes) \
    $($(module)_c_includes) \
    $($(module)_c_includes_$(build_type)) \

LOCAL_SRC_FILES := \
    $($(module)_src_files) \
    $($(module)_src_files_$(build_type)) \

LOCAL_STATIC_LIBRARIES := \
    $($(module)_static_libraries) \
    $($(module)_static_libraries_$(build_type)) \

LOCAL_SHARED_LIBRARIES := \
    $($(module)_shared_libraries) \
    $($(module)_shared_libraries_$(build_type)) \

LOCAL_LDLIBS := \
    $($(module)_ldlibs) \
    $($(module)_ldlibs_$(build_type)) \

ifeq ($(build_type),target)
  include external/stlport/libstlport.mk

  include $(BUILD_$(build_target))
endif

ifeq ($(build_type),host)
  # Only build if host builds are supported.
  ifeq ($(build_host),true)
    include $(BUILD_HOST_$(build_target))
  endif
endif
+103 −220
Original line number Diff line number Diff line
LOCAL_PATH:= $(call my-dir)
#
# Copyright (C) 2014 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

common_src := \
	BacktraceImpl.cpp \
	BacktraceMap.cpp \
	BacktraceThread.cpp \
	thread_utils.c \
LOCAL_PATH:= $(call my-dir)

common_cflags := \
	-Wall \
	-Wno-unused-parameter \
	-Werror \

common_conlyflags := \
@@ -17,274 +26,148 @@ common_conlyflags := \
common_cppflags := \
	-std=gnu++11 \

common_shared_libs := \
build_host := false
ifeq ($(HOST_OS),linux)
ifeq ($(HOST_ARCH),$(filter $(HOST_ARCH),x86 x86_64))
build_host := true
endif
endif

#-------------------------------------------------------------------------
# The libbacktrace library.
#-------------------------------------------------------------------------
libbacktrace_src_files := \
	BacktraceImpl.cpp \
	BacktraceMap.cpp \
	BacktraceThread.cpp \
	thread_utils.c \

libbacktrace_shared_libraries_target := \
	libcutils \
	libgccdemangle \
	liblog \

# To enable using libunwind on each arch, add it to this list.
libunwind_architectures := arm arm64 x86 x86_64

ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),$(libunwind_architectures)))

#----------------------------------------------------------------------------
# The native libbacktrace library with libunwind.
#----------------------------------------------------------------------------
include $(CLEAR_VARS)

LOCAL_SRC_FILES:= \
	$(common_src) \
libbacktrace_src_files += \
	UnwindCurrent.cpp \
	UnwindMap.cpp \
	UnwindPtrace.cpp \

LOCAL_CFLAGS := \
	$(common_cflags) \

LOCAL_CONLYFLAGS += \
	$(common_conlyflags) \

LOCAL_CPPFLAGS += \
	$(common_cppflags) \

LOCAL_MODULE := libbacktrace
LOCAL_MODULE_TAGS := optional

LOCAL_C_INCLUDES := \
	$(common_c_includes) \
libbacktrace_c_includes := \
	external/libunwind/include \

LOCAL_SHARED_LIBRARIES := \
	$(common_shared_libs) \
libbacktrace_shared_libraries := \
	libunwind \
	libunwind-ptrace \

LOCAL_ADDITIONAL_DEPENDENCIES := \
	$(LOCAL_PATH)/Android.mk

include external/stlport/libstlport.mk
libbacktrace_shared_libraries_host := \
	liblog \

include $(BUILD_SHARED_LIBRARY)
libbacktrace_static_libraries_host := \
	libcutils \

else

#----------------------------------------------------------------------------
# The native libbacktrace library with libcorkscrew.
#----------------------------------------------------------------------------
include $(CLEAR_VARS)

LOCAL_SRC_FILES:= \
	$(common_src) \
libbacktrace_src_files += \
	Corkscrew.cpp \

LOCAL_CFLAGS := \
	$(common_cflags) \

LOCAL_CONLYFLAGS += \
	$(common_conlyflags) \

LOCAL_CPPFLAGS += \
	$(common_cppflags) \

LOCAL_MODULE := libbacktrace
LOCAL_MODULE_TAGS := optional

LOCAL_C_INCLUDES := \
	$(common_c_includes) \
libbacktrace_c_includes := \
	system/core/libcorkscrew \

LOCAL_SHARED_LIBRARIES := \
	$(common_shared_libs) \
libbacktrace_shared_libraries := \
	libcorkscrew \
	libdl \

LOCAL_ADDITIONAL_DEPENDENCIES := \
	$(LOCAL_PATH)/Android.mk

include external/stlport/libstlport.mk
libbacktrace_shared_libraries_target += \
	libdl \

include $(BUILD_SHARED_LIBRARY)
libbacktrace_ldlibs_host := \
	-ldl \

endif

#----------------------------------------------------------------------------
# libbacktrace test library, all optimizations turned off
#----------------------------------------------------------------------------
include $(CLEAR_VARS)

LOCAL_MODULE := libbacktrace_test
LOCAL_MODULE_FLAGS := debug

LOCAL_SRC_FILES := \
	backtrace_testlib.c

LOCAL_CFLAGS += \
	-std=gnu99 \
module := libbacktrace
module_tag := optional
build_type := target
build_target := SHARED_LIBRARY
include $(LOCAL_PATH)/Android.build.mk
build_type := host
include $(LOCAL_PATH)/Android.build.mk

#-------------------------------------------------------------------------
# The libbacktrace_test library needed by backtrace_test.
#-------------------------------------------------------------------------
libbacktrace_test_cflags := \
	-O0 \

LOCAL_ADDITIONAL_DEPENDENCIES := \
	$(LOCAL_PATH)/Android.mk

include $(BUILD_SHARED_LIBRARY)

#----------------------------------------------------------------------------
# libbacktrace test executable
#----------------------------------------------------------------------------
include $(CLEAR_VARS)

LOCAL_MODULE := backtrace_test
LOCAL_MODULE_FLAGS := debug

LOCAL_SRC_FILES := \
	backtrace_test.cpp \
	thread_utils.c \

LOCAL_CFLAGS += \
	$(common_cflags) \
libbacktrace_test_src_files := \
	backtrace_testlib.c \

module := libbacktrace_test
module_tag := debug
build_type := target
build_target := SHARED_LIBRARY
include $(LOCAL_PATH)/Android.build.mk
build_type := host
include $(LOCAL_PATH)/Android.build.mk

#-------------------------------------------------------------------------
# The backtrace_test executable.
#-------------------------------------------------------------------------
backtrace_test_cflags := \
	-fno-builtin \
	-fstack-protector-all \
	-O0 \
	-g \
	-DGTEST_OS_LINUX_ANDROID \
	-DGTEST_HAS_STD_STRING \

ifeq ($(TARGET_ARCH),arm64)
ifneq ($(TARGET_ARCH),arm64)
backtrace_test_cflags += -fstack-protector-all
else
  $(info TODO: $(LOCAL_PATH)/Android.mk -fstack-protector not yet available for the AArch64 toolchain)
  LOCAL_CFLAGS += -fno-stack-protector
  common_cflags += -fno-stack-protector
endif # arm64

LOCAL_CONLYFLAGS += \
	$(common_conlyflags) \

LOCAL_CPPFLAGS += \
	$(common_cppflags) \
backtrace_test_cflags_target := \
	-DGTEST_OS_LINUX_ANDROID \

LOCAL_SHARED_LIBRARIES += \
	libcutils \
	libbacktrace_test \
	libbacktrace \
backtrace_test_src_files := \
	backtrace_test.cpp \
	thread_utils.c \

LOCAL_LDLIBS := \
backtrace_test_ldlibs := \
	-lpthread \

LOCAL_ADDITIONAL_DEPENDENCIES := \
	$(LOCAL_PATH)/Android.mk

include $(BUILD_NATIVE_TEST)

#----------------------------------------------------------------------------
# Only x86 host versions of libbacktrace supported.
#----------------------------------------------------------------------------
ifeq ($(HOST_ARCH),x86)

#----------------------------------------------------------------------------
# The host libbacktrace library using libcorkscrew
#----------------------------------------------------------------------------
include $(CLEAR_VARS)


LOCAL_CFLAGS += \
	$(common_cflags) \

LOCAL_CONLYFLAGS += \
	$(common_conlyflags) \

LOCAL_C_INCLUDES := \
	$(common_c_includes) \

LOCAL_SHARED_LIBRARIES := \
	libgccdemangle \
	liblog \

LOCAL_MODULE := libbacktrace
LOCAL_MODULE_TAGS := optional

LOCAL_ADDITIONAL_DEPENDENCIES := \
	$(LOCAL_PATH)/Android.mk

ifeq ($(HOST_OS),linux)
LOCAL_SRC_FILES += \
	$(common_src) \
	Corkscrew.cpp \

LOCAL_C_INCLUDES += \
	system/core/libcorkscrew \

LOCAL_SHARED_LIBRARIES := \
	libcorkscrew \

LOCAL_CPPFLAGS += \
	$(common_cppflags) \

LOCAL_LDLIBS += \
	-ldl \
backtrace_test_ldlibs_host := \
	-lrt \

else
LOCAL_SRC_FILES += \
	BacktraceMap.cpp \
backtrace_test_shared_libraries := \
	libbacktrace_test \
	libbacktrace \

endif
backtrace_test_shared_libraries_target := \
	libcutils \

include $(BUILD_HOST_SHARED_LIBRARY)
module := backtrace_test
module_tag := debug
build_type := target
build_target := NATIVE_TEST
include $(LOCAL_PATH)/Android.build.mk
build_type := host
include $(LOCAL_PATH)/Android.build.mk

#----------------------------------------------------------------------------
# The host test is only supported on linux.
# Special truncated libbacktrace library for mac.
#----------------------------------------------------------------------------
ifeq ($(HOST_OS),linux)
ifeq ($(HOST_OS),darwin)

#----------------------------------------------------------------------------
# libbacktrace host test library, all optimizations turned off
#----------------------------------------------------------------------------
include $(CLEAR_VARS)

LOCAL_MODULE := libbacktrace_test
LOCAL_MODULE_FLAGS := debug
LOCAL_MODULE := libbacktrace
LOCAL_MODULE_TAGS := optional

LOCAL_SRC_FILES := \
	backtrace_testlib.c

LOCAL_CFLAGS += \
	-std=gnu99 \
	-O0 \

LOCAL_ADDITIONAL_DEPENDENCIES := \
	$(LOCAL_PATH)/Android.mk
	BacktraceMap.cpp \

include $(BUILD_HOST_SHARED_LIBRARY)

#----------------------------------------------------------------------------
# libbacktrace host test executable
#----------------------------------------------------------------------------
include $(CLEAR_VARS)

LOCAL_MODULE := backtrace_test
LOCAL_MODULE_FLAGS := debug

LOCAL_SRC_FILES := \
	backtrace_test.cpp \
	thread_utils.c \

LOCAL_CFLAGS += \
	$(common_cflags) \
	-fno-builtin \
	-fstack-protector-all \
	-O0 \
	-g \
	-DGTEST_HAS_STD_STRING \

LOCAL_SHARED_LIBRARIES := \
	libbacktrace_test \
	libbacktrace \

LOCAL_LDLIBS := \
	-lpthread \

LOCAL_ADDITIONAL_DEPENDENCIES := \
	$(LOCAL_PATH)/Android.mk

include $(BUILD_HOST_NATIVE_TEST)

endif # HOST_OS == linux

endif # HOST_ARCH == x86
endif # HOST_OS-darwin