Merge pull request #82 from ceph/wip-rm-blkin
[autobuild-ceph.git] / build-kernel-deb.sh
1 #!/bin/sh -x
2 set -e
3
4 if [ ! -e Makefile ]; then
5     echo "$0: no Makefile, aborting." 1>&2
6     exit 3
7 fi
8
9 # Actually build the project
10
11 # clear out any $@ potentially passed in
12 set --
13
14 # enable ccache if it is installed
15 export CCACHE_DIR="$PWD/../../ccache"
16 if command -v ccache >/dev/null; then
17   if [ ! -e "$CCACHE_DIR" ]; then
18     echo "$0: have ccache but cache directory does not exist: $CCACHE_DIR" 1>&2
19   else
20     set -- CC='ccache gcc' CXX='ccache g++'
21   fi
22 else
23   echo "$0: no ccache found, compiles will be slower." 1>&2
24 fi
25
26 flavor=`hostname | sed -e "s|gitbuilder-\([^-]*\)-\([^-]*\)-\([^-]*\)-\([^-]*\)-\([^-]*\)$|\5|"`
27 config="../../kernel-config-deb.$flavor"
28 if [ ! -e "$config" ]; then
29     echo "no $config found for flavor $flavor"
30     exit 1
31 fi
32
33 install -d -m0755 build~/out
34 (
35     # we really need this to get the packages the way we want them, so just enforce it here
36     grep -v '^CONFIG_LOCALVERSION_AUTO=' $config
37     echo 'CONFIG_LOCALVERSION_AUTO=y'
38     ) >build~/out/.config
39
40 echo "$0: new kernel config options:"
41 # listnewconfig was contained in v2.6.36, but it seems out/ignore/*
42 # doesn't work quite right to ignore everything before that, so
43 # instead just ignore errors coming from it
44 ionice -c3 nice -n20 make O=build~/out listnewconfig "$@" || :
45
46 echo "$0: running make oldconfig..."
47 yes '' | ionice -c3 nice -n20 make O=build~/out oldconfig "$@"
48
49 #echo "$0: applying perf.patch..."
50 #patch -p1 < ../../perf.patch
51
52 echo "$0: building..."
53 # build dir has ~ suffix so it gets ignored by git and doesn't make
54 # the source tree look modified (get "+" in version); using subdir out
55 # so the debs go to e.g.
56 # build~/linux-image-2.6.38-ceph-00020-g4b2a58a_ceph_amd64.deb
57
58 NCPU=$(( 2 * `grep -c processor /proc/cpuinfo` ))
59 ionice -c3 nice -n20 make O=build~/out LOCALVERSION=-ceph deb-pkg -j$NCPU "$@" || exit 4
60
61 REV="$(git rev-parse HEAD)"
62 OUTDIR="../out/output/sha1/$REV"
63 OUTDIR_TMP="${OUTDIR}.tmp"
64 install -d -m0755 -- "$OUTDIR_TMP"
65 printf '%s\n' "$REV" >"$OUTDIR_TMP/sha1"
66 mv -- build~/*.deb "$OUTDIR_TMP/"
67 cp -- build~/out/.config $OUTDIR_TMP/config
68 cp -- build~/out/include/config/kernel.release $OUTDIR_TMP/version
69
70 # build a simple repro in OUTDIR_TMP too
71 DIST="squeeze"    # this could be anything
72 (
73     cd $OUTDIR_TMP
74
75     install -d -m0755 -- "conf"
76     cat > conf/distributions <<EOF
77 Codename: $DIST
78 Suite: stable
79 Components: main
80 Architectures: i386 amd64 source
81 Origin: New Dream Network
82 Description: Kernel autobuilds
83 DebIndices: Packages Release . .gz .bz2
84 DscIndices: Sources Release .gz .bz2
85 EOF
86
87     for f in image headers;
88     do
89         reprepro -b . includedeb $DIST linux-$f-*.deb
90
91         # make a consistently named symlink
92         normal=`ls linux-$f-*.deb | grep -v -- -dbg`
93         ln -s $normal linux-$f.deb
94
95         dbg=`ls linux-$f-*.deb | grep -- -dbg || true`
96         if [ -n "$dbd" ]; then
97             ln -s $dbg linux-$f-dbg.deb
98         fi
99     done
100 )
101
102 # we're successful, the files are ok to be published; try to be as
103 # atomic as possible about replacing potentially existing OUTDIR
104 if [ -e "$OUTDIR" ]; then
105     rm -rf -- "$OUTDIR.old"
106     mv -- "$OUTDIR" "$OUTDIR.old"
107 fi
108 mv -- "$OUTDIR_TMP" "$OUTDIR"
109 rm -rf -- "$OUTDIR.old"
110
111 exit 0