Whamcloud - gitweb
LU-351 RHEL6 U1 support.
[fs/lustre-release.git] / build / lbuild-rhel
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 all releases of this distribution (only -- if you want
5 # to force a kernel build on all distributions, update the BUILD_GEN variable
6 # in build/lbuild)
7 #BUILD_GEN+=".0"
8 #BUILD_GEN+=".1"        # refactor both rhel5 and rhel6
9 BUILD_GEN+=".0" # TT-107: don't cache the BUILD dir (reset major to 5)
10
11 DEVEL_KERNEL_TYPE="devel"
12 RPM_HELPERS_DIR="/usr/lib/rpm/redhat"
13
14 # a method which can be overriden by the release specific code
15 get_rpmbuildopts() {
16
17     return 0
18
19 }
20
21 # patching common to all releases
22 patch_spec_common() {
23
24     sed -i -e 's/^\(%define signmodules \).*/\10/' \
25            -e '/find $RPM_BUILD_ROOT\/lib\/modules\/$KernelVer/a\
26     cp -a fs/ext3/* $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/fs/ext3 \
27     cp -a fs/ext4/* $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/fs/ext4' \
28           SPECS/$SPEC_NAME 2>&1 || \
29         fatal 1 "Error while editing SPECS/$SPEC_NAME"
30
31     # XXX - a building-on-Ubuntu hack
32     if grep -q "Ubuntu" /etc/issue; then
33         sed  -i -e 's/^\(BuildPreReq: .*\)$/#NOU \1/g' \
34                -e 's/^\(BuildRequires: .*\)$/#NOU \1/g' \
35                -e 's/sha512hmac/md5sum/g' \
36             SPECS/$SPEC_NAME 2>&1 || \
37                 fatal 1 "Error while editing SPECS/$SPEC_NAME"
38     fi
39
40
41 }
42
43 prepare_and_build_srpm() {
44
45     pushd $TOPDIR >/dev/null
46
47     # create the buildid
48     local buildid="_lustre${EXTRA_VERSION##*_lustre}"
49
50     # edit the SPEC with our changes
51     patch_spec
52
53     popd >/dev/null
54
55     # this concept of being able to build a list of targets with a single
56     # lbuild is a fine idea, but in reality I think it's (very) broken.  I
57     # don't even think the lustre.spec can handle being called with "--target
58     # <multiple arches>".  It certainly can't handle the issue where each
59     # arch has it's own kernel location.
60     # but we will do the best we can and put the plumbing in place so that
61     # this could work when the other broken bits are fixed.
62     # in reality, our current use of lbuild only ever has a single arch in
63     # $BUILD_ARCHS
64     local arch
65     local targets=""
66     for arch in $BUILD_ARCHS; do
67         # XXX - ok.  so here's a hack that needs to be fixed properly
68         #       ppc64 was merged to ppc some time ago pre 2.6.18
69         if [ $arch = ppc64 ]; then
70             arch=ppc
71         fi
72         targets="--target $arch $targets"
73         # copy our .config into the RPM build tree
74         (echo "# $(basearch $arch)"; cat $CONFIG_FILE) > \
75             SOURCES/kernel-$lnxmaj-$arch.config
76
77         # XXX - hackity hack -- until we get (or generate from the base
78         #                       config) configs for xen and debug
79         local f=""
80         for f in SOURCES/kernel-${lnxmaj}-*.config; do
81             grep -q "^CONFIG_SD_IOSTATS=y" $f || \
82                 echo "CONFIG_SD_IOSTATS=y" >> $f
83         done
84     done
85
86     # do we need any special rpm build options
87     local rpmbuildopt="-bb"
88     if $DO_SRC; then
89         rpmbuildopt="-ba"
90     fi
91
92     # stupid Ubuntu's rpm doesn't do debuginfo properly
93     if [ ! -f /usr/lib/rpm/debugedit ]; then
94         rpmbuildopt="$rpmbuildopt --without debuginfo"
95     fi
96
97     # XXX - need to figure this kabichk crap out -- it fails the build
98     if ! $USE_KABI; then
99         rpmbuildopt="$rpmbuildopt --without kabichk"
100     fi
101
102     # get any release specific build options
103     rpmbuildopt="$rpmbuildopt $(get_rpmbuildopts)"
104
105     # now build it
106     if ! eval $RPMBUILD $rpmbuildopt $targets --with baseonly \
107                    --define \"_topdir $TOPDIR\" \
108                    --define \"buildid $buildid\" \
109                    --define \"_tmppath $TMPDIR\" \
110                    $TOPDIR/SPECS/$SPEC_NAME 2>&1; then
111         return 1
112     fi
113
114     # for informative purposes, display a diff between the .config that
115     # was actually built and what we proposed as a .config
116     echo "Diffs between $(basename $CONFIG_FILE) and the built kernel's .config:"
117     diff -u $CONFIG_FILE $TOPDIR/BUILD/kernel-${lnxmaj}-${lnxrel}/linux-${lnxmaj}-${lnxrel}.${BUILD_ARCHS# }/.config
118
119     return 0
120
121 }
122
123 devel_kernel_name() {
124     local lustre=${1:-false}
125
126     if $lustre; then
127         echo "kernel-lustre-$DEVEL_KERNEL_TYPE"
128     else
129         echo "kernel-$DEVEL_KERNEL_TYPE"
130     fi
131
132 }
133
134 rpm_BUILD_kernel_dirname() {
135     local rpmsmptype="$1"
136     local lnxmaj="$2"
137     local lnxmin="$3"
138     local arch="$4"
139
140     local lustre=""
141     if $KERNEL_LUSTRE_NAMING; then
142         $lustre="-lustre"
143     fi
144     echo kernel${lustre}${lnxmaj}${lnxmin}/linux-${lnxmaj}.$arch
145 }
146
147 find_linux_devel_paths() {
148     local path="$1"
149     local ARCH=$TARGET_ARCH
150
151     # If DEVEL_PATH_ARCH is set, use it. Added for fc11 as it needs i586 string for i686.
152     if [ $DEVEL_PATH_ARCH ];then
153         ARCH=$DEVEL_PATH_ARCH
154     fi
155
156     LINUX=$path/usr/src/kernels/${lnxmaj}${lnxmin}-${lnxrel}${DEVEL_PATH_ARCH_DELIMETER:-"-"}${ARCH}
157     # RHEL doesn't have the -obj tree
158     LINUXOBJ=""
159     # XXX - i don't think we need this any more
160     #LINUXRELEASE=$(find_linux_release "$LINUX")
161     #if [ -z "$LINUXRELEASE" ]; then
162     #    echo "Failed to find linux release in $LINUX"
163     #    return 255
164     #fi
165
166     return 0
167 }
168
169 unpack_linux_devel_rpm-rhel() {
170     local callers_rpm="$1"
171
172     # now just sanity check that everything needed to build properly versioned
173     # modules is in place
174     if [ ! -f usr/src/kernels/${lnxmaj}${lnxmin}-${lnxrel}${DEVEL_PATH_ARCH_DELIMETER:-"-"}$TARGET_ARCH/Module.symvers ]; then
175         fatal 1 "cannot build kernel modules: the Kernel's Module.symvers is missing."
176     fi
177
178     return 0
179
180 }
181
182 # this of course requires a sudo rule on the builder for real RHEL:
183 # hudson ALL= NOPASSWD: /usr/bin/yumdownloader
184 # also must disable the requiretty attribute in the sudoers file
185 find_linux_rpm-rhel() {
186     local prefix="$1"
187     local wanted_kernel="$2"
188     local pathtorpms=${3:-"${KERNELRPMSBASE}/${lnxmaj}/${DISTRO}/${TARGET_ARCH}"}
189
190     local tmpdir=$(mktemp -d $pathtorpms/yumXXXXXX)
191     local sudo=""
192     if [ "$(lsb_release -s -i)" = "RedHatEnterpriseServer" ]; then
193         sudo="sudo"
194     fi
195     $sudo yumdownloader --destdir "$tmpdir" kernel-devel-"$wanted_kernel" > /dev/null
196     local rpm=$(cd $tmpdir; echo *)
197     mv "$tmpdir/$rpm" "$pathtorpms"
198     rmdir $tmpdir
199     echo "$rpm"
200
201     return 0
202
203 }