Blob Blame Raw
#!/bin/bash

set -e


TARGET="coolkbd"
FLAGS="$(pkg-config --cflags --libs x11 xft xtst xrandr)"
FLAGS="$FLAGS -Wall -lm"
MODE_FLAGS="-O3 -DNDEBUG"
DEF_CONFIG="config.h"
CONFIG="$DEF_CONFIG"

while [ "$#" != "0" ]; do
  if [ "$1" = "-release" ]; then
    true
  elif [ "$1" = "-debug" ]; then
    echo "debug mode"
    MODE_FLAGS="-g -O0"
  elif [ "$1" = "-direct-touch" ]; then
    FLAGS="$FLAGS -DDIRECT_TOUCH $(pkg-config --cflags --libs mtdev)"
  elif [ "$1" = "-config" ] && [ -n "$2" ]; then
    CONFIG="$2"
    echo "use config $CONFIG"
    shift
  elif [ "$1" = "-target" ] && [ -n "$2" ]; then
    TARGET="$2"
    shift
  else
    echo "usage: ./build.sh [-debug|-release] [-direct-touch] [-config CONFIG.H] [-target TARGET]"
    exit 1
  fi
  shift
done


if [ "$CONFIG" == "$DEF_CONFIG" ] && [ ! -f "$DEF_CONFIG" ]; then
  echo "copy $DEF_CONFIG from example"
  cp config.h.example $DEF_CONFIG
fi


echo "build target: $TARGET"
echo cc main.c $MODE_FLAGS $FLAGS -include "$CONFIG" -o "$TARGET"
     cc main.c $MODE_FLAGS $FLAGS -include "$CONFIG" -o "$TARGET"


echo done