Whamcloud - gitweb
LU-11568 ldlm: Remove use of SLAB_DESTROY_BY_RCU for ldlm lock slab
[fs/lustre-release.git] / contrib / lbuild / 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 for this distribution (only -- if you want to force a kernel
5 # build on all distributions, update the BUILD_GEN variable in build/lbuild)
6 BUILD_GEN+=".0"
7
8 source ${LBUILD_DIR}/lbuild-sles
9
10 kernel_srpm_location() {
11
12     local PLEV=$(sed -n -e 's/^PATCHLEVEL = //p' /etc/SuSE-release)
13     echo "https://nu.novell.com/repo/\$RCE/SLES11-SP${PLEV}-Updates/sle-11-$(resolve_arch $TARGET_ARCH)/rpm/src/"
14
15 }
16
17 # the location of the ofed-devel-<version>.<arch>.rpm
18 OFED_DEVEL_LOCATION="$KERNELTREE"
19
20 # do we want to rebuild the OFED devel RPM or use the supplied one?
21 REBUILD_OFED_DEVEL_RPM=${REBUILD_OFED_DEVEL_RPM:-false}
22
23 edit_specs() {
24
25     # edit the SPECs with our changes
26     local spec
27     for spec in $RPMSMPTYPE source; do
28         #cp $TOPDIR/SOURCES/kernel-$spec.spec{,.orig}
29         sed -i -e "s/^Release:.*/&_${buildid}/" \
30                -e "s/^ExclusiveArch:.*/& ppc ppc64/" \
31                -e '/^# Apply the patches needed for this architecture\./a\
32 cp  %_sourcedir/linux-2.6.16-lustre.patch %_builddir/%{name}-%{version}/lustre.patch\
33 ! grep -q lustre.patch %_sourcedir/series.conf && echo -e "\\n\\tlustre.patch" >> %_sourcedir/series.conf' \
34                -e "/flavor=\${config/a\
35     [ \"\$flavor\" == \"$RPMSMPTYPE\" ] || continue" \
36           SOURCES/kernel-${spec}.spec || fatal 1 "Error while editing SOURCES/kernel-${spec}.spec"
37
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}
44 " \
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"
48         fi
49
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")/' \
56                -e 's/ -a 109//' \
57           SOURCES/kernel-${spec}.spec || fatal 1 "Error while editing SOURCES/kernel-${spec}.spec"
58      fi
59     done
60 }
61
62 unpack_linux_devel_rpm-sles10() {
63     local callers_rpm="$1"
64
65     # get the Module.symvers out of the kenrel-flavor RPM
66     local kernelrpm=${callers_rpm/-source-/-$RPMSMPTYPE-}
67
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
69         return 255
70     fi
71
72     # now just sanity check that everything needed to build properly versioned
73     # modules is in place
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."
76     fi
77     if [ ! -f boot/symsets-${lnxmaj}${lnxmin}-${lnxrel}-$RPMSMPTYPE.tar.gz ]; then
78         fatal 1 "cannot build modules: the Kernel's symsets is missing."
79     fi
80
81     return 0
82
83 }
84
85 build_sles_ofed_rpm() {
86     local variant="${1:+-$1}"
87     local add_spec_edit="$2"
88
89     if $REBUILD_OFED_DEVEL_RPM; then
90         #
91         # rebuild the $variant rpm
92         #
93
94         local SOURCE="${KERNELTREE}/ofed${variant}-${OFED_DEVEL_VERSION}.src.rpm"
95
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
99         pushd ofed-rpm
100         rpm2cpio < $KERNELTREE/ofed${variant}-${OFED_DEVEL_VERSION}.src.rpm | cpio -id
101         ed ofed${variant}.spec <<"EOF"
102 /^%define kver /c
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)
104 .
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
107 .
108 /^     make -C \/usr\/src\/linux-obj\/%_target_cpu\/\$flavor modules_install \\/c
109      make -C %kobjdir/%_target_cpu/$flavor modules_install \
110 .
111 wq
112 EOF
113         if type -p edit_spec_ofed${variant}; then
114             edit_spec_ofed${variant}
115         fi
116
117         mv ofed${variant}.spec SPECS
118         mv * SOURCES
119         mv SOURCES/S{PEC,RPM}S .
120         rpmbuild --bs --nodeps --define "_topdir $(pwd)" SPECS/ofed${variant}.spec 2>&1 || return 255
121         popd
122         mv ofed-rpm/SRPMS/* ${TOPDIR}/SRPMS/
123         rm -rf ofed-rpm
124         SOURCE="${TOPDIR}/SRPMS/ofed${variant}-${OFED_DEVEL_VERSION}.src.rpm"
125         # end of dirty hack
126
127         # dirty hack until Novell make the kernel-source location overridable
128         # when building kmps
129         # XXX - this is very racy.  let's hope we only ever have a single
130         #       instance of this running at a time
131         local tmpfile
132         if [ -f ~/.rpmmacros ]; then
133             tmpfile=$(mktemp ~/.rpmmacros.XXXXXX)
134             cp ~/.rpmmacros $tmpfile
135         fi
136         cat <<"EOF" >~/.rpmmacros
137 # an overridable specification of where the linux-obj tree is located
138 %{!?kobjdir: %define kobjdir /usr/src/linux-obj}
139
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)}" \
145         a_flavor=($flavors)
146         flavors_to_build= \
147         if [ -s %kobjdir/%_target_cpu/${a_flavor}/include/linux/utsrelease.h ]; then
148             LINUXRELEASEHEADER=utsrelease.h
149         else
150             LINUXRELEASEHEADER=version.h
151         fi
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 \
155                 case " %* " in \
156                 (*" $flavor "*) \
157                     continue ;; \
158                 esac \
159             fi \
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" \
164         done \
165         echo "%%global flavors_to_build${flavors_to_build:-%%nil}" \
166         echo "%%global kernel_source() %kobjdir/%_target_cpu/%%%%{1}" \
167         \
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_" \
173         )}
174 EOF
175         if ! rpmbuild --rebuild --nodeps --target ${TARGET_ARCH} \
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 }