Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
binary_c-config 8.76 KiB
#!/bin/bash

############################################################
#
# binary_c-config
#
# config script for binary_c to show configuration options on the
# command line, or for listing binary_c's default parameters
#
# We call binary_c and filter out the appropriate data.
# Requires grep and sed.
#
# Note that the source directory of this file is used as the
# root directory of binary_c.
#
# If you have an alternative $BINARY_C set, you should call
# the script in there (e.g. $BINARY_C/binary_c-config) and
# the location will be set automatically.
#
############################################################


# find the directory from which the script was called
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

# hence the executable
BIN="$DIR/binary_c"

# if it's not executable, fail
if [[ ! -x "$BIN" ]];then
    echo -e "\e[91m"
    echo "Looked for binary_c at $BIN but could not find an executable there :( Have you built binary_c? Is this config script located in the binary_c directory?"
    echo -e "\e[39m"
    exit
fi

# defaults
VER="$BIN version "
DEFAULTS="$BIN list_args"
GREP="grep"
TR="tr"
SED="sed"
LDD=`which ldd`
HELP=$(cat <<-EOHELP
Usage: 

     binary_c-config [OPTION]

where option is one of the following. The '--' can be '-' or just omitted.
 
--cflags        Show the flags which were used to build binary_c (same as --flags)
--libs          Show library linking information
--libs_list     Show library linking information as a space-separated list without -l
--help          Show this help and exit
--version       Show binary_c's version string.
--cc            Show the C compiler used to build binary_c
--cc_version    Show the version of the C compiler used to build binary_c
--ld            Show the linker used to build binary_c
--ldd           Show binary_c's dependencies
--incdirs       Show binary_c's include dirs (for header files)
--incdirs_list  Show binary_c's include dirs (for header files) as a space-separated list without -I
--libdirs       Show binary_c's library search directories during build
--libdirs_list  Show binary_c's library search directories during build as a space separated list without -L
--git_url       Show the URL of binary_c's git source (if available)
--git_branch    Show the git branch being used (if available)
--git_revision  Show the revision of binary_c's git source (if available)
--svn_url       Show the URL of binary_c's svn source (if available)
--svn_revision  Show the revision of binary_c's svn source (if available)
--build_date    Show the date and time of binary_c's build
--define_macros Show macros defined by -D... in the CFLAGS
--undef_macros  Show macros undefined by -U... in the CFLAGS
--defaults      Show binary_c's default settings


Note: this script requires standard tools like grep, sed, tr, ldd


EOHELP
)

# check for an argument : if none is given, show help text
if [[ -z $1 ]]; then 
    echo "$HELP"
    exit
fi

# check first argument : do what it says
while (( $# )); do
    key="$1"
    
    case $key in
        --flags|-flags|flags|--cflags|-cflags|cflags)
            # return build flags
            $VER 2>/dev/null | $GREP 'CFLAGS is \"' | $SED -e s/CFLAGS\ is\ // -e 's/^"[[:space:]]*//' -e 's/"[[:space:]]*$//'
            shift
            ;;
        --define_macros|-define_macros|define_macros)
            # return build flags
            $VER 2>/dev/null | $GREP 'CFLAGS is \"' | $SED -e s/CFLAGS\ is\ // | $SED 's/[[:space:]]\+/\n/g' | $GREP '\-D' | $TR "\n" " " | $SED -e 's/[^[-D__]]//g'  -e 's/^"[[:space:]]*//' -e 's/"[[:space:]]*$//' -e 's/$/\n/' 
            shift
            ;;
        --undef_macros|-undef_macros|undef_macros)
            # return build flags
            $VER 2>/dev/null | $GREP 'CFLAGS is \"' | $SED -e s/CFLAGS\ is\ // | $SED 's/[[:space:]]\+/\n/g' | $GREP '\-U' | $TR "\n" " " | $SED -e 's/[^[-U__]]//g'  -e 's/^"[[:space:]]*//' -e 's/"[[:space:]]*$//' -e 's/$/\n/' 
            shift
            ;;
        --defaults|-defaults|defaults)
            # show binary_c's default parameters
            $DEFAULTS 2>/dev/null | grep ARG_BEGIN -A999999 |grep -v ARG_BEGIN | grep -v __ARG_END |grep -v Normal\ exit\ from\ binary_c
            shift
            ;;
        --flags|-flags|flags|--cflags|-cflags|cflags)
            # return build flags
            $VER 2>/dev/null | $GREP 'CFLAGS is \"' | $SED -e s/CFLAGS\ is\ // -e 's/^"[[:space:]]*//' -e 's/"[[:space:]]*$//'
            shift
            ;;
        --libs|-libs|libs) 
            # show libraries
            $VER 2>/dev/null | $GREP 'LIBS is \"' | $SED -e s/LIBS\ is\ //  -e 's/-L[^[:space:]]*//g' -e 's/^"[[:space:]]*//' -e 's/"[[:space:]]*$//' -e 's/[[:space:]]\+/ /g' 
            shift
            ;;
        --libs_list|-libs_list|libs_list) 
            # show libraries in a list without -l prefix
            $VER 2>/dev/null | $GREP 'LIBS is \"' | $SED -e s/LIBS\ is\ //   -e 's/-L[^[:space:]]*//g' -e 's!-l!!g'  -e 's/^"[[:space:]]*//' -e 's/"[[:space:]]*$//' -e 's/[[:space:]]\+/ /g' 
            shift
            ;;
        --libdirs|-libdirs|libdirs) 
            # show libraries
            $VER 2>/dev/null | $GREP 'LIBDIRS is \"' | $SED -e s/LIBDIRS\ is\ //  -e 's/^"[[:space:]]*//' -e 's/"[[:space:]]*$//' -e 's!-L\.!-L'"$DIR"'!'  -e 's/[[:space:]]\+/ /g' 
            shift
            ;;
        --libdirs_list|-libdirs_list|libdirs_list) 
            # show libraries in a list without -L prefix
            $VER 2>/dev/null | $GREP 'LIBDIRS is \"' | $SED -e s/LIBDIRS\ is\ //  -e 's/^"[[:space:]]*//' -e 's/"[[:space:]]*$//' -e 's!-L\.!-L'"$DIR"'!' -e 's!-L!!g' -e 's/[[:space:]]\+/ /g' 
            shift
            ;;
        --incdirs|-incdirs|incdirs) 
            # show libraries
            $VER 2>/dev/null | $GREP 'INCDIRS is \"' | $SED -e s/INCDIRS\ is\ //   -e 's!-I\.!-I'"$DIR"'!' -e 's/[[:space:]]\+/ /g'  -e 's/^"[[:space:]]*//' -e 's/"[[:space:]]*$//'
            shift
            ;;
        --incdirs_list|-incdirs_list|incdirs_list) 
            # show libraries in a list without -I prefix
            $VER 2>/dev/null | $GREP 'INCDIRS is \"' | $SED -e s/INCDIRS\ is\ //   -e 's!-I\.!-I'"$DIR"'!' -e 's!-I!!g'  -e 's/[[:space:]]\+/ /g'  -e 's/^"[[:space:]]*//' -e 's/"[[:space:]]*$//'
            shift
            ;;
        --cc|-cc|cc)
            # show C compiler
            $VER 2>/dev/null |$GREP 'CC is \"' | $SED -e 's/CC is \"//'  -e 's/^"[[:space:]]*//' -e 's/"[[:space:]]*$//'
            shift
            ;;
        --cc_version|-cc_version|cc_version)
            # show C compiler
            $VER 2>/dev/null |$GREP '__VERSION__ is \"' | $SED -e 's/__VERSION__ is \"//'  -e 's/^"[[:space:]]*//' -e 's/"[[:space:]]*$//'
            shift
            ;;
        --ld|-ld|ld)
            # show linker
            $VER 2>/dev/null |$GREP 'LD is \"' | $SED -e 's/LD is \"//'  -e 's/^"[[:space:]]*//' -e 's/"[[:space:]]*$//'
            shift
            ;;
        --ldd|-ldd|ldd)
            # show dependencies
            $LDD $BIN | $SED -e 's/^[[:space:]]*//'
            shift
            ;;
        --svn_url|-svn_url|svn_url)
            # show svn revision
           $VER 2>/dev/null | $GREP 'SVN URL' | $SED -e 's/SVN URL //' -e 's/^"[[:space:]]*//' -e 's/"[[:space:]]*$//'
            shift
            ;;
        --svn_revision|-svn_revision|svn_revision)
            # show svn revision
           $VER 2>/dev/null | $GREP 'SVN revision' | $SED -e 's/SVN revision //' -e 's/^"[[:space:]]*//' -e 's/"[[:space:]]*$//'
            shift
            ;;
        --git_url|-git_url|git_url)
            # show git revision
           $VER 2>/dev/null | $GREP 'git URL' | $SED -e 's/git URL //' -e 's/^"[[:space:]]*//' -e 's/"[[:space:]]*$//'
            shift
            ;;
        --git_branch|-git_branch|git_branch)
            # show git revision
           $VER 2>/dev/null | $GREP 'git branch' | $SED -e 's/git branch //' -e 's/^"[[:space:]]*//' -e 's/"[[:space:]]*$//'
            shift
            ;;
        --git_revision|-git_revision|git_revision)
            # show git revision
           $VER 2>/dev/null | $GREP 'git revision' | $SED -e 's/git revision //' -e 's/^"[[:space:]]*//' -e 's/"[[:space:]]*$//'
            shift
            ;;
        --version|-version|version)
            # show binary_c's version
            $VER 2>/dev/null | $GREP 'Version '| $SED -e 's/Version //'  -e 's/^"[[:space:]]*//' -e 's/"[[:space:]]*$//'
            shift
            ;;
        --help|-help|help)
            # show help
            echo "$HELP"
            shift
            ;;
        --build_date|-build_date|build_date)
            # show binary_c's build date
            $VER 2>/dev/null | $GREP 'Build:' | $SED -e 's/Build: //'  -e 's/^"[[:space:]]*//' -e 's/"[[:space:]]*$//'
            shift
            ;;
        *)
            echo "$HELP"
            shift;
    esac
done
                     
# we're done, exit