#!/bin/sh # Generated by KMake 0.00 ## ---------------------------- ## ## Initialize common variables. ## ## ---------------------------- ## OS="${OS:-`uname -s`}" PREFIX="${PREFIX:-/usr/local}" CC="${CC}" CXX="${CXX}" LD="${LD}" AR="${AR}" YACC="${YACC}" LEX="${LEX}" RANLIB="${RANLIB}" PKGCONF="${PKGCONF}" LIBS="${LIBS}" CFLAGS="${CFLAGS}" CXXFLAGS="${CXXFLAGS}" LDFLAGS="${LDFLAGS}" YFLAGS="${YFLAGS}" LFLAGS="${LFLAGS}" ## ------------------- ## ## Initialize exports. ## ## ------------------- ## EXPORTS="CC CXX LD AR YACC LEX RANLIB PKGCONF LIBS CFLAGS LDFLAGS YFLAGS LFLAGS PREFIX" ## ------------------------------ ## ## Initialize internal variables. ## ## ------------------------------ ## EXECIF=1 CONFIG_H=0 ## ----------------- ## ## Useful functions. ## ## ----------------- ## # Check if C compiler works check_cc() { echo -n "Checking if $2 is a working compiler... " echo "int main(int argc, char** argv){return 0;}" > /tmp/$$.c $1 -o /dev/null /tmp/$$.c >/dev/null 2>/dev/null if [ "$?" = "0" ]; then echo "yes" CC="$2" else echo "no" fi rm /tmp/$$.c } # Check if C++ compiler works check_cxx() { echo -n "Checking if $2 is a working compiler... " echo "int main(int argc, char** argv){return 0;}" > /tmp/$$.cpp $1 -o /dev/null /tmp/$$.cpp >/dev/null 2>/dev/null if [ "$?" = "0" ]; then echo "yes" CXX="$2" else echo "no" fi rm /tmp/$$.cpp } # Check if pkg-config works check_pkgconf() { echo -n "Checking if $2 is a working pkg-config... " $1 --version >/dev/null 2>/dev/null if [ "$?" = "0" ]; then echo "yes" PKGCONF="$2" else echo "no" fi } # Check for C compiler probe_cc() { if [ ! "x${CC}" = "x" ]; then return fi found="" echo -n "Checking if $1 exists... " IFS=":" for i in $PATH; do if [ -e $i/$1 ]; then echo "yes" found="$i/$1" break fi done IFS=" " if [ "x$found" = "x" ]; then echo "no" else check_cc "$found" "$1" fi } # Check for C++ compiler probe_cxx() { if [ ! "x${CXX}" = "x" ]; then return fi found="" echo -n "Checking if $1 exists... " IFS=":" for i in $PATH; do if [ -e $i/$1 ]; then echo "yes" found="$i/$1" break fi done IFS=" " if [ "x$found" = "x" ]; then echo "no" else check_cxx "$found" "$1" fi } # Check for pkg-config probe_pkgconf() { if [ ! "x${PKGCONF}" = "x" ]; then return fi found="" echo -n "Checking if $1 exists... " IFS=":" for i in $PATH; do if [ -e $i/$1 ]; then echo "yes" found="$i/$1" break fi done IFS=" " if [ "x$found" = "x" ]; then echo "no" else check_pkgconf "$found" "$1" fi } # Output files output_as() { output="$1" input="${2:-${output}.in}" if [ -e "${input}" ]; then echo "Creating $output" cp "$input" ".$$.1" for i in $EXPORTS; do eval "data=\$$i" data="`echo "$data" | sed -E "s/%/\\\\\%/g"`" sed "s%@$i@%$data%g" ".$$.1" > ".$$.2" mv ".$$.2" ".$$.1" done mv ".$$.1" "$output" else echo "${input} is required to generate ${output}, but is missing" fi } # Check C header c_check_header() { echo -n "Checking if $1 exists... " echo "#include <$1>" > /tmp/$$.c echo "int main(int argc, char** argv){return 0;}" >> /tmp/$$.c $CC $CFLAGS -c -o /dev/null /tmp/$$.c >/dev/null 2>&1 if [ "$?" = "0" ]; then echo "yes" if [ "x$2" = "x1" ]; then rm /tmp/$$.c return 0 fi else echo "no" if [ "x$2" = "x1" ]; then rm /tmp/$$.c return 1 else echo "Required header is missing" kmexit 1 fi fi rm /tmp/$$.c } # Check C++ header cxx_check_header() { echo -n "Checking if $1 exists... " echo "#include <$1>" > /tmp/$$.cpp echo "int main(int argc, char** argv){return 0;}" >> /tmp/$$.c $CXX $CXXFLAGS -c -o /dev/null /tmp/$$.c >/dev/null 2>&1 if [ "$?" = "0" ]; then echo "yes" if [ "x$2" = "x1" ]; then rm /tmp/$$.c return 0 fi else if [ "x$2" = "x1" ]; then rm /tmp/$$.c return 1 else echo "Required header is missing" kmexit 1 fi fi rm /tmp/$$.cpp } # Exit kmexit() { if [ "$CONFIG_H" = "1" -a -e "config.h" ]; then rm config.h fi exit $1 } ## -------------------- ## ## Auto-generated part. ## ## -------------------- ## # Generate config.h CONFIG_H=1 echo "/* This config was auto-generated */" > config.h for i in $@; do case "$i" in --prefix=*) PREFIX="`echo "$i" | sed "s/--prefix=//g"`" ;; --help|-h) echo "This script configures the project to adapt to many kinds of systems." echo echo "Usage: $0 [options]" echo echo "Configuration:" echo " --help -h Show this help and exit" echo echo "Installation directories:" echo " --prefix=PREFIX Install prefix (default is /usr/local)" exit 0 ;; *) echo "Invalid flag: $i" exit 1 ;; esac done probe_cc "gcc" probe_cc "clang" probe_cc "cc" probe_pkgconf "pkg-config" if [ ! "x$PKGCONF" = "x" ]; then EXECIF=0 else EXECIF=1 fi CFLAGS="$CFLAGS -I../../libs/Include" LDFLAGS="$LDFLAGS -L../../libs/Library -L${PREFIX}/lib -Wl,-R${PREFIX}/lib" echo -n "Checking if the OS is NetBSD... " test "$OS" = "NetBSD" EXECIF=$? if [ "$EXECIF" = "0" ]; then echo "yes" else echo "no" fi if [ "$EXECIF" = "0" ]; then CFLAGS="$CFLAGS -I/usr/pkg/include -I/usr/X11R7/include" LDFLAGS="$LDFLAGS -Wl,-R/usr/pkg/lib -Wl,-R/usr/X11R7/lib -L/usr/pkg/lib -L/usr/X11R7/lib" fi EXECIF=1 output_as "Makefile" output_as "BusServer/Makefile"