#!/bin/bash
oldpwd=`pwd`
target=i2c-tools
# download archive
url_base="http://dl.lm-sensors.org/i2c-tools/releases"
url_file=`wget $url_base 2>/dev/null -O - \
| tr '><' '\n\n' | grep ^i2c.*\.tar\.bz2$ | tail -n1`
wget -c $url_base/$url_file
# extract archive
i2c_tools=`echo $url_file|sed -e 's|\.tar\.bz2||'`
tar -xvjf $url_file
cd $i2c_tools
# patch makefile to accept CFLAGS
cp Makefile Makefile-tc
cat Makefile-tc | sed -e 's|CFLAGS[\t]:=|CFLAGS[\t]+=|' > Makefile
rm Makefile-tc
# make
export CFLAGS="-march=i486 -mtune=i686 -Os -pipe"
export CXXFLAGS="-march=i486 -mtune=i686 -Os -pipe"
# -fno-exceptions -fno-rtti
export LDFLAGS="-Wl,-O1"
make
# install
rm -rf /tmp/package
make DESTDIR=/tmp/package install
# strip
cd /tmp/package
find . | xargs file | grep "executable" | grep ELF | grep "not stripped" \
| cut -f 1 -d : | xargs strip --strip-unneeded 2>/dev/null
find . | xargs file | grep "shared object" | grep ELF | grep "not stripped" \
| cut -f 1 -d : | xargs strip -g 2>/dev/null
# make tcz
cd /tmp
mksquashfs package $target.tcz
md5sum $target.tcz > $target.tcz.md5.txt
cd package
find usr -not -type d > ../$target.tcz.list
# mv to oldpwd
cd /tmp
mv $target.tcz $oldpwd
mv $target.tcz.md5.txt $oldpwd
mv $target.tcz.list $oldpwd
# clean
cd $oldpwd
rm -rf $i2c_tools