1 #!/bin/bash 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 3 # Use of this source code is governed by a BSD-style license that can be 4 # found in the LICENSE file. 5 6 set -o nounset 7 set -o errexit 8 9 if [[ $# -ne 3 ]]; then 10 echo "Usage: $0 [path_to_mono] [build_dir] [install_dir]" 11 exit -1 12 fi 13 14 readonly CLEAN=1 15 readonly DEBUG=0 16 readonly PARALLEL=0 17 readonly MONO_DIR=$(readlink -f $1) 18 readonly BUILD_DIR=$(readlink -f $2) 19 readonly INSTALL_DIR=$(readlink -f $3) 20 readonly ORIGINAL_CWD=$(pwd) 21 22 set +e 23 if [ -f ${BUILD_DIR}/Makefile -a ${CLEAN} != 0 ]; then 24 cd ${BUILD_DIR} 25 make distclean 26 fi 27 set -e 28 cd $ORIGINAL_CWD 29 30 case "${TARGET_ARCH}" in 31 x86-32) 32 readonly USE_PNACL=0 33 readonly USE_NEWLIB=0 34 readonly TC_FLAVOUR=linux_x86_glibc 35 readonly NACL_CROSS_PREFIX_DASH=i686-nacl- 36 CONFIG_OPTS="--host=i686-pc-linux-gnu \ 37 --build=i686-pc-linux-gnu \ 38 --target=i686-pc-linux-gnu" 39 readonly LIBDIR=lib32 40 CUSTOM_CFLAGS="" 41 readonly CUSTOM_LDFLAGS="" 42 ;; 43 x86-64) 44 readonly USE_PNACL=0 45 readonly USE_NEWLIB=0 46 readonly TC_FLAVOUR=linux_x86_glibc 47 readonly NACL_CROSS_PREFIX_DASH=x86_64-nacl- 48 CONFIG_OPTS="--host=x86_64-pc-linux-gnu \ 49 --build=x86_64-pc-linux-gnu \ 50 --target=x86_64-pc-linux-gnu" 51 readonly LIBDIR=lib 52 CUSTOM_CFLAGS="" 53 readonly CUSTOM_LDFLAGS="" 54 ;; 55 arm) 56 readonly USE_PNACL=0 57 readonly USE_NEWLIB=1 58 readonly TC_FLAVOUR=linux_arm_newlib 59 readonly NACL_CROSS_PREFIX_DASH=arm-nacl- 60 CONFIG_OPTS="--host=armv7l-unknown-linux-gnueabi \ 61 --build=x86_64-pc-linux-gnu \ 62 --target=armv7l-unknown-linux-gnueabi \ 63 --with-jumptables=yes" 64 readonly LIBDIR=libarm 65 # TODO(olonho): move it to Mono's configure, once nacl target implemented. 66 CUSTOM_CFLAGS="\ 67 -DARM_FPU_VFP=1 \ 68 -D__ARM_ARCH_7__ \ 69 -Dtimezone=_timezone \ 70 -DDISABLE_SOCKETS \ 71 -DDISABLE_ATTACH \ 72 " 73 readonly CUSTOM_LDFLAGS="" 74 ;; 75 arm-pnacl) 76 readonly USE_PNACL=1 77 readonly USE_NEWLIB=1 78 readonly TC_FLAVOUR=linux_pnacl 79 readonly NACL_CROSS_PREFIX_DASH=pnacl- 80 readonly PNACL_LINK_ARGS="-arch armv7 -O2" 81 CONFIG_OPTS="--host=armv7l-unknown-linux-gnueabi \ 82 --build=x86_64-pc-linux-gnu \ 83 --target=armv7l-unknown-linux-gnueabi \ 84 --with-jumptables=yes" 85 readonly LIBDIR=libarm 86 # TODO(olonho): move it to Mono's configure, once nacl target implemented. 87 CUSTOM_CFLAGS="\ 88 -D__arm__ \ 89 -D__ARM_ARCH_7__ \ 90 -D__portable_native_client__ \ 91 -DARM_FPU_VFP=1 \ 92 -Dtimezone=_timezone \ 93 -DDISABLE_SOCKETS \ 94 -DDISABLE_ATTACH \ 95 " 96 readonly CUSTOM_LDFLAGS=${PNACL_LINK_ARGS} 97 ;; 98 *) 99 echo "Unsupported target ${TARGET_ARCH}" 100 exit 1 101 esac 102 103 if [ ${USE_NEWLIB} == 1 ]; then 104 CUSTOM_CFLAGS="${CUSTOM_CFLAGS} -DUSE_NEWLIB" 105 CONFIG_OPTS="${CONFIG_OPTS} --enable-shared=no" 106 else 107 CONFIG_OPTS="${CONFIG_OPTS} --enable-shared=yes" 108 # UGLY hack to allow dynamic linking 109 sed -i -e s/elf_i386/elf_nacl/ -e s/elf_x86_64/elf64_nacl/ \ 110 ${MONO_DIR}/configure 111 sed -i -e s/elf_i386/elf_nacl/ -e s/elf_x86_64/elf64_nacl/ \ 112 ${MONO_DIR}/libgc/configure 113 sed -i -e s/elf_i386/elf_nacl/ -e s/elf_x86_64/elf64_nacl/ \ 114 ${MONO_DIR}/eglib/configure 115 fi 116 117 if [ ${CLEAN} != 0 ]; then 118 rm -rf ${BUILD_DIR} 119 mkdir -p ${BUILD_DIR} 120 fi 121 cd ${BUILD_DIR} 122 123 mkdir -p ${INSTALL_DIR} 124 125 readonly NACL_BIN_PATH=${NACL_SDK_ROOT}/toolchain/${TC_FLAVOUR}/bin 126 127 if [ ${USE_PNACL} == 1 ]; then 128 readonly NACLCC=${NACL_BIN_PATH}/pnacl-clang 129 readonly NACLCXX=${NACL_BIN_PATH}/pnacl-clang++ 130 else 131 readonly NACLCC=${NACL_BIN_PATH}/${NACL_CROSS_PREFIX_DASH}gcc 132 readonly NACLCXX=${NACL_BIN_PATH}/${NACL_CROSS_PREFIX_DASH}g++ 133 fi 134 readonly NACLAR=${NACL_BIN_PATH}/${NACL_CROSS_PREFIX_DASH}ar 135 readonly NACLRANLIB=${NACL_BIN_PATH}/${NACL_CROSS_PREFIX_DASH}ranlib 136 readonly NACLLD=${NACL_BIN_PATH}/${NACL_CROSS_PREFIX_DASH}ld 137 readonly NACLOBJDUMP=${NACL_BIN_PATH}/${NACL_CROSS_PREFIX_DASH}objdump 138 readonly NACLSTRIP=${NACL_BIN_PATH}/${NACL_CROSS_PREFIX_DASH}strip 139 140 if [ ${DEBUG} == 1 ]; then 141 CFLAGS="$CUSTOM_CFLAGS" 142 CONFIG_OPTS="${CONFIG_OPTS} --enable-debug=yes" 143 else 144 CFLAGS="-g $CUSTOM_CFLAGS" 145 CONFIG_OPTS="${CONFIG_OPTS} --enable-debug=no" 146 fi 147 148 if [ ${PARALLEL} == 1 ]; then 149 readonly JOBS="-j16" 150 else 151 readonly JOBS= 152 fi 153 154 155 LDFLAGS="$CUSTOM_LDFLAGS" 156 LIBS="-lnacl_dyncode -lc -lg -lnosys -lpthread" 157 158 CC=${NACLCC} CXX=${NACLCXX} LD=${NACLLD} \ 159 STRIP=${NACLSTRIP} AR=${NACLAR} RANLIB=${NACLRANLIB} OBJDUMP=${NACLOBJDUMP} \ 160 PKG_CONFIG_LIBDIR= \ 161 PATH=${NACL_BIN_PATH}:${PATH} \ 162 LIBS="${LIBS}" \ 163 CFLAGS="${CFLAGS}" \ 164 LDFLAGS="${LDFLAGS}" \ 165 ${MONO_DIR}/configure ${CONFIG_OPTS} \ 166 --exec-prefix=${INSTALL_DIR} \ 167 --libdir=${INSTALL_DIR}/${LIBDIR} \ 168 --prefix=${INSTALL_DIR} \ 169 --program-prefix=${NACL_CROSS_PREFIX_DASH} \ 170 --oldincludedir=${INSTALL_DIR}/include \ 171 --with-glib=embedded \ 172 --with-tls=pthread \ 173 --enable-threads=posix \ 174 --without-sigaltstack \ 175 --without-mmap \ 176 --with-gc=included \ 177 --enable-nacl-gc \ 178 --with-sgen=no \ 179 --enable-nls=no \ 180 --enable-nacl-codegen \ 181 --disable-system-aot \ 182 --disable-parallel-mark \ 183 --with-static-mono=no 184 185 if [ ${USE_NEWLIB} == 1 ]; then 186 # Newlib build doesn't support building shared libs, and unfortunately, this 187 # leads to libmonoruntime.la no being built as well, unless we'll do that 188 # explicitly. 189 make ${JOBS} -C mono/metadata libmonoruntime.la 190 fi 191 make ${JOBS} 192 make ${JOBS} install 193