FFmpeg更改文件名, 文件名最终格式:libavutil_avutil.h
脚本存放目录:
目录:change_name.shthininclude libavcodeclibavfilterlibavformat.....libs
#!/bin/shTHIN=$(pwd)/"thin"echo "Renaming header files and updating includes"
INCLUDE_DIR="$THIN/include"
MODULES="libavcodec libavfilter libavformat libavutil libswresample libswscale"# 临时存储重命名文件映射
RENAME_MAP=$(mktemp)# Step 1: Rename header files
for MODULE in $MODULES
doif [ -d "$INCLUDE_DIR/$MODULE" ]; thencd "$INCLUDE_DIR/$MODULE"for HEADER in *.hdoif [ -f "$HEADER" ]; then# Skip if file is already renamedif [[ "$HEADER" != ${MODULE}_* ]]; thenNEW_NAME="${MODULE}_${HEADER}"mv "$HEADER" "$NEW_NAME"echo "$MODULE/$HEADER,$NEW_NAME" >> "$RENAME_MAP"echo "Renamed $HEADER to $NEW_NAME"fifidonefi
done# Step 2: Scan and update includes
for MODULE in $MODULES
doif [ -d "$INCLUDE_DIR/$MODULE" ]; thencd "$INCLUDE_DIR/$MODULE"for FILE in *.hdoif [ -f "$FILE" ]; then# Read file and replace #include directivesTEMP_FILE="${FILE}.tmp"while IFS= read -r LINEdoif echo "$LINE" | grep -qE '^#include ".*"'; thenINCLUDE_PATH=$(echo "$LINE" | sed -E 's/^#include "(.*)"/\1/')if echo "$INCLUDE_PATH" | grep -q "/"; then# 包含路径的 #includeMODULE_PATH=$(dirname "$INCLUDE_PATH")BASE_NAME=$(basename "$INCLUDE_PATH")RENAMED_FILE=$(grep "^$MODULE_PATH/$BASE_NAME," "$RENAME_MAP" | cut -d',' -f2)if [ -n "$RENAMED_FILE" ]; thenNEW_INCLUDE="$MODULE_PATH/$RENAMED_FILE"LINE=$(printf '%s' "$LINE" | sed "s#\"$INCLUDE_PATH\"#\"$NEW_INCLUDE\"#")echo "Updated include with path in $FILE: $INCLUDE_PATH -> $NEW_INCLUDE"fielse# 不包含路径的 #includeRENAMED_FILE=$(grep "^$MODULE/$INCLUDE_PATH," "$RENAME_MAP" | cut -d',' -f2)if [ -n "$RENAMED_FILE" ]; thenNEW_INCLUDE="$RENAMED_FILE"LINE=$(printf '%s' "$LINE" | sed "s#\"$INCLUDE_PATH\"#\"$NEW_INCLUDE\"#")echo "Updated local include in $FILE: $INCLUDE_PATH -> $NEW_INCLUDE"fififiecho "$LINE" >> "$TEMP_FILE"done < "$FILE"mv "$TEMP_FILE" "$FILE"fidonefi
done# 清理临时文件
rm "$RENAME_MAP"echo "Header renaming and include updates complete!"