Index: kernel-2.6.spec
===================================================================
RCS file: /cvs/pkgs/rpms/kernel/devel/kernel-2.6.spec,v
retrieving revision 1.3245
diff -u -p -r1.3245 kernel-2.6.spec
--- kernel-2.6.spec	2 Jul 2007 17:07:41 -0000	1.3245
+++ kernel-2.6.spec	2 Jul 2007 20:17:31 -0000
@@ -1,5 +1,50 @@
 Summary: The Linux kernel (the core of the Linux operating system)
 
+# For a stable, released kernel, released_kernel should be 1. For rawhide and/or
+# a kernel built from an rc or git snapshot, released_kernel should be 0.
+%define released_kernel 0
+
+# Versions of various parts
+
+# Polite request for people who spin their own kernel rpms:
+# please modify the "buildid" define in a way that identifies
+# that the kernel isn't the stock distribution kernel, for example,
+# by setting the define to ".local" or ".bz123456"
+#
+#% define buildid .local
+
+# fedora_build defines which build revision of this kernel version we're building. In the
+# non-kernel world, this is analogous to the Release: field, and is formatted similarly.
+%define fedora_build 1%{?dist}
+
+# base_sublevel is the kernel version we're starting with and patching
+# on top of -- for example, 2.6.22-rc7-git1 starts with a 2.6.21 base,
+# which yields a base_sublevel of 21.
+%define base_sublevel 21
+
+# If this is a released kernel
+%if %{released_kernel}
+# Do we have a 2.6.21.y update to apply?
+%define stable_update 5
+# Set rpm version accordingly
+%if 0%{stable_update}
+%define stablerev .%{stable_update}
+%endif
+%define rpmversion 2.6.%{base_sublevel}%{stablerev}
+
+# The not-released-kernel case
+%else
+# The next upstream release sublevel
+%define upstream_sublevel 22
+# The rc snapshot level
+%define rcrev 7
+# The git snapshot level
+%define gitrev 0
+# Set rpm version accordingly
+%define rpmversion 2.6.%{upstream_sublevel}
+%endif
+# Nb: The above rcrev and gitrev values automagically define Patch00 and Patch01 below.
+
 # What parts do we want to build?  We must build at least one kernel.
 # These are the kernels that are built IF the architecture allows it.
 # All should default to 1 (enabled) and be flipped to 0 (disabled)
@@ -54,23 +99,25 @@ Summary: The Linux kernel (the core of t
 # See also 'make debug' and 'make release'.
 %define debugbuildsenabled 0
 
-%if ! %{debugbuildsenabled}
-%define with_debug 0
+# Want to build a vanilla kernel build without any non-upstream patches?
+# (well, almost none, we need nonintconfig for build purposes). Default to 0 (off).
+%define with_vanilla %{?_with_vanilla: 1} %{?!_with_vanilla: 0}
+
+# pkg_release is what we'll fill in for the rpm Release: field
+%if %{released_kernel}
+%define pkg_release %{fedora_build}%{?buildid}
+%else
+%if 0%{?rcrev}
+%define rctag .rc%rcrev
+%if 0%{?gitrev}
+%define gittag .git%gitrev
+%endif
+%endif
+%define pkg_release 0%{?rctag}%{?gittag}.%{fedora_build}%{?buildid}
 %endif
 
-# Versions of various parts
-
-# Polite request for people who spin their own kernel rpms:
-# please modify the "buildid" define in a way that identifies
-# that the kernel isn't the stock distribution kernel, for example,
-# by setting the define to ".local" or ".bz123456"
-#
-#% define buildid .local
-%define sublevel 21
-%define kversion 2.6.%{sublevel}
-%define rpmversion 2.6.%{sublevel}
-%define specrelease %(R="$Revision: 1.3245 $"; RR="${R##: }"; echo ${RR%%?})%{?dist}%{?buildid}
-%define release %{specrelease}
+# The kernel tarball/base version
+%define kversion 2.6.%{base_sublevel}
 
 %define make_target bzImage
 %define kernel_image x86
@@ -87,6 +134,10 @@ Summary: The Linux kernel (the core of t
 %define nopatches 0
 %endif
 
+%if %{with_vanilla}
+%define nopatches 1
+%endif
+
 %if %{nopatches}
 %define includexen 0
 %define with_xen 0
@@ -99,7 +150,11 @@ Summary: The Linux kernel (the core of t
 %if 0%{?upstream_branch:1}
 %define using_upstream_branch 1
 %define variant -%{upstream_branch}%{?variant_fedora}
-%define release %{upstream_branch_release}.%{specrelease}
+%define pkg_release %{upstream_branch_release}.%{pkg_release}
+%endif
+
+%if !%{debugbuildsenabled}
+%define with_debug 0
 %endif
 
 # if requested, only build base kernel
@@ -109,7 +164,6 @@ Summary: The Linux kernel (the core of t
 %define with_xen 0
 %define with_kdump 0
 %define with_debug 0
-%define debugbuildsenabled 0
 %endif
 
 # if requested, only build smp kernel
@@ -119,7 +173,6 @@ Summary: The Linux kernel (the core of t
 %define with_xen 0
 %define with_kdump 0
 %define with_debug 0
-%define debugbuildsenabled 0
 %endif
 
 # if requested, only build xen kernel
@@ -129,7 +182,6 @@ Summary: The Linux kernel (the core of t
 %define with_pae 0
 %define with_kdump 0
 %define with_debug 0
-%define debugbuildsenabled 0
 %endif
 
 # don't build xen or kdump kernels for OLPC
@@ -332,7 +384,7 @@ Name: kernel%{?variant}
 Group: System Environment/Kernel
 License: GPLv2
 Version: %{rpmversion}
-Release: %{release}
+Release: %{pkg_release}
 %if 0%{?olpc}
 ExclusiveArch: i386
 %else
@@ -416,7 +468,14 @@ Source82: config-olpc-generic
 ### BRANCH PATCH ###
 %else
 # Here should be only the patches up to the upstream canonical Linus tree.
-Patch00: patch-2.6.22-rc7.bz2
+# These are automagically defined by the rcrev and gitrev values set up 
+# near the top of this spec file.
+%if 0%{?rcrev}
+Patch00: patch-2.6.%{upstream_sublevel}-rc%{rcrev}.bz2
+%if 0%{?gitrev}
+Patch01: patch-2.6.%{upstream_sublevel}-rc%{rcrev}-git%{gitrev}.bz2
+%endif
+%endif
 %endif
 
 %if !%{nopatches}
@@ -861,7 +920,7 @@ against the kdump kernel package.
 if [ ! -d kernel-%{kversion}/vanilla ]; then
   # Ok, first time we do a make prep.
   rm -f pax_global_header
-%setup -q -n kernel-%{version} -c
+%setup -q -n kernel-%{kversion} -c
   mv linux-%{kversion} vanilla
 else
   # We already have a vanilla dir.
@@ -1160,12 +1219,6 @@ do
   cat .config >> configs/$i
 done
 
-# make sure the kernel has the sublevel we know it has. This looks weird
-# but for -pre and -rc versions we need it since we only want to use
-# the higher version when the final kernel is released.
-perl -p -i -e "s/^SUBLEVEL.*/SUBLEVEL = %{sublevel}/" Makefile
-perl -p -i -e "s/^EXTRAVERSION.*/EXTRAVERSION = -prep/" Makefile
-
 # get rid of unwanted files resulting from patch fuzz
 find . \( -name "*.orig" -o -name "*~" \) -exec rm -f {} \; >/dev/null
 
@@ -1473,10 +1526,10 @@ BuildKernel %make_target %kernel_image k
 %global __debug_package 1
 %files debuginfo-common
 %defattr(-,root,root)
-/usr/src/debug/%{name}-%{version}/linux-%{kversion}.%{_target_cpu}
+/usr/src/debug/%{name}-%{kversion}/linux-%{kversion}.%{_target_cpu}
 %if %{includexen}
 %if %{with_xen}
-/usr/src/debug/%{name}-%{version}/xen
+/usr/src/debug/%{name}-%{kversion}/xen
 %endif
 %endif
 %dir /usr/src/debug
