#!/bin/sh -
# Copyright (c) 2016-2018, Yannick Cote <yanick@divyan.org>. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be found
# in the LICENSE file.
set -e

verbose=0
profile=release

hstcc=
hstcc_opts="cc gcc clang i686-w64-mingw32-gcc x86_64-w64-mingw32-gcc"
hstcxx=
hstcxx_opts="c++ g++ clang++ i686-w64-mingw32-g++ x86_64-w64-mingw32-g++"
hstar=
hstld=
hstranlib=
hstobjcopy=

tgtcc=
tgtcc_opts=$hstcc_opts
tgtcxx=
tgtcxx_opts=$hstcxx_opts
tgtar=
tgtld=
tgtranlib=
tgtobjcopy=

hststatic=0
tgtstatic=0

package_name=singularity
package_version=`(git describe --match 'v[0-9]*' --dirty --always 2>/dev/null || cat VERSION 2>/dev/null || echo "") | sed -e "s/^v//;s/-/_/g;s/_/-/;s/_/./g"`

prefix=
exec_prefix=
bindir=
sbindir=
libexecdir=
datarootdir=
datadir=
sysconfdir=
sharedstatedir=
localstatedir=
runstatedir=
includedir=
oldincludedir=
docdir=
infodir=
htmldir=
dvidir=
pdfdir=
psdir=
libdir=
localedir=
mandir=


usage () {
	echo "${0##*/}: could not complete configuration"
}

usage_args () {
	echo "Usage: ${0##*/}: [-vsS] [-P profile] [-b builddir] [-c hstcc] [-C tgtcc]"
	echo "                [-V version] [-x hstcxx] [-X tgtcxx]"
	echo "                [--INSTALLDIR=ARG (see below)]"
	echo
	echo "  Makeit general options:"
	echo "     -v   build project with verbose flags on"
	echo "     -s   build final host project binary statically"
	echo "     -S   build final target project binary statically"
	echo "     -P   use config profile to configure the project:"
	echo "            *release             normal release mode (production)"
	echo "             release-stripped    release mode, stripped symbols (rpm packaging)"
	echo "             debug               CGO objects built unoptimized, with symbols"
	echo "     -b   build project in \`builddir'"
	echo "     -c   build project with host C \`compiler'"
	echo "     -C   build project with target C\`compiler'"
	echo "     -V   build project with given version"
	echo "     -x   build project with host C++ \`compiler'"
	echo "     -X   build project with target C++ \`compiler'"
	echo "     -h   this help"
	echo
	echo "  Path modification options:"
	echo "     --prefix         install project in \`prefix'"
	echo "     --exec-prefix    install project executables in \`exec-prefix'"
	echo "     --bindir         install user executables in \`bindir'"
	echo "     --sbindir        install admin executables in \`sbindir'"
	echo "     --libexecdir     install program executables in \`libexecdir'"
	echo "     --datarootdir    install read-only rootdir data in \`datarootdir'"
	echo "     --datadir        install read-only data in \`datadir'"
	echo "     --sysconfdir     install read-only config files in \`sysconfdir'"
	echo "     --sharedstatedir install writable data in \`sharedstatedir'"
	echo "     --localstatedir  install writable config files in \`localstatedir'"
	echo "     --runstatedir    install writable per-process data in \`runstatedir'"
	echo "     --includedir     install header files in \`includedir'"
	echo "     --oldincludedir  install system header files in \`oldincludedir'"
	echo "     --docdir         install root documentation in \`docdir'"
	echo "     --infodir        install info documentation in \`infodir'"
	echo "     --htmldir        install html documentation in \`htmldir'"
	echo "     --dvidir         install dvi documentation in \`dvidir'"
	echo "     --pdfdir         install pdf documentation in \`pdfdir'"
	echo "     --psdir          install ps documentation in \`psdir'"
	echo "     --libdir         install libraries in \`libdir'"
	echo "     --localedir      install locale dependent data in \`localedir'"
	echo "     --mandir         install man documentation in \`mandir'"
	echo
}

# save the command line
cmdline="`pwd -P`/${0##*/} $*"

while [ $# -ne 0 ]; do
 case $1 in
  -p|--prefix*)
   if [ "$1" = "-p" ]; then
    if ! echo "$2" | awk '/^-.*/ || /^$/ { exit 2 }'; then
     echo "error option requires an argument: $1"
     exit
    fi
    prefix=$2
    shift
   else
    if echo "$1" | awk '/^--prefix=.+$/ { exit 2 }'; then
     echo "error option requires an argument: $1"
     exit
    fi
    prefix=`echo $1 | sed -e 's|.*\=\(.*\)|\1|'`
   fi
   shift;;
  -e|--exec-prefix*)
   if [ "$1" = "-e" ]; then
    if ! echo "$2" | awk '/^-.*/ || /^$/ { exit 2 }'; then
     echo "error option requires an argument: $1"
     exit
    fi
    exec_prefix=$2
    shift
   else
    if echo "$1" | awk '/^--exec-prefix=.+$/ { exit 2 }'; then
     echo "error option requires an argument: $1"
     exit
    fi
    exec_prefix=`echo $1 | sed -e 's|.*\=\(.*\)|\1|'`
   fi
   shift;;
  --bindir*)
   if echo "$1" | awk '/^--bindir=.+$/ { exit 2 }'; then
     echo "error option requires an argument: $1"
     exit
   fi
   bindir=`echo $1 | sed -e 's|.*\=\(.*\)|\1|'`
   shift;;
  --sbindir*)
   if echo "$1" | awk '/^--sbindir=.+$/ { exit 2 }'; then
     echo "error option requires an argument: $1"
     exit
   fi
   sbindir=`echo $1 | sed -e 's|.*\=\(.*\)|\1|'`
   shift;;
  --libexecdir*)
   if echo "$1" | awk '/^--libexecdir=.+$/ { exit 2 }'; then
     echo "error option requires an argument: $1"
     exit
   fi
   libexecdir=`echo $1 | sed -e 's|.*\=\(.*\)|\1|'`
   shift;;
  --datarootdir*)
   if echo "$1" | awk '/^--datarootdir=.+$/ { exit 2 }'; then
     echo "error option requires an argument: $1"
     exit
   fi
   datarootdir=`echo $1 | sed -e 's|.*\=\(.*\)|\1|'`
   shift;;
  --datadir*)
   if echo "$1" | awk '/^--datadir=.+$/ { exit 2 }'; then
     echo "error option requires an argument: $1"
     exit
   fi
   datadir=`echo $1 | sed -e 's|.*\=\(.*\)|\1|'`
   shift;;
  --sysconfdir*)
   if echo "$1" | awk '/^--sysconfdir=.+$/ { exit 2 }'; then
     echo "error option requires an argument: $1"
     exit
   fi
   sysconfdir=`echo $1 | sed -e 's|.*\=\(.*\)|\1|'`
   shift;;
  --sharedstatedir*)
   if echo "$1" | awk '/^--sharedstatedir=.+$/ { exit 2 }'; then
     echo "error option requires an argument: $1"
     exit
   fi
   sharedstatedir=`echo $1 | sed -e 's|.*\=\(.*\)|\1|'`
   shift;;
  --localstatedir*)
   if echo "$1" | awk '/^--localstatedir=.+$/ { exit 2 }'; then
     echo "error option requires an argument: $1"
     exit
   fi
   localstatedir=`echo $1 | sed -e 's|.*\=\(.*\)|\1|'`
   shift;;
  --runstatedir*)
   if echo "$1" | awk '/^--runstatedir=.+$/ { exit 2 }'; then
     echo "error option requires an argument: $1"
     exit
   fi
   runstatedir=`echo $1 | sed -e 's|.*\=\(.*\)|\1|'`
   shift;;
  --includedir*)
   if echo "$1" | awk '/^--includedir=.+$/ { exit 2 }'; then
     echo "error option requires an argument: $1"
     exit
   fi
   includedir=`echo $1 | sed -e 's|.*\=\(.*\)|\1|'`
   shift;;
  --oldincludedir*)
   if echo "$1" | awk '/^--oldincludedir=.+$/ { exit 2 }'; then
     echo "error option requires an argument: $1"
     exit
   fi
   oldincludedir=`echo $1 | sed -e 's|.*\=\(.*\)|\1|'`
   shift;;
  --docdir*)
   if echo "$1" | awk '/^--docdir=.+$/ { exit 2 }'; then
     echo "error option requires an argument: $1"
     exit
   fi
   docdir=`echo $1 | sed -e 's|.*\=\(.*\)|\1|'`
   shift;;
  --infodir*)
   if echo "$1" | awk '/^--infodir=.+$/ { exit 2 }'; then
     echo "error option requires an argument: $1"
     exit
   fi
   infodir=`echo $1 | sed -e 's|.*\=\(.*\)|\1|'`
   shift;;
  --htmldir*)
   if echo "$1" | awk '/^--htmldir=.+$/ { exit 2 }'; then
     echo "error option requires an argument: $1"
     exit
   fi
   htmldir=`echo $1 | sed -e 's|.*\=\(.*\)|\1|'`
   shift;;
  --dvidir*)
   if echo "$1" | awk '/^--dvidir=.+$/ { exit 2 }'; then
     echo "error option requires an argument: $1"
     exit
   fi
   dvidir=`echo $1 | sed -e 's|.*\=\(.*\)|\1|'`
   shift;;
  --pdfdir*)
   if echo "$1" | awk '/^--pdfdir=.+$/ { exit 2 }'; then
     echo "error option requires an argument: $1"
     exit
   fi
   pdfdir=`echo $1 | sed -e 's|.*\=\(.*\)|\1|'`
   shift;;
  --psdir*)
   if echo "$1" | awk '/^--psdir=.+$/ { exit 2 }'; then
     echo "error option requires an argument: $1"
     exit
   fi
   psdir=`echo $1 | sed -e 's|.*\=\(.*\)|\1|'`
   shift;;
  --libdir*)
   if echo "$1" | awk '/^--libdir=.+$/ { exit 2 }'; then
     echo "error option requires an argument: $1"
     exit
   fi
   libdir=`echo $1 | sed -e 's|.*\=\(.*\)|\1|'`
   shift;;
  --localedir*)
   if echo "$1" | awk '/^--localedir=.+$/ { exit 2 }'; then
     echo "error option requires an argument: $1"
     exit
   fi
   localedir=`echo $1 | sed -e 's|.*\=\(.*\)|\1|'`
   shift;;
  --mandir*)
   if echo "$1" | awk '/^--mandir=.+$/ { exit 2 }'; then
     echo "error option requires an argument: $1"
     exit
   fi
   mandir=`echo $1 | sed -e 's|.*\=\(.*\)|\1|'`
   shift;;
  -P)
   if ! echo "$2" | awk '/^-.*/ || /^$/ { exit 2 }'; then
     echo "error option requires an argument: $1"
     exit
   fi
   profile=$2; shift; shift;;
  -b)
   if ! echo "$2" | awk '/^-.*/ || /^$/ { exit 2 }'; then
     echo "error option requires an argument: $1"
     exit
   fi
   builddir="$2"; shift; shift;;
  -c)
   if ! echo "$2" | awk '/^-.*/ || /^$/ { exit 2 }'; then
     echo "error option requires an argument: $1"
     exit
   fi
   hstcc="$2"; shift; shift;;
  -C)
   if ! echo "$2" | awk '/^-.*/ || /^$/ { exit 2 }'; then
     echo "error option requires an argument: $1"
     exit
   fi
   tgtcc="$2"; shift; shift;;
  -x)
   if ! echo "$2" | awk '/^-.*/ || /^$/ { exit 2 }'; then
     echo "error option requires an argument: $1"
     exit
   fi
   hstcxx="$2"; shift; shift;;
  -X)
   if ! echo "$2" | awk '/^-.*/ || /^$/ { exit 2 }'; then
     echo "error option requires an argument: $1"
     exit
   fi
   tgtcxx="$2"; shift; shift;;
  -s)
   hststatic=1; shift;;
  -S)
   tgtstatic=1; shift;;
  -v)
   verbose=1; shift;;
  -V)
   if ! echo "$2" | awk '/^-.*/ || /^$/ { exit 2 }'; then
     echo "error option requires an argument: $1"
     exit
   fi
   package_version="$2"; shift; shift;;
  -h) usage_args; exit 2;;
  --) shift; break;;
  ?) usage_args
     exit 2;;
  *) break;;
 esac
done
short_version="`echo "$package_version"|sed 's/-.*//'`"
#
# non-option param
if [ $# != 0 ]; then
	usage_args
	exit 2
fi

# defaults paths
if [ -z "${prefix}" ]; then
	prefix=/usr/local
fi
if [ -z "${exec_prefix}" ]; then
	exec_prefix=${prefix}
fi
if [ -z "${bindir}" ]; then
	bindir=${exec_prefix}/bin
fi
if [ -z "${sbindir}" ]; then
	sbindir=${exec_prefix}/sbin
fi
if [ -z "${libexecdir}" ]; then
	libexecdir=${exec_prefix}/libexec
fi
if [ -z "${datarootdir}" ]; then
	datarootdir=${prefix}/share
fi
if [ -z "${datadir}" ]; then
	datadir=${datarootdir}
fi
if [ -z "${sysconfdir}" ]; then
	sysconfdir=${prefix}/etc
fi
if [ -z "${sharedstatedir}" ]; then
	sharedstatedir=${prefix}/com
fi
if [ -z "${localstatedir}" ]; then
	localstatedir=${prefix}/var
fi
if [ -z "${runstatedir}" ]; then
	runstatedir=${localstatedir}/run
fi
if [ -z "${includedir}" ]; then
	includedir=${prefix}/include
fi
if [ -z "${oldincludedir}" ]; then
	oldincludedir=/usr/include
fi
if [ -z "${docdir}" ]; then
	docdir=${datarootdir}/doc/${package_name}
fi
if [ -z "${infodir}" ]; then
	infodir=${datarootdir}/info
fi
if [ -z "${htmldir}" ]; then
	htmldir=${docdir}
fi
if [ -z "${dvidir}" ]; then
	dvidir=${docdir}
fi
if [ -z "${pdfdir}" ]; then
	pdfdir=${docdir}
fi
if [ -z "${psdir}" ]; then
	psdir=${docdir}
fi
if [ -z "${libdir}" ]; then
	libdir=${exec_prefix}/lib
fi
if [ -z "${localedir}" ]; then
	localedir=${datarootdir}/locale
fi
if [ -z "${mandir}" ]; then
	mandir=${datarootdir}/man
fi

# determine package version
if [ -z "$package_version" ]; then
	echo "error: unable to determine \$package_version variable"
	echo "NOTE: Not in a git tree and VERSION file not found"
	echo "NOTE: Try running mconfig with [-V version]"
	exit 2
fi

# config profile validation
case $profile in
	release);;
	release-stripped);;
	debug);;
	*) echo "$profile: no such config profile"
	   echo "       -P use config profile to configure the project:"
	   echo "           release             (DEFAULT) normal release mode (production)"
	   echo "           release-stripped    release mode, stripped symbols (rpm packaging)"
	   echo "           debug               C portion of CGO built unoptimized, with symbols"
	   exit 2;;
esac

# sourcedir and builddir
sourcedir=`pwd -P`
if [ "$builddir" = "" ]; then
	builddir=builddir
fi
if [ -e $builddir -a $builddir != "." -a $builddir != ".." ]; then
	rm -rf $builddir
fi

# setup some makeit base directories
makeit_dir=$sourcedir/makeit
makeit_mconflist=$sourcedir/mlocal/mconflist
makeit_fragsdir=$sourcedir/mlocal/frags
makeit_checksdir=$sourcedir/mlocal/checks
# mconfig tmpfiles path
makeit_interdir=$builddir/makeit-intermediate
makeit_testprogdir=$makeit_interdir/testprogs
# final generated Makefile
makeit_makefile=$builddir/Makefile
makeit_makefile_base=$makeit_interdir/base.mk

# work directory and file creation
mkdir -p $builddir
mkdir -p $makeit_interdir
mkdir -p $makeit_testprogdir
:>$makeit_makefile_base



#######################################################################
# System build tool configuration
#######################################################################
if [ -f $makeit_checksdir/basechecks.chk ]; then
	echo "=> running base system checks ..."
	. $makeit_checksdir/basechecks.chk
else
	echo "error: file $makeit_checksdir/basechecks.chk needs to be present"
	exit 2
fi



#######################################################################
# Extra user specified system configuration checks (mlocal/checks)
#######################################################################
# write a "#define" definition entry into $builddir/config.h
config_add_def ()
{
	if [ "$1" = "" -o "$2" = "" ]; then
		return
	fi
	echo "#define $*" >> $builddir/config.h
}

rm -rf $builddir/config.h
if [ -f $makeit_checksdir/project.chk ]; then
	echo "=> running project specific checks ..."
	. $makeit_checksdir/project.chk
fi



#######################################################################
# Generate fragments
#######################################################################
echo "=> generating fragments ..."
if [ ! -d $makeit_fragsdir ]; then
	echo "error: $makeit_fragsdir should be populated with Makefile fragments."
	echo "NOTE: Fragments may be copied from examples or existing projects"
	echo "NOTE: to $sourcedir/mlocal/* and tweak for your project."
	exit 2
fi


########################
# verbosity
########################
if [ "$verbose" = 1 ]; then
	echo "# build with verbose flag on" >> $makeit_makefile_base
	echo "V :=" >> $makeit_makefile_base
else
	echo "# silent build" >> $makeit_makefile_base
	echo "V := @" >> $makeit_makefile_base
fi
echo >> $makeit_makefile_base


########################
# build tools
########################
cat >> $makeit_makefile_base << EOF
# source/build locations
BUILDDIR := .
BUILDDIR_ABSPATH := `(cd $builddir && pwd -P || false)`
SOURCEDIR := $sourcedir
CONTRIBDIR := $contribdir
PREFIX := $prefix
EXECPREFIX := $exec_prefix
BINDIR := $bindir
SBINDIR := $sbindir
LIBEXECDIR := $libexecdir
DATAROOTDIR := $datarootdir
DATADIR := $datadir
SYSCONFDIR := $sysconfdir
SHAREDSTATEDIR := $sharedstatedir
LOCALSTATEDIR := $localstatedir
RUNSTATEDIR := $runstatedir
INCLUDEDIR := $includedir
OLDINCLUDEDIR := $oldincludedir
DOCDIR := $docdir
INFODIR := $infodir
HTMLDIR := $htmldir
DVIDIR := $dvidir
PDFDIR := $pdfdir
PSDIR := $psdir
LIBDIR := $libdir
LOCALEDIR := $localedir
MANDIR := $mandir

NAME := $package_name
SHORT_VERSION := $short_version
VERSION := $package_version

HOSTAR := $hstar
HOSTCC := $hstcc
HOSTCXX := $hstcxx
HOSTLD := $hstcc
HOSTRANLIB := $hstranlib
HOSTSIZE := size
HOSTOBJCOPY := $hstobjcopy

AR := $tgtar
CC := $tgtcc
CXX := $tgtcxx
LD := $tgtld
RANLIB := $tgtranlib
SIZE := size
OBJCOPY := $tgtobjcopy

ARCH := $tgt_arch

EOF


########################
# modules
########################
:>$makeit_interdir/module.lst

found_modules=`(cat $makeit_mconflist | awk '{ printf("%s ", $0) }') 2>/dev/null || true`
if [ "$found_modules" = "" ]; then
	found_modules=`find . -name '*.mconf' -print`
	if [ "$found_modules" = "" ]; then
		echo "error: no build modules found !"
		echo
		echo "You need to at least create one \`<module_name>.mconf' "
		echo "file describing either a program, a lib, or a set of"
		echo "objects to build."
		exit 2
	fi
fi
echo " found build modules:"
echo "CPPFLAGS :=" >> $makeit_makefile_base
# NOTE: parsed module (*.mconf) files only substitute var tgt_arch for now
for m in $found_modules; do
	mod=`eval echo ${m##*./}`
	modpath=`eval echo ${mod%/*}`
	if [ ! -f $mod ]; then
		echo "error: module file \`$mod' not found!"
		exit 2
	fi
	if [ `(cd "$modpath" && pwd -P || false)` = $sourcedir ]; then
		modpath="."
	fi

	echo "   +-> $mod"
	echo "$modpath `eval basename $mod`" >> $makeit_interdir/module.lst
	mkdir -p $makeit_interdir/$modpath
	cat $mod | awk -v tgt_arch=$tgt_arch '{ gsub(/tgt_arch/, \
				tgt_arch); print }' > $makeit_interdir/${mod}.parsed
#	echo "CPPFLAGS += -iquote\$(SOURCEDIR)/$modpath" >> $makeit_makefile_base
done
echo >> $makeit_makefile_base

# init LDFLAGS if static builds are supported
if [ "$hststatic" = "1" -a "$tgtstatic" = "1" ]; then
	echo "LDFLAGS := -static" >> $makeit_makefile_base
else
	echo "LDFLAGS :=" >> $makeit_makefile_base
fi
echo >> $makeit_makefile_base

cat >> $makeit_makefile_base << EOF
# make sure \`all' is the first rule
all:
EOF


# call genmod.awk, generating Makefile components
$makeit_dir/genmod.awk modfile=$makeit_interdir/module.lst \
	makeitdir=$sourcedir \
	host=$host \
	genconfdir=$makeit_interdir \
	tmpldir=$makeit_dir/tmpl



#######################################################################
# Target Makefile
#######################################################################
drawline () {
	echo >> $makeit_makefile
	printf "# [ Embedding file : %50s ] #\n" $1 >> $makeit_makefile
	echo >> $makeit_makefile
}

echo "=> building Makefile ..."

:> $makeit_makefile
echo "#" >> $makeit_makefile
echo "# Non-recursive Makefile GENERATED by \`${0##*/}' -- `date`" >> $makeit_makefile
echo "# configured: $cmdline" >> $makeit_makefile
echo "#" >> $makeit_makefile

drawline $makeit_makefile_base
cat $makeit_makefile_base >> $makeit_makefile

drawline $makeit_fragsdir/common_opts.mk
cat $makeit_fragsdir/common_opts.mk >> $makeit_makefile


if [ "$appsec" = "1" ]; then
	drawline $makeit_fragsdir/go_appsec_opts.mk
	cat $makeit_fragsdir/go_appsec_opts.mk >> $makeit_makefile
else
	drawline $makeit_fragsdir/go_common_opts.mk
	cat $makeit_fragsdir/go_common_opts.mk >> $makeit_makefile
fi

case $profile in
	release)
		drawline $makeit_fragsdir/release_opts.mk
		cat $makeit_fragsdir/release_opts.mk >> $makeit_makefile
		drawline $makeit_fragsdir/go_normal_opts.mk
		cat $makeit_fragsdir/go_normal_opts.mk >> $makeit_makefile
		;;
	release-stripped)
		drawline $makeit_fragsdir/release_opts.mk
		cat $makeit_fragsdir/release_opts.mk >> $makeit_makefile
		drawline $makeit_fragsdir/go_stripped_opts.mk
		cat $makeit_fragsdir/go_stripped_opts.mk >> $makeit_makefile
		;;
	debug)
		drawline $makeit_fragsdir/debug_opts.mk
		cat $makeit_fragsdir/debug_opts.mk >> $makeit_makefile
		drawline $makeit_fragsdir/go_normal_opts.mk
		cat $makeit_fragsdir/go_normal_opts.mk >> $makeit_makefile
		;;
esac

if [ -f "$makeit_fragsdir/arch_${tgt_arch}_opts.mk" ]; then
	drawline $makeit_fragsdir/arch_${tgt_arch}_opts.mk
	cat $makeit_fragsdir/arch_${tgt_arch}_opts.mk >> $makeit_makefile
fi

drawline $makeit_interdir/modules.mk
cat $makeit_interdir/modules.mk >> $makeit_makefile

drawline $makeit_interdir/all.mk
cat $makeit_interdir/all.mk >> $makeit_makefile

drawline $makeit_fragsdir/Makefile.stub
# here, `depends' need to happen after all other rules; at the very end
final_all=`cat $makeit_interdir/all.mk | awk 'BEGIN { FS="all: " } { print $2 }'`
cat $makeit_fragsdir/Makefile.stub | awk \
	"{ gsub(/^collect:/, \"collect: $final_all\"); print }" >> $makeit_makefile



#######################################################################
# Rpm spec for project package
#######################################################################

RPMSPEC=singularity.spec
echo "=> generating $RPMSPEC ..."
rm -f $sourcedir/$RPMSPEC
release="`echo "$package_version"|sed 's/[^-]*-//'`"
if [ "$short_version" = "$release" ]; then
    # $package_version has no dash
    release=1
fi
sed "s/@PACKAGE_VERSION@/$short_version/;s/@PACKAGE_RELEASE@/$release/" $sourcedir/dist/rpm/$RPMSPEC.in >$sourcedir/$RPMSPEC



#######################################################################
# Configuration results
#######################################################################
echo "=> project setup with :"
echo "    - target arch: $tgt_arch"
echo "    - target compiler: $tgtcc"
echo "    - target wordsize: ${tgt_word}-bit"
echo "    - host arch: $hst_arch"
echo "    - host wordsize: ${hst_word}-bit"
echo "    - host system: $host"
echo "    - config profile: $profile"
if [ "$verbose" = 1 ]; then
	echo "    - verbose: yes"
else
	echo "    - verbose: no"
fi

echo "=> $builddir/Makefile ready, try:"
echo "   $ cd $builddir"
echo "   $ make"
