#!/bin/bash
set -e
TARGET="coolkbd"
FLAGS="$(pkg-config --cflags --libs x11 xft xtst xrandr)"
FLAGS="$FLAGS -Wall -lm"
MODE_FLAGS="-O3 -DNDEBUG"
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" = "-target" ] && [ -n "$2" ]; then
TARGET="$2"
shift
else
echo "usage: ./build.sh [-debug|-release] [-direct-touch] [-target TARGET]"
exit 1
fi
shift
done
if [ ! -f "config.h" ]; then
echo "copy config.h from example"
cp config.h.example config.h
fi
echo "build target: $TARGET"
echo cc main.c $MODE_FLAGS $FLAGS -o "$TARGET"
cc main.c $MODE_FLAGS $FLAGS -o "$TARGET"
echo done