
#! /bin/sh


CC=cc
PKG_CONFIG=/usr/bin/pkg-config


function build() {
    if (echo "$1" | grep '\.c$' > /dev/null) ; then
        SAMPLE=$(echo "$1" | sed 's/\.c$//')
        SOURCE="$1"
    else
        SAMPLE="$1"
        SOURCE="${SAMPLE}.c"
    fi

    if test -z "$SOURCE" ; then
	echo "please specify a target to build"
	return 1

    elif test ! -f "$SOURCE" ; then
	echo "file not found: $SOURCE"
	return 1
    fi

    PKG_CONFIG_PATH="$PKG_CONFIG_PATH":/usr/local/lib/pkgconfig
    export PKG_CONFIG_PATH

    CFLAGS=`$PKG_CONFIG --libs --cflags glib-2.0 meanwhile`

    "$CC" $CFLAGS -o "$SAMPLE" "$SOURCE"
    return $?
}


build $1
