#!/bin/bash

prefix=/usr/local

fail_on_error=true
#fail_on_error=false

output=tail
#output=cat

set -e

files=$(cd ${prefix}/include/gstreamer-1.0/ && find . -name '*.h')

CFLAGS=`pkg-config --cflags gstreamer-1.0`
CFLAGS="$CFLAGS -DGST_USE_UNSTABLE_API"

for each in $files ; do

  echo Testing $each...
  rm -f test.o
  cat >test.c <<-EOF
#include <glib.h>
#include <gst/gst.h>
#include <$each>
EOF
  cc $CFLAGS -Wall -Werror -c test.c -o test.o 2>&1 | tail
  $fail_on_error && test ! -f test.o && exit 1

  echo Testing $each "(no gst)..."
  rm -f test.o
  cat >test.c <<-EOF
#include <glib.h>
#include <$each>
EOF
  cc $CFLAGS -Wall -Werror -c test.c -o test.o 2>&1 | tail
  $fail_on_error && test ! -f test.o && exit 1

  echo Testing $each "(no glib)..."
  rm -f test.o
  cat >test.c <<-EOF
#include <$each>
EOF
  cc $CFLAGS -Wall -Werror -c test.c -o test.o 2>&1 | tail
  $fail_on_error && test ! -f test.o && exit 1

done

