• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# Copyright (C) 2021 Huawei Device Co., Ltd.
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# gcc-9 needed
16set -e
17
18ohos_root=$1
19ohos_hdc_build="ohos_hdc_build"
20cwddir=$(pwd)
21
22build_in_source=true
23[ "X$ohos_root" == "X" ] && build_in_source=false
24
25if [ "$build_in_source" == "true" ] ; then
26	ohos_root_real=$(realpath $ohos_root)
27fi
28
29[ "X$KEEP" == "X" ] && [ -d "$ohos_hdc_build" ] && rm -fr $ohos_hdc_build
30[ -d "$ohos_hdc_build" ] || mkdir $ohos_hdc_build
31
32STATICLIB=""
33INCLUDES=""
34
35function build_libusb ()
36{
37	libusb_install=$(realpath libusb)
38	[ "X$KEEP" == "X" ] && mkdir -pv ${libusb_install}/include && ln -svf /usr/include/libusb-1.0 ${libusb_install}/include/libusb
39	INCLUDES+="-I$(realpath ${libusb_install}/include) "
40}
41
42function build_openssl ()
43{
44	pushd third_party_openssl
45	[ "X$KEEP" == "X" ] && ./Configure no-shared linux-generic64 && make
46	STATICLIB+="$(realpath libcrypto.a) "
47	INCLUDES+="-I$(realpath include) "
48	popd
49}
50
51function build_libuv ()
52{
53	pushd third_party_libuv
54	[ "X$KEEP" == "X" ] && cmake . && make
55	STATICLIB+="$(realpath libuv_a.a) "
56	INCLUDES+="-I$(realpath include) "
57	popd
58}
59
60function build_securec ()
61{
62	pushd third_party_bounds_checking_function
63	[ "X$KEEP" == "X" ] && gcc src/*.c -I$(pwd)/include -c && ar rcs libsecurec.a *.o
64	STATICLIB+="$(realpath libsecurec.a) "
65	INCLUDES+="-I$(realpath include) "
66	popd
67}
68
69function build_lz4 ()
70{
71	pushd third_party_lz4
72	[ "X$KEEP" == "X" ] && make liblz4.a
73	STATICLIB+="$(realpath lib/liblz4.a) "
74	INCLUDES+="-I$(realpath lib) "
75	popd
76}
77
78function build_hdc ()
79{
80	pushd developtools_hdc
81	echo $STATICLIB
82	echo $INCLUDES
83
84	DEFINES="-DHDC_HOST -DHARMONY_PROJECT"
85	export LDFLAGS="-Wl,--copy-dt-needed-entries"
86	export CXXFLAGS="-std=c++17 -ggdb -O0"
87
88	g++ ${DEFINES} ${CXXFLAGS} ${INCLUDES} $(find src/common/ src/host/ \( -name "*.cpp" -or -name "*.c" \)) -lusb-1.0 -ldl -lpthread $STATICLIB -o hdc
89
90	if [ -f hdc ]; then
91		echo build success
92		cp hdc $cwddir
93	else
94		echo build fail
95	fi
96	popd
97}
98
99pushd $ohos_hdc_build
100
101if [ "X$KEEP" == "X" ]; then
102	for name in "developtools/hdc" "third_party/libuv" "third_party/openssl" "third_party/bounds_checking_function" "third_party/lz4"; do
103		reponame=$(echo $name | sed "s/\//_/g")
104		if [ "$build_in_source" == "true" ] ; then
105			cp -ra ${ohos_root_real}/${name} ${reponame} || exit 1
106		else
107			git clone https://gitee.com/openharmony/${reponame}
108		fi
109	done
110fi
111
112build_openssl
113build_libuv
114build_securec
115build_lz4
116build_libusb
117
118build_hdc
119
120popd
121