#!/bin/sh
# we are root

# configure says checking if gcc -std=gnu99 supports -fno-rtti -fno-exceptions... no
export CFLAGS="-O2 -pipe -march=i486 -mtune=i686"
export CXXFLAGS="-O2 -pipe -march=i486 -mtune=i686"

P=vlc
USER=`cat /etc/sysconfig/tcuser`

LIST="compiletc submitqc6 qt-4.x-dev libmad-dev libtheora-dev \
faad-dev x264-dev libass-dev libvdpau-dev librsvg-dev libva-dev \
avahi-dev ffmpeg-dev gettext-dev libidn-dev SDL-dev taglib-dev \ 
libcddb-dev speex-dev libmpeg2-dev automake autoconf "
for Z in $LIST
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp
su -c "/usr/local/bin/wget -nc  \
http://download.videolan.org/pub/videolan/vlc/2.2.1/vlc-2.2.1.tar.xz                                
" $USER 

# we are root for rest of commands
xz -d $P-2.2.1.tar.xz
tar xvf $P-2.2.1.tar
cd $P-*

./configure --enable-screen --disable-static --disable-a52 --disable-smbclient  \
--disable-shout --disable-live555 --disable-kate --disable-fluidsynth \
--disable-zvbi --disable-opencv --disable-libgcrypt --disable-pulse \
--disable-bluray --disable-dvdread --disable-dvdnav \
--disable-lua --disable-sout --disable-bonjour --disable-httpd --disable-vlm \
--disable-sid --disable-jack --disable-upnp --disable-gnutls  \
--disable-dc1394 --disable-linsys --disable-gnomevfs --disable-vcdx \
--disable-vnc --disable-freerdp --disable-shout --disable-mod \
--disable-gst-decode --disable-x265

# make takes about 4 minutes.....install about 1 minute
make -j5                    
mkdir -p /tmp/$P
make install DESTDIR=/tmp/$P

# Strip
#######
cd /tmp/$P/usr/local
strip --strip-all bin/vlc*
strip --strip-unneeded lib/*.so*
cd /tmp

# create dev
##########
mkdir -p $P-dev/usr/local/lib/vlc/plugins

# smaller list than vlc2
LISTD="access audio_filter audio_mixer \
audio_output codec control demux gui \
meta_engine misc packetizer \
services_discovery stream_filter text_renderer \
vdpau video_chroma video_filter video_output \
video_splitter  visualization"
for Z in $LISTD
do
SRC=/tmp/vlc/usr/local/lib/vlc/plugins/$Z
mkdir /tmp/vlc-dev/usr/local/lib/vlc/plugins/$Z
DEST=/tmp/vlc-dev/usr/local/lib/vlc/plugins/$Z
cd  $SRC
mv *.la $DEST
chmod 644 $DEST/*.la
cd /tmp
done

mv $P/usr/local/include $P-dev/usr/local/
mv $P/usr/local/lib/pkgconfig $P-dev/usr/local/lib/
mv $P/usr/local/lib/*.la $P-dev/usr/local/lib/
mv $P/usr/local/lib/vlc/*.la $P-dev/usr/local/lib/vlc/
chmod 644 $P-dev/usr/local/lib/*.la

# create locale
##############
mkdir -p $P-locale/usr/local/share
mv $P/usr/local/share/locale $P-locale/usr/local/share

# main
######
rm -rf $P/usr/local/share/kde4
mkdir -p $P/usr/local/lib/vlc/lua/playlist
mkdir -p $P/usr/local/share/vlc/ssl/certs
ln -s /usr/local/share/ca-certificates/mozilla/*  \
$P/usr/local/share/vlc/ssl/certs/

# desktop  
#########
echo "X-FullPathIcon=/usr/local/share/icons/hicolor/32x32/apps/vlc.png" \
 >> $P/usr/local/share/applications/$P.desktop

# create doc  
##########
mkdir -p $P-doc/usr/local/share
mv $P/usr/local/share/doc $P-doc/usr/local/share/
mv $P/usr/local/share/man $P-doc/usr/local/share/
cp -f vlc-*/AUTHORS $P-doc/usr/local/share/doc/$P/

# TCZ them
#######
LIST2="$P $P-dev $P-doc $P-locale "
for Z in $LIST2
do
	mksquashfs $Z $Z.tcz
	md5sum $Z.tcz > $Z.tcz.md5.txt
	cd $Z
	find usr -not -type d > /tmp/$Z.tcz.list
	cd /tmp
done

# create deps
#############
echo "qt-4.x-base.tcz
faad.tcz
libass.tcz
librsvg.tcz
alsa.tcz
libavdevice.tcz
libmpeg2.tcz
SDL.tcz
libidn.tcz
icu.tcz
libcddb.tcz
taglib.tcz
 " > $P.tcz.dep

echo "vlc.tcz" > $P-locale.tcz.dep

# create info files let submitqc6 add size
####################
echo 'Title:          vlc.tcz  TESTING
Description:    audio and video media player
Version:        2.2.1
Author:         see doc/AUTHORS        
Original-site:  http://videolan.org
Copying-policy: GPL v3
Size:		
Extension_by:   gordons64
Tags:           vlc audio video play stream encode youtube dvd
Comments:       Media player, streamer and encoder.
                alsa is loaded but some people may also need
                alsa-config read those info files if
                no sound please.

                If you need pulseaudio, dvd playback, youtube or 
                streaming support, see vlc2.tcz next command
                $ cvlc -vv (can display disabled support items)
                
                Compiled for x86 6.x
Change-log:     2014/05/01 First version, 2.1.4 bmarkus
                2015/05/04 updated 2.2.1 Juanito
Current:        2015/09/09 add streaming/youtube/dvd support gordon64 
' > $P.tcz.info

echo 'Title:          vlc-dev.tcz
Description:    vlc devs
Version:        2.2.1
Author:         see doc/AUTHORS 
Original-site:  http://videolan.org
Copying-policy: GPL v3
Size:		
Extension_by:   gordons64
Tags:           vlc 
Comments:       Development files

                Compiled for x86 6.x
Change-log:     2015/09/09 First version 
Current:        2015/09/09
' > $P-dev.tcz.info

echo "Title:          vlc-doc.tcz
Description:    vlc docs
Version:        2.2.1
Author:         see doc/AUTHORS
Original-site:  http://videolan.org
Copying-policy: GPL v3
Size:		
Extension_by:   gordons64
Tags:           vlc 
Comments:       Documents  

                Compiled for x86 6.x
Change-log:     2015/09/09 First version 
Current:        2015/09/09
" > $P-doc.tcz.info

echo "Title:          vlc-locale.tcz
Description:    vlc locales
Version:        2.2.1
Author:         see doc/AUTHORS
Original-site:  http://videolan.org
Copying-policy: GPL v3
Size:		
Extension_by:   gordons64
Tags:           vlc 
Comments:       For non-English users

                Compiled for x86 6.x
Change-log:     2015/09/09 First version 
Current:        2015/09/09
" > $P-locale.tcz.info

submitqc6