# Depends on static-perl

# Exit on error:
set -e

# The gzipped archive is 92 MB:
wget https://kernel.googlesource.com/pub/scm/linux/kernel/git/vapier/lemote/+archive/2.6.36-21.lemote.tar.gz
mkdir linux-2.6.36-21.lemote
tar xf 2.6.36-21.lemote.tar.gz -C linux-2.6.36-21.lemote

cd linux-2.6.36-21.lemote
wget http://linux-libre.fsfla.org/pub/linux-libre/releases/2.6.36-gnu1/deblob-2.6.36
wget http://linux-libre.fsfla.org/pub/linux-libre/releases/2.6.36-gnu1/deblob-check
chmod u+x deblob*
# About 60 minutes for the following command:
./deblob-2.6.36 --force
rm deblob*
cd ..
mv linux-2.6.36-21.lemote linux-2.6.36-21.lemote-gnu1
tar -cf linux-2.6.36-21.lemote-gnu1.tar linux-2.6.36-21.lemote-gnu1

cd linux-2.6.36-21.lemote-gnu1
make mrproper

make ARCH=mips headers_check
#    PERL=/static/bin/perl \
#    CC=/static/bin/musl-gcc \
#    LDFLAGS='-s -L/static/lib -static -static-libgcc' \

make ARCH=mips INSTALL_HDR_PATH=dest \
    PERL=/static/bin/perl \
    CC=/static/bin/musl-gcc \
    LDFLAGS='-s -L/static/lib -static -static-libgcc' \
    headers_install

cp -rv dest/include/* /static/include
cd ..
rm -rf linux-2.6.36-21.lemote-gnu1
rm 2.6.36-21.lemote.tar.gz

exit 0
