Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 653 lines (503 sloc) 12.084 kb
#!/bin/bash
#
# Copyright (c) 2010 William Light <wrl@illest.net>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
#
# variables and such
#
PROJECT="serialosc";
VERSION="1.0";
CC="gcc";
LD="\$(CC)";
CC_VERSION=;
CFLAGS="-ggdb";
LDFLAGS="-ggdb";
PKGCONFIG_VERSION=;
PLATFORM=;
PLATFORM_VERSION=;
DETECTOR=;
PREFIX="/usr/local";
MANDIR=;
EVLOOP="poll";
LIBUDEV_VERSION=;
DNSSD_CFLAGS=;
DNSSD_LDFLAGS="-ldns_sd";
LIBMONOME_VERSION=;
LIBMONOME_PREFIX=$PREFIX;
LIBMONOME_CFLAGS=;
LIBMONOME_LDFLAGS="-lmonome";
LO_VERSION=;
LO_PREFIX=$PREFIX;
LO_CFLAGS="";
LO_LDFLAGS="-llo -lpthread";
LIBCONFUSE_VERSION=;
LIBCONFUSE_PREFIX=$PREFIX;
LIBCONFUSE_CFLAGS="";
LIBCONFUSE_LDFLAGS="-lconfuse";
#
# functions
#
# figure out the right things to pass to echo to supress a newline
if [ "`echo -n`" = "-n" ]; then
n=""; c="\c";
else
n="-n"; c="";
fi
_echo () {
# portable (sysv/bsd) echo -n
if [ $1 = "-n" ]; then
shift;
echo $n "$*" $c;
else
echo "$*";
fi
}
echo_n () {
_echo -n "$*";
}
# color and text styles
att() {
if [ $# -eq 0 ]; then
echo -ne "\033[0m";
return 0;
fi
echo -ne "\033["
while [ $# -ge 1 ]; do
case $1 in
bold) C=1;;
underline) C=4;;
hidden) C=8;;
black) C=30;;
red) C=31;;
green) C=32;;
yellow) C=33;;
blue) C=34;;
magenta) C=35;;
cyan) C=36;;
white) C=37;;
reset)
echo -ne "0m";
return 0;
esac
echo -ne "$C"
if [ $# -ge 2 ]; then
echo -ne ";";
fi
shift;
done;
echo -ne "m";
}
style_package () { att blue bold; _echo $*; att; }
style_success () { att green; _echo $*; att; }
style_distro () { att cyan; _echo $*; att; }
style_error () { att red bold; _echo $*; att; }
style_warning () { att yellow bold; echo $*; att; }
style_link () { att blue bold underline; _echo $*; att; }
cleanup () {
rm -rf .conftests;
}
bail() {
cleanup;
exit 1;
}
die() {
style_error $*;
bail;
}
# feature test commands
try_command () {
if $* > /dev/null 2>> .config.log; then
return 0;
else
return 1;
fi
}
compile_and_run() {
FILE=$1
shift;
CMD="$CC $CFLAGS .conftests/$FILE.c -o .conftests/$FILE $LDFLAGS $*"
try_command $CMD;
RET=$?;
rm -f .conftests/$FILE.c;
[ $RET -ne 0 ] && return 1;
CMD="./.conftests/$FILE";
try_command $CMD;
RET=$?;
rm -f .conftests/$FILE;
[ $RET -ne 0 ] && return 2;
return 0;
}
check_pkgconfig () {
CMD="pkg-config --version";
if try_command $CMD; then
PKGCONFIG_VERSION=`$CMD`;
fi
}
get_platform () {
try_command "uname";
if [ $? -ne 0 ]; then
PLATFORM="dummy";
return 1;
fi
PLATFORM=`uname`;
return 0;
}
check_gcc () {
CMD="$CC -dumpversion";
try_command $CMD;
if [ $? -eq 0 ]; then
CC_VERSION=`$CMD`;
return 0;
fi
CC_VERSION=;
return 1;
}
check_poll () {
# ganked from glib's poll test
cat <<EOF > .conftests/poll.c
#include <stdlib.h>
#include <poll.h>
int main(int argc, char **argv) {
struct pollfd fds[1];
fds[0].fd = open("/dev/null", 1);
fds[0].events = POLLIN;
if( poll(fds, 1, 0) < 0 || fds[0].revents & POLLNVAL )
exit(1);
exit(0);
}
EOF
compile_and_run poll;
RET=$?;
[ $RET -ne 0 ] && return $RET;
return 0;
}
check_libudev () {
cat <<EOF > .conftests/libudev.c
#include <libudev.h>
int main(int argc, char **argv) {
struct udev *udev = udev_new();
udev_unref(udev);
return 0;
}
EOF
compile_and_run libudev "" "-ludev";
RET=$?;
[ $RET -ne 0 ] && return $RET;
if [ $PKGCONFIG_VERSION ]; then
CMD="pkg-config --modversion libudev"
LIBUDEV_VERSION=`$CMD 2> /dev/null`;
fi
return 0;
}
check_dnssd() {
cat <<EOF > .conftests/dnssd.c
#include <dns_sd.h>
int main(int argc, char **argv) {
DNSServiceRef ref;
return 0;
}
EOF
compile_and_run dnssd $DNSSD_CFLAGS $DNSSD_LDFLAGS;
RET=$?;
[ $RET -ne 0 ] && return $RET;
return 0;
}
check_lo () {
cat <<EOF > .conftests/lo.c
#include <lo/lo.h>
int main(int argc, char **argv) {
lo_address a = lo_address_new(NULL, NULL);
if( !a )
return 1;
lo_address_free(a);
return 0;
}
EOF
compile_and_run lo $LO_CFLAGS $LO_LDFLAGS;
RET=$?;
[ $RET -ne 0 ] && return $RET;
if [ $PKGCONFIG_VERSION ]; then
CMD="pkg-config --modversion liblo"
LO_VERSION=`$CMD 2> /dev/null`;
[ $? -ne 0 ] && return 0;
fi
return 0;
}
check_libconfuse () {
cat <<EOF > .conftests/libconfuse.c
#include <confuse.h>
int main(int argc, char **argv) {
cfg_t *cfg;
cfg_opt_t opts[] = {
CFG_END()
};
if( !(cfg = cfg_init(opts, CFGF_NONE)) )
return 1;
cfg_free(cfg);
return 0;
}
EOF
compile_and_run libconfuse $LIBCONFUSE_CFLAGS $LIBCONFUSE_LDFLAGS;
RET=$?;
[ $RET -ne 0 ] && return $RET;
if [ $PKGCONFIG_VERSION ]; then
CMD="pkg-config --modversion libconfuse"
LIBCONFUSE_VERSION=`$CMD 2> /dev/null`
[ $? -ne 0 ] && return 0;
fi
return 0;
}
check_libmonome () {
cat <<EOF > .conftests/monome.c
#include <monome.h>
int main(int argc, char **argv) {
monome_open(NULL);
return 0;
}
EOF
compile_and_run monome $LIBMONOME_CFLAGS $LIBMONOME_LDFLAGS;
RET=$?;
[ $RET -ne 0 ] && return $RET;
if [ $PKGCONFIG_VERSION ]; then
CMD="pkg-config --modversion libmonome"
LIBMONOME_VERSION=`$CMD 2> /dev/null`
[ $? -ne 0 ] && return 0;
fi
return 0;
}
fail_if_not_dir () {
if [ ! -d $* ]; then
echo_n " "
style_error -n $*
echo " is not a valid directory."
echo ""
exit 1
fi
}
usage () {
echo ""
echo " usage: ./configure [OPTIONS]"
echo ""
echo " options [and defaults] are:"
echo " --prefix=DIR install files in PREFIX [/usr/local]"
echo ""
echo " --lo-prefix=DIR the prefix under which liblo is installed [/usr/local]"
echo " --libmonome-prefix=DIR the prefix under which libmonome is installed [/usr/local]"
echo ""
}
#
# parse args
#
while [ -n "$1" ]; do
arg=`expr "$1" : "[^=]*=\(.*\)"`
case $1 in
--help|-h)
usage;
exit 1
;;
--prefix=*)
fail_if_not_dir $arg;
PREFIX=$arg
;;
--lo-prefix=*)
fail_if_not_dir $arg;
LO_PREFIX=$arg
;;
--libmonome-prefix=*)
fail_if_not_dir $arg;
LIBMONOME_PREFIX=$arg
;;
esac
shift;
done;
CFLAGS="$CFLAGS -I$PREFIX/include"
LDFLAGS="$LDFLAGS -L$PREFIX/lib"
LO_CFLAGS="-I$LO_PREFIX/include $LO_CFLAGS"
LO_LDFLAGS="-L$LO_PREFIX/lib -Wl,-rpath,$LO_PREFIX/lib $LO_LDFLAGS"
LIBMONOME_CFLAGS="-I$LIBMONOME_PREFIX/include $LIBMONOME_CFLAGS"
LIBMONOME_LDFLAGS="-L$LIBMONOME_PREFIX/lib -Wl,-rpath,$LIBMONOME_PREFIX/lib $LIBMONOME_LDFLAGS"
#
# main course
#
echo "";
mkdir -p .conftests
rm -f .config.log
check_pkgconfig;
att bold;
echo_n " configuring "; style_package -n $PROJECT; att; att bold; echo " ${VERSION}:";
att;
echo_n " checking platform: ";
get_platform;
case $PLATFORM in
Linux)
LIBSUFFIX=so;
PLATFORM_VERSION=`uname -r`;
LDFLAGS="-Wl,-rpath,\$(LIBDIR) $LDFLAGS"
;;
Darwin)
LIBSUFFIX=dylib;
DETECTOR=iokitlib;
CFLAGS="$CFLAGS -DDARWIN";
LDFLAGS="$LDFLAGS -framework IOKit -framework CoreFoundation";
PLATFORM_VERSION=`expr "$(sw_vers 2>&1)" : "[^0-9]*\([0-9.]*\)"`;
export PKG_CONFIG_PATH=/usr/lib/pkgconfig:/usr/local/lib/pkgconfig:/opt/local/lib/pkgconfig:$PKG_CONFIG_PATH
;;
MINGW*|mingw*)
LIBSUFFIX=dll;
PLATFORM=windows;
DETECTOR=windows;
EVLOOP=windows;
CFLAGS="$CFLAGS -DWIN32 -fms-extensions";
LO_LDFLAGS="$LO_LDFLAGS -lws2_32";
LIBCONFUSE_LDFLAGS="$LIBCONFUSE_LDFLAGS -lintl";
DNSSD_LDFLAGS="-ldnssd";
;;
*)
style_error $PLATFORM;
echo "";
echo " Your platform is not currently supported by ${PROJECT}! I'm sorry. :(";
echo "";
bail;
;;
esac
PLATFORM=`echo $PLATFORM | tr A-Z a-z`
style_success "$PLATFORM $PLATFORM_VERSION"
echo_n " checking for gcc: ";
if check_gcc; then
style_success "gcc $CC_VERSION";
else
style_error "no gcc :(";
echo "";
echo " I couldn't find gcc on your system! you will need it to compile ${PROJECT}.";
echo_n " If you're on "; style_distro -n "Ubuntu"; echo_n ", make sure to grab the "; style_package -n "build-essential"; echo " package.";
echo " On Mac OS X, you'll need to install the Xcode developer tools or MacPorts.";
echo "";
bail;
fi
conf_poll() {
echo_n " checking if poll() works: ";
if check_poll; then
style_success "fo sho";
else
echo "it's janky";
CFLAGS="$CFLAGS -DHAVE_BROKEN_POLL";
EVLOOP="select";
fi
}
conf_libudev() {
echo_n " checking for libudev: ";
if check_libudev; then
style_success "libudev $LIBUDEV_VERSION";
DETECTOR=libudev;
LDFLAGS="$LDFLAGS -ludev";
else
# why the fuck would you run a system this old
style_error "no, your system is outdated"
bail;
fi
}
conf_dnssd() {
echo_n " checking for libdns_sd: ";
if check_dnssd; then
style_success "indeed";
CFLAGS="$CFLAGS $DNSSD_CFLAGS";
LDFLAGS="$LDFLAGS $DNSSD_LDFLAGS";
else
die "no mdns";
fi
}
conf_liblo() {
echo_n " checking for liblo: ";
if check_lo; then
style_success "liblo $LO_VERSION";
else
style_error "no liblo :(";
echo "";
echo " I couldn't find liblo on your system!";
echo "";
echo_n " If you're "; att bold; echo_n sure; att; echo " you want to build without OSC, rerun ./configure";
echo_n " with the "; att bold cyan; echo_n "--disable-osc"; att; echo " option."
echo "";
echo_n " If you're on "; style_distro -n "Ubuntu"; echo_n ", make sure you have the "; style_package -n "liblo0-dev "; echo " package installed.";
echo_n " Users of "; style_distro -n "other distros"; echo_n " and "; style_distro -n "Mac OS X"; echo_n " should look for a "; style_package -n "liblo"; echo " package, or";
echo_n " get the source from the liblo homepage at "; style_link -n "http://liblo.sourceforge.net/"; echo ".";
echo "";
bail;
fi
}
conf_libmonome() {
echo_n " checking for libmonome: ";
if check_libmonome; then
style_success "libmonome $LIBMONOME_VERSION";
else
die "no libmonome :(";
fi
}
conf_libconfuse() {
echo_n " checking for libconfuse: ";
if check_libconfuse; then
style_success "libconfuse $LIBCONFUSE_VERSION";
else
die "no libconfuse :(";
fi
}
if [ $PLATFORM != "windows" ]; then
conf_poll;
fi
echo ""
if [ $PLATFORM = "linux" ]; then
conf_libudev;
fi
if [ $PLATFORM != "darwin" ]; then
conf_dnssd;
fi
conf_liblo;
conf_libconfuse;
conf_libmonome;
echo "";
att bold; echo " options:"; att;
echo_n " installation prefix: ";
att bold; echo $PREFIX; att;
echo_n " device detector: ";
att bold; echo $DETECTOR; att;
cat <<EOF > config.mk
export PROJECT = $PROJECT
export VERSION = $VERSION
export PREFIX = $PREFIX
export BINDIR = $PREFIX/bin
export LIBDIR = $PREFIX/lib
export INCDIR = $PREFIX/include
export MANDIR = $MANDIR
export PKGCONFIGDIR = \$(LIBDIR)/pkgconfig
export CC = $CC
export LD = $LD
export CFLAGS = $CFLAGS
export LDFLAGS = $LDFLAGS
export PLATFORM = $PLATFORM
export DETECTOR = $DETECTOR
export LIBSUFFIX = $LIBSUFFIX
export EVLOOP = $EVLOOP
export LO_CFLAGS = $LO_CFLAGS
export LO_LDFLAGS = $LO_LDFLAGS
export LIBMONOME_CFLAGS = $LIBMONOME_CFLAGS
export LIBMONOME_LDFLAGS = $LIBMONOME_LDFLAGS
export LIBCONFUSE_CFLAGS = $LIBCONFUSE_CFLAGS
export LIBCONFUSE_LDFLAGS = $LIBCONFUSE_LDFLAGS
EOF
echo "";
echo_n " run "; style_package -n "make"; echo " to compile ${PROJECT}.";
echo "";
cleanup;
exit 0;
Jump to Line
Something went wrong with that request. Please try again.