tools/llvm: Do not build with symbols
[minix3.git] / minix / llvm / build.llvm
blobd980e5dbfb0979386f853a1497bf36542c566911
1 #!/bin/bash
3 ############################
5 # Author: Koustubha Bhat
6 # Date : 3-April-2014
7 # VU University, Amsterdam.
9 ############################
11 set -o errexit
13 MYPWD=`pwd`
14 MINIX_ROOT=
15 MINIX_LLVM_DIR=
16 LLVMPASS=
17 LLVMARGS=
18 LLVMPASS_PATHS=
19 TARGET_MODULES=
20 MINIX_MODS=
22 # Set default values for essential variables
23 : ${GENERATE_MAP="no"}
24 : ${C="servers,drivers"}
26 function usage()
28 echo "C=<target Minix module(s)> $0 [<LLVM-pass name> ...]"
29 echo
30 echo "Examples:"
31 echo "C=pm,vfs ./$0 dummy"
32 echo "C=drivers ./$0 dummy"
33 echo
34 echo "Additional arguments to the passes may be passed through \${LLVM_PASS_ARGS}."
35 echo
38 function check_current_dir()
40 #Make sure we are running from the root dir of the Minix sources
41 if [ -d ./minix/drivers ] && [ -d ./minix/servers ] ; then
42 MINIX_ROOT="${MYPWD}"
43 elif [ -d ../../minix/drivers ] && [ -d ../../minix/servers ]; then
44 MINIX_ROOT="${MYPWD}/../.."
45 else
46 echo "Please run the script from either of the following locations:"
47 echo "> Root of the Minix sources."
48 echo " OR"
49 echo "> minix/llvm directory of the Minix sources."
50 exit 1
53 MINIX_LLVM_DIR="${MINIX_ROOT}/minix/llvm"
56 function check_args()
58 local llvmpass=
59 local llvmpass_path=
60 local exit_flag=0
62 if [ $# -ge 1 ]; then
64 if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
65 usage
66 exit 1
69 for p in "$@" ;
71 llvmpass=$p
72 # Default value for llvmargs not specified deliberately
74 if [ -f "${INSTALL_DIR}/${llvmpass}.so" ]; then
75 llvmpass_path="${INSTALL_DIR}/${llvmpass}.so"
76 elif [ -f "${MINIX_LLVM_BIN_DIR}/${llvmpass}.so" ]; then
77 llvmpass_path="${MINIX_LLVM_BIN_DIR}/${llvmpass}.so"
78 else
79 llvmpass_path=""
81 if [ "$llvmpass_path" != "" ]; then
82 LLVMPASS_PATHS+=" -load=${llvmpass_path}"
84 LLVMPASS_PATHS+=" -${llvmpass}"
85 done
87 if [ ${exit_flag} == 1 ]; then
88 echo "Searched in the following location(s):"
89 echo " ${INSTALL_DIR}"
90 echo " ${MINIX_LLVM_BIN_DIR}"
91 exit 1
94 LLVMARGS=" ${LLVM_PASS_ARGS}"
98 #Make sure we are running from the root dir of the Minix sources
99 check_current_dir
101 # set up the bridge to llvm-apps repository and initialize
102 . ${MINIX_LLVM_DIR}/minix.inc
103 [ ! -f ${ROOT}/apps/scripts/include/configure.llvm.inc ] || . ${ROOT}/apps/scripts/include/configure.llvm.inc
105 # Arguments check
106 check_args "$@"
108 if [ "$C" == "" ]; then
109 C="hello"
112 if [ "${GENERATE_MAP}" != "" ] && [[ ${GENERATE_MAP} =~ [yY][eE][sS] ]]; then
113 generate_modules_map
116 : ${OPTFLAGS="-disable-opt -disable-internalize -disable-inlining -load ${MINIX_LLVM_DIR}/bin/weak-alias-module-override.so -weak-alias-module-override"}
118 # If we are really instrumenting with some pass...
119 if [ "${LLVMPASS_PATHS}" != "" ]; then
120 OPTFLAGS=" ${OPTFLAGS} ${LLVMPASS_PATHS} ${LLVMARGS}"
123 TARGET_MODULES=`echo $C | sed -e "s/,/ /g"`
125 for m in ${TARGET_MODULES}
127 for p in `get_modules_path $m`
129 MINIX_MODS="${MINIX_MODS} $p"
130 done
131 done
133 # Show info
134 echo "Build.llvm: Executing with following parameters..."
135 echo "LLVM pass : ${LLVMPASS}"
136 echo "LLVM pass arguments : ${LLVMARGS}"
137 echo "Target Minix modules : ${MINIX_MODS}"
138 echo "OPTFLAGS value : ${OPTFLAGS}"
139 echo
141 cd ${MINIX_ROOT}
143 for m in ${MINIX_MODS}
145 echo "Instrumenting $m ..."
146 n=`get_module_name $m`
147 if [ "" == "$n" ]; then
148 echo "Error: Couldn't fetch the module name for $m"
149 continue
151 clean_module $n $m
152 OPTFLAGS=`echo ${OPTFLAGS} | sed -e "s/\ /\\\ /g"`
153 OPTFLAGS_PLACEHOLDER="OPTFLAGS.$n=${OPTFLAGS}"
155 (env "`echo ${OPTFLAGS_PLACEHOLDER}`" MKBITCODE=yes \
156 ${TOOLDIR}/nbmake-${ARCH} -C $m all install && echo "INFO: $m successfully instrumented." ) || echo "ERROR: Failed instrumenting $m"
157 echo
158 done
160 cd ${MYPWD}