minix3/llvm/build.llvm

161 lines
3.7 KiB
Bash
Executable File

#!/bin/bash
############################
#
# Author: Koustubha Bhat
# Date : 3-April-2014
# VU University, Amsterdam.
#
############################
set -o errexit
MYPWD=`pwd`
MINIX_ROOT=
MINIX_LLVM_DIR=
LLVMPASS=
LLVMARGS=
LLVMPASS_PATHS=
TARGET_MODULES=
MINIX_MODS=
# Set default values for essential variables
: ${GENERATE_MAP="no"}
: ${C="servers,drivers"}
function usage()
{
echo "C=<target Minix module(s)> $0 [<LLVM-pass name> ...]"
echo
echo "Examples:"
echo "C=pm,vfs ./$0 dummy"
echo "C=drivers ./$0 dummy"
echo
echo "Additional arguments to the passes may be passed through \${LLVM_PASS_ARGS}."
echo
}
function check_current_dir()
{
#Make sure we are running from the root dir of the Minix sources
if [ -d ./minix/drivers ] && [ -d ./minix/servers ] ; then
MINIX_ROOT="${MYPWD}"
elif [ -d ../../minix/drivers ] && [ -d ../../minix/servers ]; then
MINIX_ROOT="${MYPWD}/../.."
else
echo "Please run the script from either of the following locations:"
echo "> Root of the Minix sources."
echo " OR"
echo "> minix/llvm directory of the Minix sources."
exit 1
fi
MINIX_LLVM_DIR="${MINIX_ROOT}/minix/llvm"
}
function check_args()
{
local llvmpass=
local llvmpass_path=
local exit_flag=0
if [ $# -ge 1 ]; then
if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
usage
exit 1
fi
for p in "$@" ;
do
llvmpass=$p
# Default value for llvmargs not specified deliberately
if [ -f "${INSTALL_DIR}/${llvmpass}.so" ]; then
llvmpass_path="${INSTALL_DIR}/${llvmpass}.so"
elif [ -f "${MINIX_LLVM_BIN_DIR}/${llvmpass}.so" ]; then
llvmpass_path="${MINIX_LLVM_BIN_DIR}/${llvmpass}.so"
else
llvmpass_path=""
fi
if [ "$llvmpass_path" != "" ]; then
LLVMPASS_PATHS+=" -load=${llvmpass_path}"
fi
LLVMPASS_PATHS+=" -${llvmpass}"
done
if [ ${exit_flag} == 1 ]; then
echo "Searched in the following location(s):"
echo " ${INSTALL_DIR}"
echo " ${MINIX_LLVM_BIN_DIR}"
exit 1
fi
LLVMARGS=" ${LLVM_PASS_ARGS}"
fi
}
#Make sure we are running from the root dir of the Minix sources
check_current_dir
# set up the bridge to llvm-apps repository and initialize
. ${MINIX_LLVM_DIR}/minix.inc
[ ! -f ${ROOT}/apps/scripts/include/configure.llvm.inc ] || . ${ROOT}/apps/scripts/include/configure.llvm.inc
# Arguments check
check_args "$@"
if [ "$C" == "" ]; then
C="hello"
fi
if [ "${GENERATE_MAP}" != "" ] && [[ ${GENERATE_MAP} =~ [yY][eE][sS] ]]; then
generate_modules_map
fi
: ${OPTFLAGS="-disable-opt -disable-internalize -disable-inlining -load ${MINIX_LLVM_DIR}/bin/weak-alias-module-override.so -weak-alias-module-override"}
# If we are really instrumenting with some pass...
if [ "${LLVMPASS_PATHS}" != "" ]; then
OPTFLAGS=" ${OPTFLAGS} ${LLVMPASS_PATHS} ${LLVMARGS}"
fi
TARGET_MODULES=`echo $C | sed -e "s/,/ /g"`
for m in ${TARGET_MODULES}
do
for p in `get_modules_path $m`
do
MINIX_MODS="${MINIX_MODS} $p"
done
done
# Show info
echo "Build.llvm: Executing with following parameters..."
echo "LLVM pass : ${LLVMPASS}"
echo "LLVM pass arguments : ${LLVMARGS}"
echo "Target Minix modules : ${MINIX_MODS}"
echo "OPTFLAGS value : ${OPTFLAGS}"
echo
cd ${MINIX_ROOT}
for m in ${MINIX_MODS}
do
echo "Instrumenting $m ..."
n=`get_module_name $m`
if [ "" == "$n" ]; then
echo "Error: Couldn't fetch the module name for $m"
continue
fi
clean_module $n $m
OPTFLAGS=`echo ${OPTFLAGS} | sed -e "s/\ /\\\ /g"`
OPTFLAGS_PLACEHOLDER="OPTFLAGS.$n=${OPTFLAGS}"
(env "`echo ${OPTFLAGS_PLACEHOLDER}`" MKBITCODE=yes \
${TOOLDIR}/nbmake-${ARCH} -C $m all install && echo "INFO: $m successfully instrumented." ) || echo "ERROR: Failed instrumenting $m"
echo
done
cd ${MYPWD}