Jim Meyering
2008-Jun-16 19:16 UTC
[Ovirt-devel] [PATCH] factor common variable definitions and rules out of Makefiles
The following two patches factor out the guts of ovirt-host-creator/Makefile and wui/Makefile into the new file, common/release.mk. The first change-set merely moves things around so the part to be factored out is all together, plus the sole change: s/NAME/package/. The second change removes the common code into common/release.mk, adds the "include...", and adds a .PHONY: directive. That latter makes it so the presence of a file named e.g., "all" won't keep "make all" from working. This pair of change-sets applies on top of my series of four from yesterday.>From 19c22e8cd8efad5366950691956948462f016e03 Mon Sep 17 00:00:00 2001Date: Mon, 16 Jun 2008 20:43:35 +0200 Subject: [PATCH] */Makefile: prepare to factor out duplicate code --- ovirt-host-creator/Makefile | 22 +++++++++++----------- wui/Makefile | 22 +++++++++++----------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/ovirt-host-creator/Makefile b/ovirt-host-creator/Makefile index 322d95e..4611d17 100644 --- a/ovirt-host-creator/Makefile +++ b/ovirt-host-creator/Makefile @@ -9,21 +9,18 @@ GITRELEASE = $(X).$$(date --utc +%Y%m%d%H%M)git$(git_head) DIST = $$(rpm --eval '%{dist}') ARCH = $$(uname -i) -NAME = ovirt-host-image -SPEC_FILE = $(NAME).spec +SPEC_FILE = $(package).spec -NV = $(NAME)-$(VERSION) +NV = $(package)-$(VERSION) RPM_FLAGS = \ --define "_topdir %(pwd)/rpm-build" \ --define "_builddir %{_topdir}" \ --define "_rpmdir %{_topdir}" \ --define "_srcrpmdir %{_topdir}" \ - --define '_rpmfilename %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm' \ + --define '_rpmfilename %%{package}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm' \ --define "_specdir %{_topdir}" \ --define "_sourcedir %{_topdir}" -all: rpms - bumpgit: echo "$(VERSION) $(GITRELEASE)" > version @@ -36,6 +33,14 @@ bumpversion: setversion: echo "$(VERSION) $(RELEASE)" > version +new-rpms: bumprelease rpms + +rpms: tar + rpmbuild $(RPM_FLAGS) -ba $(SPEC_FILE) + +package = ovirt-host-image +all: rpms + clean: rm -rf ovirt-host-image-* ovirt-pxe.log @@ -54,8 +59,3 @@ tar: clean build tar zcvf rpm-build/$(NV).tar $(NV) cp version rpm-build/ rm -rf $(NV) - -new-rpms: bumprelease rpms - -rpms: tar - rpmbuild $(RPM_FLAGS) -ba $(SPEC_FILE) diff --git a/wui/Makefile b/wui/Makefile index 71239ab..86d547a 100644 --- a/wui/Makefile +++ b/wui/Makefile @@ -9,21 +9,18 @@ GITRELEASE = $(X).$$(date --utc +%Y%m%d%H%M)git$(git_head) DIST = $$(rpm --eval '%{dist}') ARCH = $$(uname -i) -NAME = ovirt-wui -SPEC_FILE = $(NAME).spec +SPEC_FILE = $(package).spec -NV = $(NAME)-$(VERSION) +NV = $(package)-$(VERSION) RPM_FLAGS = \ --define "_topdir %(pwd)/rpm-build" \ --define "_builddir %{_topdir}" \ --define "_rpmdir %{_topdir}" \ --define "_srcrpmdir %{_topdir}" \ - --define '_rpmfilename %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm' \ + --define '_rpmfilename %%{package}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm' \ --define "_specdir %{_topdir}" \ --define "_sourcedir %{_topdir}" -all: rpms - bumpgit: echo "$(VERSION) $(GITRELEASE)" > version @@ -36,6 +33,14 @@ bumpversion: setversion: echo "$(VERSION) $(RELEASE)" > version +new-rpms: bumprelease rpms + +rpms: tar + rpmbuild $(RPM_FLAGS) -ba $(SPEC_FILE) + +package = ovirt-wui +all: rpms + clean: rm -f ovirt*.gz ovirt*.rpm rm -rf ovirt-wui-* dist build @@ -53,11 +58,6 @@ tar: clean cp version rpm-build/ rm -rf $(NV) -new-rpms: bumprelease rpms - -rpms: tar - rpmbuild $(RPM_FLAGS) -ba $(SPEC_FILE) - # convience method to simulate make install, not for production use install: rpms rpm -Uvh rpm-build/ovirt-wui-$(VERSION)-$(RELEASE)$(DIST).$(ARCH).rpm --force -- 1.5.6.rc3.9.gac038>From d8ab35f63fdff24736f0b37f78c3db23bdf138c9 Mon Sep 17 00:00:00 2001Date: Mon, 16 Jun 2008 21:08:39 +0200 Subject: [PATCH] factor common variable definitions and rules out of Makefiles * common/release.mk: New file, factored out of... * ovirt-host-creator/Makefile: ...here, and... * wui/Makefile: ...here. --- common/release.mk | 47 +++++++++++++++++++++++++++++++++++++++++++ ovirt-host-creator/Makefile | 44 +++------------------------------------ wui/Makefile | 44 +++------------------------------------ 3 files changed, 55 insertions(+), 80 deletions(-) create mode 100644 common/release.mk diff --git a/common/release.mk b/common/release.mk new file mode 100644 index 0000000..72e04d0 --- /dev/null +++ b/common/release.mk @@ -0,0 +1,47 @@ +# Release/version-related Makefile variables and rules. +# This Makefile snippet is included by both ../wui/Makefile and +# ../ovirt-host-creator/Makefile. It expects the including Makefile +# to define the "package" variable, as well as a file named "version" +# in the current directory. + +VERSION := $(shell awk '{ print $$1 }' version) +RELEASE := $(shell awk '{ print $$2 }' version) +NEWVERSION = $$(awk 'BEGIN { printf "%.2f", $(VERSION) + .01 }') +NEWRELEASE = $$(($(RELEASE) + 1)) +X = $$(awk '{ split($$2,r,"."); \ + printf("%d.%d\n", r[1], r[2]+1) }' version) +git_head = $$(git show-ref --hash=7 HEAD) +GITRELEASE = $(X).$$(date --utc +%Y%m%d%H%M)git$(git_head) +DIST = $$(rpm --eval '%{dist}') +ARCH = $$(uname -i) + +SPEC_FILE = $(package).spec + +NV = $(package)-$(VERSION) +RPM_FLAGS = \ + --define "_topdir %(pwd)/rpm-build" \ + --define "_builddir %{_topdir}" \ + --define "_rpmdir %{_topdir}" \ + --define "_srcrpmdir %{_topdir}" \ + --define '_rpmfilename %%{package}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm' \ + --define "_specdir %{_topdir}" \ + --define "_sourcedir %{_topdir}" + +bumpgit: + echo "$(VERSION) $(GITRELEASE)" > version + +bumprelease: + echo "$(VERSION) $(NEWRELEASE)" > version + +bumpversion: + echo "$(NEWVERSION) 0" > version + +setversion: + echo "$(VERSION) $(RELEASE)" > version + +new-rpms: bumprelease rpms + +rpms: tar + rpmbuild $(RPM_FLAGS) -ba $(SPEC_FILE) + +.PHONY: rpms new-rpms setversion bumprelease bumpversion bumpgit diff --git a/ovirt-host-creator/Makefile b/ovirt-host-creator/Makefile index 4611d17..6b26654 100644 --- a/ovirt-host-creator/Makefile +++ b/ovirt-host-creator/Makefile @@ -1,45 +1,7 @@ -VERSION := $(shell awk '{ print $$1 }' version) -RELEASE := $(shell awk '{ print $$2 }' version) -NEWVERSION = $$(awk 'BEGIN { printf "%.2f", $(VERSION) + .01 }') -NEWRELEASE = $$(($(RELEASE) + 1)) -X = $$(awk '{ split($$2,r,"."); \ - printf("%d.%d\n", r[1], r[2]+1) }' version) -git_head = $$(git show-ref --hash=7 HEAD) -GITRELEASE = $(X).$$(date --utc +%Y%m%d%H%M)git$(git_head) -DIST = $$(rpm --eval '%{dist}') -ARCH = $$(uname -i) +package = ovirt-host-image -SPEC_FILE = $(package).spec - -NV = $(package)-$(VERSION) -RPM_FLAGS = \ - --define "_topdir %(pwd)/rpm-build" \ - --define "_builddir %{_topdir}" \ - --define "_rpmdir %{_topdir}" \ - --define "_srcrpmdir %{_topdir}" \ - --define '_rpmfilename %%{package}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm' \ - --define "_specdir %{_topdir}" \ - --define "_sourcedir %{_topdir}" - -bumpgit: - echo "$(VERSION) $(GITRELEASE)" > version - -bumprelease: - echo "$(VERSION) $(NEWRELEASE)" > version - -bumpversion: - echo "$(NEWVERSION) 0" > version - -setversion: - echo "$(VERSION) $(RELEASE)" > version - -new-rpms: bumprelease rpms - -rpms: tar - rpmbuild $(RPM_FLAGS) -ba $(SPEC_FILE) - -package = ovirt-host-image all: rpms +include ../common/release.mk clean: rm -rf ovirt-host-image-* ovirt-pxe.log @@ -59,3 +21,5 @@ tar: clean build tar zcvf rpm-build/$(NV).tar $(NV) cp version rpm-build/ rm -rf $(NV) + +.PHONY: all clean build tar diff --git a/wui/Makefile b/wui/Makefile index 86d547a..6120129 100644 --- a/wui/Makefile +++ b/wui/Makefile @@ -1,45 +1,7 @@ -VERSION := $(shell awk '{ print $$1 }' version) -RELEASE := $(shell awk '{ print $$2 }' version) -NEWVERSION = $$(awk 'BEGIN { printf "%.2f", $(VERSION) + .01 }') -NEWRELEASE = $$(($(RELEASE) + 1)) -X = $$(awk '{ split($$2,r,"."); \ - printf("%d.%d\n", r[1], r[2]+1) }' version) -git_head = $$(git show-ref --hash=7 HEAD) -GITRELEASE = $(X).$$(date --utc +%Y%m%d%H%M)git$(git_head) -DIST = $$(rpm --eval '%{dist}') -ARCH = $$(uname -i) +package = ovirt-wui -SPEC_FILE = $(package).spec - -NV = $(package)-$(VERSION) -RPM_FLAGS = \ - --define "_topdir %(pwd)/rpm-build" \ - --define "_builddir %{_topdir}" \ - --define "_rpmdir %{_topdir}" \ - --define "_srcrpmdir %{_topdir}" \ - --define '_rpmfilename %%{package}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm' \ - --define "_specdir %{_topdir}" \ - --define "_sourcedir %{_topdir}" - -bumpgit: - echo "$(VERSION) $(GITRELEASE)" > version - -bumprelease: - echo "$(VERSION) $(NEWRELEASE)" > version - -bumpversion: - echo "$(NEWVERSION) 0" > version - -setversion: - echo "$(VERSION) $(RELEASE)" > version - -new-rpms: bumprelease rpms - -rpms: tar - rpmbuild $(RPM_FLAGS) -ba $(SPEC_FILE) - -package = ovirt-wui all: rpms +include ../common/release.mk clean: rm -f ovirt*.gz ovirt*.rpm @@ -61,3 +23,5 @@ tar: clean # convience method to simulate make install, not for production use install: rpms rpm -Uvh rpm-build/ovirt-wui-$(VERSION)-$(RELEASE)$(DIST).$(ARCH).rpm --force + +.PHONY: all clean genlangs tar install -- 1.5.6.rc3.9.gac038