通过shell脚本生成C代码例程

通过shell脚本生成C代码例程:


#!/bin/sh

target=$1

BUILDER_VERSION_BRANCH=${VERSION_BRANCH}

BUILDER_VERSION_MAJOR=${VERSION_MAJOR}
BUILDER_VERSION_MINOR=${VERSION_MINOR}
BUILDER_VERSION_EXTRA=${VERSION_EXTRA}
BUILDER_VERSION_REVNO=${VERSION_REVNO}
BUILDER_VERSION_STAGE=${VERSION_STAGE}

BUILDER_CMPL_YEAR=`date +%Y | sed -e 's/^0//g'`
BUILDER_CMPL_MONTH=`date +%m | sed -e 's/^0//g'`
BUILDER_CMPL_DATE=`date +%d | sed -e 's/^0//g'`
BUILDER_CMPL_TIME="`date +%T`"

echo "/* Automatically generated file; DO NOT EDIT. */" > $target

echo "char *builder_version_branch(void)" >> $target
echo "{" >> $target
echo "   return \"${BUILDER_VERSION_BRANCH}\";" >> $target
echo "}" >> $target

echo "unsigned int builder_version_major(void)" >> $target
echo "{" >> $target
echo "  return ${BUILDER_VERSION_MAJOR};" >> $target
echo "}" >> $target

echo "unsigned int builder_version_minor(void)" >> $target
echo "{" >> $target
echo "  return ${BUILDER_VERSION_MINOR};" >> $target
echo "}" >> $target

echo "unsigned int builder_version_extra(void)" >> $target
echo "{" >> $target
echo "  return ${BUILDER_VERSION_EXTRA};" >> $target
echo "}" >> $target

echo "unsigned int builder_version_revno(void)" >> $target
echo "{" >> $target
echo "  return ${BUILDER_VERSION_REVNO};" >> $target
echo "}" >> $target

echo "char *builder_version_stage(void)" >> $target
echo "{" >> $target
echo "    return ${BUILDER_VERSION_STAGE};" >> $target
echo "}" >> $target

echo "unsigned int builder_cmpl_year(void)" >> $target
echo "{" >> $target
echo "  return ${BUILDER_CMPL_YEAR};" >> $target
echo "}" >> $target

echo "unsigned int builder_cmpl_month(void)" >> $target
echo "{" >> $target
echo "  return ${BUILDER_CMPL_MONTH};" >> $target
echo "}" >> $target

echo "unsigned int builder_cmpl_date(void)" >> $target
echo "{" >> $target
echo "  return ${BUILDER_CMPL_DATE};" >> $target
echo "}" >> $target

echo "char *builder_cmpl_time(void)" >> $target
echo "{" >> $target
echo "  return \"${BUILDER_CMPL_TIME}\";" >> $target
echo "}" >> $target

执行上面的shell。

./builder.sh abc.c

生成一下C代码:

/* Automatically generated file; DO NOT EDIT. */
char *builder_version_branch(void)
{
   return "";
}
unsigned int builder_version_major(void)
{
        return ;
}
unsigned int builder_version_minor(void)
{
        return ;
}
unsigned int builder_version_extra(void)
{
        return ;
}
unsigned int builder_version_revno(void)
{
        return ;
}
char *builder_version_stage(void)
{
    return ;
}
unsigned int builder_cmpl_year(void)
{
        return 2016;
}
unsigned int builder_cmpl_month(void)
{
        return 8;
}
unsigned int builder_cmpl_date(void)
{
        return 16;
}
char *builder_cmpl_time(void)
{
        return "10:26:48";
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值