#!/bin/bash -e
# Script & lists for building newly released Xorg 7.4
# Based on lists from BLFS for Xorg 7.2
# By Curaga

# Run from the directory where you keep your X tarballs
# Run as root, have Mesa* extracted into
export MESA_PATH="/tmp/Mesa-7.2"

export XORG_CONFIG="--prefix=/usr/local --sysconfdir=/etc \
    --mandir=/usr/local/share/man --localstatedir=/var"

export DRIVER_CONFIG="--with-xorg-module-dir=/usr/local/lib/X11/modules"

export CFLAGS="-march=i486 -mtune=i686 -Os -pipe"
export CXXFLAGS="-march=i486 -mtune=i686 -Os -pipe"
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig"

for i in *proto*bz2 evieext-1.0.2.tar.bz2; do
 ls $i
 dir=$(echo $i | sed 's/.tar.bz2//')
 tar -xf $i
 cd $dir
 ./configure $XORG_CONFIG
 make DESTDIR=/tmp/dest install
 cd ..; cp -a /tmp/dest/* /
 rm -rf $dir
done

for i in makedepend-1.0.1.tar.bz2 util-macros-1.1.6.tar.bz2; do
 ls $i
 dir=$(echo $i | sed 's/.tar.bz2//')
 tar -xf $i
 cd $dir
 ./configure $XORG_CONFIG
 make -j5
 make DESTDIR=/tmp/dest install
 cd ..; cp -a /tmp/dest/* /
 rm -rf $dir
done

for i in `cat lib.list`; do
 ls $i
 dir=$(echo $i | sed 's/.tar.bz2//')
 tar -xf $i
 cd $dir
 ./configure $XORG_CONFIG
 make -j5
 make DESTDIR=/tmp/dest install
 cd ..; cp -a /tmp/dest/* /
 rm -rf $dir
done

cd $MESA_PATH
 ./configure --with-dri-driverdir=/usr/local/lib/X11/modules/dri --with-demos=xdemos
 make -j5
 make DESTDIR=/tmp/dest install
cd -

for i in `cat app.list`; do
 ls $i
 dir=$(echo $i | sed 's/.tar.bz2//')
 tar -xf $i
 cd $dir
 ./configure $XORG_CONFIG
 make -j5
 make DESTDIR=/tmp/dest install
 cd ..; cp -a /tmp/dest/* /
 rm -rf $dir
done

for i in `cat font.list`; do
 ls $i
 dir=$(echo $i | sed 's/.tar.bz2//')
 tar -xf $i
 cd $dir
 ./configure $XORG_CONFIG
 make -j5
 make DESTDIR=/tmp/dest install
 cd ..; cp -a /tmp/dest/* /
 rm -rf $dir
done

for i in xkeyboard-config-1.3.tar.bz2; do
 ls $i
 dir=$(echo $i | sed 's/.tar.bz2//')
 tar -xf $i
 cd $dir
 ./configure $XORG_CONFIG --with-xkb-rules-symlink=xorg
 make -j5
 make DESTDIR=/tmp/dest install
 cd ..; cp -a /tmp/dest/* /
 rm -rf $dir
done

for i in luit-1.0.3.tar.bz2; do
 ls $i
 dir=$(echo $i | sed 's/.tar.bz2//')
 tar -xf $i
 cd $dir
 ./configure $XORG_CONFIG --with-localealiasfile=/usr/local/share/X11/locale/locale.alias
 make -j5
 make DESTDIR=/tmp/dest install
 cd ..; cp -a /tmp/dest/* /
 rm -rf $dir
done

for i in xorg-server-1.5.1.tar.bz2; do
 ls $i
 dir=$(echo $i | sed 's/.tar.bz2//')
 tar -xf $i
 cd $dir
 ./configure $XORG_CONFIG --enable-kdrive  --enable-install-setuid \
 --with-vendor-name="TinyCore Linux" --with-vendor-name-short="TinyCore" \
 --with-vendor-web="www.tinycorelinux.com"  \
 --with-module-dir=/usr/local/lib/X11/modules  --with-xkb-output=/var/lib/xkb \
 --with-mesa-source=$MESA_PATH  --with-dri-driver-path=/usr/local/lib/X11/modules/dri
 
 make -j5
 make DESTDIR=/tmp/dest install
 cd ..; cp -a /tmp/dest/* /
 rm -rf $dir
done

for i in `cat driver.list`; do
 ls $i
 dir=$(echo $i | sed 's/.tar.bz2//')
 tar -xf $i
 cd $dir
 ./configure $XORG_CONFIG $DRIVER_CONFIG
 make -j5
 make DESTDIR=/tmp/dest install
 cd ..; cp -a /tmp/dest/* /
 rm -rf $dir
done
