#!/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=vlc2
USER=`cat /etc/sysconfig/tcuser`

# fribidi-dev in libass-dev # libogg-dev, flac-dev and libvorbis-dev inside lame-dev

LIST="compiletc submitqc6 qt-4.x-dev libmad-dev libgcrypt-dev libdvdnav-dev \
faad-dev  libtheora-dev x264-dev libass-dev libvdpau-dev librsvg-dev libva-dev \
pulseaudio-dev avahi-dev gnutls-dev taglib-dev ffmpeg-dev gettext-dev libidn-dev \ 
libbluray-dev libcddb-dev speex-dev libmpeg2-dev automake autoconf lua-5.23-dev"
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 vlc-2.2.1.tar.xz
tar xvf vlc-2.2.1.tar
cd vlc-*

./configure --enable-screen --disable-static --disable-a52 --disable-smbclient  \
--disable-shout --disable-live555 --disable-kate --disable-fluidsynth \
--disable-zvbi --disable-opencv --disable-sid --disable-jack --disable-upnp \
--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

LISTD="access access_output audio_filter \
audio_mixer audio_output  codec control \
demux gui lua meta_engine misc mux \
packetizer services_discovery stream_filter \
stream_out text_renderer vdpau \
video_chroma video_filter video_output
video_splitter  visualization"
for Z in $LISTD
do
SRC=/tmp/vlc2/usr/local/lib/vlc/plugins/$Z
mkdir /tmp/vlc2-dev/usr/local/lib/vlc/plugins/$Z
DEST=/tmp/vlc2-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/
mv $P/usr/local/share/doc/vlc $P/usr/local/share/doc/vlc2
cp $P/usr/local/share/doc/$P/lua/playlist/youtube.lua \
$P/usr/local/lib/vlc/lua/playlist

# desktop  
#########
mv $P/usr/local/share/applications/vlc.desktop \
$P/usr/local/share/applications/vlc2.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
gnutls.tcz
libidn.tcz
icu.tcz
libcddb.tcz
taglib.tcz
libdvdnav.tcz
lua-5.23.tcz
lua-5.23-lib.tcz
openssl.tcz
 " > $P.tcz.dep

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

# create info files let submitqc6 add size
####################
echo 'Title:          vlc2.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
                to load alsa-config read those info files if
                no sound please.

                See info for pulseaudio and load it if you wish
                to use it please.

                If no dvd drive or youtube or streaming support 
                needed, see vlc.tcz
                
                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 youtube/dvd support gordon64 
' > $P.tcz.info

echo 'Title:          vlc2-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:          vlc2-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 and extra lua scripts 

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

echo "Title:          vlc2-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

# submit will report libcddb.tcz is missing in the repo as a dependency of vlc2.tcz.dep
# but its OK....tested locally works fine.