1 # vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:
3 # increment this if you have made a change that should force a new kernel
6 #BUILD_GEN=2 # bz19952: remove -lustre tag from kernel RPM names
7 BUILD_GEN=3 # bz19975 enable the building of src.rpms by default
9 source ${0%/*}/lbuild-sles
11 # the location of the ofed-devel-<version>.<arch>.rpm
12 OFED_DEVEL_LOCATION="$KERNELTREE"
14 # do we want to rebuild the OFED devel RPM or use the supplied one?
16 REBUILD_OFED_DEVEL_RPM=${REBUILD_OFED_DEVEL_RPM:-true}
18 REBUILD_OFED_DEVEL_RPM=${REBUILD_OFED_DEVEL_RPM:-false}
23 # edit the SPECs with our changes
25 for spec in $RPMSMPTYPE source; do
26 #cp $TOPDIR/SOURCES/kernel-$spec.spec{,.orig}
27 sed -i -e "s/^Release:.*/&_${buildid}/" \
28 -e "s/^ExclusiveArch:.*/& ppc ppc64/" \
29 -e '/^# Apply the patches needed for this architecture\./a\
30 cp %_sourcedir/linux-2.6.16-lustre.patch %_builddir/%{name}-%{version}/lustre.patch\
31 ! grep -q lustre.patch %_sourcedir/series.conf && echo -e "\\n\\tlustre.patch" >> %_sourcedir/series.conf' \
32 -e "/flavor=\${config/a\
33 [ \"\$flavor\" == \"$RPMSMPTYPE\" ] || continue" \
34 -e "s/^\(BuildRequires: kernel-dummy\)/# \1/" \
35 -e "s/kernel-dummy\.spec/ /g" \
36 SOURCES/kernel-${spec}.spec || fatal 1 "Error while editing SOURCES/kernel-${spec}.spec"
38 if $KERNEL_LUSTRE_NAMING; then
39 # these are all of the changes needed because we change the package names
40 # to kernel-lustre-*. these should all go away when we stop this insanity
41 sed -i -e 's/^\(Name:.*kernel-\)\(.*\)/\1lustre-\2/' \
42 -e "/^Provides: *kernel = /a\
43 Provides: kernel-$spec = %{version}-%{release}
45 -e 's/\(.*\)\([^#].*\)fookernel-source/\1\2kernel-lustre-source/g' \
46 -e '/^%build/,/^%changelog/s/kernel-\({*\)source/kernel-\1lustre-source/g' \
47 SOURCES/kernel-${spec}.spec || fatal 1 "Error while editing SOURCES/kernel-${spec}.spec"
50 # XXX - a building-on-Ubuntu hack
51 if grep -q "Ubuntu" /etc/issue; then
52 sed -i -e '/^%_sourcedir\/install-configs %_sourcedir .*/i\
53 curl ftp://ftp.kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.17/2.6.17-mm1/broken-out/i386-use-c-code-for-current_thread_info.patch | patch -p1' \
54 -e 's/^\(BuildRequires: .*\)$/#NOU \1/g' \
55 -e 's/%(\(chmod .*\))$/%(bash -c "\1")/' \
57 SOURCES/kernel-${spec}.spec || fatal 1 "Error while editing SOURCES/kernel-${spec}.spec"
62 unpack_linux_devel_rpm-sles10() {
63 local callers_rpm="$1"
65 # get the Module.symvers out of the kenrel-flavor RPM
66 local kernelrpm=${callers_rpm/-source-/-$RPMSMPTYPE-}
68 if ! rpm2cpio < "$kernelrpm" | cpio -id ./usr/src/linux-${lnxmaj}${lnxmin}-${lnxrel}-obj/$(resolve_arch $TARGET_ARCH $PATCHLESS true)/$RPMSMPTYPE/Module.symvers ./boot/sym\* > /dev/null 2>&1; then
72 # now just sanity check that everything needed to build properly versioned
74 if [ ! -f usr/src/linux-${lnxmaj}${lnxmin}-${lnxrel}-obj/$(resolve_arch $TARGET_ARCH $PATCHLESS true)/$RPMSMPTYPE/Module.symvers ]; then
75 fatal 1 "cannot build kernel modules: the Kernel's Module.symvers is missing."
77 if [ ! -f boot/symsets-${lnxmaj}${lnxmin}-${lnxrel}-$RPMSMPTYPE.tar.gz ]; then
78 fatal 1 "cannot build modules: the Kernel's symsets is missing."
85 build_sles_ofed_rpm() {
86 local variant="${1:+-$1}"
87 local add_spec_edit="$2"
89 if $REBUILD_OFED_DEVEL_RPM; then
91 # rebuild the $variant rpm
94 local SOURCE="${KERNELTREE}/ofed${variant}-${OFED_DEVEL_VERSION}.src.rpm"
96 # dirty hack until Novell make the kernel-source location overridable
97 # - unpack the src.rpm, patch the .spec and re-pack up the src.rpm
98 mkdir -p ofed-rpm/S{PEC,OURCE,RPM}S
100 rpm2cpio < $KERNELTREE/ofed${variant}-${OFED_DEVEL_VERSION}.src.rpm | cpio -id
101 ed ofed${variant}.spec <<"EOF"
103 %define kver %(flavors=($(ls %kobjdir/%_target_cpu/)); if test -s %kobjdir/%_target_cpu/${flavors[0]}/include/linux/utsrelease.h ; then LINUXRELEASEHEADER=utsrelease.h; else LINUXRELEASEHEADER=version.h; fi; sed -ne "/^#define UTS_RELEASE/s/.*\\"\\\(.*\\\)-${flavors[0]}\\"$/\\1/p" %kobjdir/%_target_cpu/${flavors[0]}/include/linux/$LINUXRELEASEHEADER)
105 /^ --kernel-version=%kver-$flavor --kernel-sources=\/usr\/src\/linux-obj\/%_target_cpu\/\$flavor/c
106 --kernel-version=%kver-$flavor --kernel-sources=%kobjdir/%_target_cpu/$flavor
108 /^ make -C \/usr\/src\/linux-obj\/%_target_cpu\/\$flavor modules_install \\/c
109 make -C %kobjdir/%_target_cpu/$flavor modules_install \
113 if type -p edit_spec_ofed${variant}; then
114 edit_spec_ofed${variant}
117 mv ofed${variant}.spec SPECS
119 mv SOURCES/S{PEC,RPM}S .
120 rpmbuild --bs --nodeps --define "_topdir $(pwd)" SPECS/ofed${variant}.spec 2>&1 || return 255
122 mv ofed-rpm/SRPMS/* ${TOPDIR}/SRPMS/
124 SOURCE="${TOPDIR}/SRPMS/ofed${variant}-${OFED_DEVEL_VERSION}.src.rpm"
127 # dirty hack until Novell make the kernel-source location overridable
129 # XXX - this is very racy. let's hope we only ever have a single
130 # instance of this running at a time
132 if [ -f ~/.rpmmacros ]; then
133 tmpfile=$(mktemp ~/.rpmmacros.XXXXXX)
134 cp ~/.rpmmacros $tmpfile
136 cat <<"EOF" >~/.rpmmacros
137 # an overridable specification of where the linux-obj tree is located
138 %{!?kobjdir: %define kobjdir /usr/src/linux-obj}
140 # Defines %flavors_to_build and %kernel_source() as a side effect.
141 %_kernel_module_package(n:v:r:s:f:Xp:) \
142 %{expand:%( subpkg=%{-s*}%{!-s:/usr/lib/rpm/rpm-suse-kernel-module-subpackage} \
143 echo "%%define _suse_kernel_module_subpackage(n:v:r:f:p:) %%{expand:%%(cd %_sourcedir; cat $subpkg; echo %%%%nil)}" \
144 flavors="%{!-X:%*}%{-X:$(ls %kobjdir/%_target_cpu 2>/dev/null)}" \
147 if [ -s %kobjdir/%_target_cpu/${a_flavor}/include/linux/utsrelease.h ]; then
148 LINUXRELEASEHEADER=utsrelease.h
150 LINUXRELEASEHEADER=version.h
152 kver=$(sed -ne "/^#define UTS_RELEASE/s/.*\\"\\\(.*\\\)-${a_flavor}\\"$/\\1/p" %kobjdir/%_target_cpu/${a_flavor}/include/linux/$LINUXRELEASEHEADER)
153 for flavor in $flavors; do \
154 if [ -n "%{-X}" ]; then \
160 krel=$(make -s -C %kobjdir/%_target_cpu/$flavor kernelrelease) \
161 [ -e %symsetsdir/symsets-$krel.tar.gz ] || continue \
162 flavors_to_build="$flavors_to_build $flavor" \
163 echo "%%_suse_kernel_module_subpackage -n %{-n*}%{!-n:%name}-kmp -v %{-v*}%{!-v:%version} -r %{-r*}%{!-r:%release} %{-p} $flavor $krel $kver" \
165 echo "%%global flavors_to_build${flavors_to_build:-%%nil}" \
166 echo "%%global kernel_source() %kobjdir/%_target_cpu/%%%%{1}" \
168 echo "%package -n %{-n*}%{!-n:%name}-kmp-_dummy_" \
169 echo "Version: %version" \
170 echo "Summary: %summary" \
171 echo "Group: %group" \
172 echo "%description -n %{-n*}%{!-n:%name}-kmp-_dummy_" \
176 for arch in $BUILD_ARCHS; do
177 targets="--target $(resolve_arch $arch $PATCHLESS) $targets"
179 if ! $RPMBUILD --rebuild --nodeps $targets \
180 --define "symsetsdir ${TOPDIR}/reused/boot" \
181 --define "kobjdir ${LINUXOBJ%/*/*}" \
182 --define "_tmppath /var/tmp" \
183 --define "_topdir ${TOPDIR}" \
186 if [ -n "$tmpfile" ]; then
187 cp $tmpfile ~/.rpmmacros
193 if [ -n "$tmpfile" ]; then
194 cp $tmpfile ~/.rpmmacros
197 fi # $REBUILD_OFED_DEVEL_RPM; then
201 # additional edits need to the ofed spec
205 /^# we assume config.mk and the include files are same for all flavors/a
206 built_flavors=(%flavors_to_build)
208 /^cp obj\/default\/config\.mk \$RPM_BUILD_ROOT\/%{_prefix}\/src\/kernel-modules-ofed/c
209 cp obj/${built_flavors[0]}/config.mk $RPM_BUILD_ROOT/%{_prefix}/src/kernel-modules-ofed
211 /^for D in obj\/default\\\\include \$(sed 's@^.*-I\\\${CWD}\/@obj\/default\\\\@' obj\/default\/config.mk); do/c
212 for D in obj/${built_flavors[0]}\\include $(sed "s@^.*-I\${CWD}/@obj/${built_flavors[0]}\\\@" obj/${built_flavors[0]}/config.mk); do
219 build_ofed-sles10() {
222 if [ -z "$outfd" ] || [ $outfd = 1 ]; then
223 fatal 1 "You must supply a file descriptor to ${FUNCNAME[0]} and it cannot be 1"
226 if $REBUILD_OFED_DEVEL_RPM; then
227 build_sles_ofed_rpm cxgb3-NIC >&${outfd} || return ${PIPESTATUS[0]}
228 build_sles_ofed_rpm >&${outfd} || return ${PIPESTATUS[0]}
229 OFED_DEVEL_LOCATION="${TOPDIR}/RPMS/$(resolve_arch $TARGET_ARCH $PATCHLESS)"
230 fi # $REBUILD_OFED_DEVEL_RPM; then
232 # XXX I'm not convinced this belongs in here, but really, this is a
233 # temporary hack until we get a base O/S intalled ofed-devel
234 local arch=$TARGET_ARCH
235 if [ -n "$OFED_VERSION" -a "$OFED_VERSION" = "inkernel" ]; then
236 local ofed_devel="${OFED_DEVEL_LOCATION}/ofed-devel-${OFED_DEVEL_VERSION}.$(resolve_arch $TARGET_ARCH "$PATCHLESS || ! $REBUILD_OFED_DEVEL_RPM").rpm"
237 if ! rpm2cpio < $ofed_devel | cpio -id; then
238 fatal 1 "could not unpack the ofed-devel rpm."
240 echo "$(pwd)/usr/src/kernel-modules-ofed/$(resolve_arch $TARGET_ARCH "$PATCHLESS || ! $REBUILD_OFED_DEVEL_RPM")/$RPMSMPTYPE"