Whamcloud - gitweb
b=23911 enable REBUILD_OFED_DEVEL_RPM by default
[fs/lustre-release.git] / build / lbuild-sles10
1 # vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:
2
3 # increment this if you have made a change that should force a new kernel
4 # to build built
5 #BUILD_GEN=1
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
8
9 source ${0%/*}/lbuild-sles
10
11 # the location of the ofed-devel-<version>.<arch>.rpm
12 OFED_DEVEL_LOCATION="$KERNELTREE"
13
14 # do we want to rebuild the OFED devel RPM or use the supplied one?
15 REBUILD_OFED_DEVEL_RPM=${REBUILD_OFED_DEVEL_RPM:-true}
16
17 edit_specs() {
18
19     # edit the SPECs with our changes
20     local spec
21     for spec in $RPMSMPTYPE source; do
22         #cp $TOPDIR/SOURCES/kernel-$spec.spec{,.orig}
23         sed -i -e "s/^Release:.*/&_${buildid}/" \
24                -e "s/^ExclusiveArch:.*/& ppc ppc64/" \
25                -e '/^# Apply the patches needed for this architecture\./a\
26 cp  %_sourcedir/linux-2.6.16-lustre.patch %_builddir/%{name}-%{version}/lustre.patch\
27 ! grep -q lustre.patch %_sourcedir/series.conf && echo -e "\\n\\tlustre.patch" >> %_sourcedir/series.conf' \
28                -e "/flavor=\${config/a\
29     [ \"\$flavor\" == \"$RPMSMPTYPE\" ] || continue" \
30                -e "s/^\(BuildRequires:  kernel-dummy\)/# \1/" \
31                -e "s/kernel-dummy\.spec/ /g" \
32           SOURCES/kernel-${spec}.spec || fatal 1 "Error while editing SOURCES/kernel-${spec}.spec"
33
34         if $KERNEL_LUSTRE_NAMING; then
35             # these are all of the changes needed because we change the package names
36             # to kernel-lustre-*.  these should all go away when we stop this insanity
37             sed -i -e 's/^\(Name:.*kernel-\)\(.*\)/\1lustre-\2/' \
38                    -e "/^Provides:  *kernel = /a\
39 Provides:       kernel-$spec = %{version}-%{release}
40 " \
41                    -e 's/\(.*\)\([^#].*\)fookernel-source/\1\2kernel-lustre-source/g' \
42                    -e '/^%build/,/^%changelog/s/kernel-\({*\)source/kernel-\1lustre-source/g' \
43               SOURCES/kernel-${spec}.spec || fatal 1 "Error while editing SOURCES/kernel-${spec}.spec"
44         fi
45
46     # XXX - a building-on-Ubuntu hack
47     if grep -q "Ubuntu" /etc/issue; then
48         sed -i -e '/^%_sourcedir\/install-configs %_sourcedir .*/i\
49 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' \
50                -e 's/^\(BuildRequires: .*\)$/#NOU \1/g' \
51                -e 's/%(\(chmod .*\))$/%(bash -c "\1")/' \
52                -e 's/ -a 109//' \
53           SOURCES/kernel-${spec}.spec || fatal 1 "Error while editing SOURCES/kernel-${spec}.spec"
54      fi
55     done
56 }
57
58 unpack_linux_devel_rpm-sles10() {
59     local callers_rpm="$1"
60
61     # get the Module.symvers out of the kenrel-flavor RPM
62     local kernelrpm=${callers_rpm/-source-/-$RPMSMPTYPE-}
63
64     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
65         return 255
66     fi
67
68     # now just sanity check that everything needed to build properly versioned
69     # modules is in place
70     if [ ! -f usr/src/linux-${lnxmaj}${lnxmin}-${lnxrel}-obj/$(resolve_arch $TARGET_ARCH $PATCHLESS true)/$RPMSMPTYPE/Module.symvers ]; then
71         fatal 1 "cannot build kernel modules: the Kernel's Module.symvers is missing."
72     fi
73     if [ ! -f boot/symsets-${lnxmaj}${lnxmin}-${lnxrel}-$RPMSMPTYPE.tar.gz ]; then
74         fatal 1 "cannot build modules: the Kernel's symsets is missing."
75     fi
76
77     return 0
78
79 }
80
81 build_sles_ofed_rpm() {
82     local variant="${1:+-$1}"
83     local add_spec_edit="$2"
84
85     if $REBUILD_OFED_DEVEL_RPM; then
86         #
87         # rebuild the $variant rpm
88         #
89
90         local SOURCE="${KERNELTREE}/ofed${variant}-${OFED_DEVEL_VERSION}.src.rpm"
91
92         # dirty hack until Novell make the kernel-source location overridable
93         # - unpack the src.rpm, patch the .spec and re-pack up the src.rpm
94         mkdir -p ofed-rpm/S{PEC,OURCE,RPM}S
95         pushd ofed-rpm
96         rpm2cpio < $KERNELTREE/ofed${variant}-${OFED_DEVEL_VERSION}.src.rpm | cpio -id
97         ed ofed${variant}.spec <<"EOF"
98 /^%define kver /c
99 %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)
100 .
101 /^              --kernel-version=%kver-$flavor --kernel-sources=\/usr\/src\/linux-obj\/%_target_cpu\/\$flavor/c
102                 --kernel-version=%kver-$flavor --kernel-sources=%kobjdir/%_target_cpu/$flavor
103 .
104 /^     make -C \/usr\/src\/linux-obj\/%_target_cpu\/\$flavor modules_install \\/c
105      make -C %kobjdir/%_target_cpu/$flavor modules_install \
106 .
107 wq
108 EOF
109         if type -p edit_spec_ofed${variant}; then
110             edit_spec_ofed${variant}
111         fi
112
113         mv ofed${variant}.spec SPECS
114         mv * SOURCES
115         mv SOURCES/S{PEC,RPM}S .
116         rpmbuild --bs --nodeps --define "_topdir $(pwd)" SPECS/ofed${variant}.spec 2>&1 || return 255
117         popd
118         mv ofed-rpm/SRPMS/* ${TOPDIR}/SRPMS/
119         rm -rf ofed-rpm
120         SOURCE="${TOPDIR}/SRPMS/ofed${variant}-${OFED_DEVEL_VERSION}.src.rpm"
121         # end of dirty hack
122
123         # dirty hack until Novell make the kernel-source location overridable
124         # when building kmps
125         # XXX - this is very racy.  let's hope we only ever have a single
126         #       instance of this running at a time
127         local tmpfile
128         if [ -f ~/.rpmmacros ]; then
129             tmpfile=$(mktemp ~/.rpmmacros.XXXXXX)
130             cp ~/.rpmmacros $tmpfile
131         fi
132         cat <<"EOF" >~/.rpmmacros
133 # an overridable specification of where the linux-obj tree is located
134 %{!?kobjdir: %define kobjdir /usr/src/linux-obj}
135
136 # Defines %flavors_to_build and %kernel_source() as a side effect.
137 %_kernel_module_package(n:v:r:s:f:Xp:) \
138 %{expand:%( subpkg=%{-s*}%{!-s:/usr/lib/rpm/rpm-suse-kernel-module-subpackage} \
139         echo "%%define _suse_kernel_module_subpackage(n:v:r:f:p:) %%{expand:%%(cd %_sourcedir; cat $subpkg; echo %%%%nil)}" \
140         flavors="%{!-X:%*}%{-X:$(ls %kobjdir/%_target_cpu 2>/dev/null)}" \
141         a_flavor=($flavors)
142         flavors_to_build= \
143         if [ -s %kobjdir/%_target_cpu/${a_flavor}/include/linux/utsrelease.h ]; then
144             LINUXRELEASEHEADER=utsrelease.h
145         else
146             LINUXRELEASEHEADER=version.h
147         fi
148         kver=$(sed -ne "/^#define UTS_RELEASE/s/.*\\"\\\(.*\\\)-${a_flavor}\\"$/\\1/p" %kobjdir/%_target_cpu/${a_flavor}/include/linux/$LINUXRELEASEHEADER)
149         for flavor in $flavors; do \
150             if [ -n "%{-X}" ]; then \
151                 case " %* " in \
152                 (*" $flavor "*) \
153                     continue ;; \
154                 esac \
155             fi \
156             krel=$(make -s -C %kobjdir/%_target_cpu/$flavor kernelrelease) \
157             [ -e %symsetsdir/symsets-$krel.tar.gz ] || continue \
158             flavors_to_build="$flavors_to_build $flavor" \
159             echo "%%_suse_kernel_module_subpackage -n %{-n*}%{!-n:%name}-kmp -v %{-v*}%{!-v:%version} -r %{-r*}%{!-r:%release} %{-p} $flavor $krel $kver" \
160         done \
161         echo "%%global flavors_to_build${flavors_to_build:-%%nil}" \
162         echo "%%global kernel_source() %kobjdir/%_target_cpu/%%%%{1}" \
163         \
164         echo "%package -n %{-n*}%{!-n:%name}-kmp-_dummy_" \
165         echo "Version: %version" \
166         echo "Summary: %summary" \
167         echo "Group: %group" \
168         echo "%description -n %{-n*}%{!-n:%name}-kmp-_dummy_" \
169         )}
170 EOF
171         local targets
172         for arch in $BUILD_ARCHS; do
173             targets="--target $(resolve_arch $arch $PATCHLESS) $targets"
174         done
175         if ! $RPMBUILD --rebuild --nodeps $targets \
176                                  --define "symsetsdir ${TOPDIR}/reused/boot" \
177                                  --define "kobjdir ${LINUXOBJ%/*/*}" \
178                                  --define "_tmppath /var/tmp" \
179                                  --define "_topdir ${TOPDIR}" \
180                       ${SOURCE} 2>&1; then
181             rm ~/.rpmmacros
182             if [ -n "$tmpfile" ]; then
183                 cp $tmpfile ~/.rpmmacros
184                 rm $tmpfile
185             fi
186             return 255
187         fi
188         rm ~/.rpmmacros
189         if [ -n "$tmpfile" ]; then
190             cp $tmpfile ~/.rpmmacros
191             rm $tmpfile
192         fi
193     fi # $REBUILD_OFED_DEVEL_RPM; then
194
195 }
196
197 # additional edits need to the ofed spec
198 edit_spec_ofed() {
199
200         ed ofed.spec <<"EOF"
201 /^# we assume config.mk and the include files are same for all flavors/a
202 built_flavors=(%flavors_to_build)
203 .
204 /^cp obj\/default\/config\.mk \$RPM_BUILD_ROOT\/%{_prefix}\/src\/kernel-modules-ofed/c
205 cp obj/${built_flavors[0]}/config.mk $RPM_BUILD_ROOT/%{_prefix}/src/kernel-modules-ofed
206 .
207 /^for D in obj\/default\\\\include \$(sed 's@^.*-I\\\${CWD}\/@obj\/default\\\\@' obj\/default\/config.mk); do/c
208 for D in obj/${built_flavors[0]}\\include $(sed "s@^.*-I\${CWD}/@obj/${built_flavors[0]}\\\@" obj/${built_flavors[0]}/config.mk); do
209 .
210 wq
211 EOF
212
213 }
214
215 build_ofed-sles10() {
216     local outfd=$1
217
218     if [ -z "$outfd" ] || [ $outfd = 1 ]; then
219         fatal 1 "You must supply a file descriptor to ${FUNCNAME[0]} and it cannot be 1"
220     fi
221
222     if $REBUILD_OFED_DEVEL_RPM; then
223         build_sles_ofed_rpm cxgb3-NIC >&${outfd} || return ${PIPESTATUS[0]}
224         build_sles_ofed_rpm >&${outfd} || return ${PIPESTATUS[0]}
225         OFED_DEVEL_LOCATION="${TOPDIR}/RPMS/$(resolve_arch $TARGET_ARCH $PATCHLESS)"
226     fi # $REBUILD_OFED_DEVEL_RPM; then
227
228     # XXX I'm not convinced this belongs in here, but really, this is a
229     # temporary hack until we get a base O/S intalled ofed-devel
230     local arch=$TARGET_ARCH
231     if [ -n "$OFED_VERSION" -a "$OFED_VERSION" = "inkernel" ]; then
232         local ofed_devel="${OFED_DEVEL_LOCATION}/ofed-devel-${OFED_DEVEL_VERSION}.$(resolve_arch $TARGET_ARCH "$PATCHLESS || ! $REBUILD_OFED_DEVEL_RPM").rpm"
233         if ! rpm2cpio < $ofed_devel | cpio -id; then
234             fatal 1 "could not unpack the ofed-devel rpm."
235         fi
236         echo "$(pwd)/usr/src/kernel-modules-ofed/$(resolve_arch $TARGET_ARCH "$PATCHLESS || ! $REBUILD_OFED_DEVEL_RPM")/$RPMSMPTYPE"
237     fi
238
239     return 0
240
241 }