|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Copyright 2026-present Alibaba Inc. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +set -euo pipefail |
| 18 | + |
| 19 | +SOURCE_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) |
| 20 | +OUTPUT_DIR="$SOURCE_ROOT/output" |
| 21 | +BUILD_TYPE="release" |
| 22 | +BUILD_NAME="paimon-cpp" |
| 23 | +MAKE_CLEAN=false |
| 24 | +PACKAGE=false |
| 25 | +CMAKE_OPTIONS="" |
| 26 | + |
| 27 | +show_help() { |
| 28 | + cat << EOF |
| 29 | +Usage: $0 [options] [cmake_options...] |
| 30 | +
|
| 31 | +Options: |
| 32 | + -r, --release Build release version (default) |
| 33 | + -d, --debug Build debug version |
| 34 | + -c, --clean Clean build directory before building |
| 35 | + -p, --package Package creation |
| 36 | + -h, --help Show this help message |
| 37 | +
|
| 38 | +CMake Options: |
| 39 | + Any unrecognized options will be passed directly to CMake. |
| 40 | + You can specify multiple CMake options. |
| 41 | +
|
| 42 | +Examples: |
| 43 | + $0 -r -p -DPAIMON_BUILD_SHARED=ON -DPAIMON_BUILD_STATIC=OFF |
| 44 | + $0 --debug --clean --package |
| 45 | +
|
| 46 | +EOF |
| 47 | +} |
| 48 | + |
| 49 | +while [[ $# -gt 0 ]]; do |
| 50 | + case "$1" in |
| 51 | + -r|--release) |
| 52 | + BUILD_TYPE="Release" |
| 53 | + shift |
| 54 | + ;; |
| 55 | + -d|--debug) |
| 56 | + BUILD_TYPE="Debug" |
| 57 | + BUILD_NAME=$BUILD_NAME"-debug" |
| 58 | + shift |
| 59 | + ;; |
| 60 | + -c|--clean) |
| 61 | + MAKE_CLEAN=true |
| 62 | + shift |
| 63 | + ;; |
| 64 | + -p|--package) |
| 65 | + PACKAGE=true |
| 66 | + shift |
| 67 | + ;; |
| 68 | + -h|--help) |
| 69 | + show_help |
| 70 | + exit 0 |
| 71 | + ;; |
| 72 | + *) |
| 73 | + # All remaining parameters are CMake options |
| 74 | + CMAKE_OPTIONS="$CMAKE_OPTIONS $1" |
| 75 | + shift |
| 76 | + ;; |
| 77 | + esac |
| 78 | +done |
| 79 | + |
| 80 | +CMAKE_OPTIONS=$(echo "$CMAKE_OPTIONS" | xargs) |
| 81 | + |
| 82 | +echo "========== Build Configuration ==========" |
| 83 | +echo "Build Type: $BUILD_TYPE" |
| 84 | +echo "Package Name: $BUILD_NAME" |
| 85 | +echo "Clean Build: $MAKE_CLEAN" |
| 86 | +echo "Package: $PACKAGE" |
| 87 | +if [ -n "$CMAKE_OPTIONS" ]; then |
| 88 | + echo "CMake Options: $CMAKE_OPTIONS" |
| 89 | +else |
| 90 | + echo "CMake Options: None" |
| 91 | +fi |
| 92 | +echo "=========================================" |
| 93 | + |
| 94 | +echo "Step 1: Downloading dependencies..." |
| 95 | +"$SOURCE_ROOT"/third_party/download_dependencies.sh |
| 96 | + |
| 97 | +echo "Step 2: Building Paimon..." |
| 98 | +BUILD_DIR="$SOURCE_ROOT/build-$BUILD_TYPE" |
| 99 | +PACKAGE_DIR="$OUTPUT_DIR/$BUILD_NAME" |
| 100 | + |
| 101 | +if [ "$MAKE_CLEAN" = true ]; then |
| 102 | + rm -rf "$BUILD_DIR" |
| 103 | +fi |
| 104 | +mkdir -p "$BUILD_DIR" |
| 105 | +cd "$BUILD_DIR" |
| 106 | +CMAKE_ARGS=( |
| 107 | + -DCMAKE_BUILD_TYPE="$BUILD_TYPE" |
| 108 | + -DCMAKE_INSTALL_PREFIX="$PACKAGE_DIR" |
| 109 | +) |
| 110 | + |
| 111 | +if [ -n "$CMAKE_OPTIONS" ]; then |
| 112 | + CMAKE_ARGS+=("$CMAKE_OPTIONS") |
| 113 | +fi |
| 114 | + |
| 115 | +cmake "${CMAKE_ARGS[@]}" .. |
| 116 | + |
| 117 | +JOBS=$(nproc 2>/dev/null || echo 4) |
| 118 | +make -j"$JOBS" |
| 119 | + |
| 120 | +if [ "$PACKAGE" = true ]; then |
| 121 | + echo "Step 3: Packaging..." |
| 122 | + mkdir -p "$OUTPUT_DIR" |
| 123 | + cd "$BUILD_DIR" |
| 124 | + make install |
| 125 | + tar -czvf "$OUTPUT_DIR/$BUILD_NAME.tar.gz" -C "$OUTPUT_DIR" "$BUILD_NAME" |
| 126 | + echo "Package created: $OUTPUT_DIR/$BUILD_NAME.tar.gz" |
| 127 | +else |
| 128 | + echo "Step 3: Packaging skipped." |
| 129 | +fi |
0 commit comments