#!/bin/sh
# This script was automatically generated by ACR v2.2.6
# @author: pancake <nopcode.org>
# @url:    http://www.nopcode.org
# @repo:   git clone https://github.com/radare/acr

[ -z "${AWK}" ] && AWK=awk
do_remove() {
if [ "${ACR_RMFILES}" ]; then
  printf "cleaning temporally files... "
  rm -f ${ACR_RMFILES}
  echo "done"
fi
}
control_c() {
  printf "\n\n^C control-c : script execution interrupted.\n"
  do_remove
  exit 1
}
trap control_c 2
split_host() {
S="$"
while : ; do
ENVWORDS="${ENVWORDS} $1_CPU $1_OS"
STR=`eval "echo ${S}$1"`
SPLIT_CPU="`echo "$STR" | cut -d - -f 1`"
SPLIT_OS="`echo "$STR" | $AWK -F - '{
	if ($2=="unknown"){
		if (NF<3) { print $2; } else { print $3; }
	} else {
		if ($2=="linux") { print $2; } else
		if (NF<3) { print $2; } else { print $3; }
	}
}'`"
eval "$1_CPU=\"$SPLIT_CPU\""
eval "$1_OS=\"$SPLIT_OS\""
shift
[ -z "$1" ] && break
done
}

QUIET=0
be_quiet() {
	QUIET=1
}

VPATH=`dirname ${0}`
if [ "${VPATH}" = "." ]; then
	WODIS=current
else
	if [ "${VPATH}" = "${PWD}" ]; then
		VPATH=.
		WODIS=current
	else
		WODIS=crosspath
		CURDIR=$PWD
		cd $VPATH
		VPATH="${PWD}/"
		cd $CURDIR
	fi
fi

guess_os() {
if [ -e "${VPATH}/config.guess" ]; then
	sh ${VPATH}/config.guess
	return
fi
CPU="`uname -m | tr 'A-Z' 'a-z' | sed -e 's, ,,g' | cut -d - -f 1`"
OS="`uname -s|tr A-Z a-z`"
uname -r | grep -qE "(Microsoft|WSL)" 2>/dev/null && OS="wsl"
GNU="`uname --help 2>&1 | grep gnu`"
[ "${GNU}" ] && OS="${OS}-gnu"
# normalize CPU
case "${CPU}" in
	ppc*|powermac*|powermacintosh*|powerpc*)
		if echo "${CPU}" | grep -q '64'; then
			CPU=powerpc64
		else
			CPU=powerpc
		fi
		;;
	*) ;;
esac
VENDOR="unknown"
if [ "${OS}" = "darwin" ]; then
	VENDOR=apple
fi
echo "${CPU}-${VENDOR}-${OS}"
}

SEARCHPATH="/usr /usr/local /usr/pkg /sw"

: ${PREFIX:=/usr/local}
CROSSBUILD=0
BUILD=`guess_os`
HOST="${BUILD}"
TARGET="${HOST}"
ETCDIR="/etc"
SYSCONFDIR=""
DESCRIPTION="automatic configuration replacement tool"

create_environ() {
: ${EPREFIX:="${PREFIX}"}
: ${SPREFIX:="${PREFIX}"}
: ${BINDIR:="${SPREFIX}/bin"}
: ${SBINDIR:="${PREFIX}/sbin"}
: ${ETCDIR:="${SPREFIX}/etc"}
: ${LIBDIR:="${SPREFIX}/lib"}
: ${PKGCFG_LIBDIR:='${exec_prefix}/lib'}
: ${PKGCFG_INCDIR:='${prefix}/include'}
: ${LIBEXECDIR:="${SPREFIX}/libexec"}
: ${INCLUDEDIR:="${SPREFIX}/include"}
: ${DATADIR:="${SPREFIX}/share"}
: ${INFODIR:="${DATADIR}/info"}
: ${MANDIR:="${DATADIR}/man"}
: ${DOCDIR:="${DATADIR}/doc/acr"}
: ${LOCALSTATEDIR:="${SPREFIX}/var"}
for A in `echo ${PATH} | sed -e 's,:, ,g'` ; do
  [ -e "$A"/ginstall ] && : ${INSTALL:="$A"/ginstall} && break
  [ -e "$A"/install ] && : ${INSTALL:="$A"/install} && break
done
: ${INSTALL_DIR:=${INSTALL} -d}
: ${INSTALL_DATA:=${INSTALL} -m 644}
: ${INSTALL_SCRIPT:=${INSTALL} -m 755}
: ${INSTALL_PROGRAM:=${INSTALL} -m 755}
: ${INSTALL_PROGRAM_STRIP:=${INSTALL} -m 755 -s}
: ${INSTALL_MAN:=${INSTALL} -m 444}
: ${INSTALL_LIB:=${INSTALL} -m 755 -c}
 PKGNAME='acr' ; VERSION='2.2.6' ; VERSION_MAJOR=2; VERSION_MINOR=2; VERSION_PATCH=6; VERSION_NUMBER=20206; CONTACT_MAIL="pancake@nopcode.org" ; CONTACT_NAME="pancake" ; CONTACT="pancake <pancake@nopcode.org>" ;
}

show_usage() {
cat <<EOF2
'configure' configures acr-2.2.6 to adapt to many kinds of systems.

Usage: ./configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:
  -h, --help              display this help and exit
  -r, --report            show what libs/programs require to work
  -q, --quiet             be quiet, less verbose (see ./configure -qV)
  -V, --version           display version information and exit

Installation directories:
  --exec-prefix=EPREFIX  install arch-dependent files in EPREFIX [PREFIX]
  --prefix=PREFIX        install arch-independent files in PREFIX [/usr/local]
  --sandbox=SPREFIX      sandbox prefix directory: SPREFIX [PREFIX]

Fine tuning of the installation directories:
  --bindir=DIR           user executables [EPREFIX/bin]
  --datadir=DIR          read-only architecture-independent data [PREFIX/share]
  --docdir=DIR           documentation directory [DATADIR/doc/acr]
  --includedir=DIR       C header files [PREFIX/include]
  --infodir=DIR          info documentation [DATADIR/info]
  --libexecdir=DIR       program executables [EPREFIX/libexec]
  --libdir=DIR           object code libraries [EPREFIX/lib]
  --libpath=DIR          set rpath/libname-path to linker
  --localstatedir=DIR    modifiable single-machine data [PREFIX/var]
  --mandir=DIR           man documentation [DATADIR/man]
  --sbindir=DIR          system admin executables [EPREFIX/sbin]
  --etcdir=DIR           same as --sysconfdir (/etc)
  --sysconfdir=DIR       read-only single-machine data [PREFIX/etc]
  --sharedstatedir=DIR   modifiable architecture-independent data [PREFIX/com]

System types:
  --build=BUILD          configure for building on BUILD [guessed]
  --host=HOST            cross-compile to build programs to run on HOST [BUILD]
  --target=TARGET        configure for building compilers for TARGET [HOST]
EOF2

printf "
Report bugs to: pancake <pancake@nopcode.org>"
echo ""
exit 0
}

take_environ() {
: ${SH:=/bin/sh}
: ${PREFIX:=/usr/local/}
}

ochof() {
	[ "$QUIET" = 1 ] && return
	printf "$*"
}

ocho() {
	[ "$QUIET" = 1 ] && return
	echo "$*"
}

show_version() {
if [ "$QUIET" = 1 ]; then
	echo "2.2.6"
	exit 0
fi
echo "acr-2.2.6 configuration script done with acr v2.2.6.
The 'Free Software Foundation' message is only for autodetection.
Originally written by pancake <nopcode.org>."
exit 0
}

parse_options() {
flag=`echo $1| cut -d = -f 1`
value=`echo $1| $AWK 'BEGIN{FS="=";}{print $2}'`
flag2=`echo $flag|cut -f2- -d -| sed -e 's,-,_,g' -e 's,^_,,g'|tr '[a-z]' '[A-Z]'`

if [ "${TARGET_OS}" = "darwin" ]; then
	LIBPATH=-Wl,-install_name,
else
	LIBPATH=-Wl,-R
fi

case $flag in
-h|--help|--hel|--h|--he|-help)
	show_usage ; ;;
-qV|-quiet-version|--quiet-version)
	be_quiet
	show_version ; ;;
-q|-quiet|--quiet)
	be_quiet ; ;;
-V|-version|--version)
	show_version ; ;;
-r|--r|--report)
echo "PKGNAME:     acr"
echo "VERSION:     2.2.6"
echo "AUTHOR:      pancake"
echo "EMAIL:       pancake@nopcode.org"
echo "DESCRIPTION: automatic configuration replacement tool"
	exit 0
	;;
--cache-file)
	# ignored: acr have no cache
	;;
--build)
	BUILD="$value"; split_host BUILD ; ;;
--host)
	CROSSBUILD=1 # XXX
	HOST="$value"; split_host HOST ; ;;
--target)
	TARGET="$value"; split_host TARGET ; ;;
--prefix)
	PREFIX="$value"; ;;
--exec-prefix)
	EPREFIX="$value"; ;;
--sandbox|--sprefix)
	SPREFIX="$value"; ;;
--bindir)
	BINDIR="$value"; ;;
--sbindir)
	SBINDIR="$value"; ;;
--libexecdir)
	LIBEXECDIR="$value"; ;;
--docdir)
	DOCDIR="$value"; ;;
--datadir)
	DATADIR="$value"; ;;
--sysconfdir)
	SYSCONFDIR="$value"
	ETCDIR="$value"; ;;
--etcdir)
	SYSCONFDIR="$value"
	ETCDIR="$value"; ;;
--sharedstatedir)
	SHAREDSTATEDIR="$value"; ;;
--localstatedir)
	LOCALSTATEDIR="$value"; ;;
--libdir)
	LIBDIR="$value"
	PKGCFG_LIBDIR="$value"; ;;
--libpath)
	LDFLAGS="${LDFLAGS} ${LIBPATH}$value"; ;;
--includedir)
	PKGCFG_INCDIR="$value"
	INCLUDEDIR="$value"; CFLAGS="${CFLAGS} -I$value"; ;;
--infodir)
	INFODIR="$value"; ;;
--mandir)
	MANDIR="$value"; ;;

*) if [ "$value" ]; then eval "`echo $flag2=$value`" ;
else echo ; echo "WARNING: Unknown flag '$flag'." >&2 ; echo ; fi ;;
esac
}

# MAIN #
take_environ
split_host BUILD HOST TARGET
[ -z "$ACRHOOK" ] && ACRHOOK=./configure.hook
[ -e "$ACRHOOK" ] && . ${ACRHOOK}

while : ; do
[ -z "$1" ] && break
parse_options "$1"
shift
done

ENVWORDS="MANDIR DESCRIPTION INFODIR LIBDIR INCLUDEDIR LOCALSTATEDIR ETCDIR SYSCONFDIR DATADIR DOCDIR LIBEXECDIR SBINDIR BINDIR EPREFIX PREFIX SPREFIX TARGET HOST BUILD INSTALL INSTALL_LIB INSTALL_MAN INSTALL_PROGRAM INSTALL_PROGRAM_STRIP INSTALL_DIR INSTALL_SCRIPT INSTALL_DATA HOST_OS HOST_CPU BUILD_OS BUILD_CPU TARGET_OS TARGET_CPU VERSION VERSION_MAJOR VERSION_MINOR VERSION_PATCH VERSION_NUMBER PKGCFG_LIBDIR PKGCFG_INCDIR PKGNAME VPATH CONTACT CONTACT_NAME CONTACT_MAIL HAVE_INSTALL"

create_environ

ocho "checking build system type... ${BUILD}"
ocho "checking host system type... ${HOST}"
ocho "checking target system type... ${TARGET}"
[ "${CROSSBUILD}" = 1 ] && echo "using crosscompilation mode."

#split_host BUILD HOST TARGET
[ -n "${prefix}" ] && PREFIX="${prefix}"
ocho "checking for working directories... ${WODIS}"
ocho "using prefix '${PREFIX}'"
ACR_RMFILES=""

ochof "checking for install... "
if [ -x "${INSTALL}" ]; then
	FIND=${INSTALL}
else
	FIND=""
	IFS=:
	for A in ${PATH} ; do
		if [ -x "${A}/install" ]; then
			FIND="${A}/install"
			break;
		fi
	done
	unset IFS
fi
if [ -n "${FIND}" ]; then
	ocho ${FIND};
HAVE_INSTALL=1
	INSTALL=${FIND}
else
	HAVE_INSTALL=0
	INSTALL=install
if [ "" = 1 ]; then
echo "Cannot find install" >&2
else
echo no
fi ; fi
SEDFLAGS=" -e '"
COUNT=0
for A in ${ENVWORDS} ; do
	[ "${A}" = VPATH ] && continue
	[ "${A}" = srcdir ] && continue
	eval "VAR=\$${A}"
	case "" in
	mingw*|cygwin*|msys*)
		VAR="`echo ${VAR} | sed -e 's/\\/\\\\/g' -e 's/\,/\\\,/g'`"
		;;
	*)
		VAR="`echo ${VAR} | sed -e 's/\,/\\\,/g'`"
		;;
	esac
	[ $COUNT = 10 ] && COUNT=0 && SEDFLAGS="${SEDFLAGS}' -e '"
	COUNT=$(($COUNT+1))
	SEDFLAGS="${SEDFLAGS}s,@${A}@,${VAR},g;"
done
SEDFLAGS="${SEDFLAGS}'"
for A in . src/vim/install.sh  ; do # SUBDIRS
if [ -f "${VPATH}/${A}.acr" ]; then
  SD_TARGET=${A}
 else
  if [ -d "${VPATH}/${A}" ]; then
   SD_TARGET=${A}/Makefile
   mkdir -p ${A}
  else
   echo "ERROR: Cannot find ${VPATH}/${A}.acr" >&2
   exit 1
  fi
 fi
 ocho "creating ${SD_TARGET}"
[ "${VPATH}" != '.' ] &&  mkdir -p $(echo ${A} | sed -e "s,/`basename ${A}`$,,g")
 cat ${VPATH}/${SD_TARGET}.acr | \
eval sed -e "s,@VPATH@,${VPATH}/${A},g" ${SEDFLAGS} > ${SD_TARGET}.tmp

for A in ${ENVWORDS}; do
VALUE=`eval echo "$"${A}`
if [ "$VALUE" = 0 ]; then ## FALSE
 MARK="##${A}##"
if [ -n "`grep \"${MARK}\" ${SD_TARGET}.tmp`" ]; then
 mv ${SD_TARGET}.tmp ${SD_TARGET}.tmp2
 cat ${SD_TARGET}.tmp2 | MARK=$MARK $AWK 'BEGIN{a=0;}{if($1==ENVIRON["MARK"]){if(a)a=0;else a=1}else{if(!a)print;}}' > ${SD_TARGET}.tmp
 fi
fi
done
 mv ${SD_TARGET}.tmp ${SD_TARGET} && rm -f ${SD_TARGET}.tmp2
 if [ ! $? = 0 ]; then echo Cannot write target file ; control_c ; fi
done

if [ "$QUIET" = 0 ]; then
echo
echo "Final report:"
for A in  SPREFIX PREFIX INSTALL VERSION CONTACT ; do
eval VAL="\$${A}"
[ -z "${VAL}" ] && VAL="\"\""
echo " - ${A} = ${VAL}"
done
fi
#ACR# /* package information */
#ACR# PKGNAME acr
#ACR# VERSION 2.2.6
#ACR# CONTACT pancake ; pancake@nopcode.org
#ACR# 
#ACR# DESCRIPTION automatic configuration replacement tool ;
#ACR# 
#ACR# /* needed programs */
#ACR# CHECK_PROGRAM INSTALL install
#ACR# 
#ACR# /* directories */
#ACR# SUBDIRS . src/vim/install.sh ;
#ACR# /* src/acr src/acr-sh */
#ACR# 
#ACR# /* final report */
#ACR# REPORT SPREFIX PREFIX INSTALL VERSION CONTACT ;
