Whamcloud - gitweb
b=20744 hacks for Novell bug 578796
[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:-false}
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           SOURCES/kernel-${spec}.spec || fatal 1 "Error while editing SOURCES/kernel-${spec}.spec"
31
32         if $KERNEL_LUSTRE_NAMING; then
33             # these are all of the changes needed because we change the package names
34             # to kernel-lustre-*.  these should all go away when we stop this insanity
35             sed -i -e 's/^\(Name:.*kernel-\)\(.*\)/\1lustre-\2/' \
36                    -e "/^Provides:  *kernel = /a\
37 Provides:       kernel-$spec = %{version}-%{release}
38 " \
39                    -e 's/\(.*\)\([^#].*\)fookernel-source/\1\2kernel-lustre-source/g' \
40                    -e '/^%build/,/^%changelog/s/kernel-\({*\)source/kernel-\1lustre-source/g' \
41               SOURCES/kernel-${spec}.spec || fatal 1 "Error while editing SOURCES/kernel-${spec}.spec"
42         fi
43
44     # XXX - a building-on-Ubuntu hack
45     if grep -q "Ubuntu" /etc/issue; then
46         sed -i -e '/^%_sourcedir\/install-configs %_sourcedir .*/i\
47 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' \
48                -e 's/^\(BuildRequires: .*\)$/#NOU \1/g' \
49                -e 's/%(\(chmod .*\))$/%(bash -c "\1")/' \
50                -e 's/ -a 109//' \
51           SOURCES/kernel-${spec}.spec || fatal 1 "Error while editing SOURCES/kernel-${spec}.spec"
52      fi
53     done
54 }
55
56 unpack_linux_devel_rpm-sles10() {
57     local callers_rpm="$1"
58
59     # get the Module.symvers out of the kenrel-flavor RPM
60     local kernelrpm=${callers_rpm/-source-/-$RPMSMPTYPE-}
61
62     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
63         return 255
64     fi
65
66     # now just sanity check that everything needed to build properly versioned
67     # modules is in place
68     if [ ! -f usr/src/linux-${lnxmaj}${lnxmin}-${lnxrel}-obj/$(resolve_arch $TARGET_ARCH $PATCHLESS true)/$RPMSMPTYPE/Module.symvers ]; then
69         fatal 1 "cannot build kernel modules: the Kernel's Module.symvers is missing."
70     fi
71     if [ ! -f boot/symsets-${lnxmaj}${lnxmin}-${lnxrel}-$RPMSMPTYPE.tar.gz ]; then
72         fatal 1 "cannot build modules: the Kernel's symsets is missing."
73     fi
74
75     return 0
76
77 }
78
79 build_sles_ofed_rpm() {
80     local variant="${1:+-$1}"
81     local add_spec_edit="$2"
82
83     if $REBUILD_OFED_DEVEL_RPM; then
84         #
85         # rebuild the $variant rpm
86         #
87
88         local SOURCE="${KERNELTREE}/ofed${variant}-${OFED_DEVEL_VERSION}.src.rpm"
89
90         # dirty hack until Novell make the kernel-source location overridable
91         # - unpack the src.rpm, patch the .spec and re-pack up the src.rpm
92         mkdir -p ofed-rpm/S{PEC,OURCE,RPM}S
93         pushd ofed-rpm
94         rpm2cpio < $KERNELTREE/ofed${variant}-${OFED_DEVEL_VERSION}.src.rpm | cpio -id
95         ed ofed${variant}.spec <<"EOF"
96 /^%define kver /c
97 %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)
98 .
99 /^              --kernel-version=%kver-$flavor --kernel-sources=\/usr\/src\/linux-obj\/%_target_cpu\/\$flavor/c
100                 --kernel-version=%kver-$flavor --kernel-sources=%kobjdir/%_target_cpu/$flavor
101 .
102 /^     make -C \/usr\/src\/linux-obj\/%_target_cpu\/\$flavor modules_install \\/c
103      make -C %kobjdir/%_target_cpu/$flavor modules_install \
104 .
105 wq
106 EOF
107         if type -p edit_spec_ofed${variant}; then
108             edit_spec_ofed${variant}
109         fi
110
111         mv ofed${variant}.spec SPECS
112         mv * SOURCES
113         mv SOURCES/S{PEC,RPM}S .
114         rpmbuild --bs --nodeps --define "_topdir $(pwd)" SPECS/ofed${variant}.spec 2>&1 || return 255
115         popd
116         mv ofed-rpm/SRPMS/* ${TOPDIR}/SRPMS/
117         rm -rf ofed-rpm
118         SOURCE="${TOPDIR}/SRPMS/ofed${variant}-${OFED_DEVEL_VERSION}.src.rpm"
119         # end of dirty hack
120
121         local targets
122         for arch in $BUILD_ARCHS; do
123             targets="--target $(resolve_arch $arch $PATCHLESS) $targets"
124         done
125         if ! $RPMBUILD --rebuild --nodeps $targets \
126                                  --define "symsetsdir ${TOPDIR}/reused/boot" \
127                                  --define "kobjdir ${LINUXOBJ%/*/*}" \
128                                  --define "_tmppath /var/tmp" \
129                                  --define "_topdir ${TOPDIR}" \
130                       ${SOURCE} 2>&1; then
131             return 255
132         fi
133     fi # $REBUILD_OFED_DEVEL_RPM; then
134
135 }
136
137 # additional edits need to the ofed spec
138 edit_spec_ofed() {
139
140         ed ofed.spec <<"EOF"
141 /^# we assume config.mk and the include files are same for all flavors/a
142 built_flavors=(%flavors_to_build)
143 .
144 /^cp obj\/default\/config\.mk \$RPM_BUILD_ROOT\/%{_prefix}\/src\/kernel-modules-ofed/c
145 cp obj/${built_flavors[0]}/config.mk $RPM_BUILD_ROOT/%{_prefix}/src/kernel-modules-ofed
146 .
147 /^for D in obj\/default\\\\include \$(sed 's@^.*-I\\\${CWD}\/@obj\/default\\\\@' obj\/default\/config.mk); do/c
148 for D in obj/${built_flavors[0]}\\include $(sed "s@^.*-I\${CWD}/@obj/${built_flavors[0]}\\\@" obj/${built_flavors[0]}/config.mk); do
149 .
150 wq
151 EOF
152
153 }
154
155 build_ofed-sles10() {
156     local outfd=$1
157
158     if [ -z "$outfd" ] || [ $outfd = 1 ]; then
159         fatal 1 "You must supply a file descriptor to ${FUNCNAME[0]} and it cannot be 1"
160     fi
161
162     if $REBUILD_OFED_DEVEL_RPM; then
163         build_sles_ofed_rpm cxgb3-NIC >&${outfd} || return ${PIPESTATUS[0]}
164         build_sles_ofed_rpm >&${outfd} || return ${PIPESTATUS[0]}
165         OFED_DEVEL_LOCATION="${TOPDIR}/RPMS/$(resolve_arch $TARGET_ARCH $PATCHLESS)"
166     fi # $REBUILD_OFED_DEVEL_RPM; then
167
168     # XXX I'm not convinced this belongs in here, but really, this is a
169     # temporary hack until we get a base O/S intalled ofed-devel
170     local arch=$TARGET_ARCH
171     if [ -n "$OFED_VERSION" -a "$OFED_VERSION" = "inkernel" ]; then
172         local ofed_devel="${OFED_DEVEL_LOCATION}/ofed-devel-${OFED_DEVEL_VERSION}.$(resolve_arch $TARGET_ARCH $PATCHLESS).rpm"
173         if ! rpm2cpio < $ofed_devel | cpio -id; then
174             fatal 1 "could not unpack the ofed-devel rpm."
175         fi
176         echo "$(pwd)/usr/src/kernel-modules-ofed/$(resolve_arch $TARGET_ARCH $PATCHLESS)/$RPMSMPTYPE"
177     fi
178
179     return 0
180
181 }