diff -r 7fe53d5d587c -r e870a7c8f223 configure --- a/configure Fri Aug 02 22:40:02 2019 +0200 +++ b/configure Sat Aug 03 17:54:54 2019 +0200 @@ -1,95 +1,488 @@ #!/bin/sh -# -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. -# -# Copyright 2013 Olaf Wintermann. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# + +HOST=`uname -n` +PREFIX=`pwd`/work +INSTALL_DIR=$PREFIX + +EPREFIX=$PREFIX + +BINDIR= +SBINDIR= +LIBDIR= +LIBEXECDIR= +DATADIR= +SYSCONFDIR= +SHAREDSTATEDIR= +LOCALSTATEDIR= +INCLUDEDIR= +INFODIR= +MANDIR= + +OS=`uname -s` +OS_VERSION=`uname -r` + +TEMP_DIR=".tmp-`uname -n`" +mkdir -p $TEMP_DIR +if [ $? -ne 0 ]; then + echo "Cannot create tmp dir" + echo "Abort" +fi +touch $TEMP_DIR/options +touch $TEMP_DIR/features + +# features + +# help text +printhelp() +{ + echo "Usage: $0 [OPTIONS]..." + cat << __EOF__ +Installation directories: + --prefix=PREFIX path prefix for architecture-independent files + [/usr] + --exec-prefix=EPREFIX path prefix for architecture-dependent files + [PREFIX] + + --bindir=DIR user executables [EPREFIX/bin] + --sbindir=DIR system admin executables [EPREFIX/sbin] + --libexecdir=DIR program executables [EPREFIX/libexec] + --sysconfdir=DIR system configuration files [PREFIX/etc] + --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] + --localstatedir=DIR modifiable single-machine data [PREFIX/var] + --libdir=DIR object code libraries [EPREFIX/lib] + --includedir=DIR C header files [PREFIX/include] + --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] + --datadir=DIR read-only architecture-independent data [DATAROOTDIR] + --infodir=DIR info documentation [DATAROOTDIR/info] + --mandir=DIR man documentation [DATAROOTDIR/man] + +Optional Features: + --enable-pg + +__EOF__ +} # -# TODO: parse arguments +# parse arguments # - -OS=`uname -s` -HOST=`uname -n` -INSTALL_DIR=`pwd`/work +for ARG in $@ +do + if [[ $ARG == --prefix=* ]]; then + PREFIX=${ARG:9} + elif [[ $ARG = --exec-prefix=* ]]; then + EPREFIX=${ARG:14} + elif [[ $ARG = --bindir=* ]]; then + BINDIR=${ARG:9} + elif [[ $ARG = --sbindir=* ]]; then + SBINDIR=${ARG:10} + elif [[ $ARG = --libdir=* ]]; then + LIBDIR=${ARG:9} + elif [[ $ARG = --libexecdir=* ]]; then + LIBEXECDIR=${ARG:13} + elif [[ $ARG = --datadir=* ]]; then + DATADIR=${ARG:10} + elif [[ $ARG = --sysconfdir=* ]]; then + SYSCONFDIR=${ARG:13} + elif [[ $ARG = --sharedstatedir=* ]]; then + SHAREDSTATEDIR=${ARG:17} + elif [[ $ARG = --localstatedir=* ]]; then + LOCALSTATEDIR=${ARG:16} + elif [[ $ARG = --includedir=* ]]; then + INCLUDEDIR=${ARG:12} + elif [[ $ARG = --infodir=* ]]; then + INFODIR=${ARG:10} + elif [[ $ARG = --mandir=* ]]; then + MANDIR=${ARG:9} + elif [ $ARG = "--help" ]; then + printhelp + exit 0 + elif [[ $ARG == --enable-pg ]]; then + FEATURE_PG=on + elif [[ $ARG == --disable-pg ]]; then + unset FEATURE_PG + fi +done -LIBS_CFLAGS=`pkg-config --cflags libxml-2.0 openssl` -LIBS_LDFLAGS=`pkg-config --libs libxml-2.0 openssl` +# set dir variables +if [ -z $BINDIR ]; then + BINDIR=$EPREFIX/bin +fi +if [ -z $SBINDIR ]; then + SBINDIR=$EPREFIX/sbin +fi +if [ -z $LIBDIR ]; then + LIBDIR=$EPREFIX/lib +fi +if [ -z $LIBEXEC ]; then + LIBEXECDIR=$EPREFIX/libexec +fi +if [ -z $DATADIR ]; then + DATADIR=$PREFIX/share +fi +if [ -z $SYSCONFDIR]; then + SYSCONFDIR=$PREFIX/etc +fi +if [ -z $SHAREDSTATEDIR ]; then + SHAREDSTATEDIR=$PREFIX/com +fi +if [ -z $LOCALSTATEDIR ]; then + LOCALSTATEDIR=$PREFIX/var +fi +if [ -z $INCLUDEDIR ]; then + INCLUDEDIR=$PREFIX/include +fi +if [ -z $INFODIR ]; then + INFODIR=$PREFIX/info +fi +if [ -z $MANDIR ]; then + MANDIR=$PREFIX/man +fi + +which pkg-config > /dev/null +if [ $? -ne 0 ]; then + PKG_CONFIG=pkg-config +else + PKG_CONFIG=false +fi -# create config.mk -echo "generate config.mk" +# Simple uname based platform detection +# $PLATFORM is used for platform dependent dependency selection +printf "detect platform... " +if [ $OS = SunOS ]; then + PLATFORM="solaris sunos unix svr4" +fi +if [ $OS = Linux ]; then + PLATFORM="linux unix" +fi +if [ $OS = FreeBSD ]; then + PLATFORM="freebsd bsd unix" +fi +if [ $OS = Darwin ]; then + PLATFORM="macos osx bsd unix" +fi +echo $OS | grep "MINGW" > /dev/null +if [ $? -eq 0 ]; then + PLATFORM="windows mingw" +fi -cat > config.mk << __EOF__ +if [ -z "$PLATFORM" ]; then + PLATFORM="unix" +fi + +for p in $PLATFORM +do + PLATFORM_NAME=$p + break +done +echo $PLATFORM_NAME + +isplatform() +{ + for p in $PLATFORM + do + if [ $p = $1 ]; then + return 0 + fi + done + return 1 +} + +# generate config.mk and config.h +cat > $TEMP_DIR/config.mk << __EOF__ # # config.mk generated by configure # -INSTALL_DIR = $INSTALL_DIR -HOST = $HOST +# general vars +HOST=$HOST +PREFIX=$PREFIX +INSTALL_DIR=$INSTALL_DIR + +EPREFIX=$EPREFIX + +BINDIR=$BINDIR +SBINDIR=$SBINDIR +LIBDIR=$LIBDIR +LIBEXECDIR=$LIBEXECDIR +DATADIR=$DATADIR +SYSCONFDIR=$SYSCONFDIR +SHAREDSTATEDIR=$SHAREDSTATEDIR +LOCALSTATEDIR=$LOCALSTATEDIR +INCLUDEDIR=$INCLUDEDIR +INFODIR=$INFODIR +MANDIR=$MANDIR __EOF__ -# platform +echo > $TEMP_DIR/make.mk -if [ $OS = SunOS ]; then - CCONF=suncc.mk - PLATFORM=solaris.mk -fi +ENV_CFLAGS=$CFLAGS +ENV_LDFLAGS=$LDFLAGS +ENV_CXXFLAGS=$CXXFLAGS + +# Toolchain detection +# this will insert make vars to config.mk +source make/toolchain.sh -if [ $OS = Linux ]; then - if `type clang > /dev/null`; then - CCONF=clang.mk - else - CCONF=gcc.mk - fi - PLATFORM=linux.mk +# add user specified flags to config.mk +echo >> $TEMP_DIR/config.mk +if [[ ! -z ${ENV_CFLAGS} ]]; then + echo "CFLAGS += $ENV_CFLAGS" >> $TEMP_DIR/config.mk fi - -if [ $OS = Darwin ]; then - CCONF=clang.mk - PLATFORM=osx.mk +if [[ ! -z ${ENV_CXXFLAGS} ]]; then + echo "CXXFLAGS += $ENV_CXXFLAGS" >> $TEMP_DIR/config.mk +fi +if [[ ! -z ${ENV_LDFLAGS} ]]; then + echo "LDFLAGS += $ENV_LDFLAGS" >> $TEMP_DIR/config.mk fi -ISBSD=`echo $OS | grep -c BSD` -if [ $ISBSD = 1 ]; then - if `type clang > /dev/null`; then - CCONF=clang.mk - else - CCONF=gcc.mk +# +# DEPENDENCIES +# + +dependency_libpq() +{ + printf "checking for libpq... " + # dependency libpq + while true + do + if [ -z "PKG_CONFIG" ]; then + break + fi + if ! pkg-config libpq ; then + break + fi + CFLAGS+=" `pkg-config --cflags libpq`" + LDFLAGS+=" `pkg-config --libs libpq`" + echo yes + return 0 + done + + echo no + return 1 +} +dependency_openssl() +{ + printf "checking for openssl... " + # dependency openssl + while true + do + if [ -z "PKG_CONFIG" ]; then + break + fi + if ! pkg-config openssl ; then + break + fi + CFLAGS+=" `pkg-config --cflags openssl`" + LDFLAGS+=" `pkg-config --libs openssl`" + echo yes + return 0 + done + + echo no + return 1 +} +dependency_libxml2() +{ + printf "checking for libxml2... " + # dependency libxml2 + while true + do + if [ -z "PKG_CONFIG" ]; then + break + fi + if ! pkg-config libxml-2.0 ; then + break + fi + CFLAGS+=" `pkg-config --cflags libxml-2.0`" + LDFLAGS+=" `pkg-config --libs libxml-2.0`" + echo yes + return 0 + done + + echo no + return 1 +} + +DEPENDENCIES_FAILED= +ERROR=0 +# general dependencies +CFLAGS= +LDFLAGS= +while true +do + if ! isplatform "linux"; then + break fi - PLATFORM=bsd.mk + while true + do + + CFLAGS+="-DLINUX" + LDFLAGS+="-lpthread -ldl -lm -lldap" + cat >> $TEMP_DIR/make.mk << __EOF__ +# platform dependend source files +PLATFORM_DAEMONOBJ = event_linux.o + +# platform dependend vars +OBJ_EXT = .o +LIB_EXT = .so +APP_EXT = + +__EOF__ + + break + done + + break +done +while true +do + if ! isplatform "bsd"; then + break + fi + if isplatform "macos"; then + break + fi + while true + do + + CFLAGS+="-DBSD" + LDFLAGS+="-lpthread -lm -lldap" + cat >> $TEMP_DIR/make.mk << __EOF__ +# platform dependend source files +PLATFORM_DAEMONOBJ = event_bsd.o + +# platform dependend vars +OBJ_EXT = .o +LIB_EXT = .so +APP_EXT = + +__EOF__ + + break + done + + break +done +while true +do + if ! isplatform "macos"; then + break + fi + while true + do + + CFLAGS+="-DBSD -DOSX" + LDFLAGS+="-lpthread -ldl -lm -lldap" + cat >> $TEMP_DIR/make.mk << __EOF__ +# platform dependend source files +PLATFORM_DAEMONOBJ = event_bsd.o + +# platform dependend vars +OBJ_EXT = .o +LIB_EXT = .dylib +APP_EXT = + +__EOF__ + + break + done + + break +done +while true +do + if ! isplatform "solaris"; then + break + fi + while true + do + + CFLAGS+="-DSOLARIS -D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS" + LDFLAGS+="-lsocket -lnsl -lsendfile -lposix4 -lpthread -ldl -lm -lmd -lldap" + cat >> $TEMP_DIR/make.mk << __EOF__ +# platform dependend source files +PLATFORM_DAEMONOBJ = event_solaris.o + +# platform dependend vars +OBJ_EXT = .o +LIB_EXT = .so +APP_EXT = + +__EOF__ + + break + done + + break +done + +# add general dependency flags to config.mk +echo >> $TEMP_DIR/config.mk +if [[ ! -z ${CFLAGS} ]]; then + echo "CFLAGS += $CFLAGS" >> $TEMP_DIR/config.mk +fi +if [[ ! -z ${CXXFLAGS} ]]; then + echo "CXXFLAGS += $CXXFLAGS" >> $TEMP_DIR/config.mk +fi +if [[ ! -z ${LDFLAGS} ]]; then + echo "LDFLAGS += $LDFLAGS" >> $TEMP_DIR/config.mk fi -echo " -include \$(BUILD_ROOT)/make/$CCONF -include \$(BUILD_ROOT)/make/$PLATFORM +# +# OPTION VALUES +# + +# +# TARGETS +# +CFLAGS= +CXXFLAGS= +LDFLAGS= -CFLAGS += $LIBS_CFLAGS -LDFLAGS += $LIBS_LDFLAGS +# Target +CFLAGS= +LDFLAGS= +CXXFLAGS= -" >> config.mk +dependency_libxml2 +if [ $? -ne 0 ]; then + DEPENDENCIES_FAILED+="libxml2 " + ERROR=1 +fi +dependency_openssl +if [ $? -ne 0 ]; then + DEPENDENCIES_FAILED+="openssl " + ERROR=1 +fi +echo >> $TEMP_DIR/config.mk +if [[ ! -z ${CFLAGS} ]]; then + echo "CFLAGS += $CFLAGS" >> $TEMP_DIR/config.mk +fi +if [[ ! -z ${CXXFLAGS} ]]; then + echo "CXXFLAGS += $CXXFLAGS" >> $TEMP_DIR/config.mk +fi +if [[ ! -z ${LDFLAGS} ]]; then + echo "LDFLAGS += $LDFLAGS" >> $TEMP_DIR/config.mk +fi +if [ $ERROR -ne 0 ]; then + echo + echo "Error: Unresolved dependencies" + echo $DEPENCIES_FAILED + rm -Rf $TEMP_DIR + exit 1 +fi + +echo "configure finished" +echo +echo "Build Config:" +echo " PREFIX: $PREFIX" +echo " TOOLCHAIN: $TOOLCHAIN_NAME" +echo +cat $TEMP_DIR/config.mk $TEMP_DIR/make.mk > config.mk +rm -Rf $TEMP_DIR + +