OLD | NEW |
| (Empty) |
1 #! /bin/sh | |
2 | |
3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | |
4 # Use of this source code is governed by a BSD-style license that can be | |
5 # found in the LICENSE file. | |
6 | |
7 # This script contains the set of commands to build a kernel package. | |
8 # | |
9 # If successful, a new linux-image-*.deb file will appear in the specified | |
10 # output directory. | |
11 # | |
12 # The user-provided kernel config file is parsed to obtain information about | |
13 # the desired kernel version and target platform. Here are the requirements: | |
14 # 1) Kernel version string in the header, e.g. "Linux kernel version: 2.6.30" | |
15 # 2) Target architecture variables set up, e.g. CONFIG_X86, CONFIG_ARM, etc. | |
16 # 3) LOCALVERSION set to describe target platform (e.g. intel-menlow). This is | |
17 # used for package naming. | |
18 SRC_ROOT=$(dirname $(readlink -f $(dirname "$0"))) | |
19 . "${SRC_ROOT}/third_party/shflags/files/src/shflags" | |
20 | |
21 KERNEL_DIR="$SRC_ROOT/third_party/kernel" | |
22 KERNEL_FDIR="$KERNEL_DIR/files" | |
23 DEFAULT_KFLAVOUR="chromeos-intel-menlow" | |
24 | |
25 # Flags | |
26 DEFAULT_BUILD_ROOT=${BUILD_ROOT:-"${SRC_ROOT}/build"} | |
27 DEFINE_string flavour "${DEFAULT_KFLAVOUR}" \ | |
28 "The kernel flavour to build." | |
29 DEFINE_string output_root "${DEFAULT_BUILD_ROOT}/x86/local_packages" \ | |
30 "Directory in which to place the resulting .deb package" | |
31 DEFINE_string build_root "$DEFAULT_BUILD_ROOT" \ | |
32 "Root of build output" | |
33 FLAGS_HELP="Usage: $0 [flags]" | |
34 | |
35 # Parse command line | |
36 FLAGS "$@" || exit 1 | |
37 eval set -- "${FLAGS_ARGV}" | |
38 | |
39 # Die on any errors. | |
40 set -e | |
41 | |
42 # TODO: We detect the ARCH below. We can sed the FLAGS_output_root to replace | |
43 # an ARCH placeholder with the proper architecture rather than assuming x86. | |
44 mkdir -p "$FLAGS_output_root" | |
45 | |
46 # Set up kernel source tree and prepare to start the compilation. | |
47 # TODO: Decide on proper working directory when building kernels. It should | |
48 # be somewhere under ${BUILD_ROOT}. | |
49 SRCDIR="${FLAGS_build_root}/kernels/kernel-${FLAGS_flavour}" | |
50 rm -rf "$SRCDIR" | |
51 mkdir -p "$SRCDIR" | |
52 cp -a "${KERNEL_FDIR}"/* "$SRCDIR" | |
53 cd "$SRCDIR" | |
54 | |
55 # | |
56 # Build the config file | |
57 # | |
58 fakeroot debian/rules clean prepare-$FLAGS_flavour | |
59 | |
60 # Parse kernel config file for target architecture information. This is needed | |
61 # to setup the environment for kernel build scripts which use "uname -m" to auto
detect architecture. | |
62 KCONFIG="$SRCDIR/debian/build/build-$FLAGS_flavour/.config" | |
63 if [ ! -f "$KCONFIG" ]; then | |
64 echo Total bummer. No config file was created. | |
65 exit 1 | |
66 fi | |
67 if [ -n $(grep 'CONFIG_X86=y' "$KCONFIG") ] | |
68 then | |
69 ARCH="i386" | |
70 elif [ -n $(grep 'CONFIG_X86_64=y' "$KCONFIG") ] | |
71 then | |
72 ARCH="x86_64" | |
73 elif [ -n $(grep 'CONFIG_ARM=y' "$KCONFIG") ] | |
74 then | |
75 ARCH="arm" | |
76 else | |
77 exit 1 | |
78 fi | |
79 | |
80 # Parse the config file for a line with "version" in it (in the header) | |
81 # and remove any leading text before the major number of the kernel version | |
82 FULLVERSION=$(dpkg-parsechangelog -l$SRCDIR/debian.chrome/changelog|grep "Versio
n:"|sed 's/^Version: //') | |
83 | |
84 # linux-image-2.6.31-0-chromeos-intel-menlow_2.6.31-0.1_i386.deb | |
85 # FULLVERSION has the form "2.6.3x-ABI-MINOR" where x is {1,2}, ABI and MINOR ar
e an integers. | |
86 #In this example MAJOR is 2.6.31, ABI is 0, MINOR is 1 | |
87 MAJOR=$(echo $FULLVERSION | sed -e 's/\(^.*\)-.*$/\1/') | |
88 ABI=$(echo $FULLVERSION | sed 's/^.*-\(.*\)\..*$/\1/') | |
89 MINOR=$(echo $FULLVERSION | sed -e 's/^.*\.\([0-9]*$\)/\1/') | |
90 PACKAGE="linux-image-${MAJOR}-${ABI}-${FLAGS_flavour}_${MAJOR}-${ABI}.${MINOR}_$
{ARCH}.deb" | |
91 | |
92 echo MAJOR $MAJOR | |
93 echo ABI $ABI | |
94 echo MINOR $MINOR | |
95 echo PACKAGE $PACKAGE | |
96 | |
97 | |
98 # Remove stale packages. debian/rules will dump the package in the parent | |
99 # directory. From there, it will be moved to the output directory. | |
100 rm -f "../${PACKAGE}" | |
101 rm -f "${FLAGS_output_root}"/linux-image-*.deb | |
102 | |
103 # Build the kernel package. | |
104 fakeroot debian/rules binary-debs flavours=${FLAGS_flavour} | |
105 | |
106 # debian/rules dumps the newly created package in the parent directory | |
107 if [ -e "../${PACKAGE}" ] | |
108 then | |
109 mv "../${PACKAGE}" "${FLAGS_output_root}" | |
110 echo "Kernel build successful, check ${FLAGS_output_root}/${PACKAGE}" | |
111 else | |
112 echo "Kernel build failed" | |
113 exit 1 | |
114 fi | |
OLD | NEW |