#!/bin/sh
#
# kTm port by Juzer
#
#       regards to hns & psych
#

# local config:
BUILD="1"
PACKAGE="gcc"

check() {
# Checking for configuration
# Downloading sources lists
INSTALLED="`ls -1 $PACKAGES/packages/|grep $PACKAGE-|cut -d "-" -f 1,2`"
$WGET -q http://ftp.gnu.org/gnu/gcc/releases/
NEW=`grep $PACKAGE index.html|cut -d '>' -f 3|cut -d '<' -f 1|cut -d '/' -f 1|tail -1`
#Checking for new version
    checkpkg
# clean
rm index.html
}

download() {
# Downloading version from "${VERFILE}"
$WGET -P $DOWNL http://ftp.gnu.org/gnu/gcc/releases/$SRC/$SRC.tar.bz2
}

build() {
# Creating new
tar jxvf $DOWNL/$SRC.tar.bz2
cd $SRC
find . -perm 777 -exec chmod 755 {} \;
find . -perm 775 -exec chmod 755 {} \;
find . -perm 754 -exec chmod 755 {} \;
find . -perm 664 -exec chmod 644 {} \;
mkdir gcc.build.lnx
cd gcc.build.lnx
../configure \
    --prefix=/usr \
    --enable-shared \
    --enable-threads=posix \
    --enable-__cxa_atexit \
    --disable-checking \
    --with-gnu-ld \
    --verbose \
    --enable-languages=c++ \
    --target=$TARGET --host=$TARGET || exit
make || exit
make install DESTDIR=$PKG || exit
make -i install-info DESTDIR=$PKG
chmod 755 $PKG/usr/lib/libgcc_s.so.1
rm -f $PKG/usr/lib/libiberty.a
rm $PKG/usr/info/dir
  ( cd $PKG
    mkdir -p lib
    cd lib
    ln -sf /usr/bin/cpp .
  )
  ( cd $PKG/usr/bin
    mv g++ g++-$SRC
    mv gcc $SRC
    ln -sf g++-$SRC g++
    ln -sf $SRC gcc
    ln -sf g++ c++
    ln -sf gcc cc
    ln -sf $SRC $TARGET-gcc
    ln -sf g++-$SRC $TARGET-c++
    ln -sf g++-$SRC $TARGET-g++
    chown root.bin * .
  )
  ( cd $PKG/usr/man
    gzip -9v */*
    cd man1
    ln -sf g++.1.gz c++.1.gz
    ln -sf gcc.1.gz cc.1.gz
  )
postbuild
}

source "${DATA:-/usr/lib/ktm}/ktm.ports.sh"

