summaryrefslogtreecommitdiffstats
path: root/bldins
blob: 43ad6ddc59a603c6352a5f7519055b7c64689061 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/bin/zsh

function pread (){
        echo "[email protected]"
        [[ $debug == 0 ]] && {
        echo
        echo -n ">_ "
        read
        }
    }
unset CFLAGS CXXFLAGS LDFLAGS CC

pushd $HOME/Arch/Build/torvalds-git

install=${INSTALL:-0}

debug=${DEBUG:-0}
export KBUILD_VERBOSE=${VERBOSE:-0}
clean=${CLEAN:-1}
conf=${CONF:-1}
MAKEFLAGS=${MAKEFLAGS:--j8}
ccache=${CCACHE:-0}
export ARCH=x86_64
export LOCALVERSION=
export INSTALL_FW_PATH=/lib/firmware
if [[ $ccache == 1 ]];then
    export PATH="/usr/lib/ccache/bin/:$PATH"
    clean=0
fi
#export BUILDCMD=" make CC=clang $MAKEFLAGS bzImage modules "
export BUILDCMD=" make $MAKEFLAGS bzImage modules "
export MENUCONFIG_COLOR=blackbg
export KRCH="x86"
LOGFILE="$HOME/logs/kbuild/kbuild-$(date +%s)"
export KCFLAGS=" -march=native -O2 -pipe "
#export LDFLAGS_MODULE="-s"
#export KBUILD_LDFLAGS_MODULE="-s"
#export INSTALL_MOD_STRIP="-s"

if [[ $install == 0 ]];then

     [[ $clean == 1 ]] &&  make clean

    if [[ $debug == 1 ]];then

        #export BUILDCMD=" make $MAKEFLAGS bzImage "
        #cp ~/config/kconfig/config.debug .config
        KCFLAGS=" -mtune=generic -O1 -pipe -g "
        BUILDCMD=" make $MAKEFLAGS bzImage "
        #LDFLAGS_MODULE=""
        unset INSTALL_MOD_STRIP
        if [[ $conf == 1 ]];then
            make localyesconfig || exit 1
        fi
    else
        #cp ~/config/kconfig/config .config
        #make menuconfig || exit 1
        if [[ $conf == 1 ]];then
            make nconfig || exit 1
        fi
        make modules_prepare || exit 1

    fi

    kernver="$(make kernelrelease)"
    echo "Kernel version $kernver"
    echo "Building bzImage!"

    #/usr/bin/time -p $=BUILDCMD | tee $LOGFILE  || exit 1
    (/usr/bin/time -p $=BUILDCMD || exit 1) |& tee $LOGFILE

    ver=${kernver[(ws:-:)-1]}
    kernelname=${1:-$ver}

    pread $kernelname $kernver
else
    kernver="$(make kernelrelease)"
    ver=${kernver[(ws:-:)-1]}
    kernelname=${1:-$ver}
fi

kernelname=$kernelname:l

if [[ $debug == 0 ]];then
    sudo cp -v  System.map /boot/System.map26${kernelname}
    sudo cp -v arch/x86/boot/bzImage /boot/vmlinuz26${kernelname} || exit 1
    sudo install -m644 -D vmlinux /usr/src/linux-${kernver}/vmlinux || exit 1
else
    cp -v  System.map ~/Arch/qemu/System.map26
    cp arch/x86/boot/bzImage ~/Arch/qemu/kvmImage || exit 1
    cp vmlinux ~/Arch/qemu/vmlinux || exit 1
    #make modules_install INSTALL_MOD_PATH=~/Arch/qemu/modules || exit 1
    #make modules_install MODLIB=~/Arch/qemu/module || exit 1
    #make headers_install INSTALL_HDR_PATH=~/Arch/qemu/header || exit 1
    exit
fi

echo "Generating mkinitcpio stuff"
/bin/echo "ALL_kver=$kernver" | sudo tee /etc/mkinitcpio.d/kernel26${kernelname}.kver

/bin/echo "
# mkinitcpio preset file for $kernelname 

########################################/
# DO NOT EDIT THIS LINE:
source /etc/mkinitcpio.d/kernel26${kernelname}.kver
########################################
ALL_config=\"/etc/mkinitcpio.conf\"

PRESETS=('default' 'fallback')

default_image=\"/boot/kernel26-${kernelname}.img\"

fallback_image=\"/boot/kernel26-fallback${kernelname}.img\" 
fallback_options=\"-S autodetect\" 
" | sudo tee /etc/mkinitcpio.d/kernel26${kernelname}.preset

echo "Verify mkinitcpio.conf and others"
echo "Installing modules to /lib/modules/$kernver"

sudo make modules_install

echo "Installing firmware"
sudo make firmware_install

echo "Time for headers..hmmm"

sudo install -D -m644 Makefile /usr/src/linux-${kernver}/Makefile
sudo install -D -m644 kernel/Makefile /usr/src/linux-${kernver}/kernel/Makefile
sudo install -D -m644 .config /usr/src/linux-${kernver}/.config
sudo mkdir -p /usr/src/linux-${kernver}/include
  
  for i in acpi asm-generic config generated linux math-emu media net pcmcia scsi sound trace video xen; do
    sudo cp -a include/$i /usr/src/linux-${kernver}/include/
  done
 
  sudo mkdir -p /usr/src/linux-${kernver}/arch/x86
  sudo cp -a arch/x86/include /usr/src/linux-${kernver}/arch/x86/

  sudo cp Module.symvers /usr/src/linux-${kernver}
  sudo cp -a scripts /usr/src/linux-${kernver}
  sudo chmod og-w -R /usr/src/linux-${kernver}/scripts
  sudo mkdir -p /usr/src/linux-${kernver}/.tmp_versions
 
   sudo mkdir -p /usr/src/linux-${kernver}/arch/$KRCH/kernel
  
   sudo cp arch/$KRCH/Makefile /usr/src/linux-${kernver}/arch/$KRCH/
   sudo cp arch/$KRCH/kernel/asm-offsets.s /usr/src/linux-${kernver}/arch/$KRCH/kernel/

 
  sudo install -D -m644 Documentation/DocBook/Makefile \
    /usr/src/linux-${kernver}/Documentation/DocBook/Makefile
  sudo mkdir -p /usr/src/linux-${kernver}/include/linux
  sudo cp include/linux/inotify.h /usr/src/linux-${kernver}/include/linux/
  sudo mkdir -p /usr/src/linux-${kernver}/fs/xfs
  sudo mkdir -p /usr/src/linux-${kernver}/mm
  sudo cp fs/xfs/xfs_sb.h /usr/src/linux-${kernver}/fs/xfs/xfs_sb.h
  sudo cp -a include/drm /usr/src/linux-${kernver}/include/
  sudo cp -a include/trace /usr/src/linux-${kernver}/include/
  for i in `find . -name "Kconfig*"`; do
    sudo mkdir -p /usr/src/linux-${kernver}/`echo $i | sed 's|/Kconfig.*||'`
    sudo cp $i /usr/src/linux-${kernver}/$i
  done
 
#sudo make headers_install INSTALL_HDR_PATH=/usr/src/linux-${kernver}/

  # copy files necessary for later builds, like nvidia and vmware

sudo chown -R root.root /usr/src/linux-${kernver}
sudo find /usr/src/linux-${kernver} -type d -exec chmod 755 {} \;

echo "Installing the initramfs image"
sudo mkinitcpio -p kernel26${kernelname}

sudo depmod $kernver

pushd /lib/modules/${kernver}
sudo rm -f build
sudo ln -sf /usr/src/linux-${kernver} build
popd
popd