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. 14set -e 15PARAMS=$* 16echo $PARAMS 17echo "begin to check input" 18target_os='linux' 19target_dir='linux' 20gn_path='linux' 21is_debug='false' 22is_clean='false' 23target='trace_streamer' 24gn='gn' 25ninja='ninja' 26case "$OSTYPE" in 27 solaris*) echo "SOLARIS" ;; 28 darwin*) gn_path='macx' target_os='macx' ;; 29 linux*) gn_path='linux' target_os='linux' ;; 30 bsd*) echo "is bsd os" ;; 31 msys*) gn_path='windows' target_os='windows' gn='gn.exe' ninja='ninja.exe' ;; 32 *) echo "unknown: $OSTYPE" ;; 33esac 34usage="Usage: $basename $0 wasm/test/fuzz/protoc debug/release/clean" 35 36 37if [ "$1" == 'windows' ];then 38 echo "gn only support linux and wasm build currently" 39 if [ ! -d "out/windows" ];then 40 mkdir out/windows 41 fi 42 touch out/windows/trace_streamer.exe 43 exit 44fi 45 46if [ "$#" -ne "0" ];then 47 if [ "$1" == "wasm" ];then 48 if [ ! -d "prebuilts/emsdk" ];then 49 echo "you need emsdk to compile wasm" 50 #mv emsdk.tar.gz prebuilts/ 51 #mv ../emsdk.tar.gz prebuilts/ 52 if [ ! -f "prebuilts/emsdk.tar.gz" ];then 53 # consider <compile_trace_streamer.md> 54 # you need to get emsdk.tar.gz some where 55 mv emsdk.tar.gz prebuilts/ 56 tar -zxvf prebuilts/emsdk.tar.gz -C prebuilts/ 57 else 58 tar -zxvf prebuilts/emsdk.tar.gz -C prebuilts/ 59 fi 60 fi 61 target='wasm' 62 fi 63 if [ "$1" == "test" ];then 64 target='test' 65 fi 66 if [ "$1" == "fuzz" ];then 67 target='fuzz' 68 fi 69 if [ "$1" == "protoc" ];then 70 target='protoc' 71 fi 72 if [ "$1" == "sdkdemo" ];then 73 target='sdkdemo' 74 fi 75 if [ "$1" == "sdkdemotest" ];then 76 target='sdkdemotest' 77 fi 78fi 79if [ "$#" -eq "2" ];then 80 if [ "$1" != 'trace' ] && [ "$1" != "linux" ] && [ "$1" != "windows" ] && [ "$1" != "macx" ] && [ "$1" != "trace_streamer" ] && [ "$1" != "wasm" ] && [ "$1" != "test" ] && [ "$1" != "fuzz" ] && [ "$1" != "protoc" ];then 81 echo "failed" 82 echo "$usage" 83 exit 84 fi 85 if [ "$2" != "debug" -a "$2" != "release" -a "$2" != "clean" ];then 86 if [ "$2" == "protoc" ];then 87 target="$2" 88 else 89 echo "failed" 90 echo "$usage" 91 exit 92 fi 93 fi 94 if [ "$2" == "debug" ];then 95 is_debug='true' 96 elif [ "$2" == "clean" ];then 97 is_clean='true' 98 else 99 is_debug='false' 100 fi 101 echo "platform is $target_os" 102 echo "isdebug: $is_debug" 103 echo "isclean: $is_clean" 104else 105 echo "$usage" 106 echo "You provided $# parameters,but 2 are required." 107 echo "use default input paramter" 108 echo "platform is $target_os" 109 echo "target is $target" 110 echo "is_debug:$is_debug" 111fi 112echo "gen ..." 113ext="" 114if [ "$is_debug" != 'false' ];then 115 ext="_debug" 116fi 117#exec "protogen.sh" 118echo "the output file will be at ""$prefix""$target_os" 119echo "" 120echo "" 121echo "-------------tips-------------" 122echo "" 123echo "if you are compiling first time, or your proto has changed, you need to run ./src/protos/protogen.sh" 124echo "" 125echo "" 126echo 127#./src/protos/protogen.sh 128if [ ! -d "prebuilts/$gn_path" ];then 129 mkdir prebuilts/$gn_path 130fi 131if [ ! -f "prebuilts/$gn_path/gn" ];then 132 echo "you may get gn for $target_os and place it in prebuilts/$target_os" 133 echo "the file can be get at https://gitee.com/su_fu/public_tools/raw/master/gn/$target_os/gn, you need to download it manually" 134 #wget https://gitee.com/su_fu/public_tools/raw/master/gn/$target_os/gn 135 #mv gn prebuilts/$target_os/ 136 #chmod +x prebuilts/$target_os/gn 137 exit 138fi 139if [ ! -f "prebuilts/$gn_path/ninja" ];then 140 echo "you may get ninja for $target_os and place it in prebuilts/$target_os" 141 ehco "the file can be get at https://gitee.com/su_fu/public_tools/raw/master/gn/$target_os/ninja, you need to download it manually" 142 #wget "https://gitee.com/su_fu/public_tools/raw/master/gn/$target_os/ninja" 143 #wget https://gitee.com/su_fu/public_tools/raw/master/gn/$target_os/ninja 144 #mv ninja prebuilts/$target_os/ 145 #chmod +x prebuilts/$target_os/* 146 exit 147fi 148echo "$is_clean" 149if [ $target == 'test' ] || [ $target == 'fuzz' ] || [ $target='wasm' ] || [ $target='sdkdemo' ] || [ $target='sdkdemotest' ];then 150 target_dir=$target 151else 152 target_dir=$target_os 153fi 154if [ $target == 'trace_streamer' ] || [ $target == 'trace' ];then 155 target_dir=$target_os 156fi 157echo "target_dir:" $target_dir 158# exit 159if [ "$is_clean" == 'true' ];then 160 prebuilts/$gn_path/$gn gen out/"$target_dir""$ext" --clean 161 prebuilts/$gn_path/$ninja -C out/"$target_dir""$ext" -t clean 162else 163 prebuilts/$gn_path/$gn gen out/"$target_dir""$ext" --args='is_debug='"$is_debug"' target="'"$target"'" target_os="'"$target_os"'"' 164 echo "begin to build ..." 165 mkdir -p out/windows 166 touch out/windows/trace_streamer.exe 167 prebuilts/$gn_path/$ninja -C out/"$target_dir""$ext" 168 # prebuilts/$gn_path/ninja -C out/"$target_os""$ext" 169fi 170