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