4coder/build_new/scripts/build-libs.sh

80 lines
2.5 KiB
Bash
Executable File

#!/bin/bash
# =============================================================================
# Configuration
# =============================================================================
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CONFIG_DIR="$SCRIPT_DIR/../config"
# Source configuration files
source "$CONFIG_DIR/build-config.sh"
source "$HELPERS_DIR/print-routines.sh"
# =============================================================================
# Build Tree Sitter
# =============================================================================
build_tree_sitter() {
BIN_NAME="custom_4coder"
CUSTOM_ROOT="$FOREIGN_DIR/tree-sitter"
INCLUDES=(
"-I$CUSTOM_ROOT/lib/src"
"-I$CUSTOM_ROOT/lib/include"
)
CLANG_OPTS=(
"-c" # Compile, don't link
"-O2" # Compile in release, regardless of 4coder build mode
"-g" # Debug info
)
TEMP_OUT_DIR=$BUILD_TEMP_DIR/tree-sitter
mkdir -p $TEMP_OUT_DIR
# Build tree-sitter.lib/.a
print_step "Building tree-sitter lib"
clang $CLANG_OPTS "${INCLUDES[@]}" "$CUSTOM_ROOT/lib/src/lib.c" -o $TEMP_OUT_DIR/tree-sitter.o
print_success "Complete"
# Lang: C++ (This needs to be two calls to clang so that you can specify the obj file names)
print_step "Building tree-sitter C++ Language Lib"
clang $CLANG_OPTS "${INCLUDES[@]}" "${CUSTOM_ROOT}/lang/cpp/parser.c" -o $TEMP_OUT_DIR/cpp_parser.o
clang $CLANG_OPTS "${INCLUDES[@]}" "${CUSTOM_ROOT}/lang/cpp/scanner.cc" -o $TEMP_OUT_DIR/cpp_scanner.o
print_success "Complete"
# Lang: C
print_step "Building tree-sitter C Language Lib"
clang $CLANG_OPTS "${INCLUDES[@]}" "${CUSTOM_ROOT}/lang/c/parser.c" -o $TEMP_OUT_DIR/c_parser.o
print_success "Complete"
# Link tree-sitter lib and parser obj files into a static library to link into main custom dll
print_step "Linking tree-sitter static library"
ar rcs $BUILD_TEMP_DIR/tree-sitter.a $TEMP_OUT_DIR/*.o
print_success "Completed"
}
# =============================================================================
# Main
# =============================================================================
main() {
local config="${1:-debug}"
local arch="${2:-x64}"
print_step "macOS Build Process"
print_info "Configuration: $config"
print_info "Architecture: $arch"
# Create build directory
mkdir -p "$BUILD_DIR"
# Execute build steps
build_tree_sitter
}
# Only run main if script is executed directly (not sourced)
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
main "$@"
fi