suicmez/compile.sh

73 lines
2.1 KiB
Bash
Raw Normal View History

2025-12-17 13:16:53 +05:30
#!/bin/bash
# Simple helper script to compile Sui code and link with libsuicmez
2025-12-17 15:38:06 +05:30
DEBUG_FLAG=""
if [ "$1" = "--debug" ]; then
DEBUG_FLAG="--debug"
shift
fi
2025-12-17 15:45:13 +05:30
OPTIMIZE_FLAG=""
if [ "$1" = "--optimize" ]; then
OPTIMIZE_FLAG="-O3"
shift
fi
2025-12-17 13:16:53 +05:30
if [ $# -eq 0 ]; then
2025-12-17 15:45:13 +05:30
echo "Usage: ./compile.sh [--debug] [--optimize] <sui_source.sui> [output_name]"
2025-12-17 13:16:53 +05:30
echo ""
2025-12-17 15:38:06 +05:30
echo "Options:"
2025-12-17 15:45:13 +05:30
echo " --debug Generate debug printf statements in the C output"
echo " --optimize Compile with -O3 optimization"
2025-12-17 15:38:06 +05:30
echo ""
echo "Examples:"
2025-12-17 13:16:53 +05:30
echo " ./compile.sh tests/structs.sui"
2025-12-17 15:38:06 +05:30
echo " ./compile.sh --debug tests/structs.sui"
2025-12-17 15:45:13 +05:30
echo " ./compile.sh --optimize tests/structs.sui"
2025-12-17 13:16:53 +05:30
echo " ./compile.sh tests/structs.sui my_program"
exit 1
fi
INPUT_SUI="$1"
2025-12-17 15:38:06 +05:30
OUTPUT_NAME="${2:-${INPUT_SUI%.sui}}"
2025-12-17 13:16:53 +05:30
if [ ! -f "$INPUT_SUI" ]; then
echo "Error: File not found: $INPUT_SUI"
exit 1
fi
# Compile Sui to C
echo "Compiling $INPUT_SUI to C..."
2025-12-17 15:38:06 +05:30
if [ -n "$DEBUG_FLAG" ]; then
cargo run -- "$DEBUG_FLAG" "$INPUT_SUI" || exit 1
else
cargo run -- "$INPUT_SUI" || exit 1
fi
2025-12-17 13:16:53 +05:30
# Get the C file name (should be next to the .sui file)
C_FILE="${INPUT_SUI%.sui}.c"
OUTPUT_BINARY="${INPUT_SUI%.sui}.o"
if [ -n "$2" ]; then
OUTPUT_BINARY="$2"
fi
if [ ! -f "$C_FILE" ]; then
echo "Error: Generated C file not found: $C_FILE"
exit 1
fi
# Get raylib compile and link flags
RAYLIB_CFLAGS=$(pkg-config --cflags raylib 2>/dev/null || echo "-I/usr/include")
RAYLIB_LIBS=$(pkg-config --libs raylib 2>/dev/null || echo "-lraylib -lm")
# Get ODE compile and link flags
ODE_CFLAGS=$(pkg-config --cflags ode 2>/dev/null || echo "-I/usr/include")
ODE_LIBS=$(pkg-config --libs ode 2>/dev/null || echo "-lode -lm")
# Compile C to executable with raylib and ODE support
echo "Compiling C code and linking with libsuicmez, raylib, and ODE..."
2025-12-17 15:45:13 +05:30
gcc $OPTIMIZE_FLAG "$C_FILE" libsuicmez/libsuicmez.c libsuicmez/suicmez_gc.c $RAYLIB_CFLAGS $RAYLIB_LIBS $ODE_CFLAGS $ODE_LIBS -lm -o "$OUTPUT_BINARY" || exit 1
2025-12-17 13:16:53 +05:30
echo "✓ Successfully created: $OUTPUT_BINARY"
echo " Run with: ./$OUTPUT_BINARY"