From patchwork Fri Oct 28 03:17:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Dufresne via libcamera-devel X-Patchwork-Id: 17720 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 D7372BD16B for ; Fri, 28 Oct 2022 03:17:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 81A9962FD1; Fri, 28 Oct 2022 05:17:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1666927064; bh=uYdZd5ooHVKC5fykrTFeNa3vGKYdFi9HN0ca8IDJYbQ=; 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=svD/T0/MvM/at9rbCP4ev0GSozrepvf/KnXfofjByZ/GbVZK3h28SXpGO1Sd/QzDH r1L2qU/eehhrnV9hrnr6FY0OaJ5etegZGhMm+Ljk4t/WU+/yh58835I/f1eu9pTamd MoKjPQNjuF93MZeWIvfhJ8TvUaCcVQgO+3+MLm/kLM6VvPduT87Lxx4uWvXUZ6fKJK t/ZY2HlGxEfWFJwjFl93nnZYap9+LeTZ10nLkobvrpjvgW189LicCSaT6+646sasmf DSOa3Q8N9+ALmtyNQGQcpxqkwYkMitG3mjjEFjpw1y9h2ex03xQLsCn2oAHjbmoJ77 +tewqw6SV8UEQ== Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 33FA962FC2 for ; Fri, 28 Oct 2022 05:17:37 +0200 (CEST) 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="A8G7lV+a"; dkim-atps=neutral Received: by mail-oi1-x22e.google.com with SMTP id u132so4980257oib.0 for ; Thu, 27 Oct 2022 20:17:37 -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:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=OrR17ZcndUu6E8+nQhvZfP/G7yO3m+iusFv1/hMho8o=; b=A8G7lV+a7Xy1zltZ9rZcH0zDeEiF1+Zhy3eEX/x8DxTKIJzdy/JywZhnk7Yptbp5Ik al6/tVQFfT6Hzu/0g6HuDrctlZ32pxvoSbmaTF+xSe17CAngYnkzmDZwG7Xb8oiAruoF 95jxYnjE2i9kF7dUb3PQI5MpgETuzGZxVWc4a/bEauK4ixH7iXl7yXIzRIMlPeEZ0mt+ g12ZJPNCeXVEgj+YDfCuHcar5ZOEYXrBsZMlIX5SfWb1st8D82fiaDhIHjauP7ZICaab mUGbCPE/VmMSF/fFU1uilDFbGR+KxINkZWkeO8tBbzmuWeEeNAXT8glqDPjQSofck3W1 C/RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:reply-to: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=OrR17ZcndUu6E8+nQhvZfP/G7yO3m+iusFv1/hMho8o=; b=kdBXD6fTA+1zZNtrOfZpHNkBpW41NIcEH28/pWN+72ZlaWtjsn07nRx0X30BO2z5RU 76Kkuna6y1M/zC+XoRi3GpzZleQRNC3Qi+ZHPZaTh6lyL1MHzVzj8Xt98kgzuSCweLAG A4/yB5yfhqToPXDTLblK8VdFqHw23E9+ZoKBnPRRUczppWSmqKMhjYOPh8/DlIaTO90T Ni1wf8bN9nU/+jZaB2q5BSeD5d5LeB282sJmPHSRZR+vK8lj05ctgdynr+SPez4Ibz7p 8YrwZuCAx5VDuozXTOoXiMSCd8lIom1gYLv+TPMF0MG/UlQIIq2xMC0N6uXyZML9enLr 2Y4Q== X-Gm-Message-State: ACrzQf1kK0zUz7Kzdr6WXGZnCQLZXNQV+nz8miHI5i07l/vs3y6FZEvz /yOePFbfMPbVyLm8UNRghBgSOWl0h3yCl3/2P6Q= X-Google-Smtp-Source: AMsMyM6NnQus5BGPnUvehcP9CigNJbonA4ws3JhbvmFJCOZRD86Pp3E0hxJBrZsGhgQ2ynRVB7D5FA== X-Received: by 2002:a05:6808:130c:b0:355:39af:eb4f with SMTP id y12-20020a056808130c00b0035539afeb4fmr7071526oiv.218.1666927055332; Thu, 27 Oct 2022 20:17:35 -0700 (PDT) Received: from nroth-pc.attlocal.net ([2600:1700:20:20c0:293a:90ce:6463:244d]) by smtp.gmail.com with ESMTPSA id fp19-20020a056870659300b0013626c1a5f6sm1527738oab.10.2022.10.27.20.17.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Oct 2022 20:17:34 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 27 Oct 2022 22:17:24 -0500 Message-Id: <20221028031726.4849-9-nicholas@rothemail.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221028031726.4849-1-nicholas@rothemail.net> References: <20221027224135.348115-1-nicholas@rothemail.net> <20221028031726.4849-1-nicholas@rothemail.net> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 08/10] 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: Nicolas Dufresne via libcamera-devel Reply-To: libcamera-devel@lists.libcamera.org Cc: nicholas@rothemail.net Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Nicholas Roth 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 $@