Whamcloud - gitweb
8611f195e2fb82ceb23458dbd9cf9238f1aaa83e
[fs/lustre-release.git] / contrib / lbuild / 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 BUILD_GEN+=".2" # LU-9850
11
12 DEVEL_KERNEL_TYPE="devel"
13 RPM_HELPERS_DIR="/usr/lib/rpm/redhat"
14
15 # a method which can be overriden by the release specific code
16 get_rpmbuildopts() {
17
18     return 0
19
20 }
21
22 # patching common to all releases
23 patch_spec_common() {
24
25     sed -i -e '/Provides: kernel-uname-r =/a\
26 Provides: kernel-lustre = %{KVRA}%{?1:.%{1}}\\' \
27            -e '/Provides: kernel-devel-uname-r =/a\
28 Provides: kernel-devel-lustre = %{KVRA}%{?1:.%{1}}\\' \
29            -e '/find $RPM_BUILD_ROOT\/lib\/modules\/$KernelVer/a\
30     cp -a fs/ext3/* $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/fs/ext3 \
31     cp -a fs/ext4/* $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/fs/ext4' \
32           SPECS/$SPEC_NAME 2>&1 || \
33         fatal 1 "Error while editing SPECS/$SPEC_NAME"
34
35     # XXX - a building-on-Ubuntu hack
36     if grep -q "Ubuntu" /etc/issue; then
37         sed  -i -e 's/^\(BuildPreReq: .*\)$/#NOU \1/g' \
38                -e 's/^\(BuildRequires: .*\)$/#NOU \1/g' \
39                -e 's/sha512hmac/md5sum/g' \
40             SPECS/$SPEC_NAME 2>&1 || \
41                 fatal 1 "Error while editing SPECS/$SPEC_NAME"
42     fi
43
44 }
45
46 prepare_and_build_srpm() {
47
48         pushd $TOPDIR >/dev/null
49         # create the buildid
50         if $ENABLE_KERNEL_DEBUG; then
51                 local buildid="_lustre_debug${EXTRA_VERSION##*_lustre}"
52         else
53                 local buildid="_lustre${EXTRA_VERSION##*_lustre}"
54         fi
55
56         # edit the SPEC with our changes
57         patch_spec
58         popd >/dev/null
59
60         # copy our .config into the RPM build tree
61         (echo "# $(basearch ${TARGET_ARCH})"; cat $CONFIG_FILE) > \
62                 SOURCES/kernel-$lnxmaj-${TARGET_ARCH}.config
63
64         # XXX - hackity hack -- until we get (or generate from the base
65         #                       config) configs for xen and debug
66         local f=""
67         for f in SOURCES/kernel-${lnxmaj}-*.config; do
68                 grep -q "^CONFIG_SD_IOSTATS=y" $f || \
69                 echo "CONFIG_SD_IOSTATS=y" >> $f
70         done
71
72     # do we need any special rpm build options
73     local rpmbuildopt="-bb"
74     if $DO_SRC; then
75         rpmbuildopt="-ba"
76     fi
77
78     # stupid Ubuntu's rpm doesn't do debuginfo properly
79     if [ ! -f /usr/lib/rpm/debugedit ]; then
80         rpmbuildopt="$rpmbuildopt --without debuginfo"
81     fi
82
83     # XXX - need to figure this kabichk crap out -- it fails the build
84     if ! $USE_KABI; then
85         rpmbuildopt="$rpmbuildopt --without kabichk"
86     fi
87
88     # get any release specific build options
89     rpmbuildopt="$rpmbuildopt $(get_rpmbuildopts)"
90
91         # now build it
92         if ! eval rpmbuild $rpmbuildopt --target ${TARGET_ARCH} --with baseonly \
93                 --define \"_topdir $TOPDIR\" \
94                 ${buildid:+--define \"buildid $buildid\"} \
95                 --define \"_tmppath $TMPDIR\" \
96                 $TOPDIR/SPECS/$SPEC_NAME 2>&1; then
97                 return 1
98         fi
99
100     # for informative purposes, display a diff between the .config that
101     # was actually built and what we proposed as a .config
102     echo "Diffs between $(basename $CONFIG_FILE) and the built kernel's .config:"
103     local rpmname="$TOPDIR/RPMS/${TARGET_ARCH}/kernel-${lnxmaj}-${lnxrel}${buildid}.${TARGET_ARCH}.rpm"
104     rpmcfg=$(rpm -qpl $rpmname | grep '/boot/config-')
105     rpm2cpio $rpmname | cpio -id .$rpmcfg
106     diff -u $CONFIG_FILE .$rpmcfg
107     rm -rf .$rpmcfg
108
109     return 0
110
111 }
112
113 devel_kernel_name() {
114     local lustre=${1:-false}
115
116     if $lustre; then
117         echo "kernel-lustre-$DEVEL_KERNEL_TYPE"
118     else
119         echo "kernel-$DEVEL_KERNEL_TYPE"
120     fi
121
122 }
123
124 rpm_BUILD_kernel_dirname() {
125     local rpmsmptype="$1"
126     local lnxmaj="$2"
127     local lnxmin="$3"
128     local arch="$4"
129
130     local lustre=""
131     if $KERNEL_LUSTRE_NAMING; then
132         $lustre="-lustre"
133     fi
134     echo kernel${lustre}${lnxmaj}${lnxmin}/linux-${lnxmaj}.$arch
135 }
136
137 find_linux_devel_paths() {
138     local path="$1"
139     local ARCH=$TARGET_ARCH
140
141     # If DEVEL_PATH_ARCH is set, use it. Added for fc11 as it needs i586 string for i686.
142     if [ $DEVEL_PATH_ARCH ];then
143         ARCH=$DEVEL_PATH_ARCH
144     fi
145
146     LINUX=$path/usr/src/kernels/${lnxmaj}${lnxmin}-${lnxrel}${DEVEL_PATH_ARCH_DELIMETER:-"-"}${ARCH}
147     # RHEL doesn't have the -obj tree
148     LINUXOBJ=""
149
150     return 0
151 }
152
153 unpack_linux_devel_rpm-rhel() {
154     local callers_rpm="$1"
155
156     # now just sanity check that everything needed to build properly versioned
157     # modules is in place
158     if [ ! -f usr/src/kernels/${lnxmaj}${lnxmin}-${lnxrel}${DEVEL_PATH_ARCH_DELIMETER:-"-"}$TARGET_ARCH/Module.symvers ]; then
159         fatal 1 "cannot build kernel modules: the Kernel's Module.symvers is missing."
160     fi
161
162     return 0
163
164 }
165
166 # this of course requires a sudo rule on the builder for real RHEL:
167 # hudson ALL= NOPASSWD: /usr/bin/yumdownloader
168 # also must disable the requiretty attribute in the sudoers file
169 find_linux_rpm-rhel() {
170     local prefix="$1"
171     local wanted_kernel="$2"
172     local pathtorpms=${3:-"$KERNELRPMSBASE/$lnxmaj/$DISTROMAJ/$TARGET_ARCH"}
173
174     local tmpdir=$(mktemp -d $pathtorpms/yumXXXXXX)
175     local sudo=""
176     if [ "$(lsb_release -s -i)" = "RedHatEnterpriseServer" ]; then
177         sudo="sudo"
178     fi
179     if ! $sudo yumdownloader --destdir "$tmpdir" kernel-devel-"$wanted_kernel" > /dev/null; then
180         fatal 1 "failed to fetch kernel-devel-$wanted_kernel with yumdownloader."
181     fi
182     local rpm=$(cd $tmpdir; echo *)
183     mv "$tmpdir/$rpm" "$pathtorpms"
184     rmdir $tmpdir
185     echo "$rpm"
186
187     return 0
188
189 }
190
191 # This function digs out the linux release from the linux source tree
192 find_linux_release() {
193         _find_linux_release $LINUX
194 }