split_lzo_lib.shui
#!/bin/sh
#輸入文件名
filename=$1
#分割文件大小
filesize=4096
#輸出庫文件名
libname="lib"$(echo $filename | tr . _)".a"
#輸出頭文件名
hname=$(echo $filename | tr . _ | awk '{print $0".h"}')
hdefine=$(echo ${hname}"_" | tr a-z A-Z | tr . _)
#echo $hname
#echo $hdefine
#echo $libname
#自動分割文件
echo split
split -a 2 -d -b $filesize $filename ${filename}"_"
#壓縮並刪除原文件
echo lzo
ls | grep ${filename}"_.." | awk '{print "minilzo-2.06.exe "$1"\r\nrm "$1}' | sh
#bin2elf
echo bin2elf
ls | grep ${filename}"_...lzo" | awk '{print "arm-none-eabi-objcopy -I binary -O elf32-littlearm -B arm --rename-section .data=.text "$1" "$1".o\r\nrm "$1}' | sh
#生成靜態庫文件
echo ar
ls | grep ${filename}"_...lzo.o" | awk '{print "arm-none-eabi-ar -rcs "libn" "$1"\r\nrm "$1}' libn=$libname | sh
#生成頭文件
echo .h
arm-none-eabi-nm $libname | awk -F ' T | A ' 'BEGIN{count=0}{if(count==0){print "#ifndef "hdef"\r\n#define "hdef;count=1}else if($2!=""){print "\textern uint32_t "$2";"}}END{print "\t#define LZO_OUT_LEN ("len")\n#endif"}' hdef=$hdefine len=$filesize > $hnameit
split_lzop_bin2elf.shio
#!/bin/sh
# 輸入文件名
filename=$1
# 分割文件大小
filesize=$2
# 輸出庫文件名
libname="lib"$(echo $filename | tr A-Z a-z)".a"
# 輸出頭文件名
hname=$(echo $filename | tr A-Z a-z | awk -F '.' '{print $1".h"}')
hdefine=$(echo ${hname}"_" | tr a-z A-Z | tr . _)
#echo $hname
#echo $hdefine
#echo $libname
# 自動分割文件
echo split
split -a 2 -d -b $filesize $filename ${filename}"_"
# 壓縮並刪除原文件
echo lzo
ls | grep ${filename}"_.." | awk '{print "lzop.exe -U -1 "$1" -o "$1".LZO"}' | sh
# bin2elf
echo bin2elf
# lzop自動把輸出文件名都變成了小寫
filename=$(echo $filename | tr A-Z a-z)
ls | grep ${filename}"_...lzo" | awk '{print "arm-none-eabi-objcopy -I binary -O elf32-littlearm -B arm --rename-section .data=.text "$1" "$1".o\r\nrm "$1}' | sh
# 生成靜態庫文件
echo ar
ls | grep ${filename}"_...lzo.o" | awk '{print "arm-none-eabi-ar -rcs "libn" "$1"\r\nrm "$1}' libn=$libname | sh
# 生成頭文件
echo .h
arm-none-eabi-nm $libname | awk -F ' T | A ' 'BEGIN{count=0}{if(count==0){print "#ifndef "hdef"\r\n#define "hdef;count=1}else if($2!=""){print "\textern uint32_t "$2";"}}END{print "#endif"}' hdef=$hdefine > $hname awk