#!/bin/sh

if [[ "$*" == *"--help"* ]] || [[ "$*" == *"-h"* ]]
then
    echo "Use environment variables to pass values:
    CC      - compiler (default: cc)
    CFLAGS  - flags for compiler
    LDFLAGS - flags for linker
    OUT     - out file (default: game
    SIZE    - size of game field
    DEFX    - start x
    DEFY    - start y"
    exit 1
fi

CC=${CC:-cc}
CFLAGS=${CFLAGS:-}
LDFLAGS=${LDFLAGS:-}
OUT=${OUT:-game}
SIZE=${SIZE:-10}
DEFX=${DEFX:-0}
DEFY=${DEFY:-0}

echo "Makefile configuration:"
echo "Compiler: $CC"
echo "CFLAGS: $CFLAGS"
echo "LDFLAGS: $LDFLAGS"
echo "Out file: $OUT"
echo
echo "Code configuration:"
echo "Size: $SIZE"
echo "Start x: $DEFX"
echo "Start y: $DEFY"

echo "CC = $CC
CFLAGS = $CFLAGS
LDFLAGS = $LDFLAGS
OUT = $OUT" > config.mk

echo "#define SIZE $SIZE
#define DEFX $DEFX
#define DEFY $DEFY" > include/config.h