[libcamera-devel,09/11] Adds Android makefiles to build libcamera inline with AOSP.
diff mbox series

Message ID 20221024055543.116040-10-nicholas@rothemail.net
State Superseded
Headers show
Series
  • [libcamera-devel,01/11] Fixes Bug 156, which breaks libcamera on Android < 12.
Related show

Commit Message

Nicolas Dufresne via libcamera-devel Oct. 24, 2022, 5:55 a.m. UTC
From: Nicholas Roth <nicholas@rothemail.net>

---
 android/Android.mk     |  86 ++++++++++++
 android/meson_cross.mk | 296 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 382 insertions(+)
 create mode 100644 android/Android.mk
 create mode 100644 android/meson_cross.mk

Comments

Laurent Pinchart Oct. 25, 2022, 12:07 a.m. UTC | #1
Hi Nicholas,

Thank you for the patch.

On Mon, Oct 24, 2022 at 12:55:41AM -0500, Nicholas Roth via libcamera-devel wrote:
> From: Nicholas Roth <nicholas@rothemail.net>

The two files list third party copyrights, could you please indicate in
the commit message where that comes from ? A link to a git tree with the
code you started from would be good.

> ---
>  android/Android.mk     |  86 ++++++++++++
>  android/meson_cross.mk | 296 +++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 382 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)),)

I assume this variable, as well as BOARD_LIBCAMERA_IPAS and
BOARD_LIBCAMERA_PIPELINES, need to be defined externally. It would be
nice to add some Android build documentation to the Documentation/
directory.

> +
> +LOCAL_PATH := $(call my-dir)
> +LIBCAMERA_TOP := $(dir $(LOCAL_PATH))
> +LIBCAMERA_MESON_VERSION := .0.0.1

Is this something that can be provided by meson, to avoid hardcoding
version numbers in multiple places ? Or can the utils/gen-version.sh
script help ?

> +
> +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,))

It would also be nice to avoid hardcoding the list of IPA modules (and
other files below), but I suppose that would be difficult ? Or could
'meson install' be used to install the files to a directory that would
then be picked by the Android build system ?

> +# 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..bb1661cd
> --- /dev/null
> +++ b/android/meson_cross.mk
> @@ -0,0 +1,296 @@
> +# 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                                                             \
> +	-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 -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 $@
Nicholas Roth Oct. 26, 2022, 2:22 a.m. UTC | #2
> The two files list third party copyrights, could you please indicate in
> the commit message where that comes from ? A link to a git tree with the
> code you started from would be good.
Happy to:
https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/android/mesa3d_cross.mk.
I'll make sure to include this in the commit message.

> I assume this variable, as well as BOARD_LIBCAMERA_IPAS and
> BOARD_LIBCAMERA_PIPELINES, need to be defined externally. It would be
> nice to add some Android build documentation to the Documentation/
> directory.
As this review is already quite large, I've created Bug 164 to track this.
For now, would it be possible to link to my doc that covers this
https://docs.google.com/document/d/1Sly_VH3w6wFIdE72WXijQegoHZh8IxEnJ9m0hH7GodU/edit
and reference Bug 164 in the commit message?

>> +LOCAL_PATH := $(call my-dir)
>> +LIBCAMERA_TOP := $(dir $(LOCAL_PATH))
>> +LIBCAMERA_MESON_VERSION := .0.0.1
> Is this something that can be provided by meson, to avoid hardcoding
> version numbers in multiple places ? Or can the utils/gen-version.sh
> script help ?
I will investigate whether utils/gen-version.sh can help. I believe running
shell scripts is deprecated, but my copy commands at the bottom of
Android.mk do the trick, so it _might_ work, at least for now.

> It would also be nice to avoid hardcoding the list of IPA modules (and
> other files below), but I suppose that would be difficult ? Or could
> 'meson install' be used to install the files to a directory that would
> then be picked by the Android build system ?
We already "meson install" the files to a known location. Those files have
to be explicitly accessed, though, because Android needs to transform the
.so files after they are built with Makefile targets. This is also why
signature verification fundamentally does not work on Android.

Thanks for your thoughtful responses.

-Nicholas

On Mon, Oct 24, 2022 at 7:08 PM Laurent Pinchart <
laurent.pinchart@ideasonboard.com> wrote:

> Hi Nicholas,
>
> Thank you for the patch.
>
> On Mon, Oct 24, 2022 at 12:55:41AM -0500, Nicholas Roth via
> libcamera-devel wrote:
> > From: Nicholas Roth <nicholas@rothemail.net>
>
> The two files list third party copyrights, could you please indicate in
> the commit message where that comes from ? A link to a git tree with the
> code you started from would be good.
>
> > ---
> >  android/Android.mk     |  86 ++++++++++++
> >  android/meson_cross.mk | 296 +++++++++++++++++++++++++++++++++++++++++
> >  2 files changed, 382 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)),)
>
> I assume this variable, as well as BOARD_LIBCAMERA_IPAS and
> BOARD_LIBCAMERA_PIPELINES, need to be defined externally. It would be
> nice to add some Android build documentation to the Documentation/
> directory.
>
> > +
> > +LOCAL_PATH := $(call my-dir)
> > +LIBCAMERA_TOP := $(dir $(LOCAL_PATH))
> > +LIBCAMERA_MESON_VERSION := .0.0.1
>
> Is this something that can be provided by meson, to avoid hardcoding
> version numbers in multiple places ? Or can the utils/gen-version.sh
> script help ?
>
> > +
> > +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,))
>
> It would also be nice to avoid hardcoding the list of IPA modules (and
> other files below), but I suppose that would be difficult ? Or could
> 'meson install' be used to install the files to a directory that would
> then be picked by the Android build system ?
>
> > +# 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..bb1661cd
> > --- /dev/null
> > +++ b/android/meson_cross.mk
> > @@ -0,0 +1,296 @@
> > +# 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
>        \
> > +     -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 -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 $@
>
> --
> Regards,
>
> Laurent Pinchart
>
Nicholas Roth Oct. 26, 2022, 3:05 a.m. UTC | #3
+Kieran Bingham <kieran.bingham@ideasonboard.com> since Laurent is out.


On Tue, Oct 25, 2022 at 9:22 PM Nicholas Roth <nicholas@rothemail.net>
wrote:

> > The two files list third party copyrights, could you please indicate in
> > the commit message where that comes from ? A link to a git tree with the
> > code you started from would be good.
> Happy to:
> https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/android/mesa3d_cross.mk.
> I'll make sure to include this in the commit message.
>
> > I assume this variable, as well as BOARD_LIBCAMERA_IPAS and
> > BOARD_LIBCAMERA_PIPELINES, need to be defined externally. It would be
> > nice to add some Android build documentation to the Documentation/
> > directory.
> As this review is already quite large, I've created Bug 164 to track this.
> For now, would it be possible to link to my doc that covers this
> https://docs.google.com/document/d/1Sly_VH3w6wFIdE72WXijQegoHZh8IxEnJ9m0hH7GodU/edit
> and reference Bug 164 in the commit message?
>
> >> +LOCAL_PATH := $(call my-dir)
> >> +LIBCAMERA_TOP := $(dir $(LOCAL_PATH))
> >> +LIBCAMERA_MESON_VERSION := .0.0.1
> > Is this something that can be provided by meson, to avoid hardcoding
> > version numbers in multiple places ? Or can the utils/gen-version.sh
> > script help ?
> I will investigate whether utils/gen-version.sh can help. I believe
> running shell scripts is deprecated, but my copy commands at the bottom of
> Android.mk do the trick, so it _might_ work, at least for now.
>
> > It would also be nice to avoid hardcoding the list of IPA modules (and
> > other files below), but I suppose that would be difficult ? Or could
> > 'meson install' be used to install the files to a directory that would
> > then be picked by the Android build system ?
> We already "meson install" the files to a known location. Those files have
> to be explicitly accessed, though, because Android needs to transform the
> .so files after they are built with Makefile targets. This is also why
> signature verification fundamentally does not work on Android.
>
> Thanks for your thoughtful responses.
>
> -Nicholas
>
> On Mon, Oct 24, 2022 at 7:08 PM Laurent Pinchart <
> laurent.pinchart@ideasonboard.com> wrote:
>
>> Hi Nicholas,
>>
>> Thank you for the patch.
>>
>> On Mon, Oct 24, 2022 at 12:55:41AM -0500, Nicholas Roth via
>> libcamera-devel wrote:
>> > From: Nicholas Roth <nicholas@rothemail.net>
>>
>> The two files list third party copyrights, could you please indicate in
>> the commit message where that comes from ? A link to a git tree with the
>> code you started from would be good.
>>
>> > ---
>> >  android/Android.mk     |  86 ++++++++++++
>> >  android/meson_cross.mk | 296 +++++++++++++++++++++++++++++++++++++++++
>> >  2 files changed, 382 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)),)
>>
>> I assume this variable, as well as BOARD_LIBCAMERA_IPAS and
>> BOARD_LIBCAMERA_PIPELINES, need to be defined externally. It would be
>> nice to add some Android build documentation to the Documentation/
>> directory.
>>
>> > +
>> > +LOCAL_PATH := $(call my-dir)
>> > +LIBCAMERA_TOP := $(dir $(LOCAL_PATH))
>> > +LIBCAMERA_MESON_VERSION := .0.0.1
>>
>> Is this something that can be provided by meson, to avoid hardcoding
>> version numbers in multiple places ? Or can the utils/gen-version.sh
>> script help ?
>>
>> > +
>> > +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,))
>>
>> It would also be nice to avoid hardcoding the list of IPA modules (and
>> other files below), but I suppose that would be difficult ? Or could
>> 'meson install' be used to install the files to a directory that would
>> then be picked by the Android build system ?
>>
>> > +# 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..bb1661cd
>> > --- /dev/null
>> > +++ b/android/meson_cross.mk
>> > @@ -0,0 +1,296 @@
>> > +# 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
>>        \
>> > +     -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 -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 $@
>>
>> --
>> Regards,
>>
>> Laurent Pinchart
>>
>
Kieran Bingham Oct. 26, 2022, 9:16 a.m. UTC | #4
Quoting Nicholas Roth (2022-10-26 04:05:38)
> +Kieran Bingham <kieran.bingham@ideasonboard.com> since Laurent is out.
> 
> 
> On Tue, Oct 25, 2022 at 9:22 PM Nicholas Roth <nicholas@rothemail.net>
> wrote:
> 
> > > The two files list third party copyrights, could you please indicate in
> > > the commit message where that comes from ? A link to a git tree with the
> > > code you started from would be good.
> > Happy to:
> > https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/android/mesa3d_cross.mk.
> > I'll make sure to include this in the commit message.
> >
> > > I assume this variable, as well as BOARD_LIBCAMERA_IPAS and
> > > BOARD_LIBCAMERA_PIPELINES, need to be defined externally. It would be
> > > nice to add some Android build documentation to the Documentation/
> > > directory.
> > As this review is already quite large, I've created Bug 164 to track this.
> > For now, would it be possible to link to my doc that covers this
> > https://docs.google.com/document/d/1Sly_VH3w6wFIdE72WXijQegoHZh8IxEnJ9m0hH7GodU/edit
> > and reference Bug 164 in the commit message?

I think that's OK for the short term, but we won't be likely to review
the document or process until it's posted to the list.

(Perhaps you don't want it reviewed yet, so that's not a problem).

> > >> +LOCAL_PATH := $(call my-dir)
> > >> +LIBCAMERA_TOP := $(dir $(LOCAL_PATH))
> > >> +LIBCAMERA_MESON_VERSION := .0.0.1
> > > Is this something that can be provided by meson, to avoid hardcoding
> > > version numbers in multiple places ? Or can the utils/gen-version.sh
> > > script help ?
> > I will investigate whether utils/gen-version.sh can help. I believe
> > running shell scripts is deprecated, but my copy commands at the bottom of
> > Android.mk do the trick, so it _might_ work, at least for now.
> >
> > > It would also be nice to avoid hardcoding the list of IPA modules (and
> > > other files below), but I suppose that would be difficult ? Or could
> > > 'meson install' be used to install the files to a directory that would
> > > then be picked by the Android build system ?
> > We already "meson install" the files to a known location. Those files have
> > to be explicitly accessed, though, because Android needs to transform the
> > .so files after they are built with Makefile targets. This is also why
> > signature verification fundamentally does not work on Android.

Can the signatures be resigned at a final stage after they are stripped?

> >
> > Thanks for your thoughtful responses.
> >
> > -Nicholas
> >
> > On Mon, Oct 24, 2022 at 7:08 PM Laurent Pinchart <
> > laurent.pinchart@ideasonboard.com> wrote:
> >
> >> Hi Nicholas,
> >>
> >> Thank you for the patch.
> >>
> >> On Mon, Oct 24, 2022 at 12:55:41AM -0500, Nicholas Roth via
> >> libcamera-devel wrote:
> >> > From: Nicholas Roth <nicholas@rothemail.net>
> >>
> >> The two files list third party copyrights, could you please indicate in
> >> the commit message where that comes from ? A link to a git tree with the
> >> code you started from would be good.
> >>
> >> > ---
> >> >  android/Android.mk     |  86 ++++++++++++
> >> >  android/meson_cross.mk | 296 +++++++++++++++++++++++++++++++++++++++++
> >> >  2 files changed, 382 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)),)
> >>
> >> I assume this variable, as well as BOARD_LIBCAMERA_IPAS and
> >> BOARD_LIBCAMERA_PIPELINES, need to be defined externally. It would be
> >> nice to add some Android build documentation to the Documentation/
> >> directory.
> >>
> >> > +
> >> > +LOCAL_PATH := $(call my-dir)
> >> > +LIBCAMERA_TOP := $(dir $(LOCAL_PATH))
> >> > +LIBCAMERA_MESON_VERSION := .0.0.1
> >>
> >> Is this something that can be provided by meson, to avoid hardcoding
> >> version numbers in multiple places ? Or can the utils/gen-version.sh
> >> script help ?
> >>
> >> > +
> >> > +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,))
> >>
> >> It would also be nice to avoid hardcoding the list of IPA modules (and
> >> other files below), but I suppose that would be difficult ? Or could
> >> 'meson install' be used to install the files to a directory that would
> >> then be picked by the Android build system ?
> >>
> >> > +# 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..bb1661cd
> >> > --- /dev/null
> >> > +++ b/android/meson_cross.mk
> >> > @@ -0,0 +1,296 @@
> >> > +# 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 "../../../../"

I'm not yet sure where / why this is used - but does "realpath
--relative-to" make sense here?

(Not a requierment, just a curiosity).

--
Kieran


> >> > +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
> >>        \
> >> > +     -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 -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 $@
> >>
> >> --
> >> Regards,
> >>
> >> Laurent Pinchart
> >>
> >
Nicholas Roth Oct. 26, 2022, 3:29 p.m. UTC | #5
> (Perhaps you don't want it reviewed yet, so that's not a problem).
That's exactly correct!

>Can the signatures be resigned at a final stage after they are stripped?
That happens deep in the bowels of Android's build system. There is no
documented way to do this, but it may be theoretically possible, especially
if distribution maintainers are willing to fork or patch the Android build
system itself. I can imagine this might create a high maintenance burden
though. The high-level API people are supposed to use is:

include $(CLEAR_VARS)
LOCAL_MODULE := foo-prebuilt
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libfoo.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_SHARED_LIBRARY)

from https://developer.android.com/ndk/guides/prebuilts.

PREBUILT_SHARED_LIBRARY, or BUILD_PREBUILT as we use in our makefile, is
what does the transformations. Maybe there's a clean way to influence its
behavior and I'm just not familiar enough with the Android make-based build
system to know what it is, although my intuition is that this would be
unlikely and perhaps considered undesirable by the Android engprod team.

> I'm not yet sure where / why this is used - but does "realpath
> --relative-to" make sense here?
This provides a relative path to the build directory IIRC (heading out to a
meeting right now).

-Nicholas


On Wed, Oct 26, 2022 at 4:16 AM Kieran Bingham <
kieran.bingham@ideasonboard.com> wrote:

> Quoting Nicholas Roth (2022-10-26 04:05:38)
> > +Kieran Bingham <kieran.bingham@ideasonboard.com> since Laurent is out.
> >
> >
> > On Tue, Oct 25, 2022 at 9:22 PM Nicholas Roth <nicholas@rothemail.net>
> > wrote:
> >
> > > > The two files list third party copyrights, could you please indicate
> in
> > > > the commit message where that comes from ? A link to a git tree with
> the
> > > > code you started from would be good.
> > > Happy to:
> > >
> https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/android/mesa3d_cross.mk
> .
> > > I'll make sure to include this in the commit message.
> > >
> > > > I assume this variable, as well as BOARD_LIBCAMERA_IPAS and
> > > > BOARD_LIBCAMERA_PIPELINES, need to be defined externally. It would be
> > > > nice to add some Android build documentation to the Documentation/
> > > > directory.
> > > As this review is already quite large, I've created Bug 164 to track
> this.
> > > For now, would it be possible to link to my doc that covers this
> > >
> https://docs.google.com/document/d/1Sly_VH3w6wFIdE72WXijQegoHZh8IxEnJ9m0hH7GodU/edit
> > > and reference Bug 164 in the commit message?
>
> I think that's OK for the short term, but we won't be likely to review
> the document or process until it's posted to the list.
>
> (Perhaps you don't want it reviewed yet, so that's not a problem).
>
> > > >> +LOCAL_PATH := $(call my-dir)
> > > >> +LIBCAMERA_TOP := $(dir $(LOCAL_PATH))
> > > >> +LIBCAMERA_MESON_VERSION := .0.0.1
> > > > Is this something that can be provided by meson, to avoid hardcoding
> > > > version numbers in multiple places ? Or can the utils/gen-version.sh
> > > > script help ?
> > > I will investigate whether utils/gen-version.sh can help. I believe
> > > running shell scripts is deprecated, but my copy commands at the
> bottom of
> > > Android.mk do the trick, so it _might_ work, at least for now.
> > >
> > > > It would also be nice to avoid hardcoding the list of IPA modules
> (and
> > > > other files below), but I suppose that would be difficult ? Or could
> > > > 'meson install' be used to install the files to a directory that
> would
> > > > then be picked by the Android build system ?
> > > We already "meson install" the files to a known location. Those files
> have
> > > to be explicitly accessed, though, because Android needs to transform
> the
> > > .so files after they are built with Makefile targets. This is also why
> > > signature verification fundamentally does not work on Android.
>
> Can the signatures be resigned at a final stage after they are stripped?
>
> > >
> > > Thanks for your thoughtful responses.
> > >
> > > -Nicholas
> > >
> > > On Mon, Oct 24, 2022 at 7:08 PM Laurent Pinchart <
> > > laurent.pinchart@ideasonboard.com> wrote:
> > >
> > >> Hi Nicholas,
> > >>
> > >> Thank you for the patch.
> > >>
> > >> On Mon, Oct 24, 2022 at 12:55:41AM -0500, Nicholas Roth via
> > >> libcamera-devel wrote:
> > >> > From: Nicholas Roth <nicholas@rothemail.net>
> > >>
> > >> The two files list third party copyrights, could you please indicate
> in
> > >> the commit message where that comes from ? A link to a git tree with
> the
> > >> code you started from would be good.
> > >>
> > >> > ---
> > >> >  android/Android.mk     |  86 ++++++++++++
> > >> >  android/meson_cross.mk | 296
> +++++++++++++++++++++++++++++++++++++++++
> > >> >  2 files changed, 382 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)),)
> > >>
> > >> I assume this variable, as well as BOARD_LIBCAMERA_IPAS and
> > >> BOARD_LIBCAMERA_PIPELINES, need to be defined externally. It would be
> > >> nice to add some Android build documentation to the Documentation/
> > >> directory.
> > >>
> > >> > +
> > >> > +LOCAL_PATH := $(call my-dir)
> > >> > +LIBCAMERA_TOP := $(dir $(LOCAL_PATH))
> > >> > +LIBCAMERA_MESON_VERSION := .0.0.1
> > >>
> > >> Is this something that can be provided by meson, to avoid hardcoding
> > >> version numbers in multiple places ? Or can the utils/gen-version.sh
> > >> script help ?
> > >>
> > >> > +
> > >> > +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,))
> > >>
> > >> It would also be nice to avoid hardcoding the list of IPA modules (and
> > >> other files below), but I suppose that would be difficult ? Or could
> > >> 'meson install' be used to install the files to a directory that would
> > >> then be picked by the Android build system ?
> > >>
> > >> > +# 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..bb1661cd
> > >> > --- /dev/null
> > >> > +++ b/android/meson_cross.mk
> > >> > @@ -0,0 +1,296 @@
> > >> > +# 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 "../../../../"
>
> I'm not yet sure where / why this is used - but does "realpath
> --relative-to" make sense here?
>
> (Not a requierment, just a curiosity).
>
> --
> Kieran
>
>
> > >> > +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
> > >>        \
> > >> > +     -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 -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 $@
> > >>
> > >> --
> > >> Regards,
> > >>
> > >> Laurent Pinchart
> > >>
> > >
>
Nicholas Roth Oct. 27, 2022, 5:58 a.m. UTC | #6
> I'm not yet sure where / why this is used - but does "realpath
> --relative-to" make sense here?

I just grepped for this in the code, and I'm not sure what you mean by
this. AOSP_ABSOLUTE_PATH -- the path to AOSP -- was the only thing I could
find. Why would we want a relative path instead?

On Wed, Oct 26, 2022 at 10:29 AM Nicholas Roth <nicholas@rothemail.net>
wrote:

> > (Perhaps you don't want it reviewed yet, so that's not a problem).
> That's exactly correct!
>
> >Can the signatures be resigned at a final stage after they are stripped?
> That happens deep in the bowels of Android's build system. There is no
> documented way to do this, but it may be theoretically possible, especially
> if distribution maintainers are willing to fork or patch the Android build
> system itself. I can imagine this might create a high maintenance burden
> though. The high-level API people are supposed to use is:
>
> include $(CLEAR_VARS)
> LOCAL_MODULE := foo-prebuilt
> LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libfoo.so
> LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
> include $(PREBUILT_SHARED_LIBRARY)
>
> from https://developer.android.com/ndk/guides/prebuilts.
>
> PREBUILT_SHARED_LIBRARY, or BUILD_PREBUILT as we use in our makefile, is
> what does the transformations. Maybe there's a clean way to influence its
> behavior and I'm just not familiar enough with the Android make-based build
> system to know what it is, although my intuition is that this would be
> unlikely and perhaps considered undesirable by the Android engprod team.
>
> > I'm not yet sure where / why this is used - but does "realpath
> > --relative-to" make sense here?
> This provides a relative path to the build directory IIRC (heading out to
> a meeting right now).
>
> -Nicholas
>
>
> On Wed, Oct 26, 2022 at 4:16 AM Kieran Bingham <
> kieran.bingham@ideasonboard.com> wrote:
>
>> Quoting Nicholas Roth (2022-10-26 04:05:38)
>> > +Kieran Bingham <kieran.bingham@ideasonboard.com> since Laurent is out.
>> >
>> >
>> > On Tue, Oct 25, 2022 at 9:22 PM Nicholas Roth <nicholas@rothemail.net>
>> > wrote:
>> >
>> > > > The two files list third party copyrights, could you please
>> indicate in
>> > > > the commit message where that comes from ? A link to a git tree
>> with the
>> > > > code you started from would be good.
>> > > Happy to:
>> > >
>> https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/android/mesa3d_cross.mk
>> .
>> > > I'll make sure to include this in the commit message.
>> > >
>> > > > I assume this variable, as well as BOARD_LIBCAMERA_IPAS and
>> > > > BOARD_LIBCAMERA_PIPELINES, need to be defined externally. It would
>> be
>> > > > nice to add some Android build documentation to the Documentation/
>> > > > directory.
>> > > As this review is already quite large, I've created Bug 164 to track
>> this.
>> > > For now, would it be possible to link to my doc that covers this
>> > >
>> https://docs.google.com/document/d/1Sly_VH3w6wFIdE72WXijQegoHZh8IxEnJ9m0hH7GodU/edit
>> > > and reference Bug 164 in the commit message?
>>
>> I think that's OK for the short term, but we won't be likely to review
>> the document or process until it's posted to the list.
>>
>> (Perhaps you don't want it reviewed yet, so that's not a problem).
>>
>> > > >> +LOCAL_PATH := $(call my-dir)
>> > > >> +LIBCAMERA_TOP := $(dir $(LOCAL_PATH))
>> > > >> +LIBCAMERA_MESON_VERSION := .0.0.1
>> > > > Is this something that can be provided by meson, to avoid hardcoding
>> > > > version numbers in multiple places ? Or can the utils/gen-version.sh
>> > > > script help ?
>> > > I will investigate whether utils/gen-version.sh can help. I believe
>> > > running shell scripts is deprecated, but my copy commands at the
>> bottom of
>> > > Android.mk do the trick, so it _might_ work, at least for now.
>> > >
>> > > > It would also be nice to avoid hardcoding the list of IPA modules
>> (and
>> > > > other files below), but I suppose that would be difficult ? Or could
>> > > > 'meson install' be used to install the files to a directory that
>> would
>> > > > then be picked by the Android build system ?
>> > > We already "meson install" the files to a known location. Those files
>> have
>> > > to be explicitly accessed, though, because Android needs to transform
>> the
>> > > .so files after they are built with Makefile targets. This is also why
>> > > signature verification fundamentally does not work on Android.
>>
>> Can the signatures be resigned at a final stage after they are stripped?
>>
>> > >
>> > > Thanks for your thoughtful responses.
>> > >
>> > > -Nicholas
>> > >
>> > > On Mon, Oct 24, 2022 at 7:08 PM Laurent Pinchart <
>> > > laurent.pinchart@ideasonboard.com> wrote:
>> > >
>> > >> Hi Nicholas,
>> > >>
>> > >> Thank you for the patch.
>> > >>
>> > >> On Mon, Oct 24, 2022 at 12:55:41AM -0500, Nicholas Roth via
>> > >> libcamera-devel wrote:
>> > >> > From: Nicholas Roth <nicholas@rothemail.net>
>> > >>
>> > >> The two files list third party copyrights, could you please indicate
>> in
>> > >> the commit message where that comes from ? A link to a git tree with
>> the
>> > >> code you started from would be good.
>> > >>
>> > >> > ---
>> > >> >  android/Android.mk     |  86 ++++++++++++
>> > >> >  android/meson_cross.mk | 296
>> +++++++++++++++++++++++++++++++++++++++++
>> > >> >  2 files changed, 382 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)),)
>> > >>
>> > >> I assume this variable, as well as BOARD_LIBCAMERA_IPAS and
>> > >> BOARD_LIBCAMERA_PIPELINES, need to be defined externally. It would be
>> > >> nice to add some Android build documentation to the Documentation/
>> > >> directory.
>> > >>
>> > >> > +
>> > >> > +LOCAL_PATH := $(call my-dir)
>> > >> > +LIBCAMERA_TOP := $(dir $(LOCAL_PATH))
>> > >> > +LIBCAMERA_MESON_VERSION := .0.0.1
>> > >>
>> > >> Is this something that can be provided by meson, to avoid hardcoding
>> > >> version numbers in multiple places ? Or can the utils/gen-version.sh
>> > >> script help ?
>> > >>
>> > >> > +
>> > >> > +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,))
>> > >>
>> > >> It would also be nice to avoid hardcoding the list of IPA modules
>> (and
>> > >> other files below), but I suppose that would be difficult ? Or could
>> > >> 'meson install' be used to install the files to a directory that
>> would
>> > >> then be picked by the Android build system ?
>> > >>
>> > >> > +# 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..bb1661cd
>> > >> > --- /dev/null
>> > >> > +++ b/android/meson_cross.mk
>> > >> > @@ -0,0 +1,296 @@
>> > >> > +# 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 "../../../../"
>>
>> I'm not yet sure where / why this is used - but does "realpath
>> --relative-to" make sense here?
>>
>> (Not a requierment, just a curiosity).
>>
>> --
>> Kieran
>>
>>
>> > >> > +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
>> > >>        \
>> > >> > +     -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 -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 $@
>> > >>
>> > >> --
>> > >> Regards,
>> > >>
>> > >> Laurent Pinchart
>> > >>
>> > >
>>
>

Patch
diff mbox series

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..bb1661cd
--- /dev/null
+++ b/android/meson_cross.mk
@@ -0,0 +1,296 @@ 
+# 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                                                             \
+	-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 -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 $@