#!/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"
rm "$1}' libn=$libname | sh
#生成头文件
echo .h
arm-none-eabi-nm $libname | awk -F ' T | A ' 'BEGIN{count=0}{if(count==0){print "#ifndef "hdef"
#define "hdef;count=1}else if($2!=""){print " extern uint32_t "$2";"}}END{print "#endif"}' hdef=$hdefine > $hname