Files
RTOS/tools/build_scripts/build_all.sh
T
root ca13734bf0 Add full automotive RTOS project
Add kernel (Cortex-M0/M3/M4, Tricore, S32K, RISC-V ports), drivers,
middleware (CAN stack, diagnostics, safety), applications, board
support, build/test tooling, and documentation.
2026-08-23 03:35:29 -04:00

213 lines
5.5 KiB
Bash
Executable File

#!/bin/bash
/**
* @file build_all.sh
* @brief Build all targets for Automotive RTOS
*/
set -e # Exit on error
# Script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
# Color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Build configuration
BUILD_DIR="${PROJECT_ROOT}/build"
LOG_DIR="${BUILD_DIR}/logs"
TARGETS=("stm32f407_discovery" "nxp_s32k144_evb" "custom_ecu")
BUILD_TYPES=("debug" "release")
# Create directories
mkdir -p "${BUILD_DIR}"
mkdir -p "${LOG_DIR}"
# Print banner
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN} Automotive RTOS Build System${NC}"
echo -e "${GREEN}========================================${NC}"
echo ""
# Function to build target
build_target() {
local target=$1
local build_type=$2
echo -e "${YELLOW}Building ${target} (${build_type})...${NC}"
local build_dir="${BUILD_DIR}/${target}/${build_type}"
mkdir -p "${build_dir}"
# Change to build directory
cd "${build_dir}"
# Run CMake
cmake "${PROJECT_ROOT}" \
-DTARGET_BOARD=${target} \
-DCMAKE_BUILD_TYPE=${build_type} \
-DCMAKE_TOOLCHAIN_FILE="${PROJECT_ROOT}/cmake/toolchain-${target}.cmake" \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
2>&1 | tee "${LOG_DIR}/${target}_${build_type}_configure.log"
# Build
make -j$(nproc) 2>&1 | tee "${LOG_DIR}/${target}_${build_type}_build.log"
# Check build result
if [ $? -eq 0 ]; then
echo -e "${GREEN}${target} (${build_type}) built successfully${NC}"
else
echo -e "${RED}${target} (${build_type}) build failed${NC}"
return 1
fi
# Generate artifacts
echo -e "${YELLOW}Generating artifacts...${NC}"
# Create hex file
arm-none-eabi-objcopy -O ihex "${build_dir}/automotive_rtos.elf" \
"${build_dir}/automotive_rtos.hex"
# Create binary file
arm-none-eabi-objcopy -O binary "${build_dir}/automotive_rtos.elf" \
"${build_dir}/automotive_rtos.bin"
# Generate size report
arm-none-eabi-size "${build_dir}/automotive_rtos.elf" > \
"${build_dir}/size_report.txt"
# Generate map file
arm-none-eabi-nm -n "${build_dir}/automotive_rtos.elf" > \
"${build_dir}/symbols.txt"
echo -e "${GREEN}✓ Artifacts generated${NC}"
echo ""
return 0
}
# Function to run tests
run_tests() {
echo -e "${YELLOW}Running unit tests...${NC}"
local test_dir="${BUILD_DIR}/tests"
mkdir -p "${test_dir}"
# Run each test
for test_file in "${PROJECT_ROOT}"/tests/unit/test_*.c; do
test_name=$(basename "${test_file}" .c)
echo -e " Testing ${test_name}..."
# Compile test
gcc -I"${PROJECT_ROOT}/kernel/include" \
-I"${PROJECT_ROOT}/tests" \
-I"${PROJECT_ROOT}/third_party/unity" \
"${test_file}" \
"${PROJECT_ROOT}/tests/unity/unity.c" \
-o "${test_dir}/${test_name}" \
-Wall -Wextra -g
# Run test
if "${test_dir}/${test_name}" > "${LOG_DIR}/${test_name}.log" 2>&1; then
echo -e "${GREEN}${test_name} passed${NC}"
else
echo -e "${RED}${test_name} failed${NC}"
cat "${LOG_DIR}/${test_name}.log"
return 1
fi
done
echo -e "${GREEN}✓ All tests passed${NC}"
echo ""
}
# Main build process
main() {
local build_failed=0
# Parse arguments
local clean_build=false
local run_all_tests=false
while [[ $# -gt 0 ]]; do
case $1 in
--clean)
clean_build=true
shift
;;
--test)
run_all_tests=true
shift
;;
--target)
TARGETS=("$2")
shift 2
;;
--type)
BUILD_TYPES=("$2")
shift 2
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
# Clean build if requested
if [ "${clean_build}" = true ]; then
echo -e "${YELLOW}Cleaning build directory...${NC}"
rm -rf "${BUILD_DIR}"
mkdir -p "${BUILD_DIR}"
echo -e "${GREEN}✓ Clean complete${NC}"
echo ""
fi
# Build all targets
for target in "${TARGETS[@]}"; do
for build_type in "${BUILD_TYPES[@]}"; do
if ! build_target "${target}" "${build_type}"; then
build_failed=1
fi
done
done
# Run tests if requested
if [ "${run_all_tests}" = true ]; then
if ! run_tests; then
build_failed=1
fi
fi
# Print summary
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN} Build Summary${NC}"
echo -e "${GREEN}========================================${NC}"
if [ ${build_failed} -eq 0 ]; then
echo -e "${GREEN}✓ All builds successful${NC}"
else
echo -e "${RED}✗ Some builds failed${NC}"
exit 1
fi
# Print size reports
echo ""
echo -e "${YELLOW}Size Reports:${NC}"
for target in "${TARGETS[@]}"; do
for build_type in "${BUILD_TYPES[@]}"; do
size_file="${BUILD_DIR}/${target}/${build_type}/size_report.txt"
if [ -f "${size_file}" ]; then
echo -e " ${target} (${build_type}):"
cat "${size_file}" | tail -n 2
fi
done
done
}
# Run main
main "$@"