1DESCRIPTION = "Various utilities from Android"
2SECTION = "console/utils"
3LICENSE = "Apache-2.0 & GPL-2.0-only & BSD-2-Clause & BSD-3-Clause"
4LIC_FILES_CHKSUM = " \
5    file://${COMMON_LICENSE_DIR}/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10 \
6    file://${COMMON_LICENSE_DIR}/GPL-2.0-only;md5=801f80980d171dd6425610833a22dbe6 \
7    file://${COMMON_LICENSE_DIR}/BSD-2-Clause;md5=cb641bc04cda31daea161b1bc15da69f \
8    file://${COMMON_LICENSE_DIR}/BSD-3-Clause;md5=550794465ba0ec5312d6919e203a55f9 \
9"
10DEPENDS = "libbsd libpcre zlib libcap libusb squashfs-tools 7zip libselinux googletest"
11
12SRCREV_core = "abfd66fafcbb691d7860df059f1df1c9b1ef29da"
13
14SRC_URI = " \
15    git://salsa.debian.org/android-tools-team/android-platform-tools;name=core;protocol=https;branch=master \
16"
17
18# Patches copied from android-platform-tools/debian/patches
19# and applied in the order defined by the file debian/patches/series
20SRC_URI += " \
21    file://debian/external/libunwind/user_pt_regs.patch \
22    file://debian/external/libunwind/legacy_built-in_sync_functions.patch \
23    file://debian/external/libunwind/20150704-CVE-2015-3239_dwarf_i.h.patch \
24    \
25    file://debian/system/core/move-log-file-to-proper-dir.patch \
26    file://debian/system/core/Added-missing-headers.patch \
27    file://debian/system/core/libusb-header-path.patch \
28    file://debian/system/core/stdatomic.patch \
29    file://debian/system/core/Nonnull.patch \
30    file://debian/system/core/Vector-cast.patch \
31    file://debian/system/core/throw-exception-on-unknown-os.patch \
32    file://debian/system/core/simg_dump-python3.patch \
33    file://debian/system/core/fix-attribute-issue-with-gcc.patch \
34    file://debian/system/core/fix-gettid-exception-declaration.patch \
35    file://debian/system/core/fix-build-on-non-x86.patch \
36    file://debian/system/core/add-missing-headers.patch \
37    file://debian/system/core/hard-code-build-number.patch \
38    file://debian/system/core/stub-out-fastdeploy.patch \
39    file://debian/system/core/fix-standard-namespace-errors.patch \
40    file://debian/system/core/Add-riscv64-support.patch \
41    \
42"
43
44# patches which don't come from debian
45SRC_URI += " \
46    file://rules_yocto.mk;subdir=git \
47    file://android-tools-adbd.service \
48    file://adbd.mk;subdir=git/debian/system/core \
49    file://remount \
50    file://0001-Fixes-for-yocto-build.patch \
51    file://0002-android-tools-modifications-to-make-it-build-in-yoct.patch \
52    file://0003-Update-usage-of-usbdevfs_urb-to-match-new-kernel-UAP.patch \
53    file://0004-adb-Fix-build-on-big-endian-systems.patch \
54    file://0005-adb-Allow-adbd-to-be-run-as-root.patch \
55    file://0001-liblp-fix-building-with-GCC-14.patch \
56"
57
58S = "${WORKDIR}/git"
59B = "${WORKDIR}/${BPN}"
60
61# http://errors.yoctoproject.org/Errors/Details/1debian881/
62ARM_INSTRUCTION_SET:armv4 = "arm"
63ARM_INSTRUCTION_SET:armv5 = "arm"
64
65COMPATIBLE_HOST:powerpc = "(null)"
66COMPATIBLE_HOST:powerpc64 = "(null)"
67COMPATIBLE_HOST:powerpc64le = "(null)"
68
69inherit systemd
70
71SYSTEMD_PACKAGES = "${PN}-adbd"
72SYSTEMD_SERVICE:${PN}-adbd = "android-tools-adbd.service"
73
74# Find libbsd headers during native builds
75CC:append:class-native = " -I${STAGING_INCDIR}"
76CC:append:class-nativesdk = " -I${STAGING_INCDIR}"
77
78PREREQUISITE_core = "liblog libbase libsparse liblog libcutils"
79TOOLS_TO_BUILD = "libcrypto_utils libadb libziparchive fastboot adb img2simg simg2img libbacktrace"
80TOOLS_TO_BUILD:append:class-target = " adbd"
81
82do_compile() {
83
84    case "${HOST_ARCH}" in
85      arm)
86        export android_arch=linux-arm
87        cpu=arm
88        deb_host_arch=arm
89      ;;
90      aarch64)
91        export android_arch=linux-arm64
92        cpu=arm64
93        deb_host_arch=arm64
94      ;;
95      riscv64)
96        export android_arch=linux-riscv64
97      ;;
98      mips|mipsel)
99        export android_arch=linux-mips
100        cpu=mips
101        deb_host_arch=mips
102      ;;
103      mips64|mips64el)
104        export android_arch=linux-mips64
105        cpu=mips64
106        deb_host_arch=mips64
107      ;;
108      powerpc|powerpc64)
109        export android_arch=linux-ppc
110      ;;
111      i586|i686|x86_64)
112        export android_arch=linux-x86
113        cpu=x86_64
114        deb_host_arch=amd64
115      ;;
116    esac
117
118    export SRCDIR=${S}
119
120    oe_runmake -f ${S}/debian/external/boringssl/libcrypto.mk -C ${S}
121    oe_runmake -f ${S}/debian/external/libunwind/libunwind.mk -C ${S} CPU=${cpu}
122
123    for tool in ${PREREQUISITE_core}; do
124      oe_runmake -f ${S}/debian/system/core/${tool}.mk -C ${S}
125    done
126
127    for i in `find ${S}/debian/system/extras/ -name "*.mk"`; do
128        oe_runmake -f $i -C ${S}
129    done
130
131    for tool in ${TOOLS_TO_BUILD}; do
132        if [ "$tool" = "libbacktrace" ]; then
133            oe_runmake -f ${S}/debian/system/core/${tool}.mk -C ${S} DEB_HOST_ARCH=${deb_host_arch}
134        else
135            oe_runmake -f ${S}/debian/system/core/${tool}.mk -C ${S}
136        fi
137    done
138
139}
140
141do_install() {
142    install -d ${D}${base_sbindir}
143    install -m 0755 ${UNPACKDIR}/remount -D ${D}${base_sbindir}/remount
144
145    for tool in img2simg simg2img fastboot adbd; do
146        if echo ${TOOLS_TO_BUILD} | grep -q "$tool" ; then
147            install -D -p -m0755 ${S}/debian/out/system/core/$tool ${D}${bindir}/$tool
148        fi
149    done
150
151    # grep adb also matches adbd, so handle adb separately from other tools
152    if echo ${TOOLS_TO_BUILD} | grep -q "adb " ; then
153        install -d ${D}${bindir}
154        install -m0755 ${S}/debian/out/system/core/adb ${D}${bindir}
155    fi
156
157    # Outside the if statement to avoid errors during do_package
158    install -D -p -m0644 ${UNPACKDIR}/android-tools-adbd.service \
159      ${D}${systemd_unitdir}/system/android-tools-adbd.service
160
161    install -d  ${D}${libdir}/android/
162    install -m0755 ${S}/debian/out/system/core/*.so.* ${D}${libdir}/android/
163    if echo ${TOOLS_TO_BUILD} | grep -q "mkbootimg" ; then
164        install -d ${D}${bindir}
165        install -m0755 ${B}/mkbootimg/mkbootimg ${D}${bindir}
166    fi
167}
168
169PACKAGES =+ "${PN}-fstools ${PN}-adbd"
170
171RDEPENDS:${BPN} = "${BPN}-conf 7zip"
172
173FILES:${PN}-adbd = "\
174    ${bindir}/adbd \
175    ${systemd_unitdir}/system/android-tools-adbd.service \
176"
177
178FILES:${PN}-fstools = "\
179    ${bindir}/ext2simg \
180    ${bindir}/ext4fixup \
181    ${bindir}/img2simg \
182    ${bindir}/make_ext4fs \
183    ${bindir}/simg2img \
184    ${bindir}/simg2simg \
185    ${bindir}/simg_dump \
186    ${bindir}/mkuserimg \
187"
188FILES:${PN} += "${libdir}/android ${libdir}/android/*"
189
190BBCLASSEXTEND = "native"
191
192android_tools_enable_devmode() {
193    touch ${IMAGE_ROOTFS}/etc/usb-debugging-enabled
194}
195
196ROOTFS_POSTPROCESS_COMMAND_${PN}-adbd += "${@bb.utils.contains("USB_DEBUGGING_ENABLED", "1", "android_tools_enable_devmode;", "", d)}"
197