1#!/bin/bash 2# 3# Copyright (c) 2018, The OpenThread Authors. 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions are met: 8# 1. Redistributions of source code must retain the above copyright 9# notice, this list of conditions and the following disclaimer. 10# 2. Redistributions in binary form must reproduce the above copyright 11# notice, this list of conditions and the following disclaimer in the 12# documentation and/or other materials provided with the distribution. 13# 3. Neither the name of the copyright holder nor the 14# names of its contributors may be used to endorse or promote products 15# derived from this software without specific prior written permission. 16# 17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27# POSSIBILITY OF SUCH DAMAGE. 28# 29 30set -e 31set -x 32 33####################################### 34# Prepare dbus source code 35# Globals: 36# None 37# Arguments: 38# None 39# Returns: 40# None 41####################################### 42prepare_dbus() 43{ 44 DBUS_SOURCE=dbus-1.4.26 45 wget --tries 4 --no-check-certificate --quiet "https://dbus.freedesktop.org/releases/dbus/${DBUS_SOURCE}.tar.gz" 46 tar xvf "${DBUS_SOURCE}.tar.gz" 47 (cd "${DBUS_SOURCE}" && ./configure --prefix= --exec-prefix=/usr \ 48 && sed -i '/HAVE_BACKTRACE/d' config.h \ 49 && sed -i 's/long/long long/' dbus/dbus-arch-deps.h) 50 cat >"${DBUS_SOURCE}/dbus/Android.mk" <<EOF 51LOCAL_PATH:= \$(call my-dir) 52include \$(CLEAR_VARS) 53 54LOCAL_SRC_FILES := \ 55 dbus-address.c \ 56 dbus-auth.c \ 57 dbus-auth-script.c \ 58 dbus-auth-util.c \ 59 dbus-bus.c \ 60 dbus-connection.c \ 61 dbus-credentials.c \ 62 dbus-credentials-util.c \ 63 dbus-dataslot.c \ 64 dbus-errors.c \ 65 dbus-file.c \ 66 dbus-file-unix.c \ 67 dbus-hash.c \ 68 dbus-internals.c \ 69 dbus-keyring.c \ 70 dbus-list.c \ 71 dbus-mainloop.c \ 72 dbus-marshal-basic.c \ 73 dbus-marshal-byteswap.c \ 74 dbus-marshal-byteswap-util.c \ 75 dbus-marshal-header.c \ 76 dbus-marshal-recursive.c \ 77 dbus-marshal-recursive-util.c \ 78 dbus-marshal-validate.c \ 79 dbus-marshal-validate-util.c \ 80 dbus-memory.c \ 81 dbus-mempool.c \ 82 dbus-message.c \ 83 dbus-message-factory.c \ 84 dbus-message-util.c \ 85 dbus-misc.c \ 86 dbus-nonce.c \ 87 dbus-object-tree.c \ 88 dbus-pending-call.c \ 89 dbus-pipe.c \ 90 dbus-pipe-unix.c \ 91 dbus-resources.c \ 92 dbus-server.c \ 93 dbus-server-debug-pipe.c \ 94 dbus-server-launchd.c \ 95 dbus-server-socket.c \ 96 dbus-server-unix.c \ 97 dbus-sha.c \ 98 dbus-shell.c \ 99 dbus-signature.c \ 100 dbus-spawn.c \ 101 dbus-string.c \ 102 dbus-string-util.c \ 103 dbus-sysdeps.c \ 104 dbus-sysdeps-pthread.c \ 105 dbus-sysdeps-unix.c \ 106 dbus-sysdeps-util.c \ 107 dbus-sysdeps-util-unix.c \ 108 dbus-test.c \ 109 dbus-test-main.c \ 110 dbus-threads.c \ 111 dbus-timeout.c \ 112 dbus-transport.c \ 113 dbus-transport-socket.c \ 114 dbus-transport-unix.c \ 115 dbus-userdb.c \ 116 dbus-userdb-util.c \ 117 dbus-uuidgen.c \ 118 dbus-watch.c \ 119 sd-daemon.c \ 120 121\$(DBUS_SOURCES:\$(LOCAL_PATH)/%=%) 122 123LOCAL_C_INCLUDES+= \$(LOCAL_PATH)/.. 124 125LOCAL_MODULE:=libdbus 126 127DBUS_HEADERS := \$(wildcard \$(LOCAL_PATH)/*.h) 128LOCAL_COPY_HEADERS := \$(DBUS_HEADERS:\$(LOCAL_PATH)/%=%) 129 130LOCAL_COPY_HEADERS_TO := dbus 131 132LOCAL_CFLAGS+= \ 133 -DDBUS_COMPILATION \ 134 -DHAVE_MONOTONIC_CLOCK \ 135 -DDBUS_MACHINE_UUID_FILE=\"/etc/machine-id\" \ 136 -DDBUS_SYSTEM_CONFIG_FILE=\"/etc/dbus-1/system.conf\" \ 137 -DDBUS_SESSION_CONFIG_FILE=\"/etc/dbus-1/session.conf\" \ 138 -Wno-empty-body \ 139 -Wno-missing-field-initializers \ 140 -Wno-pointer-sign \ 141 -Wno-sign-compare \ 142 -Wno-tautological-compare \ 143 -Wno-type-limits \ 144 -Wno-unused-parameter 145 146include \$(BUILD_SHARED_LIBRARY) 147EOF 148} 149 150####################################### 151# Prepare libmdns source code 152# Globals: 153# None 154# Arguments: 155# None 156# Returns: 157# None 158####################################### 159prepare_libmdnssd() 160{ 161 readonly MDNSRESPONDER_SOURCE=mDNSResponder-1310.80.1 162 163 [[ ${OTBR_MDNS} == mDNSResponder ]] || return 0 164 165 wget --tries 4 --no-check-certificate --quiet "https://opensource.apple.com/tarballs/mDNSResponder/${MDNSRESPONDER_SOURCE}.tar.gz" 166 tar xvf "${MDNSRESPONDER_SOURCE}.tar.gz" 167 cat >"${MDNSRESPONDER_SOURCE}/Android.mk" <<EOF 168LOCAL_PATH:= \$(call my-dir) 169 170include \$(CLEAR_VARS) 171 172LOCAL_SRC_FILES := \ 173 mDNSShared/dnssd_clientlib.c \ 174 mDNSShared/dnssd_clientstub.c \ 175 mDNSShared/dnssd_ipc.c \ 176 177LOCAL_MODULE := libmdnssd 178LOCAL_MODULE_TAGS := eng 179 180DBUS_HEADERS := \$(wildcard \$(LOCAL_PATH)/mDNSShared/*.h) 181LOCAL_COPY_HEADERS := \$(DBUS_HEADERS:\$(LOCAL_PATH)/%=%) 182 183LOCAL_EXPORT_C_INCLUDE_DIRS := \$(LOCAL_PATH)/mDNSShared 184 185LOCAL_CFLAGS := -O2 -g -W -Wall -D_GNU_SOURCE -DHAVE_IPV6 -DNOT_HAVE_SA_LEN -DUSES_NETLINK -DTARGET_OS_LINUX -fno-strict-aliasing -DHAVE_LINUX -DMDNS_DEBUGMSGS=0 186 187include \$(BUILD_SHARED_LIBRARY) 188EOF 189} 190 191prepare_openthread() 192{ 193 cat >>buildspec.mk <<EOF 194 195USE_OTBR_DAEMON := 1 196OTBR_ENABLE_ANDROID_MK := 1 197OPENTHREAD_ENABLE_ANDROID_MK := 1 198ANDROID_NDK := 1 199OPENTHREAD_PROJECT_CFLAGS := \ 200 -DOPENTHREAD_CONFIG_MLE_STEERING_DATA_SET_OOB_ENABLE=1 \ 201 -DOPENTHREAD_PROJECT_CORE_CONFIG_FILE=\"openthread-core-posix-config.h\" \ 202 -std=c99 203EOF 204} 205 206####################################### 207# Check build with android build system 208# Globals: 209# None 210# Arguments: 211# None 212# Returns: 213# None 214####################################### 215main() 216{ 217 prepare_dbus 218 prepare_libmdnssd 219 prepare_openthread 220 221 make showcommands otbr-agent otbr-agent.conf 222 223 test -f out/target/product/generic/system/bin/otbr-agent 224 test -f out/target/product/generic/system/etc/dbus-1/system.d/otbr-agent.conf 225 226 [[ ${OTBR_MDNS} != mDNSResponder ]] || test out/target/product/generic/system/lib/libmdnssd.so 227} 228 229main "$@" 230