#!/bin/bash
# this declares that current user is a sudoer
sudo tee /etc/sudoers.d/$USER <<END
END

BUILDDIR=$HOME/GIT/GSTREAMER/UBUNTU1604/gst
NEWPREFIX=/media/build/usr

GST_MODULES="gstreamer gst-plugins-base gst-plugins-good gst-plugins-ugly gst-plugins-bad gst-libav gst-rtsp-server"
#GST_MODULES="gstreamer"

for MODULE in $GST_MODULES ; do
    cd $BUILDDIR/$MODULE
	make clean
    git pull --rebase origin master
    PATH=$NEWPREFIX/bin:$PATH PKG_CONFIG_PATH=$NEWPREFIX/lib/pkgconfig ./autogen.sh --prefix $NEWPREFIX && \
    make -j10 CFLAGS+="-I$NEWPREFIX/include -I$NEWPREFIX/include/gstreamer-1.0 -I$NEWPREFIX/lib/gstreamer-1.0/include" LDFLAGS+="-L$NEWPREFIX/lib -L$NEWPREFIX/lib/gstreamer-1.0" && \
	sudo make install
done

# then to remove the sudo access from the current user
sudo /bin/rm /etc/sudoers.d/$USER
sudo -k

