#!/bin/sh
#
#         Name: configure (shell script)
#               part of the standard recipe
#       Author: Rick Troth, rogue programmer
#         Date: 2023-03-16 (Thu)
#
#

cd `dirname "$0"`

PREFIX=/usr

while [ ! -z "$*" ] ; do
  case "$1" in
    --prefix)
      shift ; PREFIX="$1"
      ;;
    --prefix=*)
      PREFIX=`echo "$1" | awk -F= '{print $2}'`
      ;;
    *)
      echo "ignoring '$1'"
      ;;
  esac
  shift
done

LOCDIR=$PREFIX/share/locale
#
US=`uname -s | sed 's#/##g'`
UM=`uname -m | sed 's#^i.86$#i386#' | sed 's#^armv.l$#arm#'`
case "$US" in
  Linux|FreeBSD)
    CFLAGS="$CFLAGS -fPIC"
#   LDFLAGS=
    SHFLAGS="$LDFLAGS -shared"
    if [ "$US" = FreeBSD -a ! -d "$LOCDIR" -a -d /usr/share/nls ] ; then
                                          LOCDIR=/usr/share/nls ; fi
    # xmsgtest: size of MSGSTRUCT is 232 bytes (FreeBSD-amd64)
    ;;
  CYGWIN*)
    US="CYGWIN"
    SHFLAGS="$LDFLAGS -shared"
    ;;
  SunOS|AIX)
    UM=`uname -p`
    # size of MSGSTRUCT is 172 bytes (SunOS-i386)
    # size of MSGSTRUCT is 232 bytes (SunOS-x86_64)
    ;;
  OS390)
    UM="s390x" # guessing! since both "s390x" and "s390" are viable
    CC="xlc"
    LDFLAGS="-O -qxplink"
    SHFLAGS="$LDFLAGS -qdll"
    if [ -d /usr/lib/nls/msg ] ; then LOCDIR=/usr/lib/nls/msg ; fi
    # size of MSGSTRUCT is 172 bytes (amode=31)
    ;;
esac

#/usr/share/locale/
#/usr/lib/nls/msg/
#/usr/share/nls/
#LOCALE=en_US.UTF-8
#LOCALE=en_US

if [ ! -z "$CHICORY_SYSTEM" ] ; then SYSTEM=CHICORY_SYSTEM
                                else SYSTEM="$US-$UM" ; fi

# create proper makefile from reference input
cat makefile.in \
  | sed "s#%CFLAGS%#$CFLAGS#g" \
  | sed "s#%PREFIX%#$PREFIX#g" \
  | sed "s#%SYSTEM%#$SYSTEM#g" \
  | sed "s#%LDFLAGS%#$LDFLAGS#g" \
  | sed "s#%SHFLAGS%#$SHFLAGS#g" \
  | sed "s#%LOCDIR%#$LOCDIR#g" \
  > makefile

# create configuration header file
rm -f xmmconfig.tmp
echo "CFLAGS=#$CFLAGS#"  >> xmmconfig.tmp
echo "PREFIX=#$PREFIX#"  >> xmmconfig.tmp
echo "SYSTEM=#$SYSTEM#"  >> xmmconfig.tmp
echo "LDFLAGS=#$LDFLAGS#" >> xmmconfig.tmp
echo "SHFLAGS=#$SHFLAGS#" >> xmmconfig.tmp
echo "LOCDIR=#$LOCDIR#"  >> xmmconfig.tmp

# create a header for C sources
sed 's/#/"/g' < xmmconfig.tmp \
  | awk '{print "#define" , $0}' > xmmconfig.h
#define VERSION not needed
#define LOCALE not needed

# create a shell resource config file
sed 's/#/"/g' < xmmconfig.tmp > xmmconfig.sh

rm xmmconfig.tmp

exit


FreeBSD:
 make a shared library:
  /usr/bin/cc -fPIC -shared -Wl,-soname,libxmitmsgxdyn.so -o libxmitmsgxdyn.so CMakeFiles/xmitmsgxdyn.dir/xmitmsgx.c.o
 make a static library:
  /usr/bin/ar qc libxmitmsgx.a CMakeFiles/xmitmsgx.dir/xmitmsgx.c.o
  /usr/bin/ranlib libxmitmsgx.a


CMAKE_SHARED_LINKER_FLAGS


