From patchwork Sun Oct 30 23:04:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Roth X-Patchwork-Id: 17733 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 38854C3286 for ; Sun, 30 Oct 2022 23:05:25 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 812986303A; Mon, 31 Oct 2022 00:05:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1667171124; bh=int3DXSER2y4bHLWI5tO7WBEjsT0vuKkbqaXKdVrHak=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=j1aLwhOlgyk6i757mIOrjr+zOOvmCGobOTNQ6ylB+jPLwTXpJo0VrdMjVLLlAizHl ewlj49djS2W1R3PqWYPODTH/LOue1k86ubEAfy1k+hznwfSzUgjHMg2qn67S9mQ8t+ N/hJQXLzcZ8YOWeflTkHAXG2h/rLQgurgtcMdzRsxnjFZb+XHODmBuL8KvfovX9oZZ LJOniymZkAHBZDqWerf/db1txoVFoUlCQTaVY2blpp7Qu8zKvOPK3UDFl+IxzahQGu 9Sd0E9yR9hGrpLpDyxV7rEdXgh1aGEu6wseM37vEA/ti2eZHnuIx2epZ3vqk9Y9Q6J m7y451TaeUH3A== Received: from mail-oa1-x36.google.com (mail-oa1-x36.google.com [IPv6:2001:4860:4864:20::36]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5644D63035 for ; Mon, 31 Oct 2022 00:05:20 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=rothemail-net.20210112.gappssmtp.com header.i=@rothemail-net.20210112.gappssmtp.com header.b="HI46O8l7"; dkim-atps=neutral Received: by mail-oa1-x36.google.com with SMTP id 586e51a60fabf-12c8312131fso11948308fac.4 for ; Sun, 30 Oct 2022 16:05:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rothemail-net.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2fgyLAxEoO+w9DXEdyO+8hcm3SYYAwIfeE6edp/CNpk=; b=HI46O8l7l/0htKz9IRxm4IEj9aDDD9Y2EwM8ZCaisvulYhYWVdhSiaMglmv2CKkneU /sqp4soXMtuYHoMOMhTidI33hCcvfrZmRVtWjQBja/6VxGBpHutGlnupH/1jjz4WNPav 8pURkxxMFYIvYhyO8wsIWVcdXUW4sWGHsQiCaBabMEjTBcyb4XTs24PM7evWhe9zI/C1 dC9XoCK53C8gKQWcFH+mXKXsFNR6FEDq9Eq+xlQE5Ck4Wloat+A7T2edSmo+Z2ucNUvE Pyw6LPxALTIoktfRPsCeKSu+bZEYAWi/uW1cFtqlu4+lRjW3fmD7jC2brXwG4VqBymvk Cj/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2fgyLAxEoO+w9DXEdyO+8hcm3SYYAwIfeE6edp/CNpk=; b=kNxit3gSq6nDS8+09bwWkz4mX+cWAF9j93crobVz/C0Rh533MyXgzaIYZhTsfWl/R6 fesvht4kvGXG5korjUN3C//f4MhsJDhdbdovoirIsIApvzuZCakK+JSU4jlA4l86HJhi mcBPvUhIgyYdX2ZwShDao4vSKElt9HLf9HhyrLZUWDEEVEAimxm6jahBEYOPL7JQhN2X UAxXUF2k5C+q3Bt6WNcGjxwFCADfDVHhb8j/gny5FhbYml8UAwAGnyKzQcOAdssXxXkV huy3VnJbQV95ygJPIuFz/MsZ12sA9NB82Z7EJvMHpJhFwqnSqBvw43aEEo00PwI/zIUG yorg== X-Gm-Message-State: ACrzQf2FuCcyJ2BGWO0r43z/3fD4VzsPGps+/rPoxHiNenrynqoOE4oi 6jV0rK3I8P+gF2h68wzgbtPc6zo8b54uww== X-Google-Smtp-Source: AMsMyM6JWpvBYHwdq3MKMUWPLWwZZHvrDVqTReeMx6PXpNtsJ5UhefzQsRW2wXeEE9rk2e+tUZjroA== X-Received: by 2002:a05:6870:89a3:b0:12b:45b6:80de with SMTP id f35-20020a05687089a300b0012b45b680demr6023550oaq.263.1667171118749; Sun, 30 Oct 2022 16:05:18 -0700 (PDT) Received: from nroth-pc.attlocal.net (104-5-61-214.lightspeed.austtx.sbcglobal.net. [104.5.61.214]) by smtp.gmail.com with ESMTPSA id u4-20020a056871008400b0013c8ae74a14sm2269403oaa.42.2022.10.30.16.05.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Oct 2022 16:05:18 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Sun, 30 Oct 2022 18:04:59 -0500 Message-Id: <20221030230500.74842-5-nicholas@rothemail.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221030230500.74842-1-nicholas@rothemail.net> References: <20221030230500.74842-1-nicholas@rothemail.net> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 4/5] android: add makefiles to build inline with AOSP X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Nicholas Roth via libcamera-devel From: Nicholas Roth Reply-To: Nicholas Roth Cc: Nicholas Roth Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Currently, while libcamera advertises Android support, there is no easy way to integrate libcamera into an Android distribution. This commit adds makefiles that allow libcamera to build inline with AOSP, with one example of how to do so documented in [0]. Note that meson_cross.mk is adapted from the Mesa project [1]. As Android support matures, it will be useful to document how to integrate libcamera for distribution owners [Bug]. [0] https://docs.google.com/document/d/1Sly_VH3w6wFIdE72WXijQegoHZh8IxEnJ9m0hH7GodU/edit [1] https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/android/mesa3d_cross.mk Bug https://bugs.libcamera.org/show_bug.cgi?id=164 Signed-off-by: Nichoals Roth --- android/Android.mk | 86 ++++++++++++ android/meson_cross.mk | 298 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 384 insertions(+) create mode 100644 android/Android.mk create mode 100644 android/meson_cross.mk diff --git a/android/Android.mk b/android/Android.mk new file mode 100644 index 00000000..ff0d1472 --- /dev/null +++ b/android/Android.mk @@ -0,0 +1,86 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# Copyright (C) 2021, GlobalLogic Ukraine +# Copyright (C) 2021, Roman Stratiienko (r.stratiienko@gmail.com) +# +# Android.mk - Android makefile +# + +ifneq ($(filter true, $(BOARD_LIBCAMERA_USES_MESON_BUILD)),) + +LOCAL_PATH := $(call my-dir) +LIBCAMERA_TOP := $(dir $(LOCAL_PATH)) +LIBCAMERA_MESON_VERSION := .0.0.1 + +include $(CLEAR_VARS) + +LOCAL_SHARED_LIBRARIES := libc libexif libjpeg libyuv_chromium libdl libyaml +MESON_GEN_PKGCONFIGS := libexif libjpeg yaml-0.1 libyuv dl + +ifeq ($(TARGET_IS_64_BIT),true) +LOCAL_MULTILIB := 64 +else +LOCAL_MULTILIB := 32 +endif +include $(LOCAL_PATH)/meson_cross.mk + +ifdef TARGET_2ND_ARCH +LOCAL_MULTILIB := 32 +include $(LOCAL_PATH)/meson_cross.mk +endif + +#------------------------------------------------------------------------------- + +define libcamera-lib +LOCAL_MODULE_CLASS := SHARED_LIBRARIES +LOCAL_MODULE := $1 +LOCAL_VENDOR_MODULE := true +LOCAL_MODULE_RELATIVE_PATH := $2 +ifdef TARGET_2ND_ARCH +LOCAL_SRC_FILES_$(TARGET_ARCH) := $(call relative_top_path,$(LOCAL_PATH))$($3) +LOCAL_SRC_FILES_$(TARGET_2ND_ARCH) := $(call relative_top_path,$(LOCAL_PATH))$(2ND_$3) +LOCAL_MULTILIB := both +else +LOCAL_SRC_FILES := $(call relative_top_path,$(LOCAL_PATH))$($3) +endif +LOCAL_CHECK_ELF_FILES := false +LOCAL_MODULE_SUFFIX := .so$(${4}) +include $(BUILD_PREBUILT) +include $(CLEAR_VARS) +endef + +__MY_SHARED_LIBRARIES := $(LOCAL_SHARED_LIBRARIES) +include $(CLEAR_VARS) +LOCAL_SHARED_LIBRARIES := $(__MY_SHARED_LIBRARIES) + +# Modules 'libcamera', produces '/vendor/lib{64}/libcamera.so' +$(eval $(call libcamera-lib,libcamera,,LIBCAMERA_BIN,LIBCAMERA_MESON_VERSION)) +# Modules 'libcamera-base', produces '/vendor/lib{64}/libcamera-base.so' +$(eval $(call libcamera-lib,libcamera-base,,LIBCAMERA_BASE_BIN,LIBCAMERA_MESON_VERSION)) +# Modules 'ipa_rkisp1', produces '/vendor/lib{64}/ipa_rkisp1.so' +$(eval $(call libcamera-lib,ipa_rkisp1,,LIBCAMERA_IPA_RKISP1_BIN,)) +# Modules 'ipa_rkisp1', produces '/vendor/lib{64}/ipa_rpi.so' +$(eval $(call libcamera-lib,ipa_rpi,,LIBCAMERA_IPA_RASPBERRYPI_BIN,)) +# Modules 'ipa_rkisp1', produces '/vendor/lib{64}/ipa_ipu3.so' +$(eval $(call libcamera-lib,ipa_ipu3,,LIBCAMERA_IPA_IPU3_BIN,)) +# Modules 'ipa_rkisp1', produces '/vendor/lib{64}/ipa_vimc.so' +$(eval $(call libcamera-lib,ipa_vimc,,LIBCAMERA_IPA_VIMC_BIN,)) + +# Modules 'camera.libcamera', produces '/vendor/lib{64}/hw/camera.libcamera.so' HAL +$(eval $(call libcamera-lib,camera.libcamera,hw,LIBCAMERA_HAL_BIN,)) + +LOCAL_SHARED_LIBRARIES += libcamera libcamera-base ipa_rkisp1 ipa_rpi ipa_ipu3 ipa_vimc +LOCAL_REQUIRED_MODULES := libcamera libcamera-base ipa_rkisp1 ipa_rpi ipa_ipu3 ipa_vimc + +$(shell mkdir -p $(TARGET_OUT_VENDOR_ETC)/rkisp1/) +$(shell mkdir -p $(TARGET_OUT_VENDOR_ETC)/rpi/) +$(shell mkdir -p $(TARGET_OUT_VENDOR_ETC)/ipu3/) +$(shell mkdir -p $(TARGET_OUT_VENDOR_ETC)/vimc/) +$(shell cp $(LIBCAMERA_IPA_RKISP1_CONFIGS)/* $(TARGET_OUT_VENDOR_ETC)/rkisp1/) +$(shell cp $(LIBCAMERA_IPA_RASPBERRYPI_CONFIGS)/* $(TARGET_OUT_VENDOR_ETC)/rpi/) +$(shell cp $(LIBCAMERA_IPA_IPU3_CONFIGS)/* $(TARGET_OUT_VENDOR_ETC)/ipu3/) +$(shell cp $(LIBCAMERA_IPA_VIMC_CONFIGS)/* $(TARGET_OUT_VENDOR_ETC)/vimc/) + +#------------------------------------------------------------------------------- + +endif diff --git a/android/meson_cross.mk b/android/meson_cross.mk new file mode 100644 index 00000000..7a222f9c --- /dev/null +++ b/android/meson_cross.mk @@ -0,0 +1,298 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# Copyright (C) 2021, GlobalLogic Ukraine +# Copyright (C) 2021, Roman Stratiienko (r.stratiienko@gmail.com) +# +# meson_cross.mk - Android makefile +# + +# Turn "dir1/dir2/dir3/dir4" into "../../../../" +define relative_top_path +$(eval __s:=) \ +$(foreach tmp,$(subst /,$(space),$1),$(eval __s:=$(__s)../)) \ +$(__s) +endef + +MY_PATH := $(call my-dir) + +AOSP_ABSOLUTE_PATH := $(realpath .) + +libcam_m_dummy_$(LOCAL_MULTILIB) := $(TARGET_OUT_INTERMEDIATES)/LIBCAM_DUMMY_$(LOCAL_MULTILIB)/dummy.c + +$(libcam_m_dummy_$(LOCAL_MULTILIB)): + mkdir -p $(dir $@) + touch $@ + +LOCAL_SRC_FILES := $(call relative_top_path,$(MY_PATH))$(libcam_m_dummy_$(LOCAL_MULTILIB)) +LOCAL_VENDOR_MODULE := true +LOCAL_MODULE := libcam.dummy.$(LOCAL_MULTILIB) + +# Prepare intermediate variables by AOSP make/core internals +include $(BUILD_SHARED_LIBRARY) + +LOCAL_PATH := $(MY_PATH) + +link_deps := \ + $(built_static_libraries) \ + $(built_shared_libraries) \ + $(built_whole_libraries) \ + $(strip $(all_objects)) \ + $(my_target_libatomic) \ + $(my_target_libcrt_builtins) \ + $(my_target_crtbegin_so_o) \ + $(my_target_crtend_so_o) + +# Build using intermediate variables provided by AOSP make/core internals +M_TARGET_PREFIX := $(my_2nd_arch_prefix) + +LIBCAMERA_LIB_DIR := lib$(subst 32,,$(LOCAL_MULTILIB)) + +MESON_OUT_DIR := $($(M_TARGET_PREFIX)TARGET_OUT_INTERMEDIATES)/MESON_LIBCAMERA +MESON_GEN_DIR := $(MESON_OUT_DIR)_GEN +MESON_GEN_FILES_TARGET := $(MESON_GEN_DIR)/.timestamp + +$(M_TARGET_PREFIX)LIBCAMERA_BIN := $(MESON_OUT_DIR)/install/usr/local/lib/libcamera.so +$(M_TARGET_PREFIX)LIBCAMERA_HAL_BIN := $(MESON_OUT_DIR)/install/usr/local/lib/libcamera-hal.so +$(M_TARGET_PREFIX)LIBCAMERA_BASE_BIN := $(MESON_OUT_DIR)/install/usr/local/lib/libcamera-base.so +$(M_TARGET_PREFIX)LIBCAMERA_IPA_RKISP1_BIN := $(MESON_OUT_DIR)/install/usr/local/lib/libcamera/ipa_rkisp1.so +$(M_TARGET_PREFIX)LIBCAMERA_IPA_RASPBERRYPI_BIN := $(MESON_OUT_DIR)/install/usr/local/lib/libcamera/ipa_rpi.so +$(M_TARGET_PREFIX)LIBCAMERA_IPA_IPU3_BIN := $(MESON_OUT_DIR)/install/usr/local/lib/libcamera/ipa_ipu3.so +$(M_TARGET_PREFIX)LIBCAMERA_IPA_VIMC_BIN := $(MESON_OUT_DIR)/install/usr/local/lib/libcamera/ipa_vimc.so +$(M_TARGET_PREFIX)LIBCAMERA_IPA_RKISP1_CONFIGS := $(MESON_OUT_DIR)/install/usr/local/share/libcamera/ipa/rkisp1 +$(M_TARGET_PREFIX)LIBCAMERA_IPA_RASPBERRYPI_CONFIGS := $(MESON_OUT_DIR)/install/usr/local/share/libcamera/ipa/raspberrypi +$(M_TARGET_PREFIX)LIBCAMERA_IPA_IPU3_CONFIGS := $(MESON_OUT_DIR)/install/usr/local/share/libcamera/ipa/ipu3 +$(M_TARGET_PREFIX)LIBCAMERA_IPA_VIMC_CONFIGS := $(MESON_OUT_DIR)/install/usr/local/share/libcamera/ipa/vimc + +LIBCAMERA_BINS := \ + $($(M_TARGET_PREFIX)LIBCAMERA_BIN) \ + $($(M_TARGET_PREFIX)LIBCAMERA_HAL_BIN) \ + $($(M_TARGET_PREFIX)LIBCAMERA_BASE_BIN) \ + $($(M_TARGET_PREFIX)LIBCAMERA_IPA_RKISP1_BIN) \ + $($(M_TARGET_PREFIX)LIBCAMERA_IPA_RASPBERRYPI_BIN) \ + $($(M_TARGET_PREFIX)LIBCAMERA_IPA_IPU3_BIN) \ + $($(M_TARGET_PREFIX)LIBCAMERA_IPA_VIMC_BIN) + +MESON_GEN_NINJA := \ + cd $(MESON_OUT_DIR) && PATH=/usr/bin:/usr/local/bin:$$PATH meson ./build \ + --cross-file $(AOSP_ABSOLUTE_PATH)/$(MESON_GEN_DIR)/aosp_cross \ + --buildtype=release \ + -Dandroid=enabled \ + -Dipas=$(subst $(space),$(comma),$(BOARD_LIBCAMERA_IPAS)) \ + -Dpipelines=$(subst $(space),$(comma),$(BOARD_LIBCAMERA_PIPELINES)) \ + -Dsysconfdir=/vendor/etc \ + -Dtest=false \ + -Dwerror=false \ + -Dallow_unsigned_ipas_in_process=true + +MESON_BUILD := PATH=/usr/bin:/bin:/sbin:$$PATH ninja -C $(MESON_OUT_DIR)/build + +$(MESON_GEN_FILES_TARGET): MESON_CPU_FAMILY := $(subst arm64,aarch64,$(TARGET_$(M_TARGET_PREFIX)ARCH)) + +define create-pkgconfig +echo -e "Name: $2" \ + "\nDescription: $2" \ + "\nVersion: $3" > $1/$2.pc + +endef + +# Taken from build/make/core/binary.mk. We need this +# to use definitions from build/make/core/definitions.mk +$(MESON_GEN_FILES_TARGET): PRIVATE_GLOBAL_C_INCLUDES := $(my_target_global_c_includes) +$(MESON_GEN_FILES_TARGET): PRIVATE_GLOBAL_C_SYSTEM_INCLUDES := $(my_target_global_c_system_includes) + +$(MESON_GEN_FILES_TARGET): PRIVATE_TARGET_GLOBAL_CFLAGS := $(my_target_global_cflags) +$(MESON_GEN_FILES_TARGET): PRIVATE_TARGET_GLOBAL_CONLYFLAGS := $(my_target_global_conlyflags) +$(MESON_GEN_FILES_TARGET): PRIVATE_TARGET_GLOBAL_CPPFLAGS := $(my_target_global_cppflags) + +$(MESON_GEN_FILES_TARGET): PRIVATE_2ND_ARCH_VAR_PREFIX := $(M_TARGET_PREFIX) +$(MESON_GEN_FILES_TARGET): PRIVATE_CC := $(my_cc) +$(MESON_GEN_FILES_TARGET): PRIVATE_LINKER := $(my_linker) +$(MESON_GEN_FILES_TARGET): PRIVATE_CXX := $(my_cxx) +$(MESON_GEN_FILES_TARGET): PRIVATE_CXX_LINK := $(my_cxx_link) +$(MESON_GEN_FILES_TARGET): PRIVATE_YACCFLAGS := $(LOCAL_YACCFLAGS) +$(MESON_GEN_FILES_TARGET): PRIVATE_ASFLAGS := $(my_asflags) +$(MESON_GEN_FILES_TARGET): PRIVATE_CONLYFLAGS := $(my_conlyflags) +$(MESON_GEN_FILES_TARGET): PRIVATE_CFLAGS := $(my_cflags) +$(MESON_GEN_FILES_TARGET): PRIVATE_CPPFLAGS := $(my_cppflags) +$(MESON_GEN_FILES_TARGET): PRIVATE_CFLAGS_NO_OVERRIDE := $(my_cflags_no_override) +$(MESON_GEN_FILES_TARGET): PRIVATE_CPPFLAGS_NO_OVERRIDE := $(my_cppflags_no_override) +$(MESON_GEN_FILES_TARGET): PRIVATE_RTTI_FLAG := $(LOCAL_RTTI_FLAG) +$(MESON_GEN_FILES_TARGET): PRIVATE_DEBUG_CFLAGS := $(debug_cflags) +$(MESON_GEN_FILES_TARGET): PRIVATE_C_INCLUDES := $(my_c_includes) +$(MESON_GEN_FILES_TARGET): PRIVATE_IMPORTED_INCLUDES := $(imported_includes) +$(MESON_GEN_FILES_TARGET): PRIVATE_LDFLAGS := $(my_ldflags) +$(MESON_GEN_FILES_TARGET): PRIVATE_LDLIBS := $(my_ldlibs) +$(MESON_GEN_FILES_TARGET): PRIVATE_TARGET_GLOBAL_LDFLAGS := $(my_target_global_ldflags) +$(MESON_GEN_FILES_TARGET): PRIVATE_TIDY_CHECKS := $(my_tidy_checks) +$(MESON_GEN_FILES_TARGET): PRIVATE_TIDY_FLAGS := $(my_tidy_flags) +$(MESON_GEN_FILES_TARGET): PRIVATE_ARFLAGS := $(my_arflags) +$(MESON_GEN_FILES_TARGET): PRIVATE_ALL_SHARED_LIBRARIES := $(built_shared_libraries) +$(MESON_GEN_FILES_TARGET): PRIVATE_ALL_STATIC_LIBRARIES := $(built_static_libraries) +$(MESON_GEN_FILES_TARGET): PRIVATE_ALL_WHOLE_STATIC_LIBRARIES := $(built_whole_libraries) +$(MESON_GEN_FILES_TARGET): PRIVATE_ALL_OBJECTS := $(strip $(all_objects)) + +$(MESON_GEN_FILES_TARGET): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) + +$(MESON_GEN_FILES_TARGET): PRIVATE_TARGET_LIBCRT_BUILTINS := $(my_target_libcrt_builtins) +$(MESON_GEN_FILES_TARGET): PRIVATE_TARGET_LIBATOMIC := $(my_target_libatomic) +$(MESON_GEN_FILES_TARGET): PRIVATE_TARGET_CRTBEGIN_SO_O := $(my_target_crtbegin_so_o) +$(MESON_GEN_FILES_TARGET): PRIVATE_TARGET_CRTEND_SO_O := $(my_target_crtend_so_o) +## + +define m-lld-flags + -nostdlib -Wl,--gc-sections \ + $(PRIVATE_TARGET_CRTBEGIN_SO_O) \ + $(PRIVATE_ALL_OBJECTS) \ + -Wl,--whole-archive \ + $(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES) \ + -Wl,--no-whole-archive \ + $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \ + $(PRIVATE_ALL_STATIC_LIBRARIES) \ + $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \ + $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_COVERAGE_LIB)) \ + $(PRIVATE_TARGET_LIBCRT_BUILTINS) \ + $(PRIVATE_TARGET_LIBATOMIC) \ + $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \ + $(PRIVATE_LDFLAGS) \ + $(PRIVATE_ALL_SHARED_LIBRARIES) \ + $(PRIVATE_TARGET_CRTEND_SO_O) \ + $(PRIVATE_LDLIBS) +endef + +define m-lld-flags-cleaned + $(subst prebuilts/,$(AOSP_ABSOLUTE_PATH)/prebuilts/, \ + $(subst out/,$(AOSP_ABSOLUTE_PATH)/out/, \ + $(subst -Wl$(comma)--fatal-warnings,, \ + $(subst -Wl$(comma)--no-undefined-version,, \ + $(subst -Wl$(comma)--gc-sections,, \ + $(patsubst %dummy.o,, \ + $(m-lld-flags))))))) +endef + +define m-cpp-flags + $(PRIVATE_TARGET_GLOBAL_CFLAGS) \ + $(PRIVATE_TARGET_GLOBAL_CPPFLAGS) \ + $(PRIVATE_ARM_CFLAGS) \ + $(PRIVATE_RTTI_FLAG) \ + $(PRIVATE_CFLAGS) \ + $(PRIVATE_CPPFLAGS) \ + $(PRIVATE_DEBUG_CFLAGS) \ + $(PRIVATE_CFLAGS_NO_OVERRIDE) \ + $(PRIVATE_CPPFLAGS_NO_OVERRIDE) +endef + +define m-c-flags + $(PRIVATE_TARGET_GLOBAL_CFLAGS) \ + $(PRIVATE_TARGET_GLOBAL_CONLYFLAGS) \ + $(PRIVATE_ARM_CFLAGS) \ + $(PRIVATE_CFLAGS) \ + $(PRIVATE_CONLYFLAGS) \ + $(PRIVATE_DEBUG_CFLAGS) \ + $(PRIVATE_CFLAGS_NO_OVERRIDE) +endef + +define filter-c-flags + $(subst -std=gnu++17,, \ + $(subst -stdlib=libc++,, \ + $(subst -fno-rtti,, \ + $(patsubst -W%,, \ + $1)))) +endef + +define m-c-includes-common +$(addprefix -I , $(PRIVATE_C_INCLUDES)) \ +$(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),,\ + $(addprefix -I ,\ + $(filter-out $(PRIVATE_C_INCLUDES), \ + $(PRIVATE_GLOBAL_C_INCLUDES))) \ + $(addprefix -isystem ,\ + $(filter-out $(PRIVATE_C_INCLUDES), \ + $(PRIVATE_GLOBAL_C_SYSTEM_INCLUDES)))) +endef + +ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 30; echo $$?), 0) +# Android 11+ +define m-c-includes +$(foreach i,$(PRIVATE_IMPORTED_INCLUDES),$(EXPORTS.$(i)))\ +$(m-c-includes-common) +endef +define postprocess-includes +endef +else +# Android 10,9 +$(MESON_GEN_FILES_TARGET): PRIVATE_IMPORT_INCLUDES := $(import_includes) +define postprocess-includes + echo " $$(cat $(PRIVATE_IMPORT_INCLUDES)) " > $(MESON_GEN_DIR)/import_includes && \ + sed -i -e ':a;N;$$!ba;s/\n/ /g' \ + -e 's# \{2,\}# #g' \ + -e 's# -isystem # -isystem#g' \ + -e 's# -I # -I#g' \ + -e 's# -I# -I$(AOSP_ABSOLUTE_PATH)/#g' \ + -e 's# -isystem# -isystem$(AOSP_ABSOLUTE_PATH)/#g' \ + -e "s# #','#g" $(MESON_GEN_DIR)/import_includes && \ + sed -i "s#<_IMPORT_INCLUDES>#$$(cat $(MESON_GEN_DIR)/import_includes)#g" $(MESON_GEN_DIR)/aosp_cross +endef +define m-c-includes +<_IMPORT_INCLUDES> $(m-c-includes-common) +endef +endif + +define m-c-abs-includes + $(subst $(space)-isystem,$(space)-isystem$(AOSP_ABSOLUTE_PATH)/, \ + $(subst $(space)-I, -I$(AOSP_ABSOLUTE_PATH)/, \ + $(subst $(space)-I$(space),$(space)-I, \ + $(subst $(space)-isystem$(space),$(space)-isystem, \ + $(strip $(m-c-includes)))))) +endef + +$(MESON_GEN_FILES_TARGET): MESON_GEN_PKGCONFIGS:=$(MESON_GEN_PKGCONFIGS) +$(MESON_GEN_FILES_TARGET): MESON_GEN_DIR:=$(MESON_GEN_DIR) +$(MESON_GEN_FILES_TARGET): $(sort $(shell find -L $(LIBCAMERA_TOP) -not -path '*/\.*')) + mkdir -p $(dir $@) + echo -e "[properties]\n" \ + "c_args = [$(foreach flag, $(call filter-c-flags,$(m-c-flags) $(m-c-abs-includes)),'$(flag)', )'']\n" \ + "cpp_args = [$(foreach flag, $(call filter-c-flags,$(m-cpp-flags) $(m-c-abs-includes)),'$(flag)', )'']\n" \ + "c_link_args = [$(foreach flag, $(m-lld-flags-cleaned),'$(flag)',)'']\n" \ + "cpp_link_args = [$(foreach flag, $(m-lld-flags-cleaned),'$(flag)',)'']\n" \ + "needs_exe_wrapper = true\n" \ + "[binaries]\n" \ + "ar = '$(AOSP_ABSOLUTE_PATH)/$($($(M_TARGET_PREFIX))TARGET_AR)'\n" \ + "c = [$(foreach arg,$(PRIVATE_CC),'$(subst prebuilts/,$(AOSP_ABSOLUTE_PATH)/prebuilts/,$(arg))',)'']\n" \ + "cpp = [$(foreach arg,$(PRIVATE_CXX),'$(subst prebuilts/,$(AOSP_ABSOLUTE_PATH)/prebuilts/,$(arg))',)'']\n" \ + "c_ld = 'lld'\n" \ + "cpp_ld = 'lld'\n\n" \ + "pkgconfig = ['env', 'PKG_CONFIG_LIBDIR=' + '$(AOSP_ABSOLUTE_PATH)/$(MESON_GEN_DIR)', '/usr/bin/pkg-config']\n\n" \ + "llvm-config = '/dev/null'\n" \ + "[host_machine]\n" \ + "system = 'linux'\n" \ + "cpu_family = '$(MESON_CPU_FAMILY)'\n" \ + "cpu = '$(MESON_CPU_FAMILY)'\n" \ + "endian = 'little'" > $(dir $@)/aosp_cross + + # + $(foreach pkg, $(MESON_GEN_PKGCONFIGS), $(call create-pkgconfig,$(dir $@),$(word 1, $(subst :, ,$(pkg))),$(word 2, $(subst :, ,$(pkg))))) + touch $@ + +$(MESON_OUT_DIR)/.build.timestamp: MESON_GEN_NINJA:=$(MESON_GEN_NINJA) +$(MESON_OUT_DIR)/.build.timestamp: MESON_BUILD:=$(MESON_BUILD) +$(MESON_OUT_DIR)/.build.timestamp: $(MESON_GEN_FILES_TARGET) $(link_deps) + rm -rf $(dir $@) + mkdir -p $(dir $@) + mkdir -p $(dir $@)/build + # Meson will update timestamps in sources directory, continuously retriggering the build + # even if nothing changed. Copy sources into intermediate dir to avoid this effect. + cp -r $(LIBCAMERA_TOP)/* $(dir $@) + $(MESON_GEN_NINJA) + $(MESON_BUILD) + touch $@ + +$(MESON_OUT_DIR)/install/.install.timestamp: MESON_BUILD:=$(MESON_BUILD) +$(MESON_OUT_DIR)/install/.install.timestamp: $(MESON_OUT_DIR)/.build.timestamp + rm -rf $(dir $@) + mkdir -p $(dir $@) + DESTDIR=$(AOSP_ABSOLUTE_PATH)/$(dir $@) $(MESON_BUILD) install + touch $@ + +$(LIBCAMERA_BINS): $(MESON_OUT_DIR)/install/.install.timestamp + echo "Build $@" + touch $@