This commit is contained in:
81
build.sh
81
build.sh
@@ -28,37 +28,60 @@ function die() {
|
||||
exit 1
|
||||
}
|
||||
|
||||
function build_for_arch() {
|
||||
# Arguments: <arch> <musl_path> <c_compiler> <cxx_compiler> <exe_linker_flags> <cxx_flags> <cmake_system_processor>
|
||||
local arch="$1"
|
||||
local musl_path="$2"
|
||||
local c_compiler="$3"
|
||||
local cxx_compiler="$4"
|
||||
local exe_linker_flags="$5"
|
||||
local cxx_flags="$6"
|
||||
local cmake_system_processor="$7"
|
||||
|
||||
echo "Building for $arch (musl)..."
|
||||
|
||||
local build_dir="build_${arch}"
|
||||
local cmake_args=(
|
||||
-B "$build_dir"
|
||||
-DCMAKE_BUILD_TYPE=Release
|
||||
"-DCMAKE_C_COMPILER=$musl_path/bin/$c_compiler"
|
||||
"-DCMAKE_CXX_COMPILER=$musl_path/bin/$cxx_compiler"
|
||||
-DCMAKE_EXE_LINKER_FLAGS="$exe_linker_flags"
|
||||
-DCMAKE_CXX_FLAGS="$cxx_flags"
|
||||
.
|
||||
)
|
||||
if [[ -n "$cmake_system_processor" ]]; then
|
||||
cmake_args+=("-DCMAKE_SYSTEM_PROCESSOR=$cmake_system_processor")
|
||||
fi
|
||||
|
||||
cmake "${cmake_args[@]}"
|
||||
cmake --build "$build_dir" --target simple_object_storage --config Release -j"$JOBS"
|
||||
mkdir -p "${EXE_DIR}"
|
||||
cp "$build_dir/${PROJECTNAME}" "${EXE_DIR}/${PROJECTNAME}.$arch"
|
||||
|
||||
echo "$arch executable built: ${PROJECTNAME}.$arch"
|
||||
}
|
||||
|
||||
function build_amd64() {
|
||||
# Build for amd64 (musl)
|
||||
echo "Building for amd64 (musl)..."
|
||||
|
||||
MUSLPATH="$HOME/.musl-cross/x86_64-linux-musl-cross"
|
||||
|
||||
cmake -B build_amd64 -DCMAKE_BUILD_TYPE=Release \
|
||||
"-DCMAKE_C_COMPILER=$MUSLPATH/bin/x86_64-linux-musl-gcc" \
|
||||
"-DCMAKE_CXX_COMPILER=$MUSLPATH/bin/x86_64-linux-musl-g++" \
|
||||
-DCMAKE_EXE_LINKER_FLAGS="-static" \
|
||||
-DCMAKE_CXX_FLAGS="-march=x86-64" .
|
||||
cmake --build build_amd64 --target simple_object_storage --config Release -j"$JOBS"
|
||||
mkdir -p "${EXE_DIR}"
|
||||
cp "build_amd64/${PROJECTNAME}" "${EXE_DIR}/${PROJECTNAME}.amd64"
|
||||
build_for_arch \
|
||||
"amd64" \
|
||||
"$HOME/.musl-cross/x86_64-linux-musl-cross" \
|
||||
"x86_64-linux-musl-gcc" \
|
||||
"x86_64-linux-musl-g++" \
|
||||
"-static" \
|
||||
"-march=x86-64" \
|
||||
""
|
||||
}
|
||||
|
||||
function build_arm64() {
|
||||
# Build for arm64 (musl)
|
||||
echo "Building for arm64 (musl)..."
|
||||
|
||||
MUSLPATH="$HOME/.musl-cross/aarch64-linux-musl-cross"
|
||||
|
||||
cmake -B build_arm64 -DCMAKE_BUILD_TYPE=Release \
|
||||
"-DCMAKE_C_COMPILER=$MUSLPATH/bin/aarch64-linux-musl-gcc" \
|
||||
"-DCMAKE_CXX_COMPILER=$MUSLPATH/bin/aarch64-linux-musl-g++" \
|
||||
-DCMAKE_EXE_LINKER_FLAGS="-static" \
|
||||
-DCMAKE_CXX_FLAGS="-march=armv8-a" \
|
||||
-DCMAKE_SYSTEM_PROCESSOR=aarch64 .
|
||||
cmake --build build_arm64 --target simple_object_storage --config Release -j"$JOBS"
|
||||
mkdir -p "${EXE_DIR}"
|
||||
cp "build_arm64/${PROJECTNAME}" "${EXE_DIR}/${PROJECTNAME}.arm64"
|
||||
build_for_arch \
|
||||
"arm64" \
|
||||
"$HOME/.musl-cross/aarch64-linux-musl-cross" \
|
||||
"aarch64-linux-musl-gcc" \
|
||||
"aarch64-linux-musl-g++" \
|
||||
"-static" \
|
||||
"-march=armv8-a" \
|
||||
"aarch64"
|
||||
}
|
||||
|
||||
#--------------------------------
|
||||
@@ -74,15 +97,11 @@ mkdir -p "${EXE_DIR}"
|
||||
BUILDSTR="${1:-amd64}"
|
||||
|
||||
if [ "$BUILDSTR" = "all" ] || [ "$BUILDSTR" = "arm64" ]; then
|
||||
title "Building linux-arm64 executable"
|
||||
build_arm64 || die "Failed to build linux-arm64 executable"
|
||||
echo "arm64 executable: ./simple_object_storage-linux-arm64"
|
||||
fi
|
||||
|
||||
if [ "$BUILDSTR" = "all" ] || [ "$BUILDSTR" = "amd64" ]; then
|
||||
title "Building linux-x86_64 executable"
|
||||
build_amd64 || die "Failed to build linux-x86_64 executable"
|
||||
echo "amd64 executable: ./simple_object_storage-linux-amd64"
|
||||
fi
|
||||
|
||||
echo "Build completed successfully!"
|
||||
|
Reference in New Issue
Block a user