mozcoreconf-v4.eclass 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. # Copyright 1999-2015 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. #
  4. # @ECLASS: mozcoreconf-v4.eclass
  5. # @MAINTAINER:
  6. # Mozilla team <mozilla@gentoo.org>
  7. # @BLURB: core options and configuration functions for mozilla
  8. # @DESCRIPTION:
  9. #
  10. # inherit mozconfig-v6.* or above for mozilla configuration support
  11. # @ECLASS-VARIABLE: MOZILLA_FIVE_HOME
  12. # @DESCRIPTION:
  13. # This is an eclass-generated variable that defines the rpath that the mozilla
  14. # product will be installed in. Read-only
  15. if [[ ! ${_MOZCORECONF} ]]; then
  16. PYTHON_COMPAT=( python2_7 )
  17. PYTHON_REQ_USE='ncurses,sqlite,ssl,threads'
  18. inherit multilib toolchain-funcs flag-o-matic python-any-r1 versionator
  19. IUSE="${IUSE} custom-cflags custom-optimization"
  20. DEPEND="virtual/pkgconfig
  21. ${PYTHON_DEPS}"
  22. # @FUNCTION: mozconfig_annotate
  23. # @DESCRIPTION:
  24. # add an annotated line to .mozconfig
  25. #
  26. # Example:
  27. # mozconfig_annotate "building on ultrasparc" --enable-js-ultrasparc
  28. # => ac_add_options --enable-js-ultrasparc # building on ultrasparc
  29. mozconfig_annotate() {
  30. declare reason=$1 x ; shift
  31. [[ $# -gt 0 ]] || die "mozconfig_annotate missing flags for ${reason}\!"
  32. for x in ${*}; do
  33. echo "ac_add_options ${x} # ${reason}" >>.mozconfig
  34. done
  35. }
  36. # @FUNCTION: mozconfig_use_enable
  37. # @DESCRIPTION:
  38. # add a line to .mozconfig based on a USE-flag
  39. #
  40. # Example:
  41. # mozconfig_use_enable truetype freetype2
  42. # => ac_add_options --enable-freetype2 # +truetype
  43. mozconfig_use_enable() {
  44. declare flag=$(use_enable "$@")
  45. mozconfig_annotate "$(use $1 && echo +$1 || echo -$1)" "${flag}"
  46. }
  47. # @FUNCTION mozconfig_use_with
  48. # @DESCRIPTION
  49. # add a line to .mozconfig based on a USE-flag
  50. #
  51. # Example:
  52. # mozconfig_use_with kerberos gss-api /usr/$(get_libdir)
  53. # => ac_add_options --with-gss-api=/usr/lib # +kerberos
  54. mozconfig_use_with() {
  55. declare flag=$(use_with "$@")
  56. mozconfig_annotate "$(use $1 && echo +$1 || echo -$1)" "${flag}"
  57. }
  58. # @FUNCTION mozconfig_use_extension
  59. # @DESCRIPTION
  60. # enable or disable an extension based on a USE-flag
  61. #
  62. # Example:
  63. # mozconfig_use_extension gnome gnomevfs
  64. # => ac_add_options --enable-extensions=gnomevfs
  65. mozconfig_use_extension() {
  66. declare minus=$(use $1 || echo -)
  67. mozconfig_annotate "${minus:-+}$1" --enable-extensions=${minus}${2}
  68. }
  69. moz_pkgsetup() {
  70. # Ensure we use C locale when building
  71. export LANG="C"
  72. export LC_ALL="C"
  73. export LC_MESSAGES="C"
  74. export LC_CTYPE="C"
  75. # Ensure we use correct toolchain
  76. export HOST_CC="$(tc-getBUILD_CC)"
  77. export HOST_CXX="$(tc-getBUILD_CXX)"
  78. tc-export CC CXX LD PKG_CONFIG
  79. # Ensure that we have a sane build enviroment
  80. export MOZILLA_CLIENT=1
  81. export BUILD_OPT=1
  82. export NO_STATIC_LIB=1
  83. export USE_PTHREADS=1
  84. export ALDFLAGS=${LDFLAGS}
  85. # ensure MOZCONFIG is not defined
  86. unset MOZCONFIG
  87. # set MOZILLA_FIVE_HOME
  88. export MOZILLA_FIVE_HOME="/usr/$(get_libdir)/${PN}"
  89. # nested configure scripts in mozilla products generate unrecognized options
  90. # false positives when toplevel configure passes downwards.
  91. export QA_CONFIGURE_OPTIONS=".*"
  92. if [[ $(gcc-major-version) -eq 3 ]]; then
  93. ewarn "Unsupported compiler detected, DO NOT file bugs for"
  94. ewarn "outdated compilers. Bugs opened with gcc-3 will be closed"
  95. ewarn "invalid."
  96. fi
  97. python-any-r1_pkg_setup
  98. }
  99. # @FUNCTION: mozconfig_init
  100. # @DESCRIPTION:
  101. # Initialize mozilla configuration and populate with core settings.
  102. # This should be called in src_configure before any other mozconfig_* functions.
  103. mozconfig_init() {
  104. declare enable_optimize pango_version myext x
  105. declare XUL=$([[ ${PN} == xulrunner ]] && echo true || echo false)
  106. declare FF=$([[ ${PN} == firefox ]] && echo true || echo false)
  107. declare SM=$([[ ${PN} == seamonkey ]] && echo true || echo false)
  108. declare TB=$([[ ${PN} == thunderbird ]] && echo true || echo false)
  109. ####################################
  110. #
  111. # Setup the initial .mozconfig
  112. # See http://www.mozilla.org/build/configure-build.html
  113. #
  114. ####################################
  115. case ${PN} in
  116. *xulrunner)
  117. cp xulrunner/config/mozconfig .mozconfig \
  118. || die "cp xulrunner/config/mozconfig failed" ;;
  119. *firefox)
  120. cp browser/config/mozconfig .mozconfig \
  121. || die "cp browser/config/mozconfig failed" ;;
  122. seamonkey)
  123. # Must create the initial mozconfig to enable application
  124. : >.mozconfig || die "initial mozconfig creation failed"
  125. mozconfig_annotate "" --enable-application=suite ;;
  126. *thunderbird)
  127. # Must create the initial mozconfig to enable application
  128. : >.mozconfig || die "initial mozconfig creation failed"
  129. mozconfig_annotate "" --enable-application=mail ;;
  130. esac
  131. ####################################
  132. #
  133. # CFLAGS setup and ARCH support
  134. #
  135. ####################################
  136. # Set optimization level
  137. if [[ ${ARCH} == hppa ]]; then
  138. mozconfig_annotate "more than -O0 causes a segfault on hppa" --enable-optimize=-O0
  139. elif [[ ${ARCH} == x86 ]]; then
  140. mozconfig_annotate "less then -O2 causes a segfault on x86" --enable-optimize=-O2
  141. elif use custom-optimization || [[ ${ARCH} =~ (alpha|ia64) ]]; then
  142. # Set optimization level based on CFLAGS
  143. if is-flag -O0; then
  144. mozconfig_annotate "from CFLAGS" --enable-optimize=-O0
  145. elif [[ ${ARCH} == ppc ]] && has_version '>=sys-libs/glibc-2.8'; then
  146. mozconfig_annotate "more than -O1 segfaults on ppc with glibc-2.8" --enable-optimize=-O1
  147. elif is-flag -O4; then
  148. mozconfig_annotate "from CFLAGS" --enable-optimize=-O4
  149. elif is-flag -O3; then
  150. mozconfig_annotate "from CFLAGS" --enable-optimize=-O3
  151. elif is-flag -O1; then
  152. mozconfig_annotate "from CFLAGS" --enable-optimize=-O1
  153. elif is-flag -Os; then
  154. mozconfig_annotate "from CFLAGS" --enable-optimize=-Os
  155. else
  156. mozconfig_annotate "Gentoo's default optimization" --enable-optimize=-O2
  157. fi
  158. else
  159. # Enable Mozilla's default
  160. mozconfig_annotate "mozilla default" --enable-optimize
  161. fi
  162. # Strip optimization so it does not end up in compile string
  163. filter-flags '-O*'
  164. # Strip over-aggressive CFLAGS
  165. use custom-cflags || strip-flags
  166. # Additional ARCH support
  167. case "${ARCH}" in
  168. alpha)
  169. # Historically we have needed to add -fPIC manually for 64-bit.
  170. # Additionally, alpha should *always* build with -mieee for correct math
  171. # operation
  172. append-flags -fPIC -mieee
  173. ;;
  174. ia64)
  175. # Historically we have needed to add this manually for 64-bit
  176. append-flags -fPIC
  177. ;;
  178. ppc64)
  179. append-flags -fPIC -mminimal-toc
  180. ;;
  181. esac
  182. # We need to append flags for gcc-6 support
  183. if [[ $(gcc-major-version) -ge 6 ]]; then
  184. append-cxxflags -fno-delete-null-pointer-checks -fno-lifetime-dse -fno-schedule-insns2
  185. fi
  186. # Go a little faster; use less RAM
  187. append-flags "$MAKEEDIT_FLAGS"
  188. # Use the MOZILLA_FIVE_HOME for the rpath
  189. append-ldflags -Wl,-rpath="${MOZILLA_FIVE_HOME}",--enable-new-dtags
  190. # Set MOZILLA_FIVE_HOME in mozconfig
  191. mozconfig_annotate '' --with-default-mozilla-five-home=${MOZILLA_FIVE_HOME}
  192. ####################################
  193. #
  194. # mozconfig setup
  195. #
  196. ####################################
  197. mozconfig_annotate disable_update_strip \
  198. --disable-updater \
  199. --disable-strip \
  200. --disable-install-strip
  201. # jemalloc won't build with older glibc
  202. ! has_version ">=sys-libs/glibc-2.4" && mozconfig_annotate "we have old glibc" --disable-jemalloc
  203. }
  204. # @FUNCTION: mozconfig_final
  205. # @DESCRIPTION:
  206. # Display a table describing all configuration options paired
  207. # with reasons, then clean up extensions list.
  208. # This should be called in src_configure at the end of all other mozconfig_* functions.
  209. mozconfig_final() {
  210. declare ac opt hash reason
  211. echo
  212. echo "=========================================================="
  213. echo "Building ${PF} with the following configuration"
  214. grep ^ac_add_options .mozconfig | while read ac opt hash reason; do
  215. [[ -z ${hash} || ${hash} == \# ]] \
  216. || die "error reading mozconfig: ${ac} ${opt} ${hash} ${reason}"
  217. printf " %-30s %s\n" "${opt}" "${reason:-mozilla.org default}"
  218. done
  219. echo "=========================================================="
  220. echo
  221. # Resolve multiple --enable-extensions down to one
  222. declare exts=$(sed -n 's/^ac_add_options --enable-extensions=\([^ ]*\).*/\1/p' \
  223. .mozconfig | xargs)
  224. sed -i '/^ac_add_options --enable-extensions/d' .mozconfig
  225. echo "ac_add_options --enable-extensions=${exts// /,}" >> .mozconfig
  226. }
  227. _MOZCORECONF=1
  228. fi