#!/bin/sh # # gcsd # # gcsd the generic command sequencer daemon can be used to serialize # commands sent over various paralell communication channels to a # single command output. It can be seen as a multiplexer for any # kind of communication between a single resource and various clients # which want to submit commands to it or query information from it. # gcsd is written in C and Lua. The goal is to provide an easy to # understand high level API based on Lua which can be used to # implement the business logic of the so formed multiplexer daemon. # # # Copyright (C) 2009-2010 Markus Grueneis # Christian Pointner # # This file is part of gcsd. # # gcsd is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # any later version. # # gcsd is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with gcsd. If not, see . # TARGET=`uname -s` EBUILD_COMPAT=0 USE_CLANG=0 LUA_DIR='' LUA='' LUAC='' LUA_VER='' PREFIX='/usr/local' BINDIR='' ETCDIR='' MODULESDIR='' MANDIR='' INSTALLMANPAGE=1 EXAMPLESDIR='' INSTALLEXAMPLES=1 print_usage() { echo "configure --help print this" echo " --target= build target i.e. Linux (default: autodetect)" echo " --prefix= the installation prefix (default: /usr/local)" echo " --bindir= the path to the bin directory (default: $PREFIX/bin)" echo " --sysconfdir= the path to the system configuration directory (default: $PREFIX/etc)" echo " --modulesdir= the path to the gcsd modules (default: $PREFIX/lib/gcsd)" echo " --mandir= the path to the system man pages (default: $PREFIX/share/man)" echo " --no-manpage dont't install manpage" echo " --examplesdir= the path to the examples files (default: $PREFIX/share/examples)" echo " --no-examples dont't install example files" echo " --with-lua= use this lua tree instead of system default" echo " --lua-version=nnn set fixed Lua version for automatic detection (501 -> 5.1, 502 -> 5.2)" echo " --use-clang use clang/llvm as compiler/linker" } for arg do case $arg in --target=*) TARGET=${arg#--target=} ;; --use-clang) USE_CLANG=1 ;; --prefix=*) PREFIX=${arg#--prefix=} ;; --bindir=*) BINDIR=${arg#--bindir=} ;; --sysconfdir=*) ETCDIR=${arg#--sysconfdir=} ;; --modulesdir=*) MODULESDIR=${arg#--modulesdir=} ;; --mandir=*) MANDIR=${arg#--mandir=} ;; --no-manpage) INSTALLMANPAGE=0 ;; --examplesdir=*) EXAMPLESDIR=${arg#--examplesdir=} ;; --no-examples) INSTALLEXAMPLES=0 ;; --with-lua=*) LUA_DIR=${arg#--with-lua=} ;; --lua-version=*) LUA_VER=${arg#--lua-version=} ;; --ebuild-compat) EBUILD_COMPAT=1 ;; --help) print_usage exit 0 ;; *) ERRORS="$ERRORS $arg" ;; esac done if [ -n "$ERRORS" ] && [ $EBUILD_COMPAT -ne 1 ]; then for error in $ERRORS; do echo "Unknown argument: $error" done print_usage exit 1 fi if [ $USE_CLANG -eq 0 ]; then CFLAGS='-g -Wall -O2' LDFLAGS='-g -Wall -O2 -lm' COMPILER='gcc' else CFLAGS='-g -O2' LDFLAGS='-g -O2 -lm' COMPILER='clang' fi rm -f config.h rm -f include.mk case $TARGET in Linux) LDFLAGS=$LDFLAGS' -ldl' ;; OpenBSD|FreeBSD|NetBSD|GNU/kFreeBSD) CFLAGS=$CFLAGS' -I/usr/local/include' LDFLAGS=$LDFLAGS' -L/usr/local/lib' ;; MINGW*) CFLAGS=$CFLAGS' -DWINVER=0x501 -D_WIN32_WINNT -D_WIN32' LDFLAGS=$LDFLAGS' -lwsock32' TARGET=mingw if [ -z "$LUA_DIR" ]; then echo "No Lua tree specified, use --with-lua" exit 1 fi echo "WARNING: don't use install target on this platform" ;; *) echo "platform not supported" exit 1; ;; esac test_lua_version() { LUA_VERSION_MAJ=`cat $1 | grep "#define LUA_VERSION_MAJOR[ ]" | cut -f2- | tr -d '"'` LUA_VERSION_MIN=`cat $1 | grep "#define LUA_VERSION_MINOR[ ]" | cut -f2- | tr -d '"'` LUA_VERSION_REL=`cat $1 | grep "#define LUA_VERSION_RELEASE[ ]" | cut -f2- | tr -d '"'` LUA_VERSION="$LUA_VERSION_MAJ.$LUA_VERSION_MIN" LUA_RELEASE="$LUA_VERSION_MAJ.$LUA_VERSION_MIN.$LUA_VERSION_REL" if [ -z "$LUA_VERSION_MAJ" ]; then LUA_VERSION=`cat $1 | grep "#define LUA_VERSION[ ]" | cut -f2- | tr -d '"' | sed -e 's/Lua \([0-9][0-9.]*\)/\1/'` LUA_RELEASE=`cat $1 | grep "#define LUA_RELEASE[ ]" | cut -f2- | tr -d '"' | sed -e 's/Lua //'` fi LUA_VERSION_NUM=`cat $1 | grep "#define LUA_VERSION_NUM" | awk '{ print $3 }'` if [ -n "$LUA_VER" ]; then if [ "$LUA_VER" -eq $LUA_VERSION_NUM ]; then return 1 else return 0 fi else if [ $LUA_VERSION_NUM -ge 501 ]; then return 1 else return 0 fi fi } if [ -z "$LUA_DIR" ]; then for prefix in /usr /usr/local; do if [ -e $prefix/include/lua.h ]; then test_lua_version $prefix/include/lua.h if [ $? -eq 1 ]; then echo "using Lua $LUA_VERSION ($LUA_RELEASE) found at $prefix/include" CFLAGS="$CFLAGS -I'$prefix/include'" LDFLAGS="$LDFLAGS -L'$prefix/lib' -llua" LUA=$prefix/lua LUAC=$prefix/luac break fi else for dir in `ls -r -d $prefix/include/lua* 2> /dev/null`; do if [ -e $dir/lua.h ]; then test_lua_version $dir/lua.h if [ $? -eq 1 ]; then echo "using Lua $LUA_VERSION ($LUA_RELEASE) found at $dir" CFLAGS="$CFLAGS -I$dir" if [ -x "$prefix/bin/lua$LUA_VERSION" ]; then LDFLAGS="$LDFLAGS -L'$prefix/lib' -llua$LUA_VERSION" LUA=$prefix/bin/lua$LUA_VERSION LUAC=$prefix/bin/luac$LUA_VERSION elif [ -x "$prefix/bin/lua-$LUA_VERSION" ]; then LDFLAGS="$LDFLAGS -L'$prefix/lib' -llua-$LUA_VERSION" LUA=$prefix/bin/lua-$LUA_VERSION LUAC=$prefix/bin/luac-$LUA_VERSION else echo "ERROR: found lua.h at $dir/lua.h but no matching lua and luac" return 1 fi break fi fi done if [ -n "$LUAC" ]; then break fi fi done if [ -z "$LUAC" ]; then echo "ERROR: no suitable lua found .. please install lua 5.1 or higher or use --with-lua" return 1 fi else CFLAGS="$CFLAGS -I'$LUA_DIR/include'" LDFLAGS="$LDFLAGS '$LUA_DIR/lib/liblua.a'" LUA=$LUA_DIR/bin/lua LUAC=$LUA_DIR/bin/luac fi if [ -z "$BINDIR" ]; then BINDIR=$PREFIX/bin fi if [ -z "$ETCDIR" ]; then ETCDIR=$PREFIX/etc fi if [ -z "$MODULESDIR" ]; then MODULESDIR=$PREFIX/lib/gcsd fi if [ -z "$MANDIR" ]; then MANDIR=$PREFIX/share/man fi if [ -z "$EXAMPLESDIR" ]; then EXAMPLESDIR=$PREFIX/share/examples fi cat > include.mk <> include.mk echo "installing manpage" else echo "not installing manpage" fi if [ $INSTALLEXAMPLES -eq 1 ]; then echo "EXAMPLESDIR := '$EXAMPLESDIR'" >> include.mk echo "installing example files" else echo "not installing example files" fi VERSION=`cat ../version` if which git >/dev/null; then GIT_HASH=`git rev-parse HEAD 2> /dev/null` if [ -n "$GIT_HASH" ]; then VERSION="$VERSION (git $GIT_HASH)" fi fi else VERSION=`cat ../version` fi HOSTNAME=`hostname` DATE=`date +"%d.%m.%Y %H:%M:%S %Z"` cat > config.h <