#!/bin/sh
# test we are root
if [ "$(id -u)" != "0" ]; then
   echo "run as root now exitting"
   exit 1
fi

# due to meson recreate missing la file
########################################
cat >> /usr/local/lib/libatk-1.0.la  <<'EOF'
# libatk-1.0.la - a libtool library file
# Generated by libtool (GNU libtool) 2.4.6 Debian-2.4.6-0.1
#
# Please DO NOT delete this file!
# It is necessary for linking the library.

# The name that we can dlopen(3).
dlname='libatk-1.0.so.0'

# Names of this library.
library_names='libatk-1.0.so.0.22810.1 libatk-1.0.so.0 libatk-1.0.so'

# The name of the static archive.
old_library=''

# Linker flags that cannot go in dependency_libs.
inherited_linker_flags=''

# Libraries that this one depends upon.
dependency_libs=' -L/usr/local/lib /usr/local/lib/libgobject-2.0.la /usr/local/lib/libffi.la /usr/local/lib/libglib-2.0.la /usr/local/lib/libpcre.la -lpthread'

# Names of additional weak libraries provided by this library
weak_library_names=''

# Version information for libatk-1.0.
current=22810
age=22810
revision=1

# Is this an already installed library?
installed=yes

# Should we warn about portability when linking against -modules?
shouldnotlink=no

# Files to dlopen/dlpreopen
dlopen=''
dlpreopen=''

# Directory that this library needs to be installed in:
libdir='/usr/local/lib'
EOF

CFLAGS="-mtune=generic -Os -pipe"
CXX="g++ -flto -fuse-linker-plugin -mtune=generic -Os -pipe "

P=xfwm4
V=4.13.0
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc intltool gtk2-dev libxfce4ui-dev \
libxfce4util-dev libwnck-2.30-dev"
for Z in $LIST 
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp
su -c "/usr/local/bin/wget -nc --no-check-certificate \
https://mirror.vinahost.vn/xfce/src/xfce/$P/4.13/$SRC.tar.bz2 " $USER
mkdir $P
tar jxvf $P*bz2
cd $SRC 
./configure --disable-debug --enable-epoxy \
--enable-startup-notification --enable-xsync \
--enable-render --enable-randr --enable-compositor \
--with-x --disable-xpresent
####################################
# Build Configuration for xfwm4 
#  Startup notification support: yes
#  XSync support:                yes
#  Render support:               yes
#  Xrandr support:               yes
#  Xpresent support:             no
#  Embedded compositor:          yes
#  Epoxy support:                yes
#  KDE systray protocol proxy:   no
####################################
make check
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/doc/$P
cp $SRC/AUTHORS $P-doc/usr/local/share/doc/$P
cp $SRC/COPYING $P-doc/usr/local/share/doc/$P

# no dev
#####

# main
###################################
mkdir -p $P/usr/local/share/doc/$P
echo 'see doc tcz for license' > $P/usr/local/share/doc/$P/COPYING

# desktops
###########
# desktops only appear in XFCE 

# MAIN tce.installed
##############
mkdir -p $P/usr/local/tce.installed
cat > $P/usr/local/tce.installed/$P << 'EOF'
#!/bin/sh
gtk-update-icon-cache -f -t /usr/local/share/icons/hicolor
EOF
chown -R root:staff $P/usr/local/tce.installed
chmod -R 755 $P/usr/local/tce.installed

##################
# special list TCZ
##################

# list tce.installed
############################
mkdir -p $P-list/usr/local/tce.installed

cat > $P-list/usr/local/tce.installed/$P-list << 'EOF'
#!/bin/sh
LOOP=/tmp/tcloop/xfwm4-list/usr/local/share/doc/xfwm4/xfce.lst
TB=/etc/sysconfig/backup_device
TDIR=/mnt/`cat $TB`
USER=`cat /etc/sysconfig/tcuser`
if [ ! -f $TDIR/xfce.lst ] ; then
    cp $LOOP $TDIR/
    chown $USER $TDIR/xfce.lst
    chgrp staff $TDIR/xfce.lst
    chmod 664 $TDIR/xfce.lst
fi
EOF
chown -R root:staff $P-list/usr/local/tce.installed
chmod -R 755 $P-list/usr/local/tce.installed

# ^^ its not accepting my attempt to change group 
# owner appears ok group=root

# LIST
######
mkdir -p $P-list/usr/local/share/doc/$P

echo 'xfwm4.tcz
aterm.tcz
graphics-KERNEL.tcz
Xorg-7.7.tcz ' > $P-list/usr/local/share/doc/$P/xfce.lst

# split out most themes
mkdir -p $P-extra-themes/usr/local/share/themes/
mv $P/usr/local/share/themes/Daloa $P-extra-themes/usr/local/share/themes/
mv $P/usr/local/share/themes/Default-hdpi $P-extra-themes/usr/local/share/themes/
mv $P/usr/local/share/themes/Default-xhdpi $P-extra-themes/usr/local/share/themes/
mv $P/usr/local/share/themes/Kokodi $P-extra-themes/usr/local/share/themes/
mv $P/usr/local/share/themes/Moheli $P-extra-themes/usr/local/share/themes/

# TCZ them
#######
LIST="$P $P-doc $P-locale $P-list $P-extra-themes"
for Z in $LIST
do
	mksquashfs $Z $Z.tcz
	md5sum $Z.tcz > $Z.tcz.md5.txt
	cd $Z
	find usr -not -type d > /tmp/$Z.tcz.list
        sed 's|usr|/usr|g' -i /tmp/$Z.tcz.list
	cd /tmp
done

echo 'xfwm4.tcz ' > $P-extra-themes.tcz.dep

echo 'xfwm4.tcz
intltool.tcz 
gtk2-dev.tcz 
libxfce4ui-dev.tcz 
libxfce4util-dev.tcz 
libwnck-2.30-dev.tcz ' > $P-dev.tcz.dep

echo 'xfdesktop.tcz 
graphics-KERNEL.tcz
Xorg-7.7.tcz' > $P.tcz.dep

# $P-list must have no deps

echo 'Title:          xfwm4.tcz BETA 
Description:    xfce window manager
Version:        4.13.0
Author:         see doc for authors  
Original-site:  xfce.org
Copying-policy: GPL v2
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           xfce 
Comments:       xfce window manager. BETA
                
                If you wish to try out XFCE, please follow these steps
                In APPS choose download rather than onboot. 
                               ###########################

                In Apps download xfwm4 and xfwm4-list ( APPS will also 
                download lots of dependencies as XFCE is not a light 
                window manager)

                The main reason for the below steps is if you do not 
                like XFCE, you have not corrupted your current 
                boot list, likely to be onboot.lst. So if you find any 
                gremlins simply use the exit menu or if that is not 
                working, press your hardware reboot button and reboot 
                into your preferred window manager.  Leaping ahead, my 
                list is small. On boot up to XFCE, you can use Apps ->
                Maintenance -> Onboard Maintenance to add in your fav apps.
                (APPS is smart to alter only the current boot-list file!!!)
                
                2. After download of those 2 TCZs, in a terminal
                $ tce-load -i xfwm4-list
                This will create xfce.lst into your tcedir. Note it is
                xfce.lst for list not xfce.1st Please check its there 
                before reboot! The xfwm4-list TCZ is designed to be run once,
                while the main or doc etc can be run multiple times.

                3. Reboot into your bootloader
                If you have xbase.lst entry, manually change 
                that entry from xbase.lst to xfce.lst
                and use your bootloader to boot
                (For grub2 users press F10)
                
                If you have no list showing in bootloader 
                menu, edit your bootloader menu manually,
                find the line that included tce=sd(etc)
                add this extra bit
                lst=xfce.lst 
                and then boot with that amended entry.

                If your bootloader menu is missing tce=(etc)
                add lst=xfce.lst to whatever is your kernel
                line for grub/2 
                OR for APPEND line for syslinux.cfg

                If in doubt seek help in the forum.

                4. If after testing, you like XFCE seek help
                on how to add a new entry. I use another 
                distro grub2 to boot into TC.

                5. Newbies should not delete any entry for xfce.lst
                without forum or email help. However, if you have
                intel graphics do not  delete graphics-KERNEL.tcz 
                
                My build no longer uses /etc/sysconfig/desktop
                If you wish to check you are on XFCE the 
                correct command to run is
                $ echo $XDG_CURRENT_DESKTOP
                (expected result=XFCE)

                PLEASE READ THE INFO for
                ########################
                xfce4-xkb-plugin....Thunar
                xfce4-panel.........xfce4-session
                xfce4-settings......xfdesktop
                
                and any other info files mentioned in them

                Optional Dependency
                ###################
                xfwm4-extra-themes.tcz

                Good Luck!
 
                REFERENCES
                ##########
                http://wiki.tinycorelinux.net/wiki:extlinux
                http://distro.ibiblio.org/tinycorelinux/faq.html#bootcodes
                http://wiki.tinycorelinux.net/wiki:boot_codes_explained

                Compiled for 64 9x
Change-log:     2018/04/22  First version 
Current:        2018/05/24 rebuild for gtk3 issue ' > $P.tcz.info

echo 'Title:          xfwm4-doc.tcz
Description:    docs
Version:        4.13.0
Author:         see doc for authors 
Original-site:  xfce.org
Copying-policy: GPL v2
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           xfce 
Comments:       Some docs

                Compiled for 64 9x
Change-log:     2018/04/22  First version 
Current:        2018/05/24 rebuild for gtk3 issue ' > $P-doc.tcz.info


echo 'Title:          xfwm4-locale.tcz
Description:    locales
Version:        4.13.0
Author:         see doc for authors 
Original-site:  xfce.org
Copying-policy: GPL v2
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           xfce 
Comments:       for non-english users untested

                Compiled for 64 9x
Change-log:     2018/04/22  First version 
Current:        2018/05/24 rebuild for gtk3 issue' > $P-locale.tcz.info

echo 'Title:          xfwm4-list.tcz
Description:    special TCZ to create xfce.lst
Version:        4.13.0
Author:         aus9
Original-site:  aus9 at gmx dot com
Copying-policy: GPL v2
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           xfce 
Comments:       Designed to be run once by TC members
                who wish to try out XFCE.

                An install script will place
                xfce.lst into your TCEDIR

                Members can then use Apps once they 
                have booted up with lst=xfce.lst to 
                add their preferred software.

                Compiled for 64 9x
Change-log:     2018/04/22  First version 
Current:        2018/05/24 rebuild for gtk3 issue' > $P-list.tcz.info

echo 'Title:          xfwm4-extra-themes.tcz
Description:    extra themes 
Version:        4.13.0
Author:         aus9
Original-site:  aus9 at gmx dot com
Copying-policy: GPL v2
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           xfce 
Comments:       xfwm4 has only one theme
                These add the others.
                Settings -> Window Manager
                (Not for Appearance)

                Compiled for 64 9x
Change-log:     2018/04/22  First version 
Current:        2018/05/24 rebuild for gtk3 issue ' > $P-extra-themes.tcz.info


submitqc --libs
