split_lzo_lib.sh

split_lzo_lib.sh

 

#!/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 > $hname

 

split_lzop_bin2elf.sh

 

#!/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

 

posted @ 2019-03-29 20:29  阿C  阅读(123)  评论(0编辑  收藏  举报