Whamcloud - gitweb
LU-15825 ldlm: remove linefeed from LDLM_DEBUG
[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         if [[ $DISTROMAJ == "rhel7" ]];then
62                 local cfg_file_name=kernel-$lnxmaj-${TARGET_ARCH}.config
63         else
64                 local cfg_file_name=kernel-${TARGET_ARCH}.config
65         fi
66         (echo "# $(basearch ${TARGET_ARCH})"; cat $CONFIG_FILE) > \
67                 SOURCES/$cfg_file_name
68
69         # XXX - hackity hack -- until we get (or generate from the base
70         #                       config) configs for xen and debug
71         local f=""
72         for f in SOURCES/kernel-*.config; do
73                 grep -q "^CONFIG_SD_IOSTATS=y" $f || \
74                 echo "CONFIG_SD_IOSTATS=y" >> $f
75         done
76
77     # do we need any special rpm build options
78     local rpmbuildopt="-bb"
79     if $DO_SRC; then
80         rpmbuildopt="-ba"
81     fi
82
83     # stupid Ubuntu's rpm doesn't do debuginfo properly
84     if [ ! -f /usr/lib/rpm/debugedit ]; then
85         rpmbuildopt="$rpmbuildopt --without debuginfo"
86     fi
87
88     # XXX - need to figure this kabichk crap out -- it fails the build
89     if ! $USE_KABI; then
90         rpmbuildopt="$rpmbuildopt --without kabichk"
91     fi
92
93     # get any release specific build options
94     rpmbuildopt="$rpmbuildopt $(get_rpmbuildopts)"
95
96         # now build it
97         if ! eval rpmbuild $rpmbuildopt --target ${TARGET_ARCH} \
98                 --define \"_topdir $TOPDIR\" \
99                 ${buildid:+--define \"buildid $buildid\"} \
100                 --define \"_tmppath $TMPDIR\" \
101                 $TOPDIR/SPECS/$SPEC_NAME 2>&1; then
102                 return 1
103         fi
104
105     # for informative purposes, display a diff between the .config that
106     # was actually built and what we proposed as a .config
107     echo "Diffs between $(basename $CONFIG_FILE) and the built kernel's .config:"
108     local rpmname="$TOPDIR/RPMS/${TARGET_ARCH}/kernel-${lnxmaj}-${lnxrel}${buildid}.${TARGET_ARCH}.rpm"
109     rpmcfg=$(rpm -qpl $rpmname | grep '/boot/config-')
110     rpm2cpio $rpmname | cpio -id .$rpmcfg
111     diff -u $CONFIG_FILE .$rpmcfg
112     rm -rf .$rpmcfg
113
114     return 0
115
116 }
117
118 devel_kernel_name() {
119     local lustre=${1:-false}
120
121     if $lustre; then
122         echo "kernel-lustre-$DEVEL_KERNEL_TYPE"
123     else
124         echo "kernel-$DEVEL_KERNEL_TYPE"
125     fi
126
127 }
128
129 rpm_BUILD_kernel_dirname() {
130     local rpmsmptype="$1"
131     local lnxmaj="$2"
132     local lnxmin="$3"
133     local arch="$4"
134
135     local lustre=""
136     if $KERNEL_LUSTRE_NAMING; then
137         $lustre="-lustre"
138     fi
139     echo kernel${lustre}${lnxmaj}${lnxmin}/linux-${lnxmaj}.$arch
140 }
141
142 find_linux_devel_paths() {
143     local path="$1"
144     local ARCH=$TARGET_ARCH
145
146     # If DEVEL_PATH_ARCH is set, use it. Added for fc11 as it needs i586 string for i686.
147     if [ $DEVEL_PATH_ARCH ];then
148         ARCH=$DEVEL_PATH_ARCH
149     fi
150
151     LINUX=$path/usr/src/kernels/${lnxmaj}${lnxmin}-${lnxrel}${DEVEL_PATH_ARCH_DELIMETER:-"-"}${ARCH}
152     # RHEL doesn't have the -obj tree
153     LINUXOBJ=""
154
155     return 0
156 }
157
158 unpack_linux_devel_rpm-rhel() {
159     local callers_rpm="$1"
160
161     # now just sanity check that everything needed to build properly versioned
162     # modules is in place
163     if [ ! -f usr/src/kernels/${lnxmaj}${lnxmin}-${lnxrel}${DEVEL_PATH_ARCH_DELIMETER:-"-"}$TARGET_ARCH/Module.symvers ]; then
164         fatal 1 "cannot build kernel modules: the Kernel's Module.symvers is missing."
165     fi
166
167     return 0
168
169 }
170
171 # this of course requires a sudo rule on the builder for real RHEL:
172 # hudson ALL= NOPASSWD: /usr/bin/yumdownloader
173 # also must disable the requiretty attribute in the sudoers file
174 find_linux_rpm-rhel() {
175     local prefix="$1"
176     local wanted_kernel="$2"
177     local pathtorpms=${3:-"$KERNELRPMSBASE/$lnxmaj/$DISTROMAJ/$TARGET_ARCH"}
178
179     local tmpdir=$(mktemp -d $pathtorpms/yumXXXXXX)
180     local sudo=""
181     if [ "$(lsb_release -s -i)" = "RedHatEnterpriseServer" ]; then
182         sudo="sudo"
183     fi
184     if ! $sudo yumdownloader --destdir "$tmpdir" kernel-devel-"$wanted_kernel" > /dev/null; then
185         fatal 1 "failed to fetch kernel-devel-$wanted_kernel with yumdownloader."
186     fi
187     local rpm=$(cd $tmpdir; echo *)
188     mv "$tmpdir/$rpm" "$pathtorpms"
189     rmdir $tmpdir
190     echo "$rpm"
191
192     return 0
193
194 }
195
196 # This function digs out the linux release from the linux source tree
197 find_linux_release() {
198         _find_linux_release $LINUX
199 }