1e5b75505Sopenharmony_ci#!/bin/bash
2e5b75505Sopenharmony_ciset -e
3e5b75505Sopenharmony_ciROOT_DIR=$(dirname "$0")
4e5b75505Sopenharmony_ci
5e5b75505Sopenharmony_cistrip_and_copy_to()
6e5b75505Sopenharmony_ci{
7e5b75505Sopenharmony_ci    if [ "$3" == "clang" ];
8e5b75505Sopenharmony_ci    then
9e5b75505Sopenharmony_ci        $COMPILER_DIR/bin/llvm-strip $ROOT_DIR/build/$2
10e5b75505Sopenharmony_ci    else
11e5b75505Sopenharmony_ci        if [ "$4" == "linux" ];
12e5b75505Sopenharmony_ci        then
13e5b75505Sopenharmony_ci            arm-himix410-linux-strip $ROOT_DIR/build/$2
14e5b75505Sopenharmony_ci        else
15e5b75505Sopenharmony_ci             $ROOT_DIR/../../../prebuilts/gcc/linux-x86/arm/arm-linux-ohoseabi-gcc/bin/arm-linux-ohoseabi-strip $ROOT_DIR/build/$2
16e5b75505Sopenharmony_ci        fi
17e5b75505Sopenharmony_ci    fi
18e5b75505Sopenharmony_ci
19e5b75505Sopenharmony_ci    cp $ROOT_DIR/build/$2 $1
20e5b75505Sopenharmony_ci}
21e5b75505Sopenharmony_ci
22e5b75505Sopenharmony_cicopy_to()
23e5b75505Sopenharmony_ci{
24e5b75505Sopenharmony_ci    if [ -f $ROOT_DIR/build/$2 ];then
25e5b75505Sopenharmony_ci        mkdir -p $1/obj/third_party/wpa_supplicant/wpa_supplicant-2.9
26e5b75505Sopenharmony_ci        cp $ROOT_DIR/build/$2 $1/obj/third_party/wpa_supplicant/wpa_supplicant-2.9/
27e5b75505Sopenharmony_ci    fi
28e5b75505Sopenharmony_ci}
29e5b75505Sopenharmony_ci
30e5b75505Sopenharmony_cibuild_for_ndk()
31e5b75505Sopenharmony_ci{
32e5b75505Sopenharmony_ci    cp $ROOT_DIR/build/libwpa_client.so $1/ndk/sysroot/usr/lib
33e5b75505Sopenharmony_ci    cp $ROOT_DIR/build/libwpa.so $1/ndk/sysroot/usr/lib
34e5b75505Sopenharmony_ci    cp $ROOT_DIR/src/common/wpa_ctrl.h $1/ndk/sysroot/usr/include
35e5b75505Sopenharmony_ci}
36e5b75505Sopenharmony_ci
37e5b75505Sopenharmony_ci# LIB_TYPE: 0 is static library, 1 is sharedlibrary
38e5b75505Sopenharmony_ci# COMPILER_TYPE gcc or clang
39e5b75505Sopenharmony_cido_build()
40e5b75505Sopenharmony_ci{
41e5b75505Sopenharmony_ci    if [ -d "$ROOT_DIR/build/objs" ]; then
42e5b75505Sopenharmony_ci    rm -rf $ROOT_DIR/build/objs
43e5b75505Sopenharmony_ci    fi
44e5b75505Sopenharmony_ci    mkdir -p $ROOT_DIR/build/objs
45e5b75505Sopenharmony_ci
46e5b75505Sopenharmony_ci    make -C $ROOT_DIR/wpa_supplicant/ clean
47e5b75505Sopenharmony_ci    make DEPDIR=$1 COMPILER_TYPE=$3 LIB_TYPE=$2 DEBUG=$4 COMPILER_DIR=$5 KERNEL_TYPE=$6 -C $ROOT_DIR/wpa_supplicant/ -j
48e5b75505Sopenharmony_ci
49e5b75505Sopenharmony_ci    make -C $ROOT_DIR/hostapd/ clean
50e5b75505Sopenharmony_ci    make DEPDIR=$1 COMPILER_TYPE=$3 LIB_TYPE=$2 DEBUG=$4 COMPILER_DIR=$5 KERNEL_TYPE=$6 -C $ROOT_DIR/hostapd/ -j
51e5b75505Sopenharmony_ci
52e5b75505Sopenharmony_ci    make -C $ROOT_DIR/build/ clean
53e5b75505Sopenharmony_ci    make DEPDIR=$1 COMPILER_TYPE=$3 LIB_TYPE=$2 DEBUG=$4 COMPILER_DIR=$5 KERNEL_TYPE=$6 -C $ROOT_DIR/build/
54e5b75505Sopenharmony_ci
55e5b75505Sopenharmony_ci    if [ "$2" = 1 ]; then
56e5b75505Sopenharmony_ci        strip_and_copy_to $1 libwpa.so $3 $6
57e5b75505Sopenharmony_ci    else
58e5b75505Sopenharmony_ci        copy_to $1 libwpa.a
59e5b75505Sopenharmony_ci    fi
60e5b75505Sopenharmony_ci
61e5b75505Sopenharmony_ci    if [ "$2" = 1 ]; then
62e5b75505Sopenharmony_ci        make DEPDIR=DEPDIR=$1 COMPILER_TYPE=$3 LIB_TYPE=$2 DEBUG=$4 COMPILER_DIR=$5 KERNEL_TYPE=$6 -C $ROOT_DIR/wpa_supplicant/ libwpa_client.so -j
63e5b75505Sopenharmony_ci        strip_and_copy_to $1 libwpa_client.so $3 $6
64e5b75505Sopenharmony_ci    else
65e5b75505Sopenharmony_ci        make DEPDIR=DEPDIR=$1 COMPILER_TYPE=$3 LIB_TYPE=$2 DEBUG=$4 COMPILER_DIR=$5 KERNEL_TYPE=$6 -C $ROOT_DIR/wpa_supplicant/ libwpa_client.a -j
66e5b75505Sopenharmony_ci        copy_to $1 libwpa_client.a
67e5b75505Sopenharmony_ci    fi
68e5b75505Sopenharmony_ci}
69e5b75505Sopenharmony_ci
70e5b75505Sopenharmony_cimain()
71e5b75505Sopenharmony_ci{
72e5b75505Sopenharmony_ci    OUT_DIR=$1
73e5b75505Sopenharmony_ci    COMPILER_TYPE=$2
74e5b75505Sopenharmony_ci    NDK_FLAG=$3
75e5b75505Sopenharmony_ci    DEBUG=$4
76e5b75505Sopenharmony_ci    COMPILER_DIR=$5
77e5b75505Sopenharmony_ci    KERNEL_TYPE=$6
78e5b75505Sopenharmony_ci
79e5b75505Sopenharmony_ci    if [ "$4" == "debug" ]; then
80e5b75505Sopenharmony_ci        DEBUG=1
81e5b75505Sopenharmony_ci    else
82e5b75505Sopenharmony_ci        DEBUG=0
83e5b75505Sopenharmony_ci    fi
84e5b75505Sopenharmony_ci
85e5b75505Sopenharmony_ci    do_build $OUT_DIR 0 $COMPILER_TYPE $DEBUG $COMPILER_DIR $KERNEL_TYPE
86e5b75505Sopenharmony_ci    do_build $OUT_DIR 1 $COMPILER_TYPE $DEBUG $COMPILER_DIR $KERNEL_TYPE
87e5b75505Sopenharmony_ci
88e5b75505Sopenharmony_ci    if [ "$NDK_FLAG" = true ]; then
89e5b75505Sopenharmony_ci        build_for_ndk $OUT_DIR
90e5b75505Sopenharmony_ci    fi
91e5b75505Sopenharmony_ci}
92e5b75505Sopenharmony_ci
93e5b75505Sopenharmony_ciif [ "x" != "x$7" ]; then
94e5b75505Sopenharmony_ciexport SYSROOT_PATH=$7
95e5b75505Sopenharmony_cifi
96e5b75505Sopenharmony_ciif [ "x" != "x$8" ]; then
97e5b75505Sopenharmony_ciexport ARCH_CFLAGS="$8"
98e5b75505Sopenharmony_cifi
99e5b75505Sopenharmony_ci
100e5b75505Sopenharmony_cimain $1 $2 $3 $4 $5 $6
101