# The POSIX default used for an unknown/unset TARGET
# $Id: T_posix,v 1.17 2021/03/08 08:55:32 tlaronde Exp $
#
# Copyright 2004-2013, 2016-2017, 2019--2020
#     Thierry LARONDE <tlaronde@polynum.com>
# Public Domain. NO GUARANTEES!

# This default is precisely used when user doesn't know and we do not
# have a specific TARGET file. So the values are fixed for the "system"
# and customizable for the user level.
#
# It is also used to determine what variables have to be exported in
# the final config file.
#

#----- TARGET environment dependent

TARGET="$(uname -s)"
TARGET_RELEASE="$(uname -r)"
TARGET_ARCH="$(uname -p)"
TARGET_MACHINE="$(uname -m)"
TARGET_TYPE="unix" # Wider than TARGET
TARGET_SUBTYPE=${TARGET_SUBTYPE:-GENERIC} # Narrower than TARGET
TARGET_2D_TYPE=${TARGET_2D_TYPE:-dumb2D} #unsupported
TARGET_NCPU=${TARGET_NCPU:-1}

SYS_LIB_PATH="/usr/lib:/lib"
HEADER_SEARCH_PATH="SYS"
LIB_SEARCH_PATH="SYS"

OBJECT_FORMAT=

# What kind of libraries are supported? static, sshared (static shared),
# dshared (dynamic shared), or unset if use default. This is only
# documentation about the target, since the actual supported types are
# deduced from the definition of the tools.
#
LIB_TYPES="static"

# The default substitution expression for translating rkcomp
# fixed library naming scheme in the host supported one. 
# static lib.
#
# Not exported (only for rkbuild).
	LIB_A_TR=${LIB_A_TR:-'-e s!\(lib[^/][^/]*\)__\([0-9.]*\)!\1.a!'}

# Static shared.
#
# Not exported (only for rkbuild).
	LIB_SSH_TR=${LIB_SSH_TR:-'d'}

# And to find the shared lib name (the default does not care about
# versioning. You'd better define something corresponding to your real
# TARGET!).
#
# Not exported (only for rkbuild).
	LIB_DSH_TR=${LIB_DSH_TR:-'-e s!\(lib[^/][^/]*\)__[0-9.]*!\1.so!'}

# Standard libes shall be mapped.
#
CLIB="libc__ stdio.h"
MATHLIB="libm__ math.h"
YACCLIB="liby__ NULL"
LEXLIB="libl__ NULL"

# POSIX extensions.
#
ICONVLIB="libiconv__ iconv.h"
RK_PTY_TYPE=PTY_UNIX98

# C99.
#
HAVE_VSNPRINTF=NO

# Some libraries may need to be linked in a dynamically linked program
# since they call functions only in a dynamically linked CLIB.
#
DO_NOT_MAKE_STATIC=

# Some libraries must not be used static even if provided (libdl...).
# But this is OS dependent, not user configurable.
#
DO_NOT_USE_STATIC_LIBES=

# Allow unprivileged install and customization of what is not "system".
#
USER0=${USER0:-root}
GROUP0=${GROUP0:-root}

TARGETOPTDIR=${TARGETOPTDIR:-"/usr/local"}
# LIB is for machine independent; LIB1 would be bin1 lib; LIB2 bin2.
#
TARGETLIBDIR="$TARGETOPTDIR/share"
TARGETBINDIR="$TARGETOPTDIR/bin"
TARGETSBINDIR="$TARGETOPTDIR/sbin"
TARGETDOCDIR="$TARGETOPTDIR/share/doc"
TARGETTMPDIR="/tmp"
TARGETSHELL="/bin/sh"
TARGETRMDIR="rmdir"
SYSTEM_ENCODING=RK_ICONV_ASCII

# These ones are only important for shells: even Windows understand
# '/' as a path separtor; this is cmd.exe that treats it as an option
# prefix.
#
T_DIR_SEP="/"
T_PATH_SEP=":"

# Map ftn so called with all fields and args i.e $# == 7.
# ck_status is global and shall be set to non 0 (rkconfig debugging)
# and nothing echoed.
#

# The man related functions are independant from the rootdir where the
# hierarchy of manpages is rooted.

# Tmandir() used in map for setting correct man section subdir.
#
# dst=some_dir/{0,*}
#   -> some_dir/man/ if basename == 0,
#   -> some_dir/man/man$basename if basename != 0.
#
Tmandir()
{
	if test $# -ne 7; then
		log "Incorrect Tmandir ftn call with '$*'"
		ck_status=1
		return
	fi
	 
	action="$1"; ftype="$2"; owner="$3"; mod="$4"; src="$5"; dst="$6";
	# args ignored.

  	rootdir=$(dirname $dst)
	section=$(basename $dst)
  	if test $section -eq 0; then
    	dst="$rootdir/man"
  	else
    	dst="$rootdir/man/man$section"
	fi

	echo "$action" "$ftype" "$owner" "$mod" "$src" "$dst"
}

# Qualifying the files. Add the subdir and the suffix to the file.
# Map substitution ftn (see above).
#
# dst=rootdir/section/manpage
#
Tman()
{
	if test $# -ne 7; then
		log "Incorrect Tman ftn call with '$*'"
		ck_status=1
		return
	fi
	 
	action="$1"; ftype="$2"; owner="$3"; mod="$4"; src="$5"; dst="$6";
	# args ignored.

	manpage=$(basename $dst)
	rootdir=$(dirname $dst)
	section=$(basename $rootdir)
	if test "x$section" = x; then
		log "Incorrect $0 ftn call with '$*'"
		ck_status=1
		return
	fi

	rootdir=$(dirname $rootdir)
	if test $section -eq 0; then
		dst="$rootdir/man/$manpage"
	else
		dst="$rootdir/man/man$section/$manpage.$section"
	fi

	echo "$action" "$ftype" "$owner" "$mod" "$src" "$dst"
}


# For now, the default librkcompsh version for explicating libraries map
# instructions will do.
# It is used only at rkconfig() time, not on the TARGET (but is TARGET
# dependant via the regexp).
#
Tlibexpl()
{
	rk_expl_lib "$@"
}
