aboutsummaryrefslogtreecommitdiff
path: root/personal/linux/build
blob: 6f77fd3510afe15e5180ffdcadab4e24d3b795a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/sh -e

# POSIX install functions, similar to 'install -Dm'
# and 'install -Dm* -t'
kinstall() {
    # usage: kinstall 644 file /usr/bin/prog
    mkdir -p "${3%/*}"; rmdir "$3" 2>/dev/null ||:
    cp "$2" "$3"
    [ -d "$3" ] && set -- "$1" "$3/${2##*/}"
    chmod "$1" "${3:-$2}"
}

kinstall_t() {
    # usage: kinstall_t 644 /usr/bin prog1 prog2
    mod=$1 dir=$2; mkdir -p "$dir"
    shift 2
    for file; do
        cp "$file" "$dir"
        chmod "$mod" "$dir/${file##*/}"
    done
}

# Use an out function similar to KISS' log.
out() { printf '\033[1;33m-> \033[1;36mlinux \033[m%s\n' "$@" >&2 ;}

patch -p1 < kernel-no-perl.patch

cp .config oldconfig
make olddefconfig

# Store the build version in a file and a variable.
make kernelrelease > version
read ver < version

modulepath="$1/usr/lib/modules/$ver/build"

out "Compiling the kernel"
make

out "Installing the kernel"
kinstall 644 "$(make -s image_name)" "$1/boot/vmlinuz-$ver"
kinstall 644 System.map              "$1/boot/System.map-$ver"
kinstall 644 .config                 "$1/boot/Config-$ver"

out "Installing kernel modules"
make INSTALL_MOD_PATH="$1/usr" modules_install

out "Creating module source directory"
rm -f "${modulepath%/*}/build" "${modulepath%/*}/source"
kinstall_t 644 "$modulepath/arch/x86"        arch/x86/Makefile
kinstall_t 644 "$modulepath/arch/x86/kernel" arch/x86/kernel/asm-offsets.s
kinstall_t 644 "$modulepath/kernel"          kernel/Makefile
kinstall_t 644 "$modulepath/drivers/md"      drivers/md/*.h
kinstall_t 644 "$modulepath/net/mac80211"    net/mac80211/*.h
kinstall_t 755 "$modulepath/tools/objtool"   tools/objtool/objtool
kinstall_t 644 "$modulepath"                 .config Makefile Module.symvers \
                                             System.map version vmlinux


cp -a scripts          "$modulepath/scripts"
cp -a include          "$modulepath/include"
cp -a arch/x86/include "$modulepath/arch/x86/include"

find . -name 'Kconfig*' | while read -r file; do
    kinstall 644 "$file" "$modulepath/$file"
done

out "Removing junk"
find -L "${modulepath%/*}" -type l             -exec rm -rf {} +
find    "${modulepath%/*}" -type f -name '*.o' -exec rm -rf {} +

out "Linking /usr/src/linux to the module directory"
mkdir -p "$1/usr/src"
ln -sf "${modulepath#$1}" "$1/usr/src/linux"

out Done.