From 68d2c9ede68e29dafe06c3af561b195264614e5f Mon Sep 17 00:00:00 2001
From: Jan Lieskovsky <jlieskov@redhat.com>
Date: Thu, 26 Sep 2013 16:23:23 +0200
Subject: [PATCH] [Fedora] Introduce better rpm versioning scheme


Signed-off-by: Jan Lieskovsky <jlieskov@redhat.com>
---
 Fedora/scap-security-guide.spec |  6 +++--
 Makefile                        | 57 ++++++++++++++++++++++++++---------------
 2 files changed, 40 insertions(+), 23 deletions(-)

diff --git a/Fedora/scap-security-guide.spec b/Fedora/scap-security-guide.spec
index 2268a17..e91d955 100644
--- a/Fedora/scap-security-guide.spec
+++ b/Fedora/scap-security-guide.spec
@@ -5,14 +5,16 @@
 # file one level up - in the main scap-security-guide directory (instead of
 # this one).
 
+%global	fedorassgrelease	1
+
 Name:		scap-security-guide
 Version:	0.1
-Release:	1.fc19
+Release:	%{fedorassgrelease}%{?dist}
 Summary:	Security guidance and baselines in SCAP formats
 Group:		Applications/System
 License:	Public Domain
 URL:		https://fedorahosted.org/scap-security-guide/
-Source0:	http://fedorapeople.org/~jlieskov/%{name}-%{version}.tar.gz
+Source0:	http://fedorapeople.org/~jlieskov/%{name}-%{version}-%{fedorassgrelease}.tar.gz
 BuildRoot:	%(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
 BuildArch:	noarch
 BuildRequires:	coreutils, libxslt, expat, python, openscap-utils >= 0.9.1, python-lxml
diff --git a/Makefile b/Makefile
index 7f3dc95..260c833 100644
--- a/Makefile
+++ b/Makefile
@@ -10,12 +10,10 @@ PACKAGER := scap-security-guide
 ROOT_DIR ?= $(CURDIR)
 
 RPM_SPEC := $(ROOT_DIR)/scap-security-guide.spec
-FEDORA_SPEC := $(ROOT_DIR)/Fedora/scap-security-guide.spec
 
 TARBALL = $(RPM_TOPDIR)/SOURCES/$(PKG).tar.gz
 
 RPM_DEPS := tarball $(RPM_SPEC) Makefile
-FEDORA_RPM_DEPS := $(FEDORA_SPEC) Makefile
 
 RPM_TMPDIR ?= $(ROOT_DIR)/rpmbuild
 RPM_TOPDIR ?= $(RPM_TMPDIR)/src/redhat
@@ -26,6 +24,20 @@ MKDIR = test -d $(1) || mkdir -p $(1)
 
 RPMBUILD_ARGS := --define '_topdir $(RPM_TOPDIR)'  --define '_tmppath $(RPM_TMPDIR)'
 
+# Define Fedora specific variables below
+FEDORA_SPEC := $(ROOT_DIR)/Fedora/scap-security-guide.spec
+FEDORA_RPM_DEPS := $(FEDORA_SPEC) Makefile
+
+FEDORA_NAME := $(PKGNAME)
+FEDORA_VERSION := $(shell sed -ne 's/Version:\t\(.*\)/\1/p' $(FEDORA_SPEC))
+FEDORA_SSG_RELEASE := $(shell sed -ne 's/^\(.*\)\tfedorassgrelease\t\(.*\)/\2/p' $(FEDORA_SPEC))
+
+FEDORA_PKG := $(FEDORA_NAME)-$(FEDORA_VERSION)-$(FEDORA_SSG_RELEASE)
+FEDORA_TARBALL := $(RPM_TOPDIR)/SOURCES/$(FEDORA_PKG).tar.gz
+FEDORA_DIST := $(shell rpm --eval '%{dist}')
+
+# Define custom canned sequences / macros below
+
 define rpm-prep
 	$(call MKDIR,$(RPM_TMPDIR)/$(PKG))
 	$(call MKDIR,$(RPM_BUILDROOT))
@@ -37,6 +49,8 @@ define rpm-prep
 	$(call MKDIR,$(RPM_TOPDIR)/ZIP)
 endef
 
+# Define Makefile targets below
+
 all: rhel6 openstack rhevm3 rpm zipfile
 
 rhel6:
@@ -68,17 +82,21 @@ tarball:
 fedora-tarball:
 	$(call rpm-prep)
 
+	# rpm-prep creates $(RPM_TMPDIR)/$(PKG) => move it
+	# to proper Fedora package location first
+	mv $(RPM_TMPDIR)/$(PKG) $(RPM_TMPDIR)/$(FEDORA_PKG)
+
 	# Copy the source tree for Fedora content
-	cp -r Fedora $(RPM_TMPDIR)/$(PKG)
+	cp -r Fedora $(RPM_TMPDIR)/$(FEDORA_PKG)
 
-        # Don't trust the developers, clean out the build
-        # environment before packaging
-	cd $(RPM_TMPDIR)/$(PKG)/Fedora && $(MAKE) clean
+	# Don't trust the developers, clean out the build
+	# environment before packaging
+	cd $(RPM_TMPDIR)/$(FEDORA_PKG)/Fedora && $(MAKE) clean
 
-        # Create the source tar, copy it to $TARBALL
-        # (e.g. somewhere in the SOURCES directory)
-	cd $(RPM_TMPDIR) && tar -czf $(PKG).tar.gz $(PKG)
-	cp $(RPM_TMPDIR)/$(PKG).tar.gz $(TARBALL)
+	# Create the source tar, copy it to $TARBALL
+	# (e.g. somewhere in the SOURCES directory)
+	cd $(RPM_TMPDIR) && tar -czf $(FEDORA_PKG).tar.gz $(FEDORA_PKG)
+	cp $(RPM_TMPDIR)/$(FEDORA_PKG).tar.gz $(FEDORA_TARBALL)
 
 zipfile:
 	# Create a zipfile release, since many SCAP
@@ -106,16 +124,15 @@ srpm: $(RPM_DEPS)
 fedora-srpm: $(FEDORA_RPM_DEPS)
 	# Create the necessary directory structure
 	$(call rpm-prep)
-	# Obtain name, version, and source from Fedora's spec file
-	$(eval FEDORA_NAME := $(shell sed -ne 's/Name:\t\t\(.*\)/\1/p' $(FEDORA_SPEC)))
-	$(eval FEDORA_VERSION := $(shell sed -ne 's/Version:\t\(.*\)/\1/p' $(FEDORA_SPEC)))
+	# Obtain the source from Fedora's spec file
 	$(eval FEDORA_SOURCE := $(shell sed -ne 's/Source0:\t\(.*\)/\1/p' $(FEDORA_SPEC)))
-	# Substitute %{name} and %{version} with actual values
-	$(eval FEDORA_TARBALL := $(shell echo $(FEDORA_SOURCE) | sed -ne "s/%{name}/$(FEDORA_NAME)/p"))
-	$(eval FEDORA_TARBALL := $(shell echo $(FEDORA_TARBALL) | sed -ne "s/%{version}/$(FEDORA_VERSION)/p"))
+	# Substitute %{name}, %{version}, and %{fedorassgrelease} with their actual values
+	$(eval FEDORA_SOURCE := $(shell echo $(FEDORA_SOURCE) | sed -ne "s/%{name}/$(FEDORA_NAME)/p"))
+	$(eval FEDORA_SOURCE := $(shell echo $(FEDORA_SOURCE) | sed -ne "s/%{version}/$(FEDORA_VERSION)/p"))
+	$(eval FEDORA_SOURCE := $(shell echo $(FEDORA_SOURCE) | sed -ne "s/%{fedorassgrelease}/$(FEDORA_SSG_RELEASE)/p"))
 	# Download the tarball
 	@echo "Downloading the $(FEDORA_TARBALL) tarball..."
-	@wget -O $(TARBALL) $(FEDORA_TARBALL)
+	@wget -O $(FEDORA_TARBALL) $(FEDORA_SOURCE)
 	@echo "Copying $(FEDORA_SPEC) file to proper location..."
 	cat $(FEDORA_SPEC) > $(RPM_TOPDIR)/SPECS/$(notdir $(FEDORA_SPEC))
 	@echo "Building Fedora source $(PKGNAME) RPM package..."
@@ -126,10 +143,8 @@ rpm: srpm
 	 cd $(RPM_TOPDIR)/SRPMS && rpmbuild --rebuild --target=$(ARCH) $(RPMBUILD_ARGS) --buildroot $(RPM_BUILDROOT) -bb $(PKG)-$(RELEASE).src.rpm
 
 fedora-rpm: fedora-srpm
-	# Obtain Fedora package release from Fedora spec file
-	$(eval FEDORA_RELEASE := $(shell sed -ne 's/Release:\t\(.*\)/\1/p' $(FEDORA_SPEC)))
-	@echo "Building Fedora $(PKG) RPM package..."
-	cd $(RPM_TOPDIR)/SRPMS && rpmbuild --rebuild --target=$(ARCH) $(RPMBUILD_ARGS) --buildroot $(RPM_BUILDROOT) -bb $(PKG)-$(FEDORA_RELEASE).src.rpm
+	@echo "Building Fedora $(FEDORA_PKG) RPM package..."
+	cd $(RPM_TOPDIR)/SRPMS && rpmbuild --rebuild --target=$(ARCH) $(RPMBUILD_ARGS) --buildroot $(RPM_BUILDROOT) -bb $(FEDORA_PKG)$(FEDORA_DIST).src.rpm
 
 clean:
 	rm -rf $(RPM_TMPDIR)
-- 
1.7.11.7

