#!/bin/sh # $Id$ # vim: syntax=sh PKG_NAME="@PKG_NAME@" EXPORTS="CC AR CFLAGS LDFLAGS LIBS" PREFIX="/usr/local" SKIP=0 HAVE="" for i in $@; do case "$i" in --prefix=*) PREFIX="`echo "$i" | sed "s/--prefix=//g"`" ;; esac done echo "Configuring $PKG_NAME" . ./config for i in $EXPORTS; do if [ "x`eval echo \\\$$i`" = "x" ]; then eval $i="" fi export $i done if [ "x$PKGCONF" = "x" ]; then for i in pkg-config; do FOUND=no ( $i --version >/dev/null 2>/dev/null ) && FOUND=yes if [ "$FOUND" = "yes" ]; then echo "Found working pkg-config: $i" PKGCONF="$i" fi if [ ! "x$PKGCONF" = "x" ]; then break fi done else echo "Using user-provided pkg-config: $PKGCONF" fi if [ "x$PKGCONF" = "x" ]; then echo "pkg-config not found, will not use it" fi if [ "x$CC" = "x" ]; then for i in gcc clang cc; do FOUND=no ( echo "int main(){return 0;}" | $i -x c -o /dev/null - >/dev/null 2>/dev/null ) && FOUND=yes if [ "$FOUND" = "yes" ]; then echo "Found working C compiler: $i" CC="$i" fi if [ ! "x$CC" = "x" ]; then break fi done else echo "Using user-provided C compiler: $CC" fi if [ "x$CC" = "x" ]; then echo "C compiler not found" exit 1 fi if [ "x$AR" = "x" ]; then for i in gar ar; do FOUND=no ( $i --version >/dev/null 2>&1 ) && FOUND=yes if [ "$FOUND" = "yes" ]; then echo "Found working archiver: $i" AR="$i" fi if [ ! "x$AR" = "x" ]; then break fi done else echo "Using user-provided archiver: $AR" fi if [ "x$AR" = "x" ]; then echo "Archiver not found" exit 1 fi if [ "x$RANLIB" = "x" ]; then for i in granlib ranlib; do FOUND=no ( $i --version >/dev/null 2>&1 ) && FOUND=yes if [ "$FOUND" = "yes" ]; then echo "Found working ranlib: $i" RANLIB="$i" fi if [ ! "x$RANLIB" = "x" ]; then break fi done else echo "Using user-provided ranlib: $RANLIB" fi if [ "x$RANLIB" = "x" ]; then echo "Ranlib not found" exit 1 fi CFLAGS="$CFLAGS -fPIC" if [ ! "x$PKGCONF" = "x" ]; then for i in $TRY_PKGCONF; do CFLAGS="$CFLAGS `$PKGCONF --cflags $i`" LIBS="$LIBS `$PKGCONF --libs $i`" done fi if [ "$SKIP" = "0" ]; then for i in $REQUIRED_HEADERS; do FOUND=no echo -n "Checking if header $i exists... " ( printf "#include <$i>\nint main(){return 0;}" | $CC -c $CFLAGS -x c -o /dev/null - >/dev/null 2>/dev/null ) && FOUND=yes if [ "$FOUND" = "yes" ]; then echo "yes" else echo "no" if [ "$OPTIONAL" = "1" ]; then SKIP=1 echo "This is optional package, simply not building" break else echo "Cannot continue" exit 1 fi fi done fi if [ "$SKIP" = "0" ]; then for i in $REQUIRED_LIBS; do FOUND=no echo -n "Checking if library $i exists... " ( printf "int main(){return 0;}" | $CC $CFLAGS $LDFLAGS -x c -o /dev/null - -l$i >/dev/null 2>/dev/null ) && FOUND=yes if [ "$FOUND" = "yes" ]; then echo "yes" LIBS="$LIBS -l$i" else echo "no" if [ "$OPTIONAL" = "1" ]; then SKIP=1 echo "This is optional package, simply not building" break else echo "Cannot continue" exit 1 fi fi done fi if [ "$SKIP" = "0" ]; then for i in $OPTIONAL_FUNCTIONS; do FOUND=no HEADER="`echo $i | sed 's/.*@//g'`" SYMBOL="`echo $i | sed 's/@.*//g'`" DEF=0 echo -n "Checking if $SYMBOL exists in $HEADER... " ( printf "#include <$HEADER>\nint main(){void* sym = $SYMBOL;return 0;}" | $CC -c $CFLAGS -Werror -x c -o /dev/null - >/dev/null 2>/dev/null ) && FOUND=yes if [ "$FOUND" = "yes" ]; then echo "yes" DEF=1 else echo "no" fi HAVE="$HAVE HAVE_`echo $HEADER | sed 's%\.%_%g' | sed 's%/%_%g' | tr "[a-z]" "[A-Z]"`__`echo $SYMBOL | sed 's%/%_%g' | tr "[a-z]" "[A-Z]"`=$DEF" done fi if [ "$SKIP" = "0" ]; then for i in $OPTIONAL_VALUES; do FOUND=no HEADER="`echo $i | sed 's/.*@//g'`" SYMBOL="`echo $i | sed 's/@.*//g'`" DEF=0 echo -n "Checking if $SYMBOL exists in $HEADER... " ( printf "#include <$HEADER>\nint main(){(void)$SYMBOL;return 0;}" | $CC -c $CFLAGS -Werror -x c -o /dev/null - >/dev/null 2>/dev/null ) && FOUND=yes if [ "$FOUND" = "yes" ]; then echo "yes" DEF=1 else echo "no" fi HAVE="$HAVE HAVE_`echo $HEADER | sed 's%\.%_%g' | sed 's%/%_%g' | tr "[a-z]" "[A-Z]"`__`echo $SYMBOL | sed 's%/%_%g' | tr "[a-z]" "[A-Z]"`=$DEF" done fi if [ "$SKIP" = "0" ]; then for i in $OPTIONAL_LIBS; do FOUND=no echo -n "Checking if library $i exists... " ( printf "int main(){return 0;}" | $CC $CFLAGS $LDFLAGS -Werror -x c -o /dev/null - -l$i >/dev/null 2>/dev/null ) && FOUND=yes if [ "$FOUND" = "yes" ]; then echo "yes" LIBS="$LIBS -l$i" else echo "no" fi done fi if [ "$SKIP" = "0" ]; then echo "Generating config.h" echo "#ifndef __CONFIG_H__" > config.h echo "#define __CONFIG_H__" >> config.h for i in $HAVE; do echo "#define `echo $i | sed "s/=/ /g"`" >> config.h done echo "#endif" >> config.h fi echo "Generating Makefile" echo "# This file was auto-generated" > Makefile echo "CC=$CC" >> Makefile echo "AR=$AR" >> Makefile echo "RANLIB=$RANLIB" >> Makefile echo "CFLAGS=$CFLAGS" >> Makefile echo "LDFLAGS=$LDFLAGS" >> Makefile echo "LIBS=$LIBS" >> Makefile echo >> Makefile echo ".SUFFIXES: .c .o" >> Makefile echo ".PHONY: all clean install" >> Makefile echo "all: $TARGET" >> Makefile echo >> Makefile echo "clean:" >> Makefile echo " rm -f *.o *.so $TARGET" >> Makefile echo >> Makefile echo "$TARGET: $OBJS" >> Makefile if [ "$SKIP" = "1" ]; then echo " @echo Not building" >> Makefile elif [ "$TYPE" = "static" ]; then echo " \$(AR) rc $TARGET $OBJS" >> Makefile echo " \$(RANLIB) $TARGET" >> Makefile elif [ "$TYPE" = "exec" ]; then echo " \$(CC) \$(LDFLAGS) -o $TARGET $OBJS \$(LIBS)" >> Makefile elif [ "$TYPE" = "shared" -o "$TYPE" = "driver" ]; then echo " \$(CC) \$(LDFLAGS) -shared -o $TARGET $OBJS \$(LIBS)" >> Makefile fi echo >> Makefile echo "install: all" >> Makefile if [ "$SKIP" = "1" ]; then echo " @echo Not installing" >> Makefile elif [ "$TYPE" = "static" ]; then : elif [ "$TYPE" = "exec" ]; then echo " mkdir -p $PREFIX/bin" >> Makefile echo " cp $TARGET $PREFIX/bin/$TARGET" >> Makefile elif [ "$TYPE" = "driver" ]; then echo " mkdir -p $PREFIX/lib/multiview" >> Makefile echo " cp $TARGET $PREFIX/lib/multiview/$TARGET" >> Makefile elif [ "$TYPE" = "shared" ]; then echo " mkdir -p $PREFIX/lib" >> Makefile echo " cp $TARGET $PREFIX/lib/$TARGET" >> Makefile fi echo >> Makefile echo ".c.o:" >> Makefile echo " \$(CC) \$(CFLAGS) -c -o \$@ \$<" >> Makefile