build.sh 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. #!/bin/bash
  2. #-------------------------------------------------------------------------------------------------------
  3. # Copyright (C) Microsoft. All rights reserved.
  4. # Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  5. #-------------------------------------------------------------------------------------------------------
  6. SAFE_RUN() {
  7. local SF_RETURN_VALUE=$($1 2>&1)
  8. if [[ $? != 0 ]]; then
  9. >&2 echo $SF_RETURN_VALUE
  10. exit 1
  11. fi
  12. echo $SF_RETURN_VALUE
  13. }
  14. ERROR_EXIT() {
  15. if [[ $? != 0 ]]; then
  16. echo $($1 2>&1)
  17. exit 1;
  18. fi
  19. }
  20. ERROR_CLANG() {
  21. echo "ERROR: clang++ not found."
  22. echo -e "\nYou could use clang++ from a custom location.\n"
  23. PRINT_USAGE
  24. exit 1
  25. }
  26. PRINT_USAGE() {
  27. echo ""
  28. echo "[ChakraCore Build Script Help]"
  29. echo ""
  30. echo "build.sh [options]"
  31. echo ""
  32. echo "options:"
  33. echo " --arch[=S] Set target arch (arm, x86, amd64)"
  34. echo " --cc=PATH Path to Clang (see example below)"
  35. echo " --cxx=PATH Path to Clang++ (see example below)"
  36. echo " --create-deb[=V] Create .deb package with given V version."
  37. echo " -d, --debug Debug build. Default: Release"
  38. echo " --extra-defines=DEF=VAR,DEFINE,..."
  39. echo " Compile with additional defines"
  40. echo " -h, --help Show help"
  41. echo " --custom-icu=PATH The path to ICUUC headers"
  42. echo " If --libs-only --static is not specified,"
  43. echo " PATH/../lib must be the location of ICU libraries"
  44. echo " Example: /usr/local/opt/icu4c/include when using ICU from homebrew"
  45. echo " --system-icu Use the ICU that you installed globally on your machine"
  46. echo " (where ICU headers and libraries are in your system's search path)"
  47. echo " --embed-icu Download ICU 57.1 and link statically with it"
  48. echo " --no-icu Compile without ICU (disables Unicode and Intl features)"
  49. echo " -j[=N], --jobs[=N] Multicore build, allow N jobs at once."
  50. echo " -n, --ninja Build with ninja instead of make."
  51. echo " --no-jit Disable JIT"
  52. echo " --libs-only Do not build CH and GCStress"
  53. echo " --lto Enables LLVM Full LTO"
  54. echo " --lto-thin Enables LLVM Thin LTO - xcode 8+ or clang 3.9+"
  55. echo " --lttng Enables LTTng support for ETW events"
  56. echo " --static Build as static library. Default: shared library"
  57. echo " --sanitize=CHECKS Build with clang -fsanitize checks,"
  58. echo " e.g. undefined,signed-integer-overflow."
  59. echo " -t, --test-build Test build. Enables test flags on a release build."
  60. echo " --target[=S] Target OS (i.e. android)"
  61. echo " --target-path[=S] Output path for compiled binaries. Default: out/"
  62. echo " --trace Enables experimental built-in trace."
  63. echo " --xcode Generate XCode project."
  64. echo " --without-intl Disable Intl (ECMA 402) support"
  65. echo " --without=FEATURE,FEATURE,..."
  66. echo " Disable FEATUREs from JSRT experimental features."
  67. echo " --valgrind Enable Valgrind support"
  68. echo " !!! Disables Concurrent GC (lower performance)"
  69. echo " --ccache[=NAME] Enable ccache, optionally with a custom binary name."
  70. echo " Default: ccache"
  71. echo " -v, --verbose Display verbose output including all options"
  72. echo " --wb-check CPPFILE"
  73. echo " Write-barrier check given CPPFILE (git path)"
  74. echo " --wb-analyze CPPFILE"
  75. echo " Write-barrier analyze given CPPFILE (git path)"
  76. echo " --wb-args=PLUGIN_ARGS"
  77. echo " Write-barrier clang plugin args"
  78. echo " -y Automatically answer Yes to questions asked by"
  79. echo " this script (use at your own risk)"
  80. echo ""
  81. echo "example:"
  82. echo " ./build.sh --cxx=/path/to/clang++ --cc=/path/to/clang -j"
  83. echo "with icu:"
  84. echo " ./build.sh --custom-icu=/usr/local/opt/icu4c"
  85. echo ""
  86. }
  87. pushd `dirname $0` > /dev/null
  88. CHAKRACORE_DIR=`pwd -P`
  89. popd > /dev/null
  90. _CXX=""
  91. _CC=""
  92. VERBOSE="0"
  93. BUILD_TYPE="Release"
  94. CMAKE_GEN=
  95. EXTRA_DEFINES=""
  96. MAKE=make
  97. MULTICORE_BUILD=""
  98. NO_JIT=
  99. CMAKE_ICU="-DICU_SETTINGS_RESET=1"
  100. CMAKE_INTL="-DINTL_ICU_SH=1" # default to enabling intl
  101. USE_LOCAL_ICU=0 # default to using system version of ICU
  102. STATIC_LIBRARY="-DSHARED_LIBRARY_SH=1"
  103. SANITIZE=
  104. WITHOUT_FEATURES=""
  105. CREATE_DEB=0
  106. ARCH="-DCC_USES_SYSTEM_ARCH_SH=1"
  107. OS_LINUX=0
  108. OS_APT_GET=0
  109. OS_UNIX=0
  110. LTO=""
  111. LTTNG=""
  112. TARGET_OS=""
  113. ENABLE_CC_XPLAT_TRACE=""
  114. WB_CHECK=
  115. WB_ANALYZE=
  116. WB_ARGS=
  117. TARGET_PATH=0
  118. VALGRIND=0
  119. # -DCMAKE_EXPORT_COMPILE_COMMANDS=ON useful for clang-query tool
  120. CMAKE_EXPORT_COMPILE_COMMANDS="-DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
  121. LIBS_ONLY_BUILD=
  122. ALWAYS_YES=
  123. CCACHE_NAME=
  124. PYTHON2_BINARY=$(which python2.7 || which python2 || which python 2> /dev/null)
  125. UNAME_S=`uname -s`
  126. if [[ $UNAME_S =~ 'Linux' ]]; then
  127. OS_LINUX=1
  128. PROC_INFO=$(which apt-get)
  129. if [[ ${#PROC_INFO} > 0 && -f "$PROC_INFO" ]]; then
  130. OS_APT_GET=1
  131. fi
  132. elif [[ $UNAME_S =~ "Darwin" ]]; then
  133. OS_UNIX=1
  134. else
  135. echo -e "Warning: Installation script couldn't detect host OS..\n" # exit ?
  136. fi
  137. SET_CUSTOM_ICU() {
  138. ICU_PATH=$1
  139. if [[ ! -d "$ICU_PATH" || ! -d "$ICU_PATH/unicode" ]]; then
  140. ICU_PATH_LOCAL="$CHAKRACORE_DIR/$ICU_PATH"
  141. if [[ ! -d "$ICU_PATH_LOCAL" || ! -d "$ICU_PATH_LOCAL/unicode" ]]; then
  142. # if a path was explicitly provided, do not fallback to no-icu
  143. echo "!!! couldn't find ICU at either $ICU_PATH or $ICU_PATH_LOCAL"
  144. exit 1
  145. else
  146. ICU_PATH="$ICU_PATH_LOCAL"
  147. fi
  148. fi
  149. CMAKE_ICU="-DICU_INCLUDE_PATH_SH=$ICU_PATH"
  150. USE_LOCAL_ICU=0
  151. }
  152. while [[ $# -gt 0 ]]; do
  153. case "$1" in
  154. --arch=*)
  155. ARCH=$1
  156. ARCH="${ARCH:7}"
  157. ;;
  158. --cxx=*)
  159. _CXX=$1
  160. _CXX=${_CXX:6}
  161. ;;
  162. --cc=*)
  163. _CC=$1
  164. _CC=${_CC:5}
  165. ;;
  166. -h | --help)
  167. PRINT_USAGE
  168. exit
  169. ;;
  170. -v | --verbose)
  171. VERBOSE="1"
  172. ;;
  173. -d | --debug)
  174. BUILD_TYPE="Debug"
  175. ;;
  176. --extra-defines=*)
  177. DEFINES=$1
  178. DEFINES=${DEFINES:16} # value after --extra-defines=
  179. for x in ${DEFINES//,/ } # replace comma with space then split
  180. do
  181. if [[ "$EXTRA_DEFINES" == "" ]]; then
  182. EXTRA_DEFINES="-DEXTRA_DEFINES_SH="
  183. else
  184. EXTRA_DEFINES="$EXTRA_DEFINES;"
  185. fi
  186. EXTRA_DEFINES="${EXTRA_DEFINES}-D${x}"
  187. done
  188. ;;
  189. -t | --test-build)
  190. BUILD_TYPE="Test"
  191. ;;
  192. -j | --jobs)
  193. if [[ "$1" == "-j" && "$2" =~ ^[^-] ]]; then
  194. MULTICORE_BUILD="-j $2"
  195. shift
  196. else
  197. MULTICORE_BUILD="-j $(nproc)"
  198. fi
  199. ;;
  200. -j=* | --jobs=*) # -j=N syntax used in CI
  201. MULTICORE_BUILD=$1
  202. if [[ "$1" =~ ^-j= ]]; then
  203. MULTICORE_BUILD="-j ${MULTICORE_BUILD:3}"
  204. else
  205. MULTICORE_BUILD="-j ${MULTICORE_BUILD:7}"
  206. fi
  207. ;;
  208. --custom-icu=*)
  209. ICU_PATH=$1
  210. # `eval` used to resolve tilde in the path
  211. eval ICU_PATH="${ICU_PATH:13}"
  212. SET_CUSTOM_ICU $ICU_PATH
  213. ;;
  214. # allow legacy --icu flag for compatability
  215. --icu=*)
  216. ICU_PATH=$1
  217. # `eval` used to resolve tilde in the path
  218. eval ICU_PATH="${ICU_PATH:6}"
  219. SET_CUSTOM_ICU $ICU_PATH
  220. ;;
  221. --embed-icu)
  222. USE_LOCAL_ICU=1
  223. ;;
  224. --system-icu)
  225. CMAKE_ICU="-DSYSTEM_ICU_SH=1"
  226. USE_LOCAL_ICU=0
  227. ;;
  228. --no-icu)
  229. CMAKE_ICU="-DNO_ICU_SH=1"
  230. USE_LOCAL_ICU=0
  231. ;;
  232. --libs-only)
  233. LIBS_ONLY_BUILD="-DLIBS_ONLY_BUILD_SH=1"
  234. ;;
  235. --lto)
  236. LTO="-DENABLE_FULL_LTO_SH=1"
  237. HAS_LTO=1
  238. ;;
  239. --lto-thin)
  240. LTO="-DENABLE_THIN_LTO_SH=1"
  241. HAS_LTO=1
  242. ;;
  243. --lttng)
  244. LTTNG="-DENABLE_JS_LTTNG_SH=1"
  245. HAS_LTTNG=1
  246. ;;
  247. -n | --ninja)
  248. CMAKE_GEN="-G Ninja"
  249. MAKE=ninja
  250. ;;
  251. --no-jit)
  252. NO_JIT="-DNO_JIT_SH=1"
  253. ;;
  254. --without-intl)
  255. CMAKE_INTL="-DINTL_ICU_SH=0"
  256. ;;
  257. --xcode)
  258. CMAKE_GEN="-G Xcode -DCC_XCODE_PROJECT=1"
  259. CMAKE_EXPORT_COMPILE_COMMANDS=""
  260. MAKE=0
  261. ;;
  262. --create-deb=*)
  263. CREATE_DEB=$1
  264. CREATE_DEB="${CREATE_DEB:13}"
  265. ;;
  266. --static)
  267. STATIC_LIBRARY="-DSTATIC_LIBRARY_SH=1"
  268. ;;
  269. --sanitize=*)
  270. SANITIZE=$1
  271. SANITIZE=${SANITIZE:11} # value after --sanitize=
  272. SANITIZE="-DCLANG_SANITIZE_SH=${SANITIZE}"
  273. ;;
  274. --target=*)
  275. _TARGET_OS=$1
  276. _TARGET_OS="${_TARGET_OS:9}"
  277. if [[ $_TARGET_OS =~ "android" ]]; then
  278. if [[ -z "$TOOLCHAIN" ]]; then
  279. OLD_PATH=$PATH
  280. export TOOLCHAIN=$PWD/android-toolchain-arm
  281. export PATH=$TOOLCHAIN/bin:$OLD_PATH
  282. export AR=arm-linux-androideabi-ar
  283. export CC=arm-linux-androideabi-clang
  284. export CXX=arm-linux-androideabi-clang++
  285. export LINK=arm-linux-androideabi-clang++
  286. export STRIP=arm-linux-androideabi-strip
  287. # override CXX and CC
  288. _CXX="${TOOLCHAIN}/bin/${CXX}"
  289. _CC="${TOOLCHAIN}/bin/${CC}"
  290. fi
  291. TARGET_OS="-DCC_TARGET_OS_ANDROID_SH=1 -DANDROID_TOOLCHAIN_DIR=${TOOLCHAIN}/arm-linux-androideabi"
  292. # inherit CXX and CC
  293. _CXX="${CXX}"
  294. _CC="${CC}"
  295. fi
  296. ;;
  297. --trace)
  298. ENABLE_CC_XPLAT_TRACE="-DENABLE_CC_XPLAT_TRACE_SH=1"
  299. ;;
  300. --target-path=*)
  301. TARGET_PATH=$1
  302. TARGET_PATH=${TARGET_PATH:14}
  303. ;;
  304. --ccache=*)
  305. CCACHE_NAME="$1"
  306. CCACHE_NAME=${CCACHE_NAME:9}
  307. CCACHE_NAME="-DCCACHE_PROGRAM_NAME_SH=${CCACHE_NAME}"
  308. ;;
  309. --ccache)
  310. CCACHE_NAME="-DCCACHE_PROGRAM_NAME_SH=ccache"
  311. ;;
  312. --without=*)
  313. FEATURES=$1
  314. FEATURES=${FEATURES:10} # value after --without=
  315. for x in ${FEATURES//,/ } # replace comma with space then split
  316. do
  317. if [[ "$WITHOUT_FEATURES" == "" ]]; then
  318. WITHOUT_FEATURES="-DWITHOUT_FEATURES_SH="
  319. else
  320. WITHOUT_FEATURES="$WITHOUT_FEATURES;"
  321. fi
  322. WITHOUT_FEATURES="${WITHOUT_FEATURES}-DCOMPILE_DISABLE_${x}=1"
  323. done
  324. ;;
  325. --wb-check)
  326. if [[ "$2" =~ ^[^-] ]]; then
  327. WB_CHECK="$2"
  328. shift
  329. else
  330. WB_CHECK="*" # check all files
  331. fi
  332. ;;
  333. --wb-analyze)
  334. if [[ "$2" =~ ^[^-] ]]; then
  335. WB_ANALYZE="$2"
  336. shift
  337. else
  338. PRINT_USAGE && exit 1
  339. fi
  340. ;;
  341. --wb-args=*)
  342. WB_ARGS=$1
  343. WB_ARGS=${WB_ARGS:10}
  344. WB_ARGS=${WB_ARGS// /;} # replace space with ; to generate a cmake list
  345. ;;
  346. --valgrind)
  347. VALGRIND="-DENABLE_VALGRIND_SH=1"
  348. ;;
  349. -y | -Y)
  350. ALWAYS_YES=-y
  351. ;;
  352. *)
  353. echo "Unknown option $1"
  354. PRINT_USAGE
  355. exit -1
  356. ;;
  357. esac
  358. shift
  359. done
  360. if [[ $USE_LOCAL_ICU == 1 ]]; then
  361. LOCAL_ICU_DIR="$CHAKRACORE_DIR/deps/Chakra.ICU/icu"
  362. if [[ ! -d $LOCAL_ICU_DIR ]]; then
  363. "$PYTHON2_BINARY" "$CHAKRACORE_DIR/tools/icu/configure.py" 63.2 $ALWAYS_YES
  364. fi
  365. # if there is still no directory, then the user declined the license agreement
  366. if [[ ! -d $LOCAL_ICU_DIR ]]; then
  367. echo "You must accept the ICU license agreement in order to use this configuration"
  368. exit 1
  369. fi
  370. LOCAL_ICU_DIST="$LOCAL_ICU_DIR/output"
  371. if [ ! -d "$LOCAL_ICU_DIST" ]; then
  372. set -e
  373. pushd "$LOCAL_ICU_DIR/source"
  374. ./configure --with-data-packaging=static\
  375. --prefix="$LOCAL_ICU_DIST"\
  376. --enable-static\
  377. --disable-shared\
  378. --with-library-bits=64\
  379. --disable-icuio\
  380. --disable-layout\
  381. --disable-tests\
  382. --disable-samples\
  383. CXXFLAGS="-fPIC"\
  384. CFLAGS="-fPIC"
  385. ERROR_EXIT "rm -rf $LOCAL_ICU_DIST"
  386. make STATICCFLAGS="-fPIC" STATICCXXFLAGS="-fPIC" STATICCPPFLAGS="-DPIC" install
  387. ERROR_EXIT "rm -rf $LOCAL_ICU_DIST"
  388. popd
  389. fi
  390. CMAKE_ICU="-DICU_INCLUDE_PATH_SH=$LOCAL_ICU_DIST/include"
  391. fi
  392. if [[ "$MAKE" == "ninja" ]]; then
  393. if [[ "$VERBOSE" == "1" ]]; then
  394. VERBOSE="-v"
  395. else
  396. VERBOSE=""
  397. fi
  398. else
  399. if [[ "$VERBOSE" == "1" ]]; then
  400. VERBOSE="VERBOSE=1"
  401. else
  402. VERBOSE=""
  403. fi
  404. fi
  405. if [[ "$VERBOSE" != "" ]]; then
  406. # echo options back to the user
  407. echo "Printing command line options back to the user:"
  408. echo "_CXX=${_CXX}"
  409. echo "_CC=${_CC}"
  410. echo "BUILD_TYPE=${BUILD_TYPE}"
  411. echo "MULTICORE_BUILD=${MULTICORE_BUILD}"
  412. echo "CMAKE_ICU=${CMAKE_ICU}"
  413. echo "CMAKE_GEN=${CMAKE_GEN}"
  414. echo "MAKE=${MAKE} $VERBOSE"
  415. echo ""
  416. fi
  417. # if LTO build is enabled and cc-toolchain/clang was compiled, use it instead
  418. if [[ $HAS_LTO == 1 ]]; then
  419. if [[ -f "${CHAKRACORE_DIR}/cc-toolchain/build/bin/clang++" ]]; then
  420. SELF=`pwd`
  421. _CXX="$CHAKRACORE_DIR/cc-toolchain/build/bin/clang++"
  422. _CC="$CHAKRACORE_DIR/cc-toolchain/build/bin/clang"
  423. else
  424. # Linux LD possibly doesn't support LLVM LTO, check.. and compile clang if not
  425. if [[ $OS_LINUX == 1 ]]; then
  426. if [[ ! `ld -v` =~ 'GNU gold' ]]; then
  427. pushd "$CHAKRACORE_DIR" > /dev/null
  428. $CHAKRACORE_DIR/tools/compile_clang.sh
  429. if [[ $? != 0 ]]; then
  430. echo -e "tools/compile_clang.sh has failed.\n"
  431. echo "Try with 'sudo' ?"
  432. popd > /dev/null
  433. exit 1
  434. fi
  435. _CXX="$CHAKRACORE_DIR/cc-toolchain/build/bin/clang++"
  436. _CC="$CHAKRACORE_DIR/cc-toolchain/build/bin/clang"
  437. popd > /dev/null
  438. fi
  439. fi
  440. fi
  441. fi
  442. if [ "${HAS_LTO}${OS_LINUX}" == "11" ]; then
  443. echo "lto: ranlib disabled"
  444. export RANLIB=/bin/true
  445. fi
  446. CLANG_PATH=
  447. if [[ ${#_CXX} > 0 || ${#_CC} > 0 ]]; then
  448. if [[ ${#_CXX} == 0 || ${#_CC} == 0 ]]; then
  449. echo "ERROR: '-cxx' and '-cc' options must be used together."
  450. exit 1
  451. fi
  452. echo "Custom CXX ${_CXX}"
  453. echo "Custom CC ${_CC}"
  454. if [[ ! -f $_CXX || ! -f $_CC ]]; then
  455. echo "ERROR: Custom compiler not found on given path"
  456. exit 1
  457. fi
  458. CLANG_PATH=$_CXX
  459. else
  460. RET_VAL=$(SAFE_RUN 'c++ --version')
  461. if [[ ! $RET_VAL =~ "clang" ]]; then
  462. echo "Searching for Clang..."
  463. if [[ -f /usr/bin/clang++ ]]; then
  464. echo "Clang++ found at /usr/bin/clang++"
  465. _CXX=/usr/bin/clang++
  466. _CC=/usr/bin/clang
  467. CLANG_PATH=$_CXX
  468. else
  469. # try env CXX and CC
  470. if [[ ! -f $CXX || ! -f $CC ]]; then
  471. ERROR_CLANG
  472. fi
  473. _CXX=$CXX
  474. _CC=$CC
  475. CLANG_PATH=$CXX
  476. VERSION=$($CXX --version)
  477. if [[ ! $VERSION =~ "clang" ]]; then
  478. ERROR_CLANG
  479. fi
  480. echo -e "Clang++ not found on PATH.\nTrying CCX -> ${CCX} and CC -> ${CC}"
  481. fi
  482. else
  483. CLANG_PATH=c++
  484. fi
  485. fi
  486. # check clang version (min required 3.7)
  487. VERSION=$($CLANG_PATH --version | grep "version [0-9]*\.[0-9]*" --o -i | grep "[0-9]*\.[0-9]*" --o)
  488. VERSION=${VERSION/./}
  489. if [[ $VERSION -lt 37 ]]; then
  490. echo "ERROR: Minimum required Clang version is 3.7"
  491. exit 1
  492. fi
  493. CC_PREFIX=""
  494. if [[ ${#_CXX} > 0 ]]; then
  495. CC_PREFIX="-DCMAKE_CXX_COMPILER=$_CXX -DCMAKE_C_COMPILER=$_CC"
  496. fi
  497. RELATIVE_BUILD_PATH="../.."
  498. if [[ $TARGET_PATH == 0 ]]; then
  499. TARGET_PATH="$CHAKRACORE_DIR/out"
  500. else
  501. if [[ $TARGET_PATH =~ "~/" ]]; then
  502. echo "Do not use '~/' for '--target-path'"
  503. echo -e "\nAborting Build."
  504. exit 1
  505. fi
  506. fi
  507. export TARGET_PATH
  508. if [[ $HAS_LTTNG == 1 ]]; then
  509. CHAKRACORE_ROOT=`dirname $0`
  510. "$PYTHON2_BINARY" $CHAKRACORE_ROOT/tools/lttng.py --man $CHAKRACORE_ROOT/manifests/Microsoft-Scripting-Chakra-Instrumentation.man --intermediate $TARGET_PATH/intermediate
  511. mkdir -p $TARGET_PATH/lttng
  512. (diff -q $TARGET_PATH/intermediate/lttng/jscriptEtw.h $TARGET_PATH/lttng/jscriptEtw.h && echo "jscriptEtw.h up to date; skipping") || cp $TARGET_PATH/intermediate/lttng/* $TARGET_PATH/lttng/
  513. fi
  514. BUILD_DIRECTORY="${TARGET_PATH}/${BUILD_TYPE:0}"
  515. echo "Build path: ${BUILD_DIRECTORY}"
  516. BUILD_RELATIVE_DIRECTORY=$("$PYTHON2_BINARY" -c "import os.path;print \
  517. os.path.relpath('${CHAKRACORE_DIR}', '$BUILD_DIRECTORY')")
  518. ################# Write-barrier check/analyze run #################
  519. WB_FLAG=
  520. WB_TARGET=
  521. if [[ $WB_CHECK || $WB_ANALYZE ]]; then
  522. # build software write barrier checker clang plugin
  523. $CHAKRACORE_DIR/tools/RecyclerChecker/build.sh --cxx=$_CXX || exit 1
  524. if [[ $WB_CHECK && $WB_ANALYZE ]]; then
  525. echo "Please run only one of --wb-check or --wb-analyze" && exit 1
  526. fi
  527. if [[ $WB_CHECK ]]; then
  528. WB_FLAG="-DWB_CHECK_SH=1"
  529. WB_FILE=$WB_CHECK
  530. fi
  531. if [[ $WB_ANALYZE ]]; then
  532. WB_FLAG="-DWB_ANALYZE_SH=1"
  533. WB_FILE=$WB_ANALYZE
  534. fi
  535. if [[ $WB_ARGS ]]; then
  536. if [[ $WB_ARGS =~ "-fix" ]]; then
  537. MULTICORE_BUILD="-j 1" # 1 job only if doing write barrier fix
  538. fi
  539. WB_ARGS="-DWB_ARGS_SH=$WB_ARGS"
  540. fi
  541. # support --wb-check ONE_CPP_FILE
  542. if [[ $WB_FILE != "*" ]]; then
  543. if [[ $MAKE != 'ninja' ]]; then
  544. echo "--wb-check/wb-analyze ONE_FILE only works with --ninja" && exit 1
  545. fi
  546. if [[ -f $CHAKRACORE_DIR/$WB_FILE ]]; then
  547. touch $CHAKRACORE_DIR/$WB_FILE
  548. else
  549. echo "$CHAKRACORE_DIR/$WB_FILE not found. Please use full git path for $WB_FILE." && exit 1
  550. fi
  551. WB_FILE_DIR=`dirname $WB_FILE`
  552. WB_FILE_BASE=`basename $WB_FILE`
  553. WB_FILE_CMAKELISTS="$CHAKRACORE_DIR/$WB_FILE_DIR/CMakeLists.txt"
  554. if [[ -f $WB_FILE_CMAKELISTS ]]; then
  555. SUBDIR=$(grep -i add_library $WB_FILE_CMAKELISTS | sed "s/.*(\([^ ]*\) .*/\1/")
  556. else
  557. echo "$WB_FILE_CMAKELISTS not found." && exit 1
  558. fi
  559. WB_TARGET="$WB_FILE_DIR/CMakeFiles/$SUBDIR.dir/$WB_FILE_BASE.o"
  560. fi
  561. fi
  562. # prepare DbgController.js.h
  563. CH_DIR="${CHAKRACORE_DIR}/bin/ch"
  564. "${CH_DIR}/jstoc.py" "${CH_DIR}/DbgController.js" controllerScript
  565. if [[ $? != 0 ]]; then
  566. exit 1
  567. fi
  568. if [ ! -d "$BUILD_DIRECTORY" ]; then
  569. SAFE_RUN `mkdir -p $BUILD_DIRECTORY`
  570. fi
  571. pushd $BUILD_DIRECTORY > /dev/null
  572. if [[ $ARCH =~ "x86" ]]; then
  573. ARCH="-DCC_TARGETS_X86_SH=1"
  574. echo "Compile Target : x86"
  575. elif [[ $ARCH =~ "arm" ]]; then
  576. ARCH="-DCC_TARGETS_ARM_SH=1"
  577. echo "Compile Target : arm"
  578. elif [[ $ARCH =~ "amd64" ]]; then
  579. ARCH="-DCC_TARGETS_AMD64_SH=1"
  580. echo "Compile Target : amd64"
  581. else
  582. ARCH="-DCC_USES_SYSTEM_ARCH_SH=1"
  583. echo "Compile Target : System Default"
  584. fi
  585. echo Generating $BUILD_TYPE makefiles
  586. echo $EXTRA_DEFINES
  587. cmake $CMAKE_GEN $CC_PREFIX $CMAKE_ICU $LTO $LTTNG $STATIC_LIBRARY $ARCH $TARGET_OS \
  588. $ENABLE_CC_XPLAT_TRACE $EXTRA_DEFINES -DCMAKE_BUILD_TYPE=$BUILD_TYPE $SANITIZE $NO_JIT $CMAKE_INTL \
  589. $WITHOUT_FEATURES $WB_FLAG $WB_ARGS $CMAKE_EXPORT_COMPILE_COMMANDS $LIBS_ONLY_BUILD\
  590. $VALGRIND $BUILD_RELATIVE_DIRECTORY $CCACHE_NAME
  591. _RET=$?
  592. if [[ $? == 0 ]]; then
  593. if [[ $MAKE != 0 ]]; then
  594. if [[ $MAKE != 'ninja' ]]; then
  595. # $MFLAGS comes from host `make` process. Sub `make` process needs this (recursional make runs)
  596. TEST_MFLAGS="${MFLAGS}*!"
  597. if [[ $TEST_MFLAGS != "*!" ]]; then
  598. # Get -j flag from the host
  599. MULTICORE_BUILD=""
  600. fi
  601. $MAKE $MFLAGS $MULTICORE_BUILD $VERBOSE $WB_TARGET 2>&1 | tee build.log
  602. else
  603. $MAKE $MULTICORE_BUILD $VERBOSE $WB_TARGET 2>&1 | tee build.log
  604. fi
  605. _RET=${PIPESTATUS[0]}
  606. else
  607. echo "Visit given folder above for xcode project file ----^"
  608. fi
  609. fi
  610. if [[ $_RET != 0 ]]; then
  611. echo "See error details above. Exit code was $_RET"
  612. else
  613. if [[ $CREATE_DEB != 0 ]]; then
  614. DEB_FOLDER=`realpath .`
  615. DEB_FOLDER="${DEB_FOLDER}/chakracore_${CREATE_DEB}"
  616. mkdir -p $DEB_FOLDER/usr/local/bin
  617. mkdir -p $DEB_FOLDER/DEBIAN
  618. cp $DEB_FOLDER/../ch $DEB_FOLDER/usr/local/bin/
  619. if [[ $STATIC_LIBRARY == "-DSHARED_LIBRARY_SH=1" ]]; then
  620. cp $DEB_FOLDER/../*.so $DEB_FOLDER/usr/local/bin/
  621. fi
  622. echo -e "Package: ChakraCore"\
  623. "\nVersion: ${CREATE_DEB}"\
  624. "\nSection: base"\
  625. "\nPriority: optional"\
  626. "\nArchitecture: amd64"\
  627. "\nDepends: libc6 (>= 2.19), uuid-dev (>> 0), libicu-dev (>> 0)"\
  628. "\nMaintainer: ChakraCore <[email protected]>"\
  629. "\nDescription: Chakra Core"\
  630. "\n Open source Core of Chakra Javascript Engine"\
  631. > $DEB_FOLDER/DEBIAN/control
  632. dpkg-deb --build $DEB_FOLDER
  633. _RET=$?
  634. if [[ $_RET == 0 ]]; then
  635. echo ".deb package is available under $BUILD_DIRECTORY"
  636. fi
  637. fi
  638. fi
  639. popd > /dev/null
  640. exit $_RET