#!/bin/sh
# test we are root
if [ "$USER" != "root" ] ; then
   echo "Run as root please, exiting." 
   exit 1                                                      
fi

export CFLAGS="-mtune=generic -Os -pipe"
export CXXFLAGS="-mtune=generic -Os -pipe -fno-exceptions -fno-rtti"

P=lxrandr
V=0.3.3
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc automake gettext-dev glib2-dev gtk3-dev intltool lxde-icon-theme Xorg-7.7-bin   "
for Z in $LIST 
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp
/usr/local/bin/wget -nc --no-check-certificate \
https://github.com/lxde/$P/archive/refs/tags/$V.tar.gz \
https://xorg.freedesktop.org/archive/individual/app/xrandr-1.2.1.tar.bz2
tar jxvf xrandr-1.2.1.tar.bz2 # I grab header of xrandr.c for licence

tar xvf $V*gz
cd $SRC
./autogen.sh
./autogen.sh autoupdate
./configure --prefix=/usr/local --enable-gtk3
find . -name Makefile -type f -exec sed -i 's/-g -O2//g' {} \;
make -j6 # 2 seconds
make install-strip DESTDIR=/tmp/$P
cd /tmp

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

# doc
#####
mkdir -p $P-doc/usr/local/share
mv $P/usr/local/share/man $P-doc/usr/local/share

# main
###### 
# desktop
#########
DESK=$P/usr/local/share/applications/$P.desktop
sed 's|video-display|lxrandr|' -i $DESK
sed 's|GTK;Settings;HardwareSettings;X-LXDE-Settings;|Settings;System;Utility;|' -i $DESK
echo 'X-FullPathIcon=/usr/local/share/pixmaps/lxrandr.png' >> $DESK

# pixmap
#########
mkdir -p $P/usr/local/share/pixmaps
SRC2=/usr/local/share/icons/nuoveXT2/48x48/apps/utilities-system-monitor.png
cp $SRC2 $P/usr/local/share/pixmaps/lxrandr.png

# the rest
###########
mkdir -p $P/usr/local/share/doc/$P
echo 'GPL v 2' > $P/usr/local/share/doc/$P/COPYING-lxrandr
echo ' * Copyright © 2001 Keith Packard, member of The XFree86 Project, Inc.
 * Copyright © 2002 Hewlett Packard Company, Inc.
 * Copyright © 2006 Intel Corporation
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that copyright
 * notice and this permission notice appear in supporting documentation, and
 * that the name of the copyright holders not be used in advertising or
 * publicity pertaining to distribution of the software without specific,
 * written prior permission.  The copyright holders make no representations
 * about the suitability of this software for any purpose.  It is provided "as
 * is" without express or implied warranty.
 *
 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
 * OF THIS SOFTWARE.
 *
 * Thanks to Jim Gettys who wrote most of the client side code,
 * and part of the server code for randr.' > $P/usr/local/share/doc/$P/COPYING-xrandr

# bin file
SRC3=/tmp/tcloop/Xorg-7.7-bin/usr/local/bin/xrandr
cp $SRC3 $P/usr/local/bin

# TCZ them
#######
LIST="$P $P-doc $P-locale"
for Z in $LIST
do
	mksquashfs $Z $Z.tcz
	md5sum $Z.tcz > $Z.tcz.md5.txt
	cd $Z
	find . -not -type d | cut -c 2- | sort > /tmp/$Z.tcz.list
	cd /tmp
done

ls -hal

echo 'Title:          lxrandr-doc.tcz
Description:    man page
Version:        0.3.3                
Author:         Hong Jen Yee, LXDE developers, Martin Bagge, Ingo Brückl
Original-site:  https://github.com/lxde
Copying-policy: main:GPL v 2 
Size:           4.0K
Extension_by:   aus9  @ linuxquestions.org
Tags:           monitor resolution 
Comments:       man pages
                
Change-log:     2014/01/19 v 0.1.2 (bmarkus)
Current:        2026/10/04 v 0.3.3 on 17x (aus9)  ' > lxrandr-doc.tcz.info
echo 'man-db.tcz' >  lxrandr-doc.tcz.dep

echo 'Title:          lxrandr-locale.tcz
Description:    locales
Version:        0.3.3
Author:         Hong Jen Yee, LXDE developers, Martin Bagge, Ingo Brückl
Original-site:  https://github.com/lxde
Copying-policy: main:GPL v 2 
Size:           100K
Extension_by:   aus9  @ linuxquestions.org
Tags:           monitor resolution
Comments:       untested by me

Change-log:     2014/01/19 v 0.1.2 (bmarkus)
Current:        2026/10/04 v 0.3.3 on 17x (aus9)  ' > $P-locale.tcz.info
echo 'lxrandr.tcz' > $P-locale.tcz.dep

echo 'Title:          lxrandr.tcz  
Description:    gtk3 monitor tool
Version:        0.3.3
Author:         Hong Jen Yee, LXDE developers, Martin Bagge, Ingo Brückl
Original-site:  https://github.com/lxde
Copying-policy: main:GPL v 2 
Size:           24K
Extension_by:   aus9  @ linuxquestions.org
Tags:           monitor resolution
Comments:       smaller in total to arandr   
                
Change-log:     2014/01/19 v 0.1.2 (bmarkus)
Current:        2026/10/04 v 0.3.3 on 17x (aus9) ' > $P.tcz.info 
readelf -d $P/usr/local/bin/* | grep 'NEEDED'
# libgtk-3.so.0][libgdk-3.so.0] gtk3
# libpangocairo-1.0.so.0][libpango-1.0.so.0 pango gtk3
# libharfbuzz.so.0 harfbuzz gtk3
# libatk-1.0.so.0 at-spi2-core gtk3
# libcairo-gobject.so.2][libcairo.so.2 cairo gtk3
# libgdk_pixbuf-2.0.so.0 gdk-pixbuf2 gtk3
# libgio-2.0.so.0]libgobject-2.0.so.0]libglib-2.0.so.0] glib2 gtk3

echo 'gtk3.tcz
Xorg-7.7-bin.tcz' > $P.tcz.dep

