Files
Loongson_2k0300_SmartCar/pack_code.sh
T

54 lines
1.2 KiB
Bash

#!/bin/bash
# pack_code.sh — 将所有代码源文件打包为单个 txt
# 用法: bash pack_code.sh [输出文件名]
# 默认输出: smartcar2_code.txt
OUT="${1:-smartcar2_code.txt}"
> "$OUT"
# 分隔符
sep() { echo "" >> "$OUT"; echo "============================================================" >> "$OUT"; }
# 逐个追入,带文件路径头
append_file() {
local f="$1"
if [ ! -f "$f" ]; then return; fi
sep
echo "// FILE: $f" >> "$OUT"
sep
cat "$f" >> "$OUT"
}
# ── src/ 源文件 ──
for f in src/*.cpp src/*.hpp; do
[ -f "$f" ] && append_file "$f"
done
# ── lib/ 头文件 ──
for f in lib/*.h; do
[ -f "$f" ] && append_file "$f"
done
# ── main/ ──
append_file main/main.cpp
append_file main/CMakeLists.txt
# ── 顶层构建/配置 ──
append_file CMakeLists.txt
append_file cross.cmake
append_file ctl.sh
append_file start.sh
append_file .gitignore
# ── 独立 demo ──
append_file encoder_brake_demo.cpp
# ── 统计 ──
LINES=$(wc -l < "$OUT")
FILES=$(grep -c "// FILE:" "$OUT")
echo ""
echo "=== 打包完成 ==="
echo " 输出: $OUT"
echo " 文件数: $FILES"
echo " 总行数: $LINES"