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 p7zip 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"
56
57S = "${WORKDIR}/git"
58B = "${WORKDIR}/${BPN}"
59
60# http://errors.yoctoproject.org/Errors/Details/1debian881/
61ARM_INSTRUCTION_SET:armv4 = "arm"
62ARM_INSTRUCTION_SET:armv5 = "arm"
63
64COMPATIBLE_HOST:powerpc = "(null)"
65COMPATIBLE_HOST:powerpc64 = "(null)"
66COMPATIBLE_HOST:powerpc64le = "(null)"
67
68inherit systemd
69
70SYSTEMD_SERVICE:${PN}-adbd = "android-tools-adbd.service"
71
72# Find libbsd headers during native builds
73CC:append:class-native = " -I${STAGING_INCDIR}"
74CC:append:class-nativesdk = " -I${STAGING_INCDIR}"
75
76PREREQUISITE_core = "liblog libbase libsparse liblog libcutils"
77TOOLS_TO_BUILD = "libcrypto_utils libadb libziparchive fastboot adb img2simg simg2img libbacktrace"
78TOOLS_TO_BUILD:append:class-target = " adbd"
79
80do_compile() {
81
82    case "${HOST_ARCH}" in
83      arm)
84        export android_arch=linux-arm
85        cpu=arm
86        deb_host_arch=arm
87      ;;
88      aarch64)
89        export android_arch=linux-arm64
90        cpu=arm64
91        deb_host_arch=arm64
92      ;;
93      riscv64)
94        export android_arch=linux-riscv64
95      ;;
96      mips|mipsel)
97        export android_arch=linux-mips
98        cpu=mips
99        deb_host_arch=mips
100      ;;
101      mips64|mips64el)
102        export android_arch=linux-mips64
103        cpu=mips64
104        deb_host_arch=mips64
105      ;;
106      powerpc|powerpc64)
107        export android_arch=linux-ppc
108      ;;
109      i586|i686|x86_64)
110        export android_arch=linux-x86
111        cpu=x86_64
112        deb_host_arch=amd64
113      ;;
114    esac
115
116    export SRCDIR=${S}
117
118    oe_runmake -f ${S}/debian/external/boringssl/libcrypto.mk -C ${S}
119    oe_runmake -f ${S}/debian/external/libunwind/libunwind.mk -C ${S} CPU=${cpu}
120
121    for tool in ${PREREQUISITE_core}; do
122      oe_runmake -f ${S}/debian/system/core/${tool}.mk -C ${S}
123    done
124
125    for i in `find ${S}/debian/system/extras/ -name "*.mk"`; do
126        oe_runmake -f $i -C ${S}
127    done
128
129    for tool in ${TOOLS_TO_BUILD}; do
130        if [ "$tool" = "libbacktrace" ]; then
131            oe_runmake -f ${S}/debian/system/core/${tool}.mk -C ${S} DEB_HOST_ARCH=${deb_host_arch}
132        else
133            oe_runmake -f ${S}/debian/system/core/${tool}.mk -C ${S}
134        fi
135    done
136
137}
138
139do_install() {
140    install -d ${D}${base_sbindir}
141    install -m 0755 ${S}/../remount -D ${D}${base_sbindir}/remount
142
143    for tool in img2simg simg2img fastboot adbd; do
144        if echo ${TOOLS_TO_BUILD} | grep -q "$tool" ; then
145            install -D -p -m0755 ${S}/debian/out/system/core/$tool ${D}${bindir}/$tool
146        fi
147    done
148
149    # grep adb also matches adbd, so handle adb separately from other tools
150    if echo ${TOOLS_TO_BUILD} | grep -q "adb " ; then
151        install -d ${D}${bindir}
152        install -m0755 ${S}/debian/out/system/core/adb ${D}${bindir}
153    fi
154
155    # Outside the if statement to avoid errors during do_package
156    install -D -p -m0644 ${WORKDIR}/android-tools-adbd.service \
157      ${D}${systemd_unitdir}/system/android-tools-adbd.service
158
159    install -d  ${D}${libdir}/android/
160    install -m0755 ${S}/debian/out/system/core/*.so.* ${D}${libdir}/android/
161    if echo ${TOOLS_TO_BUILD} | grep -q "mkbootimg" ; then
162        install -d ${D}${bindir}
163        install -m0755 ${B}/mkbootimg/mkbootimg ${D}${bindir}
164    fi
165}
166
167PACKAGES =+ "${PN}-fstools ${PN}-adbd"
168
169RDEPENDS:${BPN} = "${BPN}-conf p7zip"
170
171FILES:${PN}-adbd = "\
172    ${bindir}/adbd \
173    ${systemd_unitdir}/system/android-tools-adbd.service \
174"
175
176FILES:${PN}-fstools = "\
177    ${bindir}/ext2simg \
178    ${bindir}/ext4fixup \
179    ${bindir}/img2simg \
180    ${bindir}/make_ext4fs \
181    ${bindir}/simg2img \
182    ${bindir}/simg2simg \
183    ${bindir}/simg_dump \
184    ${bindir}/mkuserimg \
185"
186FILES:${PN} += "${libdir}/android ${libdir}/android/*"
187
188BBCLASSEXTEND = "native"
189
190android_tools_enable_devmode() {
191    touch ${IMAGE_ROOTFS}/var/usb-debugging-enabled
192}
193
194ROOTFS_POSTPROCESS_COMMAND_${PN}-adbd += "${@bb.utils.contains("USB_DEBUGGING_ENABLED", "1", "android_tools_enable_devmode;", "", d)}"
195