bin2lib shell腳本

#!/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
#bin2elf
echo bin2elf
arm-none-eabi-objcopy -I binary -O elf32-littlearm -B arm --rename-section .data=.text $filename ${filename}".o"
#生成靜態庫文件
echo ar
ls | grep ${filename}".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 > $hnameui

相關文章
相關標籤/搜索