如何在Makefile中自动设置版本号?

时间:2015-09-01 13:29:09

标签: makefile debian packaging rpmbuild

我有一个Makefile,我用它来启动包构建工具。我在同一目录中有debian个文件和rpm个构建文件,我可以说build debbuild rpm并构建包。

现在,当我更新软件包时,我会根据需要调整源代码,并手动更新Makefile新版本号。我想自动化版本号,因为它很乏味但我不知道如何去做。

我的Makefile看起来像这样:

# a list of tools we depend on and must install if they're missing
DEBTOOLS=/usr/bin/debuild-pbuilder
RPMBUILD=/usr/bin/rpmbuild

# convenience target for "make deb"
deb: my-packages_1.1.1_all.deb

# check for the pbuilder package
/usr/bin/debuild-pbuilder:
    apt-get -y install pbuilder

# convenience target for "make rpm".  This should acctually be strutured to depend on the RPM file as "deb" does
rpm:
    my-package-1.1.1-Public.noarch.rpm

# the target package (on Ubuntu at least)
my-package_1.0_all.deb: $(DEBTOOLS)
    cd my-package; debuild-pbuilder -us -uc

my-package-1.1-Public.noarch.rpm: $(RPMBUILD) tar-source
    cd my-package-rpm; rpmbuild -bb SPECS/my-packages.spec

tar-source:
    tar -cvzf my-packages-1.1.1.tar.gz my-package-1.1.1/

2 个答案:

答案 0 :(得分:0)

我不知道rpm,但对于debian,你可以使用-v参数创建一个调用debchange的目标

未经测试的样本:

VERSION=`git describe`

bump-version:
            dch -v $(VERSION)

答案 1 :(得分:0)

您可以尝试使用以下内容来获取Debian版本字符串:

dpkg-parsechangelog --show-field Version

我不知道转速情况。