minix/minix/llvm/relink.llvm
David van Moolenbroek 949a3e52e5 Break loose from llvm-apps entirely
Change-Id: I532f5f44c785c1a72407b504568d54fc6cbabf8f
2015-09-17 13:58:57 +00:00

146 lines
3 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=
TARGET_MODULES=
MINIX_MODS=
STATIC_LIBS=
LDFLAGS_PLACEHOLDER=" "
# Set default values to essential variables.
: ${GENERATE_MAP="no"}
: ${C="servers,fs,net,drivers"}
function usage()
{
echo "C=<target Minix module> $0 [<static library name>]"
echo
echo "Examples:"
echo "C=pm,vfs ./$0 dummy"
echo "C=drivers ./$0 dummy"
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"
}
# Copied from configure.llvm.inc
function build_llvm_libs()
{
local LIBS=""
for a in $*
do
LIBS="$LIBS `find $INSTALL_DIR -maxdepth 1 -name ${a}\*.bcc | xargs`"
done
echo $LIBS
}
function find_static_libs()
{
local stat_libs_llvmapps=
local stat_libs_minix=
local install_dir_save=
stat_libs_llvmapps=`build_llvm_libs $*`
install_dir_save=${INSTALL_DIR}
INSTALL_DIR=${MINIX_LLVM_BIN_DIR}
stat_libs_minix=`build_llvm_libs $*`
INSTALL_DIR=${install_dir_save}
echo "${stat_libs_llvmapps} ${stat_libs_minix}"
}
#Make sure we are running from the right directory
check_current_dir
# Arguments check
if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
usage
exit 1
fi
. ${MINIX_LLVM_DIR}/minix.inc
echo ".so and .bcc binaries of LLVM passes set to be picked up from:"
echo " ${INSTALL_DIR}"
echo " and"
echo " ${MINIX_LLVM_BIN_DIR}"
echo
# Picking up the selected modules
if [ "${GENERATE_MAP}" != "" ] && [[ ${GENERATE_MAP} =~ [yY][eE][sS] ]]; then
generate_modules_map
fi
STATIC_LIBS=`find_static_libs $*`
TARGET_MODULES=`echo " $C " | sed -e "s/,/ /g" -e "s/ rd / ramdisk memory /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 "relink.llvm: Executing with following parameters..."
echo "LIBRARIES : $*"
echo "Target Minix modules : ${MINIX_MODS}"
echo
cd ${MINIX_ROOT}
for m in ${MINIX_MODS}
do
echo "Relinking $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 "relink"
if [ "${STATIC_LIBS}"!="" ]; then
STATIC_LIBS=`echo ${STATIC_LIBS} | sed -e "s/\ /\\\ /g"`
LDFLAGS_PLACEHOLDER="BITCODE_LD_FLAGS_1ST.$n=${STATIC_LIBS}"
fi
env "`echo ${LDFLAGS_PLACEHOLDER}`" MKBITCODE=yes \
${TOOLDIR}/nbmake-${ARCH} -C $m all install
echo
done
cd ${MYPWD}