Luca Saiu — temporary or extemporary notes

This is a page for random unorganized notes that I may need to share with others occasionally.

Anything here can change or be removed at any time. If you are interested in some piece of information shared in this page please save a copy for yourself.


My Bash function add-prefix

HOSTNAME="$(hostname)"
function add-prefix {
    partial="no"
    case "$#" in
        1) prefix="$1";;
        2) prefix="$1"
           if [[ "$2" == "partial" ]]; then
               partial="yes"
           else
               echo "$0: the second argument, if specified, must be \"partial\"."
               return -1
           fi;;
        *) echo "$0: either one argument (the prefix path) or two: prefix path, \"partial\"."
           return -1;;
    esac
    case "$HOSTNAME" in
        sussman)
            TRIPLET="mipsel-linux-gnu"
            ;;
        abelson | moore)
            TRIPLET="x86_64-linux-gnu"
            ;;
        knuth)
            TRIPLET="powerpc-linux-gnu"
            ;;
        *)
            # Let's hope this exactly matches multilib paths
            TRIPLET="$(uname --machine)-linux-gnu"
            ;;
    esac
    # Let's hope $PATH is already defined...
    export PATH="$prefix/sbin:$prefix/bin:$PATH"

    # FIXME: is the order correct?
    export PATH="$prefix/libexec:$PATH"

    if [[ "$partial" != "yes" ]]; then
        if [[ "$LIBRARY_PATH" == "" ]]; then
            export LIBRARY_PATH="/lib/$TRIPLET:/lib:/usr/local/lib/$TRIPLET:/usr/local/lib:/usr/lib/$TRIPLET:/usr/lib:/usr/X11R6/lib:/lib64:/usr/local/lib64:/usr/lib64:/usr/X11R6/lib64"
        fi
        export LIBRARY_PATH="$prefix/lib/$TRIPLET:$prefix/lib:$prefix/lib64:$LIBRARY_PATH"

        if [[ "$LD_LIBRARY_PATH" == "" ]]; then
            export LD_LIBRARY_PATH="/lib/$TRIPLET:/lib:/usr/local/lib/$TRIPLET:/usr/local/lib:/usr/lib/$TRIPLET:/usr/lib:/usr/X11R6/lib:/lib64:/usr/local/lib64:/usr/lib64:/usr/X11R6/lib64"
            #export LD_LIBRARY_PATH="/lib:/usr/local/lib:/usr/lib:/usr/X11R6/lib:/lib64:/usr/local/lib64:/usr/lib64:/usr/X11R6/lib64:/lib/mipsel-linux-gnu"
        fi
        export LD_LIBRARY_PATH="$prefix/lib/$TRIPLET:$prefix/lib:$prefix/lib64:$LD_LIBRARY_PATH"
    fi

    if [[ "$MANPATH" == "" ]]; then
        export MANPATH="/usr/local/man:/usr/local/share/man:/usr/man:/usr/share/man:/usr/X11R6/man:/usr/X11R6/share/man"
    fi
    export MANPATH="$prefix/man:$prefix/share/man:$MANPATH"

    if [[ "$INFOPATH" == "" ]]; then
        export INFOPATH="/usr/local/info:/usr/local/share/info:/usr/info:/usr/share/info:/usr/X11R6/info:/usr/X11R6/share/info"
    fi

    export INFOPATH="$prefix/info:$prefix/share/info:$INFOPATH"
    if [[ "$partial" != "yes" ]]; then
        if [[ "$CPATH" == "" ]]; then
            export CPATH="/usr/local/include/$TRIPLET:/usr/local/include:/usr/include/$TRIPLET:/usr/include:/usr/X11R6/include:/usr/include/X11"
            #export CPATH="/usr/local/include:/usr/include:/usr/X11R6/include:/usr/include/X11"
        fi
        export CPATH="$prefix/include/$TRIPLET:$prefix/include:$CPATH"
        if [[ "$C_INCLUDE_PATH" == "" ]]; then
            export C_INCLUDE_PATH="/usr/local/include/$TRIPLET:/usr/local/include:/usr/include/$TRIPLET:/usr/include:/usr/X11R6/include:/usr/include/X11"
        fi
        export C_INCLUDE_PATH="$prefix/include/$TRIPLET:$prefix/include:$C_INCLUDE_PATH"

        if [[ "$CPLUS_INCLUDE_PATH" == "" ]]; then
            CPLUS_INCLUDE_PATH="/usr/local/include/$TRIPLET:/usr/local/include:/usr/include/$TRIPLET:/usr/include:/usr/X11R6/include:/usr/include/X11"
            #export CPLUS_INCLUDE_PATH="/usr/local/include:/usr/include:/usr/X11R6/include:/usr/include/X11"
        fi
        export CPLUS_INCLUDE_PATH="$prefix/include/$TRIPLET:$prefix/include:$CPLUS_INCLUDE_PATH"

        if [[ "$OBJC_INCLUDE_PATH" == "" ]]; then
            export OBJC_INCLUDE_PATH="/usr/local/include/$TRIPLET:/usr/local/include:/usr/include/$TRIPLET:/usr/include:/usr/X11R6/include:/usr/include/X11"
            #export OBJC_INCLUDE_PATH="/usr/local/include:/usr/include:/usr/X11R6/include:/usr/include/X11"
        fi
        export OBJC_INCLUDE_PATH="$prefix/include/$TRIPLET:$prefix/include:$OBJC_INCLUDE_PATH"

        if [[ "$PKG_CONFIG_PATH" == "" ]]; then
            export PKG_CONFIG_PATH=/usr/local/share/pkgconfig:/usr/share/pkgconfig:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig
        fi
        export PKG_CONFIG_PATH="$prefix/share/pkgconfig:$prefix/lib/pkgconfig:$PKG_CONFIG_PATH"
    fi

    if [[ $ACLOCAL_PATH == "" ]]; then
        if [ -d /usr/share/aclocal ]; then
            export ACLOCAL_PATH="/usr/share/aclocal"
        fi
        if [ -d /usr/local/share/aclocal ]; then
            export ACLOCAL_PATH="/usr/local/share/aclocal:$ACLOCAL_PATH"
        fi
    fi
    export ACLOCAL_PATH="$prefix/share/aclocal:$ACLOCAL_PATH"
}


[hacker emblem]
Luca Saiu
Last modified: 2021-09-03

Copyright © 2012, 2013, 2014, 2015, 2016, 2018, 2019 Luca Saiu
Verbatim copying and redistribution of this entire page are permitted provided this notice is preserved.