#!/bin/sh
cat << 'EEE' > /dev/null
/* Copyright (C) 2021 Momi-g
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
EEE

set -eu	#exit 1 if anycmd rtns $? = 1
(
pdir=`pwd`	#parent, callsrc dir
cd `dirname $0`	#base $0 dir
bdir=`pwd`
cd ../
topdir=`pwd`	#configure root
test -d exdir || mkdir -p exdir
cd $bdir

v_afiles=`ls *.tar.gz *.zip 2>/dev/null || :`
[ ${#v_afiles} = 0 ] && exit 0

for v_afile in $v_afiles;do
	conflg=0
	cd $bdir
	v_dname=${v_afile%.tar.gz}
	v_dname=${v_dname%.zip}
	ucmd="tar -xf $v_afile"
	[ "$v_dname" = "${v_afile%.tar.gz}" ] || ucmd="unzip $v_afile"
	[ "../$v_dname" -nt "$v_afile" ] && continue ||
	{
		cp $v_afile ../
		cd ../
		rm -rf "$v_dname"
		eval "$ucmd"
		touch "$v_dname"
		conflg=1
		rm $v_afile
		cd $bdir
	}
	cd ../$v_dname	
# [ ${v_afile#app123} != $v_afile ] && make,cp,remove,ls,copy etc. not autotool pkg
	case "$v_dname" in
	ureg*)
		[ $conflg = 0 ] || ./configure
		make CFLAGS="-fPIC -g -ggdb3 -pg"
		make DESTDIR="$topdir/exdir" install
	;;
	lbc*)
		[ $conflg = 0 ] || ./configure
		make CFLAGS="-fPIC  -g -ggdb3 -pg"
		make DESTDIR="$topdir/exdir" install
	;;
	*)
		echo "unreachable code, $0" >/dev/stderr
		exit 1
	;;
	esac
done
cd "$topdir/exdir"	
buf=`find ./	\
	-name '*.a'		\
-o	-name '*.h'		\
`
for i in $buf;do
	cp $i ../src
done
)
