#! /bin/bash PROJECT=libraries # Available sub-projects. AVAILABLE_PROJECTS=( libraries ) # Enabled sub-projects. PROJECTS=( libraries ) # Additional options (see functions sources below). # Options followed by a ':' require an argument, by '::' allow an optional argument. SHORT_OPTIONS= # Long options are not available with BSD getopt. LONG_OPTIONS= # Help for additional options usage() { # option h "help" "display this help and exit" return } # Find the directory containing this script. source="${BASH_SOURCE[0]}" while [ -h "${source}" ] ; do SCRIPTS="$(cd -P "$(dirname "${source}")" && pwd)" source="$(readlink "${source}")" [[ ${source} != /* ]] && source="$DIR/${source}" done SCRIPTS="$(cd -P "$(dirname "${source}")" && pwd)" check_target() { if [ "${TARGET}" = "all" ] ; then echo "" else echo ${TARGETTUPLE} fi } # Get the list of available targets. get_targets() { cat ${TOOLINFO}/libraries | grep -v ^\# | sed -e 's/.*-elk*//g' } # Get the list of libraries to build. get_libraries() { cat ${SCRIPTS}/libraries | grep -v ^\# } # Get support functions and definitions. source ${SCRIPTS}/support # Build the libraries for a target. build_library() { # musl and compiler-rt are prerequisites for all the other libraries. if [ ! -d ${SRCTOP}/musl ] ; then # Get and patch the musl sources. run ${SCRIPTS}/build-musl -cp ${TARGETTUPLE} fi # Configure and install musl headers. echo "Building musl for ${1}." run ${SCRIPTS}/build-musl -Ci ${1} if [ ! -d ${SRCTOP}/compiler-rt ] ; then # Get and patch the compiler-rt sources. run ${SCRIPTS}/build-compiler-rt -cp ${TARGETTUPLE} fi # Configure, build, and install compiler-rt. echo "Building compiler-rt for ${1}." run ${SCRIPTS}/build-compiler-rt -Cbi ${1} # Configure, build, and install musl. echo "Building musl for ${1}." run ${SCRIPTS}/build-musl -Cbi ${1} # Build all the other libraries. for library in $(get_libraries) ; do if [ ! -r ${SCRIPTS}/build-${library} ] ; then bailout "There is no 'build-${library}' script to build '${library}'." fi if [ ! -d ${SRCTOP}/${library} ] ; then # Get and patch the sources. run ${SCRIPTS}/build-${library} -cp ${TARGETTUPLE} fi # Configure, build, and install the library echo "Building ${library} for ${1}." run ${SCRIPTS}/build-${library} -Cbi ${1} done } if [ "${TOOLS}" != "ecc" ] ; then # We need ecc to build the libraries bailout "ecc is unavailable. Run make-ecc first." fi if [ "${TARGET}" != "" -a "${TARGET}" != "all" ] ; then # Build for a single host. if [ "$(get_toolinfo ${TARGET})" = "" ] ; then bailout "'${TARGET}' is not a valid target." fi build_library ${TARGET} elif [ "${TARGET}" = "all" ] ; then # Build for all known targets. for target in ${TARGETS} ; do build_library ${target} done fi