Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / ot-br-posix / repo / tests / scripts / check-android-build
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
30 set -e
31 set -x
32
33 #######################################
34 # Prepare dbus source code
35 # Globals:
36 #   None
37 # Arguments:
38 #   None
39 # Returns:
40 #   None
41 #######################################
42 prepare_dbus()
43 {
44     DBUS_SOURCE=dbus-1.4.26
45     wget -nv "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
51 LOCAL_PATH:= \$(call my-dir)
52 include \$(CLEAR_VARS)
53
54 LOCAL_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
123 LOCAL_C_INCLUDES+= \$(LOCAL_PATH)/..
124
125 LOCAL_MODULE:=libdbus
126
127 DBUS_HEADERS := \$(wildcard \$(LOCAL_PATH)/*.h)
128 LOCAL_COPY_HEADERS := \$(DBUS_HEADERS:\$(LOCAL_PATH)/%=%)
129
130 LOCAL_COPY_HEADERS_TO := dbus
131
132 LOCAL_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
146 include \$(BUILD_SHARED_LIBRARY)
147 EOF
148 }
149
150 #######################################
151 # Prepare libmdns source code
152 # Globals:
153 #   None
154 # Arguments:
155 #   None
156 # Returns:
157 #   None
158 #######################################
159 prepare_libmdnssd()
160 {
161     readonly MDNSRESPONDER_SOURCE=mDNSResponder-878.30.4
162
163     [[ ${OTBR_MDNS} == mDNSResponder ]] || return 0
164
165     wget -nv "https://opensource.apple.com/tarballs/mDNSResponder/${MDNSRESPONDER_SOURCE}.tar.gz"
166     tar xvf "${MDNSRESPONDER_SOURCE}.tar.gz"
167     cat >"${MDNSRESPONDER_SOURCE}/Android.mk" <<EOF
168 LOCAL_PATH:= \$(call my-dir)
169
170 include \$(CLEAR_VARS)
171
172 LOCAL_SRC_FILES :=  \
173     mDNSShared/dnssd_clientlib.c  \
174     mDNSShared/dnssd_clientstub.c \
175     mDNSShared/dnssd_ipc.c \
176
177 LOCAL_MODULE := libmdnssd
178 LOCAL_MODULE_TAGS := eng
179
180 DBUS_HEADERS := \$(wildcard \$(LOCAL_PATH)/mDNSShared/*.h)
181 LOCAL_COPY_HEADERS := \$(DBUS_HEADERS:\$(LOCAL_PATH)/%=%)
182
183 LOCAL_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
184
185 include \$(BUILD_SHARED_LIBRARY)
186 EOF
187 }
188
189 prepare_openthread()
190 {
191     SRC_DIR="$(
192         cd "$(dirname "$0")"
193         pwd -P
194     )"
195     mkdir -p external
196     mv "${SRC_DIR}"/../../third_party/openthread/repo external/openthread
197     cat >>buildspec.mk <<EOF
198
199 USE_OTBR_DAEMON := 1
200 OTBR_ENABLE_ANDROID_MK := 1
201 OPENTHREAD_ENABLE_ANDROID_MK := 1
202 ANDROID_NDK := 1
203 OPENTHREAD_PROJECT_CFLAGS := \
204     -DOPENTHREAD_CONFIG_MLE_STEERING_DATA_SET_OOB_ENABLE=1 \
205     -DOPENTHREAD_CONFIG_FILE=\<openthread-config-android.h\> \
206     -DOPENTHREAD_PROJECT_CORE_CONFIG_FILE=\"openthread-core-posix-config.h\"
207 EOF
208 }
209
210 #######################################
211 # Check build with android build system
212 # Globals:
213 #   None
214 # Arguments:
215 #   None
216 # Returns:
217 #   None
218 #######################################
219 main()
220 {
221     prepare_dbus
222     prepare_libmdnssd
223     prepare_openthread
224
225     make showcommands otbr-agent otbr-agent.conf
226
227     test -f out/target/product/generic/system/bin/otbr-agent
228     test -f out/target/product/generic/system/etc/dbus-1/system.d/otbr-agent.conf
229 }
230
231 main "$@"