common.sh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. # Copyright (c) 2011 The Native Client Authors. All rights reserved.
  2. # Use of this source code is governed by a BSD-style license that be
  3. # found in the LICENSE file.
  4. #
  5. set -o nounset
  6. set -o errexit
  7. # scripts that source this file must be run from within packages tree
  8. readonly SAVE_PWD=$(pwd)
  9. # Pick platform directory for compiler.
  10. readonly OS_NAME=$(uname -s)
  11. if [ $OS_NAME = "Darwin" ]; then
  12. readonly OS_SUBDIR="mac"
  13. readonly OS_SUBDIR_SHORT="mac"
  14. elif [ $OS_NAME = "Linux" ]; then
  15. readonly OS_SUBDIR="linux"
  16. readonly OS_SUBDIR_SHORT="linux"
  17. else
  18. readonly OS_SUBDIR="windows"
  19. readonly OS_SUBDIR_SHORT="win"
  20. fi
  21. readonly MACHINE=$(uname -m)
  22. if [ $MACHINE = "x86_64" ]; then
  23. readonly TARGET_BITSIZE=${TARGET_BITSIZE:-"64"}
  24. readonly HOST_BITSIZE=${HOST_BITSIZE:-"64"}
  25. else
  26. # uname -m reports i686 on Linux and i386 on Mac
  27. readonly TARGET_BITSIZE=${TARGET_BITSIZE:-"32"}
  28. readonly HOST_BITSIZE=${HOST_BITSIZE:-"32"}
  29. fi
  30. if [ $TARGET_BITSIZE == "64" ]; then
  31. readonly TARGET_BIT_PREFIX="64"
  32. readonly CROSS_ID=x86_64
  33. else
  34. readonly TARGET_BIT_PREFIX=""
  35. readonly CROSS_ID=i686
  36. fi
  37. # we might want to override the detected host platform (e.g. on OSX 10.6)
  38. if [ $HOST_BITSIZE == "64" ]; then
  39. readonly HOST_BIT_PREFIX="64"
  40. else
  41. readonly HOST_BIT_PREFIX=""
  42. fi
  43. export NACL_CROSS_PREFIX=${CROSS_ID}-nacl
  44. export NACL_CROSS_PREFIX_DASH=${NACL_CROSS_PREFIX}-
  45. readonly NACL_NEWLIB=${NACL_NEWLIB:-"0"}
  46. if [ $NACL_NEWLIB = "1" ]; then
  47. readonly NACL_SDK_BASE=${NACL_SDK_ROOT}/toolchain/${OS_SUBDIR_SHORT}_x86_newlib
  48. else
  49. case "${NACL_SDK_ROOT}" in
  50. *pepper_15* | *pepper_16* | *pepper_17*)
  51. readonly NACL_SDK_BASE=${NACL_SDK_ROOT}/toolchain/${OS_SUBDIR_SHORT}_x86
  52. ;;
  53. *)
  54. readonly NACL_SDK_BASE=${NACL_SDK_ROOT}/toolchain/${OS_SUBDIR_SHORT}_x86_glibc
  55. ;;
  56. esac
  57. fi
  58. readonly NACL_BIN_PATH=${NACL_SDK_BASE}/bin
  59. export NACLCC=${NACL_BIN_PATH}/${NACL_CROSS_PREFIX_DASH}gcc
  60. export NACLCXX=${NACL_BIN_PATH}/${NACL_CROSS_PREFIX_DASH}g++
  61. export NACLAR=${NACL_BIN_PATH}/${NACL_CROSS_PREFIX_DASH}ar
  62. export NACLRANLIB=${NACL_BIN_PATH}/${NACL_CROSS_PREFIX_DASH}ranlib
  63. export NACLLD=${NACL_BIN_PATH}/${NACL_CROSS_PREFIX_DASH}ld
  64. export NACLAS=${NACL_BIN_PATH}/${NACL_CROSS_PREFIX_DASH}as
  65. # NACL_SDK_GCC_SPECS_PATH is where nacl-gcc 'specs' file will be installed
  66. readonly NACL_SDK_GCC_SPECS_PATH=${NACL_SDK_BASE}/lib/gcc/x86_64-nacl/4.4.3
  67. # NACL_SDK_USR is where the headers, libraries, etc. will be installed
  68. readonly NACL_SDK_USR=${NACL_SDK_BASE}/${NACL_CROSS_PREFIX}/usr
  69. readonly NACL_SDK_USR_INCLUDE=${NACL_SDK_USR}/include
  70. readonly NACL_SDK_USR_LIB=${NACL_SDK_USR}/lib
  71. ######################################################################
  72. # Helper functions
  73. ######################################################################
  74. Banner() {
  75. echo "######################################################################"
  76. echo $*
  77. echo "######################################################################"
  78. }
  79. VerifyPath() {
  80. # make sure path isn't all slashes (possibly from an unset variable)
  81. local PATH=$1
  82. local TRIM=${PATH##/}
  83. if [ ${#TRIM} -ne 0 ]; then
  84. return 0
  85. else
  86. return 1
  87. fi
  88. }
  89. ChangeDir() {
  90. local NAME=$1
  91. if VerifyPath ${NAME}; then
  92. cd ${NAME}
  93. else
  94. echo "ChangeDir called with bad path."
  95. exit -1
  96. fi
  97. }
  98. Remove() {
  99. local NAME=$1
  100. if VerifyPath ${NAME}; then
  101. rm -rf ${NAME}
  102. else
  103. echo "Remove called with bad path."
  104. exit -1
  105. fi
  106. }
  107. MakeDir() {
  108. local NAME=$1
  109. if VerifyPath ${NAME}; then
  110. mkdir -p ${NAME}
  111. else
  112. echo "MakeDir called with bad path."
  113. exit -1
  114. fi
  115. }
  116. PatchSpecFile() {
  117. # fix up spaces so gcc sees entire path
  118. local SED_SAFE_SPACES_USR_INCLUDE=${NACL_SDK_USR_INCLUDE/ /\ /}
  119. local SED_SAFE_SPACES_USR_LIB=${NACL_SDK_USR_LIB/ /\ /}
  120. # have nacl-gcc dump specs file & add include & lib search paths
  121. ${NACL_SDK_BASE}/bin/x86_64-nacl-gcc -dumpspecs |\
  122. sed "/*cpp:/{
  123. N
  124. s|$| -I${SED_SAFE_SPACES_USR_INCLUDE}|
  125. }" |\
  126. sed "/*link_libgcc:/{
  127. N
  128. s|$| -L${SED_SAFE_SPACES_USR_LIB}|
  129. }" >${NACL_SDK_GCC_SPECS_PATH}/specs
  130. }
  131. DefaultConfigureStep() {
  132. Banner "Configuring ${PACKAGE_NAME}"
  133. # export the nacl tools
  134. export CC=${NACLCC}
  135. export CXX=${NACLCXX}
  136. export AR=${NACLAR}
  137. export RANLIB=${NACLRANLIB}
  138. export PKG_CONFIG_PATH=${NACL_SDK_USR_LIB}/pkgconfig
  139. export PKG_CONFIG_LIBDIR=${NACL_SDK_USR_LIB}
  140. export PATH=${NACL_BIN_PATH}:${PATH};
  141. ChangeDir ${NACL_PACKAGES_REPOSITORY}/${PACKAGE_NAME}
  142. Remove ${PACKAGE_NAME}-build
  143. MakeDir ${PACKAGE_NAME}-build
  144. cd ${PACKAGE_NAME}-build
  145. ../configure \
  146. --host=nacl \
  147. --disable-shared \
  148. --prefix=${NACL_SDK_USR} \
  149. --exec-prefix=${NACL_SDK_USR} \
  150. --libdir=${NACL_SDK_USR_LIB} \
  151. --oldincludedir=${NACL_SDK_USR_INCLUDE} \
  152. --with-http=off \
  153. --with-html=off \
  154. --with-ftp=off \
  155. --with-x=no
  156. }
  157. DefaultBuildStep() {
  158. # assumes pwd has makefile
  159. make clean
  160. if [ $TARGET_BITSIZE == "64" ]; then
  161. make -j8
  162. else
  163. make
  164. fi
  165. }
  166. DefaultInstallStep() {
  167. # assumes pwd has makefile
  168. make install
  169. }
  170. DefaultCleanUpStep() {
  171. PatchSpecFile
  172. ChangeDir ${SAVE_PWD}
  173. }
  174. DefaultPackageInstall() {
  175. DefaultPreInstallStep
  176. DefaultDownloadStep
  177. DefaultExtractStep
  178. DefaultPatchStep
  179. DefaultConfigureStep
  180. DefaultBuildStep
  181. DefaultInstallStep
  182. DefaultCleanUpStep
  183. }