1*4882a593SmuzhiyunDESCRIPTION = "Different utilities from Android"
2*4882a593SmuzhiyunSECTION = "console/utils"
3*4882a593SmuzhiyunLICENSE = "Apache-2.0 & GPL-2.0-only & BSD-2-Clause & BSD-3-Clause"
4*4882a593SmuzhiyunLIC_FILES_CHKSUM = " \
5*4882a593Smuzhiyun    file://${COMMON_LICENSE_DIR}/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10 \
6*4882a593Smuzhiyun    file://${COMMON_LICENSE_DIR}/GPL-2.0-only;md5=801f80980d171dd6425610833a22dbe6 \
7*4882a593Smuzhiyun    file://${COMMON_LICENSE_DIR}/BSD-2-Clause;md5=cb641bc04cda31daea161b1bc15da69f \
8*4882a593Smuzhiyun    file://${COMMON_LICENSE_DIR}/BSD-3-Clause;md5=550794465ba0ec5312d6919e203a55f9 \
9*4882a593Smuzhiyun"
10*4882a593SmuzhiyunDEPENDS = "libbsd libpcre zlib libcap libusb squashfs-tools p7zip libselinux"
11*4882a593Smuzhiyun
12*4882a593SmuzhiyunANDROID_MIRROR = "android.googlesource.com"
13*4882a593Smuzhiyun
14*4882a593Smuzhiyun# matches with 10.0.0+r36
15*4882a593SmuzhiyunSRCREV_boringssl = "ae2dd49c7cb74d04bdba7c1c9bd62c1e9cdf98f6"
16*4882a593SmuzhiyunSRCREV_core = "5aa13b053182b758d7a19db0c83e1b9b5bf1ec2e"
17*4882a593SmuzhiyunSRCREV_extras = "d31740f9d0399f8b938e88e58843d966e1cccab6"
18*4882a593SmuzhiyunSRCREV_libhardware = "c6925520342a7d37758f85eb1cf3baa20a7b7a18"
19*4882a593SmuzhiyunSRCREV_build = "28768b3120f751583a2743101b892f210d4715cf"
20*4882a593SmuzhiyunSRCREV_libunwind = "03a963ecf6ea836b38b3537cbcda0ecfd7a77393"
21*4882a593Smuzhiyun
22*4882a593SmuzhiyunSRC_URI = " \
23*4882a593Smuzhiyun    git://salsa.debian.org/android-tools-team/android-platform-external-boringssl;name=boringssl;protocol=https;nobranch=1;destsuffix=git/external/boringssl \
24*4882a593Smuzhiyun    git://salsa.debian.org/android-tools-team/android-platform-system-core;name=core;protocol=https;nobranch=1;destsuffix=git/system/core \
25*4882a593Smuzhiyun    git://salsa.debian.org/android-tools-team/android-platform-system-extras;name=extras;protocol=https;nobranch=1;destsuffix=git/system/extras \
26*4882a593Smuzhiyun    git://${ANDROID_MIRROR}/platform/hardware/libhardware;name=libhardware;protocol=https;nobranch=1;destsuffix=git/hardware/libhardware \
27*4882a593Smuzhiyun    git://salsa.debian.org/android-tools-team/android-platform-build.git;name=build;protocol=https;nobranch=1;destsuffix=git/build \
28*4882a593Smuzhiyun    git://salsa.debian.org/android-tools-team/android-platform-external-libunwind.git;protocol=https;name=libunwind;nobranch=1;destsuffix=git/external/libunwind \
29*4882a593Smuzhiyun"
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun# Patches copied from android-platform-system-core/debian/patches
32*4882a593Smuzhiyun# and applied in the order defined by the "series" file
33*4882a593SmuzhiyunSRC_URI += " \
34*4882a593Smuzhiyun    file://core-debian/move-log-file-to-proper-dir.patch;patchdir=system/core \
35*4882a593Smuzhiyun    file://core-debian/Added-missing-headers.patch;patchdir=system/core \
36*4882a593Smuzhiyun    file://core-debian/libusb-header-path.patch;patchdir=system/core \
37*4882a593Smuzhiyun    file://core-debian/stdatomic.patch;patchdir=system/core \
38*4882a593Smuzhiyun    file://core-debian/Nonnull.patch;patchdir=system/core \
39*4882a593Smuzhiyun    file://core-debian/Vector-cast.patch;patchdir=system/core \
40*4882a593Smuzhiyun    file://core-debian/use-Python-3-for-mkbootimg.patch;patchdir=system/core \
41*4882a593Smuzhiyun    file://core-debian/throw-exception-on-unknown-os.patch;patchdir=system/core \
42*4882a593Smuzhiyun    file://core-debian/simg_dump-python3.patch;patchdir=system/core \
43*4882a593Smuzhiyun    file://core-debian/fix-attribute-issue-with-gcc.patch;patchdir=system/core \
44*4882a593Smuzhiyun    file://core-debian/workaround-error-expected-primary-expression-before-.-token.patch;patchdir=system/core \
45*4882a593Smuzhiyun    file://core-debian/fix-gettid-exception-declaration.patch;patchdir=system/core \
46*4882a593Smuzhiyun    file://core-debian/fix-build-on-non-x86.patch;patchdir=system/core \
47*4882a593Smuzhiyun    file://core-debian/add-missing-headers.patch;patchdir=system/core \
48*4882a593Smuzhiyun    file://core-debian/hard-code-build-number.patch;patchdir=system/core \
49*4882a593Smuzhiyun    file://core-debian/fix-gcc-11-ftbfs.patch;patchdir=system/core \
50*4882a593Smuzhiyun    file://core-debian/fix-gnu-hurd.patch;patchdir=system/core \
51*4882a593Smuzhiyun"
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun# Patches copied from android-platform-external-libunwind/debian/patches
54*4882a593Smuzhiyun# and applied in the order defined by the "series" file
55*4882a593SmuzhiyunSRC_URI += " \
56*4882a593Smuzhiyun    file://libunwind-debian/user_pt_regs.patch;patchdir=external/libunwind \
57*4882a593Smuzhiyun    file://libunwind-debian/legacy_built-in_sync_functions.patch;patchdir=external/libunwind \
58*4882a593Smuzhiyun    file://libunwind-debian/20150704-CVE-2015-3239_dwarf_i.h.patch;patchdir=external/libunwind \
59*4882a593Smuzhiyun"
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun# meta-clang specific patches + files:
62*4882a593SmuzhiyunSRC_URI += " \
63*4882a593Smuzhiyun    file://core/0001-patching-adb.mk-to-build-in-yocto-environment.patch;patchdir=system/core \
64*4882a593Smuzhiyun    file://core/0002-libadb.mk-modifications-to-make-it-build-in-yocto-en.patch;patchdir=system/core \
65*4882a593Smuzhiyun    file://core/0003-socket.h-removing-dependency-of-gtest.patch;patchdir=system/core \
66*4882a593Smuzhiyun    file://core/0004-patching-fastboot.mk-to-build-in-yocto-environment.patch;patchdir=system/core \
67*4882a593Smuzhiyun    file://core/0005-fastboot-don-t-use-sparse_file_import_auto-in-load_b.patch;patchdir=system/core \
68*4882a593Smuzhiyun    file://core/0006-libbase.mk-modifications-to-make-it-build-in-yocto-e.patch;patchdir=system/core \
69*4882a593Smuzhiyun    file://core/0007-libcrypto_utils.mk-modifications-to-make-it-build-in.patch;patchdir=system/core \
70*4882a593Smuzhiyun    file://core/0008-libcutils-modifications-to-make-it-build-in-yocto-en.patch;patchdir=system/core \
71*4882a593Smuzhiyun    file://core/0009-patching-img2simg.mk-to-build-in-yocto-environment.patch;patchdir=system/core \
72*4882a593Smuzhiyun    file://core/0010-patching-simg2img.mk-to-build-in-yocto-environment.patch;patchdir=system/core \
73*4882a593Smuzhiyun    file://core/0011-patching-liblog.mk-to-build-in-yocto-environment.patch;patchdir=system/core \
74*4882a593Smuzhiyun    file://core/0012-patching-libsparse.mk-to-build-in-yocto-environment.patch;patchdir=system/core \
75*4882a593Smuzhiyun    file://core/0013-patching-libziparchive.mk-to-build-in-yocto-environm.patch;patchdir=system/core \
76*4882a593Smuzhiyun    file://core/0014-patching-libbacktrace.mk-to-build-in-yocto-environme.patch;patchdir=system/core \
77*4882a593Smuzhiyun    file://core/0015-Use-namespace-std-to-compile-libbacktrace.patch;patchdir=system/core \
78*4882a593Smuzhiyun    file://0001-libcrypto.mk-modifications-to-make-it-build-in-yocto.patch;patchdir=external/boringssl \
79*4882a593Smuzhiyun    file://0001-patching-libundwind-to-build-in-yocto-environment.patch;patchdir=external/libunwind \
80*4882a593Smuzhiyun    file://0001-libext4_utils.mk-modifications-to-make-it-build-in-y.patch;patchdir=system/extras \
81*4882a593Smuzhiyun    file://0002-libfec-change-out_dir-in-makefile.patch;patchdir=system/extras \
82*4882a593Smuzhiyun    file://rules_yocto.mk;subdir=git \
83*4882a593Smuzhiyun    file://android-tools-adbd.service \
84*4882a593Smuzhiyun"
85*4882a593Smuzhiyun
86*4882a593SmuzhiyunS = "${WORKDIR}/git"
87*4882a593SmuzhiyunB = "${WORKDIR}/${BPN}"
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun# http://errors.yoctoproject.org/Errors/Details/1debian881/
90*4882a593SmuzhiyunARM_INSTRUCTION_SET:armv4 = "arm"
91*4882a593SmuzhiyunARM_INSTRUCTION_SET:armv5 = "arm"
92*4882a593Smuzhiyun
93*4882a593SmuzhiyunCOMPATIBLE_HOST:powerpc = "(null)"
94*4882a593SmuzhiyunCOMPATIBLE_HOST:powerpc64 = "(null)"
95*4882a593SmuzhiyunCOMPATIBLE_HOST:powerpc64le = "(null)"
96*4882a593Smuzhiyun
97*4882a593Smuzhiyuninherit systemd clang
98*4882a593Smuzhiyun
99*4882a593SmuzhiyunTOOLCHAIN = "clang"
100*4882a593SmuzhiyunTOOLCHAIN:class-native = "clang"
101*4882a593SmuzhiyunDEPENDS:append:class-target = "\
102*4882a593Smuzhiyun    clang-cross-${TARGET_ARCH} \
103*4882a593Smuzhiyun"
104*4882a593SmuzhiyunDEPENDS:append:class-native = " clang-native"
105*4882a593Smuzhiyun
106*4882a593SmuzhiyunSYSTEMD_SERVICE:${PN} = "android-tools-adbd.service"
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun# Find libbsd headers during native builds
109*4882a593SmuzhiyunCC:append:class-native = " -I${STAGING_INCDIR}"
110*4882a593SmuzhiyunCC:append:class-nativesdk = " -I${STAGING_INCDIR}"
111*4882a593Smuzhiyun
112*4882a593SmuzhiyunPREREQUISITE_core = "libbase libsparse liblog libcutils"
113*4882a593SmuzhiyunTOOLS_TO_BUILD = "libcrypto_utils libadb libziparchive fastboot adb img2simg simg2img libbacktrace"
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun# Adb needs sys/capability.h, which is not available for native*
116*4882a593SmuzhiyunTOOLS:class-native = "boringssl fastboot ext4_utils mkbootimg"
117*4882a593SmuzhiyunTOOLS:class-nativesdk = "boringssl fastboot ext4_utils mkbootimg"
118*4882a593Smuzhiyun
119*4882a593Smuzhiyundo_compile() {
120*4882a593Smuzhiyun
121*4882a593Smuzhiyun    case "${HOST_ARCH}" in
122*4882a593Smuzhiyun      arm)
123*4882a593Smuzhiyun        export android_arch=linux-arm
124*4882a593Smuzhiyun        cpu=arm
125*4882a593Smuzhiyun        deb_host_arch=arm
126*4882a593Smuzhiyun      ;;
127*4882a593Smuzhiyun      aarch64)
128*4882a593Smuzhiyun        export android_arch=linux-arm64
129*4882a593Smuzhiyun        cpu=arm64
130*4882a593Smuzhiyun        deb_host_arch=arm64
131*4882a593Smuzhiyun      ;;
132*4882a593Smuzhiyun      riscv64)
133*4882a593Smuzhiyun        export android_arch=linux-riscv64
134*4882a593Smuzhiyun      ;;
135*4882a593Smuzhiyun      mips|mipsel)
136*4882a593Smuzhiyun        export android_arch=linux-mips
137*4882a593Smuzhiyun        cpu=mips
138*4882a593Smuzhiyun        deb_host_arch=mips
139*4882a593Smuzhiyun      ;;
140*4882a593Smuzhiyun      mips64|mips64el)
141*4882a593Smuzhiyun        export android_arch=linux-mips64
142*4882a593Smuzhiyun        cpu=mips64
143*4882a593Smuzhiyun        deb_host_arch=mips64
144*4882a593Smuzhiyun      ;;
145*4882a593Smuzhiyun      powerpc|powerpc64)
146*4882a593Smuzhiyun        export android_arch=linux-ppc
147*4882a593Smuzhiyun      ;;
148*4882a593Smuzhiyun      i586|i686|x86_64)
149*4882a593Smuzhiyun        export android_arch=linux-x86
150*4882a593Smuzhiyun        cpu=x86_64
151*4882a593Smuzhiyun        deb_host_arch=amd64
152*4882a593Smuzhiyun      ;;
153*4882a593Smuzhiyun    esac
154*4882a593Smuzhiyun
155*4882a593Smuzhiyun    export SRCDIR=${S}
156*4882a593Smuzhiyun
157*4882a593Smuzhiyun    oe_runmake -f ${S}/external/boringssl/debian/libcrypto.mk -C ${S}/external/boringssl
158*4882a593Smuzhiyun    oe_runmake -f ${S}/external/libunwind/debian/libunwind.mk -C ${S}/external/libunwind CPU=${cpu}
159*4882a593Smuzhiyun
160*4882a593Smuzhiyun    for tool in ${PREREQUISITE_core}; do
161*4882a593Smuzhiyun      oe_runmake -f ${S}/system/core/debian/${tool}.mk -C ${S}/system/core
162*4882a593Smuzhiyun    done
163*4882a593Smuzhiyun
164*4882a593Smuzhiyun    for i in `find ${S}/system/extras/debian/ -name "*.mk"`; do
165*4882a593Smuzhiyun        oe_runmake -f $i -C ${S}/system/extras
166*4882a593Smuzhiyun    done
167*4882a593Smuzhiyun
168*4882a593Smuzhiyun    for tool in ${TOOLS_TO_BUILD}; do
169*4882a593Smuzhiyun        if [ "$tool" == "libbacktrace" ]; then
170*4882a593Smuzhiyun            oe_runmake -f ${S}/system/core/debian/${tool}.mk -C ${S}/system/core DEB_HOST_ARCH=${deb_host_arch}
171*4882a593Smuzhiyun        else
172*4882a593Smuzhiyun            oe_runmake -f ${S}/system/core/debian/${tool}.mk -C ${S}/system/core
173*4882a593Smuzhiyun        fi
174*4882a593Smuzhiyun    done
175*4882a593Smuzhiyun
176*4882a593Smuzhiyun}
177*4882a593Smuzhiyun
178*4882a593Smuzhiyundo_install() {
179*4882a593Smuzhiyun    if echo ${TOOLS_TO_BUILD} | grep -q "ext4_utils" ; then
180*4882a593Smuzhiyun        install -D -p -m0755 ${S}/system/core/libsparse/simg_dump.py ${D}${bindir}/simg_dump
181*4882a593Smuzhiyun    fi
182*4882a593Smuzhiyun
183*4882a593Smuzhiyun    if echo ${TOOLS_TO_BUILD} | grep -q "adb " ; then
184*4882a593Smuzhiyun        install -d ${D}${bindir}
185*4882a593Smuzhiyun        install -m0755 ${S}/debian/out/usr/lib/android/adb/adb ${D}${bindir}
186*4882a593Smuzhiyun    fi
187*4882a593Smuzhiyun
188*4882a593Smuzhiyun    if echo ${TOOLS_TO_BUILD} | grep -q "adbd" ; then
189*4882a593Smuzhiyun        install -d ${D}${bindir}
190*4882a593Smuzhiyun        install -m0755 ${B}/adbd/adbd ${D}${bindir}
191*4882a593Smuzhiyun    fi
192*4882a593Smuzhiyun
193*4882a593Smuzhiyun    # Outside the if statement to avoid errors during do_package
194*4882a593Smuzhiyun    install -D -p -m0644 ${WORKDIR}/android-tools-adbd.service \
195*4882a593Smuzhiyun      ${D}${systemd_unitdir}/system/android-tools-adbd.service
196*4882a593Smuzhiyun
197*4882a593Smuzhiyun    if echo ${TOOLS_TO_BUILD} | grep -q "fastboot" ; then
198*4882a593Smuzhiyun        install -d ${D}${bindir}
199*4882a593Smuzhiyun        install -m0755 ${S}/debian/out/usr/bin/fastboot/fastboot ${D}${bindir}
200*4882a593Smuzhiyun    fi
201*4882a593Smuzhiyun
202*4882a593Smuzhiyun    install -d  ${D}${libdir}/android/
203*4882a593Smuzhiyun    install -m0755 ${S}/debian/out/usr/lib/android/*.so.* ${D}${libdir}/android/
204*4882a593Smuzhiyun    if echo ${TOOLS_TO_BUILD} | grep -q "mkbootimg" ; then
205*4882a593Smuzhiyun        install -d ${D}${bindir}
206*4882a593Smuzhiyun        install -m0755 ${B}/mkbootimg/mkbootimg ${D}${bindir}
207*4882a593Smuzhiyun    fi
208*4882a593Smuzhiyun}
209*4882a593Smuzhiyun
210*4882a593SmuzhiyunPACKAGES += "${PN}-fstools"
211*4882a593Smuzhiyun
212*4882a593SmuzhiyunRDEPENDS:${BPN} = "${BPN}-conf p7zip"
213*4882a593Smuzhiyun
214*4882a593SmuzhiyunFILES:${PN}-fstools = "\
215*4882a593Smuzhiyun    ${bindir}/ext2simg \
216*4882a593Smuzhiyun    ${bindir}/ext4fixup \
217*4882a593Smuzhiyun    ${bindir}/img2simg \
218*4882a593Smuzhiyun    ${bindir}/make_ext4fs \
219*4882a593Smuzhiyun    ${bindir}/simg2img \
220*4882a593Smuzhiyun    ${bindir}/simg2simg \
221*4882a593Smuzhiyun    ${bindir}/simg_dump \
222*4882a593Smuzhiyun    ${bindir}/mkuserimg \
223*4882a593Smuzhiyun"
224*4882a593SmuzhiyunFILES:${PN} += "${libdir}/android ${libdir}/android/*"
225*4882a593Smuzhiyun
226*4882a593SmuzhiyunBBCLASSEXTEND = "native"
227