Files
open-im-server/scripts/build_all_service.sh
T

85 lines
2.8 KiB
Bash
Raw Normal View History

2023-06-30 23:22:58 +08:00
#!/usr/bin/env bash
2023-07-04 11:15:20 +08:00
# Copyright © 2023 OpenIM. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
2023-08-10 17:47:26 +08:00
# This script runs `make build` command.
# The command compiles all Makefile configs.
# Args:
# WHAT: Directory names to build. If any of these directories has a 'main'
2023-08-10 21:08:44 +08:00
# package, the build will produce executable files under $(OUT_DIR)/bin/platforms OR $(OUT_DIR)/bin—tools/platforms.
2023-08-10 17:47:26 +08:00
# If not specified, "everything" will be built.
2023-08-11 15:13:37 +08:00
# Usage: `scripts/build_all_service.sh`.
2023-08-10 17:47:26 +08:00
# Example: `hack/build-go.sh WHAT=cmd/kubelet`.
set -o errexit
set -o nounset
set -o pipefail
2023-07-10 14:56:52 +08:00
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
2023-08-10 17:47:26 +08:00
source "${OPENIM_ROOT}/scripts/lib/init.sh"
2023-07-10 14:56:52 +08:00
2023-07-13 17:07:42 +08:00
# CPU core number
# Check the system type
system_type=$(uname)
if [[ "$system_type" == "Darwin" ]]; then
# macOS (using sysctl)
cpu_count=$(sysctl -n hw.ncpu)
elif [[ "$system_type" == "Linux" ]]; then
# Linux (using lscpu)
cpu_count=$(lscpu --parse | grep -E '^([^#].*,){3}[^#]' | sort -u | wc -l)
else
echo "Unsupported operating system: $system_type"
exit 1
fi
2023-07-13 17:07:42 +08:00
echo -e "${GREEN_PREFIX}======> cpu_count=$cpu_count${COLOR_SUFFIX}"
2023-08-11 15:13:37 +08:00
openim::log::info "Building OpenIM, Parallel compilation compile=$cpu_count"
2023-07-13 17:07:42 +08:00
compile_count=$((cpu_count / 2))
2023-08-10 21:08:44 +08:00
# For help output
ARGHELP=""
if [[ "$#" -gt 0 ]]; then
ARGHELP="'$*'"
2023-07-12 19:21:55 +08:00
fi
2023-08-10 21:08:44 +08:00
openim::color::echo $COLOR_CYAN "NOTE: $0 has been replaced by 'make multiarch' or 'make build'"
echo
echo "The equivalent of this invocation is: "
echo " make build ${ARGHELP}"
2023-08-11 15:13:37 +08:00
echo " ./scripts/build_all_service.sh ${ARGHELP}"
2023-08-10 21:08:44 +08:00
echo
echo " Example: "
echo " Print a single binary:"
echo " make build BINS=openim-api"
2023-08-11 15:13:37 +08:00
echo " ./scripts/build_all_service.sh BINS=openim-api"
2023-08-10 21:08:44 +08:00
echo " Print : Enable debugging and logging"
echo " make build BINS=openim-api V=1 DEBUG=1"
2023-08-11 15:13:37 +08:00
echo " ./scripts/build_all_service.sh BINS=openim-api V=1 DEBUG=1"
2023-08-10 21:08:44 +08:00
echo
2023-08-11 15:13:37 +08:00
if [ -z "$*" ]; then
openim::log::info "no args, build all service"
make --no-print-directory -C "${OPENIM_ROOT}" -j$compile_count build
else
openim::log::info "build service: $*"
make --no-print-directory -C "${OPENIM_ROOT}" -j$compile_count build "$*"
fi
2023-08-10 21:08:44 +08:00
if [ $? -eq 0 ]; then
openim::log::success "all service build success, run 'make start' or './scripts/start_all.sh'"
2023-07-07 18:20:08 +08:00
else
2023-08-10 21:08:44 +08:00
openim::log::error "make build Error, script exits"
2023-07-07 18:20:08 +08:00
fi