freebsd.eclass 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. # Copyright 1999-2015 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. #
  4. # @MAINTAINER:
  5. # maintainer-needed@gentoo.org
  6. # @AUTHOR:
  7. # Diego Pettenò <flameeyes@gentoo.org>
  8. inherit versionator eutils flag-o-matic bsdmk
  9. # Drop patch level from ${PV}
  10. MY_PV=${PV/_p*}
  11. PLEVEL=${PV##*_p}
  12. LICENSE="BSD"
  13. HOMEPAGE="http://www.freebsd.org/"
  14. # Define global package names
  15. LIB="freebsd-lib-${PV}"
  16. BIN="freebsd-bin-${PV}"
  17. CONTRIB="freebsd-contrib-${PV}"
  18. SHARE="freebsd-share-${PV}"
  19. UBIN="freebsd-ubin-${PV}"
  20. USBIN="freebsd-usbin-${PV}"
  21. CRYPTO="freebsd-crypto-${PV}"
  22. LIBEXEC="freebsd-libexec-${PV}"
  23. SBIN="freebsd-sbin-${PV}"
  24. GNU="freebsd-gnu-${PV}"
  25. ETC="freebsd-etc-${PV}"
  26. SYS="freebsd-sys-${PV}"
  27. INCLUDE="freebsd-include-${PV}"
  28. RESCUE="freebsd-rescue-${PV}"
  29. CDDL="freebsd-cddl-${PV}"
  30. SECURE="freebsd-secure-${PV}"
  31. # Release version (5.3, 5.4, 6.0, etc)
  32. RV="$(get_version_component_range 1-2 ${MY_PV})"
  33. # SVN ebuild support.
  34. # 9.1.0.9999 --> release/9.1.0
  35. # 9.1.9999 --> releng/9.1
  36. # 9.9999 --> stable/9
  37. # 9999 --> head
  38. #
  39. # svn revision can be specified by patch level:
  40. # freebsd-lib-9.9999_p247000 --> set svn -r 247000
  41. if [[ ${MY_PV} == *9999* ]]; then
  42. inherit subversion
  43. # Set SVN revision using patch level.
  44. [[ ${PV} == *_p* ]] && ESVN_REVISION="${PLEVEL}"
  45. case ${MY_PV%.9999} in
  46. *.*.*) BRANCH="release";;
  47. *.*) BRANCH="releng" ;;
  48. 9999) BRANCH="head" ;;
  49. *) BRANCH="stable" ;;
  50. esac
  51. if [[ ${BRANCH} == head ]] ; then
  52. SVN_SUB_URI="${BRANCH}"
  53. else
  54. SVN_SUB_URI="${BRANCH}/${MY_PV%.9999}"
  55. fi
  56. ESVN_REPO_URI="svn://svn.freebsd.org/base/${SVN_SUB_URI}"
  57. ESVN_PROJECT="freebsd-${BRANCH}"
  58. fi
  59. # use the original source code.
  60. if [[ ${MY_PV} != *9999* ]] && version_is_at_least 10.0 ${RV} ; then
  61. DL_PV=${MY_PV/_rc/-RC}
  62. DL_PV=${DL_PV/_beta/-BETA}
  63. DL_PV=${DL_PV/_alpha/-ALPHA}
  64. if [[ ${DL_PV} == ${MY_PV} ]]; then
  65. DL_PV="${DL_PV}-RELEASE"
  66. fi
  67. SRC_URI="mirror://freebsd/releases/i386/${DL_PV}/src.txz -> freebsd-src-${MY_PV}.tar.xz"
  68. fi
  69. IUSE="profile"
  70. #unalias -a
  71. alias install-info='/usr/bin/bsdinstall-info'
  72. EXPORT_FUNCTIONS src_compile src_install src_unpack
  73. # doperiodic <kind> <file> ...
  74. doperiodic() {
  75. local kind=$1
  76. shift
  77. ( # dont want to pollute calling env
  78. insinto /etc/periodic/${kind}
  79. insopts -m 0755
  80. doins "$@"
  81. )
  82. }
  83. freebsd_get_bmake() {
  84. local bmake
  85. bmake=$(get_bmake)
  86. if version_is_at_least 11.0 ${RV} ; then
  87. if [[ ${CBUILD} == *-freebsd* ]] ; then
  88. bmake="${bmake} -m /usr/share/mk/system"
  89. else
  90. bmake="${bmake} -m /usr/share/mk/freebsd/system"
  91. fi
  92. else
  93. [[ ${CBUILD} == *-freebsd* ]] || bmake="${bmake} -m /usr/share/mk/freebsd"
  94. fi
  95. echo "${bmake}"
  96. }
  97. # Generates a patch SRC_URI or DISTDIR of upstream.
  98. freebsd_upstream_patches() {
  99. local opt=$1
  100. [[ ${#UPSTREAM_PATCHES[@]} -eq 0 ]] && return 1
  101. for x in "${UPSTREAM_PATCHES[@]}"
  102. do
  103. local out=${PN}-${x/\//-}
  104. out=${out/:/}
  105. if [[ ${opt} == -s ]] ; then
  106. echo "${DISTDIR}/${out}"
  107. else
  108. echo "https://security.freebsd.org/patches/${x} -> ${out}"
  109. fi
  110. done
  111. }
  112. freebsd_do_patches() {
  113. if [[ ${#PATCHES[@]} -gt 1 ]] ; then
  114. for x in "${PATCHES[@]}"; do
  115. epatch "${x}"
  116. done
  117. else
  118. for x in ${PATCHES} ; do
  119. epatch "${x}"
  120. done
  121. fi
  122. # Upstream patches need to be applied on WORKDIR.
  123. if [[ ${#UPSTREAM_PATCHES[@]} -gt 0 ]] ; then
  124. cd "${WORKDIR}" || die
  125. epatch $(freebsd_upstream_patches -s)
  126. cd "${S}" || die
  127. fi
  128. epatch_user
  129. }
  130. freebsd_rename_libraries() {
  131. ebegin "Renaming libraries"
  132. # We don't use libtermcap, we use libncurses
  133. find "${S}" -name Makefile -print0 | xargs -0 \
  134. sed -i -e 's:-ltermcap:-lncurses:g; s:{LIBTERMCAP}:{LIBNCURSES}:g'
  135. # flex provides libfl, not libl
  136. find "${S}" -name Makefile -print0 | xargs -0 \
  137. sed -i -e 's:-ll$:-lfl:g; s:-ll :-lfl :g; s:{LIBL}:{LIBFL}:g'
  138. # ncurses provides libncursesw not libcursesw
  139. find "${S}" -name Makefile -print0 | xargs -0 \
  140. sed -i -e 's:-lcursesw:-lncursesw:g'
  141. # we use expat instead of bsdxml
  142. find "${S}" -name Makefile -print0 | xargs -0 \
  143. sed -i -e 's:-lbsdxml:-lexpat:g'
  144. eend $?
  145. }
  146. freebsd_src_unpack() {
  147. if [[ ${MY_PV} == *9999* ]]; then
  148. S="${WORKDIR}" subversion_src_unpack
  149. # When share/mk exists in ${WORKDIR}, it is used on FreeBSD 10.0
  150. # Removed "${WORKDIR}"/share/mk/*.mk, use to force /usr/share/mk.
  151. if [[ ${PN} != freebsd-mk-defs ]] ; then
  152. [[ -e "${WORKDIR}"/share/mk ]] && rm -rf "${WORKDIR}"/share/mk/*.mk
  153. fi
  154. else
  155. if version_is_at_least 10.0 ${RV} ; then
  156. local tarball="freebsd-src-${MY_PV}.tar.xz"
  157. local topdir="usr/src/"
  158. local extractlist=()
  159. for i in ${EXTRACTONLY} ; do
  160. extractlist+=( ${topdir}${i} )
  161. done
  162. ebegin "Unpacking parts of ${tarball} to ${WORKDIR}"
  163. cd "${WORKDIR}" || die
  164. tar -xJpf "${DISTDIR}/${tarball}" --strip-components=2 "${extractlist[@]}" 2> /dev/null || die "tar extract command failed"
  165. cd - || die
  166. else
  167. for f in ${A} ; do
  168. [[ ${f} == *.tar.* ]] && unpack ${f}
  169. done
  170. fi
  171. fi
  172. cd "${S}"
  173. dummy_mk ${REMOVE_SUBDIRS}
  174. freebsd_do_patches
  175. if ! version_is_at_least 11.0 ${RV} ; then
  176. freebsd_rename_libraries
  177. fi
  178. # Starting from FreeBSD 9.2, its install command supports the -l option and
  179. # they now use it. Emulate it if we are on a system that does not have it.
  180. if version_is_at_least 9.2 ${RV} && ! has_version '>=sys-freebsd/freebsd-ubin-9.2_beta1' ; then
  181. export INSTALL_LINK="ln -f"
  182. export INSTALL_SYMLINK="ln -fs"
  183. fi
  184. if version_is_at_least 11.0 ${RV} ; then
  185. export RSYMLINK=" -l s"
  186. fi
  187. # When CC=clang, force use clang-cpp #478810, #595878
  188. if [[ $(tc-getCC) == *clang* ]] ; then
  189. if type -P clang-cpp > /dev/null ; then
  190. export CPP=clang-cpp
  191. else
  192. mkdir "${WORKDIR}"/workaround_clang-cpp || die "Could not create ${WORKDIR}/workaround_clang-cpp"
  193. ln -s "$(type -P clang)" "${WORKDIR}"/workaround_clang-cpp/clang-cpp || die "Could not create clang-cpp symlink."
  194. export CPP="${WORKDIR}/workaround_clang-cpp/clang-cpp"
  195. fi
  196. fi
  197. # Add a special CFLAGS required for multilib support.
  198. use amd64-fbsd && export CFLAGS_x86_fbsd="${CFLAGS_x86_fbsd} -DCOMPAT_32BIT -B/usr/lib32 -L/usr/lib32"
  199. }
  200. freebsd_src_compile() {
  201. use profile && filter-flags "-fomit-frame-pointer"
  202. if version_is_at_least 11.0 ${RV} ; then
  203. if ! use profile ; then
  204. mymakeopts="${mymakeopts} WITHOUT_PROFILE= "
  205. fi
  206. # Disable debugging info, use FEATURES=splitdebug instead.
  207. mymakeopts="${mymakeopts} WITHOUT_DEBUG_FILES= "
  208. # Test does not support yet.
  209. mymakeopts="${mymakeopts} WITHOUT_TESTS= "
  210. # Force set SRCTOP.
  211. mymakeopts="${mymakeopts} SRCTOP=${WORKDIR} "
  212. # Set common option.
  213. mymakeopts="${mymakeopts} WITHOUT_MANCOMPRESS= WITHOUT_INFOCOMPRESS= "
  214. else
  215. use profile || mymakeopts="${mymakeopts} NO_PROFILE= "
  216. mymakeopts="${mymakeopts} NO_MANCOMPRESS= NO_INFOCOMPRESS= "
  217. fi
  218. mymakeopts="${mymakeopts} NO_FSCHG="
  219. # Make sure to use FreeBSD definitions while crosscompiling
  220. [[ -z "${BMAKE}" ]] && BMAKE="$(freebsd_get_bmake)"
  221. # Create objdir if MAKEOBJDIRPREFIX is defined, so that we can make out of
  222. # tree builds easily.
  223. if [[ -n "${MAKEOBJDIRPREFIX}" ]] ; then
  224. mkmake obj || die
  225. fi
  226. bsdmk_src_compile "$@"
  227. }
  228. # Helper function to make a multilib build with FreeBSD Makefiles.
  229. # Usage:
  230. # MULTIBUILD_VARIANTS=( $(get_all_abis) )
  231. # multibuild_foreach_variant freebsd_multilib_multibuild_wrapper my_function
  232. #
  233. # Important note: To use this function you _have_ to:
  234. # - inherit multilib.eclass and multibuild.eclass
  235. # - set MULTIBUILD_VARIANTS
  236. freebsd_multilib_multibuild_wrapper() {
  237. # Get the ABI from multibuild.eclass
  238. # This assumes MULTIBUILD_VARIANTS contains only valid ABIs.
  239. local ABI=${MULTIBUILD_VARIANT}
  240. # First, save the variables: CFLAGS, CXXFLAGS, LDFLAGS, LDADD and mymakeopts.
  241. for i in CFLAGS CXXFLAGS LDFLAGS LDADD mymakeopts ; do
  242. export ${i}_SAVE="${!i}"
  243. done
  244. # Setup the variables specific to this ABI.
  245. multilib_toolchain_setup "${ABI}"
  246. local target="$(tc-arch-kernel ${CHOST})"
  247. mymakeopts="${mymakeopts} TARGET=${target} MACHINE=${target} MACHINE_ARCH=${target} SHLIBDIR=/usr/$(get_libdir) LIBDIR=/usr/$(get_libdir)"
  248. if [ "${ABI}" != "${DEFAULT_ABI}" ] ; then
  249. mymakeopts="${mymakeopts} COMPAT_32BIT="
  250. fi
  251. einfo "Building for ABI=${ABI} and TARGET=${target}"
  252. export MAKEOBJDIRPREFIX="${BUILD_DIR}"
  253. if [ ! -d "${MAKEOBJDIRPREFIX}" ] ; then
  254. mkdir "${MAKEOBJDIRPREFIX}" || die "Could not create ${MAKEOBJDIRPREFIX}."
  255. fi
  256. CTARGET="${CHOST}" "$@"
  257. # Restore the variables now.
  258. for i in CFLAGS CXXFLAGS LDFLAGS LDADD mymakeopts ; do
  259. ii="${i}_SAVE"
  260. export ${i}="${!ii}"
  261. done
  262. }
  263. freebsd_src_install() {
  264. if version_is_at_least 11.0 ${RV} ; then
  265. if ! use profile ; then
  266. mymakeopts="${mymakeopts} WITHOUT_PROFILE= "
  267. fi
  268. # Disable debugging info, use FEATURES=splitdebug instead.
  269. mymakeopts="${mymakeopts} WITHOUT_DEBUG_FILES= "
  270. # Test does not support yet.
  271. mymakeopts="${mymakeopts} WITHOUT_TESTS= "
  272. # Force set SRCTOP.
  273. mymakeopts="${mymakeopts} SRCTOP=${WORKDIR} "
  274. # Set common option.
  275. mymakeopts="${mymakeopts} WITHOUT_MANCOMPRESS= WITHOUT_INFOCOMPRESS= "
  276. else
  277. use profile || mymakeopts="${mymakeopts} NO_PROFILE= "
  278. mymakeopts="${mymakeopts} NO_MANCOMPRESS= NO_INFOCOMPRESS= "
  279. fi
  280. mymakeopts="${mymakeopts} NO_FSCHG="
  281. [[ -z "${BMAKE}" ]] && BMAKE="$(freebsd_get_bmake)"
  282. bsdmk_src_install "$@"
  283. }