1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # maintainer-needed@gentoo.org
7 # Diego Pettenò <flameeyes@gentoo.org>
9 inherit versionator eutils flag-o-matic bsdmk
11 # Drop patch level from ${PV}
16 HOMEPAGE="http://www.freebsd.org/"
18 # Define global package names
19 LIB="freebsd-lib-${PV}"
20 BIN="freebsd-bin-${PV}"
21 CONTRIB="freebsd-contrib-${PV}"
22 SHARE="freebsd-share-${PV}"
23 UBIN="freebsd-ubin-${PV}"
24 USBIN="freebsd-usbin-${PV}"
25 CRYPTO="freebsd-crypto-${PV}"
26 LIBEXEC="freebsd-libexec-${PV}"
27 SBIN="freebsd-sbin-${PV}"
28 GNU="freebsd-gnu-${PV}"
29 ETC="freebsd-etc-${PV}"
30 SYS="freebsd-sys-${PV}"
31 INCLUDE="freebsd-include-${PV}"
32 RESCUE="freebsd-rescue-${PV}"
33 CDDL="freebsd-cddl-${PV}"
34 SECURE="freebsd-secure-${PV}"
36 # Release version (5.3, 5.4, 6.0, etc)
37 RV="$(get_version_component_range 1-2 ${MY_PV})"
40 # 9.1.0.9999 --> release/9.1.0
41 # 9.1.9999 --> releng/9.1
45 # svn revision can be specified by patch level:
46 # freebsd-lib-9.9999_p247000 --> set svn -r 247000
48 if [[ ${MY_PV} == *9999* ]]; then
51 # Set SVN revision using patch level.
52 [[ ${PV} == *_p* ]] && ESVN_REVISION="${PLEVEL}"
54 case ${MY_PV%.9999} in
55 *.*.*) BRANCH="release";;
56 *.*) BRANCH="releng" ;;
57 9999) BRANCH="head" ;;
61 if [[ ${BRANCH} == head ]] ; then
62 SVN_SUB_URI="${BRANCH}"
64 SVN_SUB_URI="${BRANCH}/${MY_PV%.9999}"
67 ESVN_REPO_URI="svn://svn.freebsd.org/base/${SVN_SUB_URI}"
68 ESVN_PROJECT="freebsd-${BRANCH}"
71 # Use the original source code.
72 if [[ ${MY_PV} != *9999* ]] && version_is_at_least 10.0 ${RV} ; then
73 DL_PV=${MY_PV/_rc/-RC}
74 DL_PV=${DL_PV/_beta/-BETA}
75 DL_PV=${DL_PV/_alpha/-ALPHA}
76 if [[ ${DL_PV} == ${MY_PV} ]]; then
77 DL_PV="${DL_PV}-RELEASE"
79 SRC_URI="mirror://freebsd/releases/i386/${DL_PV}/src.txz -> freebsd-src-${MY_PV}.tar.xz"
85 alias install-info='/usr/bin/bsdinstall-info'
87 EXPORT_FUNCTIONS src_compile src_install src_unpack
89 # doperiodic <kind> <file> ...
94 ( # dont want to pollute calling env
95 insinto /etc/periodic/${kind}
101 freebsd_get_bmake() {
104 if version_is_at_least 11.0 ${RV} ; then
105 if [[ ${CBUILD} == *-freebsd* ]] ; then
106 bmake="${bmake} -m /usr/share/mk/system"
108 bmake="${bmake} -m /usr/share/mk/freebsd/system"
111 [[ ${CBUILD} == *-freebsd* ]] || bmake="${bmake} -m /usr/share/mk/freebsd"
117 # Generates SRC_URI or DISTDIR for the upstream patch.
118 freebsd_upstream_patches() {
120 [[ ${#UPSTREAM_PATCHES[@]} -eq 0 ]] && return 1
121 for x in "${UPSTREAM_PATCHES[@]}"
123 local out=${PN}-${x/\//-}
125 if [[ ${opt} == -s ]] ; then
126 echo "${DISTDIR}/${out}"
128 echo "https://security.freebsd.org/patches/${x} -> ${out}"
133 freebsd_do_patches() {
134 if [[ ${#PATCHES[@]} -gt 1 ]] ; then
135 for x in "${PATCHES[@]}"; do
139 for x in ${PATCHES} ; do
144 # Upstream patches need to be applied on WORKDIR.
145 if [[ ${#UPSTREAM_PATCHES[@]} -gt 0 ]] ; then
146 cd "${WORKDIR}" || die
147 epatch $(freebsd_upstream_patches -s)
153 freebsd_rename_libraries() {
154 ebegin "Renaming libraries"
155 # We don't use libtermcap, we use libncurses
156 find "${S}" -name Makefile -print0 | xargs -0 \
157 sed -i -e 's:-ltermcap:-lncurses:g; s:{LIBTERMCAP}:{LIBNCURSES}:g'
158 # flex provides libfl, not libl
159 find "${S}" -name Makefile -print0 | xargs -0 \
160 sed -i -e 's:-ll$:-lfl:g; s:-ll :-lfl :g; s:{LIBL}:{LIBFL}:g'
161 # ncurses provides libncursesw not libcursesw
162 find "${S}" -name Makefile -print0 | xargs -0 \
163 sed -i -e 's:-lcursesw:-lncursesw:g'
164 # we use expat instead of bsdxml
165 find "${S}" -name Makefile -print0 | xargs -0 \
166 sed -i -e 's:-lbsdxml:-lexpat:g'
171 freebsd_src_unpack() {
172 if [[ ${MY_PV} == *9999* ]]; then
173 S="${WORKDIR}" subversion_src_unpack
175 # When share/mk exists in ${WORKDIR}, BSD's make will try to use it on FreeBSD 10.0 or later.
176 # We should remove "${WORKDIR}"/share/mk/*.mk to use /usr/share/mk{,/system}.
177 if [[ ${PN} != freebsd-mk-defs ]] ; then
178 [[ -e "${WORKDIR}"/share/mk ]] && rm -rf "${WORKDIR}"/share/mk/*.mk
181 if version_is_at_least 10.0 ${RV} ; then
182 local tarball="freebsd-src-${MY_PV}.tar.xz"
183 local topdir="usr/src/"
185 for i in ${EXTRACTONLY} tools/ ; do
186 extractlist+=( ${topdir}${i} )
188 ebegin "Unpacking parts of ${tarball} to ${WORKDIR}"
189 cd "${WORKDIR}" || die
190 tar -xJpf "${DISTDIR}/${tarball}" --strip-components=2 "${extractlist[@]}" 2> /dev/null || die "tar extract command failed"
194 [[ ${f} == *.tar.* ]] && unpack ${f}
200 dummy_mk ${REMOVE_SUBDIRS}
203 if ! version_is_at_least 11.0 ${RV} ; then
204 freebsd_rename_libraries
207 # Starting from FreeBSD 9.2, its install command supports the -l option and
208 # they now use it. Emulate it if we are on a system that does not have it.
209 if version_is_at_least 9.2 ${RV} && ! has_version '>=sys-freebsd/freebsd-ubin-9.2_beta1' ; then
210 export INSTALL_LINK="ln -f"
211 export INSTALL_SYMLINK="ln -fs"
213 # An older version of install command doesn't support the -T option.
214 if version_is_at_least 11.0 ${RV} && ! has_version ">=sys-freebsd/freebsd-ubin-${RV}" ; then
215 export INSTALL="sh ${WORKDIR}/tools/install.sh"
218 # If CC=clang, we should use clang-cpp instead of cpp. #478810, #595878
219 if [[ $(tc-getCC) == *clang* ]] ; then
220 if type -P clang-cpp > /dev/null ; then
223 mkdir "${WORKDIR}"/workaround_clang-cpp || die "Could not create ${WORKDIR}/workaround_clang-cpp"
224 ln -s "$(type -P clang)" "${WORKDIR}"/workaround_clang-cpp/clang-cpp || die "Could not create clang-cpp symlink."
225 export CPP="${WORKDIR}/workaround_clang-cpp/clang-cpp"
229 # Add the special CFLAGS required for multilib support.
230 use amd64-fbsd && export CFLAGS_x86_fbsd="${CFLAGS_x86_fbsd} -DCOMPAT_32BIT -B/usr/lib32 -L/usr/lib32"
233 freebsd_src_compile() {
234 use profile && filter-flags "-fomit-frame-pointer"
235 if version_is_at_least 11.0 ${RV} ; then
236 if ! use profile ; then
237 mymakeopts="${mymakeopts} WITHOUT_PROFILE= "
239 # Disable the debugging information, use FEATURES=splitdebug instead.
240 mymakeopts="${mymakeopts} WITHOUT_DEBUG_FILES= "
241 # We don't support test yet.
242 mymakeopts="${mymakeopts} WITHOUT_TESTS= "
243 # Set the SRCTOP to detect the source directory.
244 mymakeopts="${mymakeopts} SRCTOP=${WORKDIR} "
245 # Set the common settings.
246 mymakeopts="${mymakeopts} WITHOUT_MANCOMPRESS= WITHOUT_INFOCOMPRESS= "
248 use profile || mymakeopts="${mymakeopts} NO_PROFILE= "
249 mymakeopts="${mymakeopts} NO_MANCOMPRESS= NO_INFOCOMPRESS= "
252 mymakeopts="${mymakeopts} NO_FSCHG="
254 # Make sure to use FreeBSD definitions while crosscompiling
255 [[ -z "${BMAKE}" ]] && BMAKE="$(freebsd_get_bmake)"
257 # Create objdir if MAKEOBJDIRPREFIX is defined, so that we can make out of
258 # tree builds easily.
259 if [[ -n "${MAKEOBJDIRPREFIX}" ]] ; then
263 bsdmk_src_compile "$@"
266 # Helper function to make a multilib build with FreeBSD Makefiles.
268 # MULTIBUILD_VARIANTS=( $(get_all_abis) )
269 # multibuild_foreach_variant freebsd_multilib_multibuild_wrapper my_function
271 # Important note: To use this function you _have_ to:
272 # - inherit multilib.eclass and multibuild.eclass
273 # - set MULTIBUILD_VARIANTS
275 freebsd_multilib_multibuild_wrapper() {
276 # Get the ABI from multibuild.eclass
277 # This assumes MULTIBUILD_VARIANTS contains only valid ABIs.
278 local ABI=${MULTIBUILD_VARIANT}
280 # First, save the variables: CFLAGS, CXXFLAGS, LDFLAGS, LDADD and mymakeopts.
281 for i in CFLAGS CXXFLAGS LDFLAGS LDADD mymakeopts ; do
282 export ${i}_SAVE="${!i}"
285 # Setup the variables specific to this ABI.
286 multilib_toolchain_setup "${ABI}"
288 local target="$(tc-arch-kernel ${CHOST})"
289 mymakeopts="${mymakeopts} TARGET=${target} MACHINE=${target} MACHINE_ARCH=${target} SHLIBDIR=/usr/$(get_libdir) LIBDIR=/usr/$(get_libdir)"
290 if [ "${ABI}" != "${DEFAULT_ABI}" ] ; then
291 mymakeopts="${mymakeopts} COMPAT_32BIT="
294 einfo "Building for ABI=${ABI} and TARGET=${target}"
296 export MAKEOBJDIRPREFIX="${BUILD_DIR}"
297 if [ ! -d "${MAKEOBJDIRPREFIX}" ] ; then
298 mkdir "${MAKEOBJDIRPREFIX}" || die "Could not create ${MAKEOBJDIRPREFIX}."
301 CTARGET="${CHOST}" "$@"
303 # Restore the variables now.
304 for i in CFLAGS CXXFLAGS LDFLAGS LDADD mymakeopts ; do
310 freebsd_src_install() {
311 if version_is_at_least 11.0 ${RV} ; then
312 if ! use profile ; then
313 mymakeopts="${mymakeopts} WITHOUT_PROFILE= "
315 # Disable the debugging information, use FEATURES=splitdebug instead.
316 mymakeopts="${mymakeopts} WITHOUT_DEBUG_FILES= "
317 # We don't support test yet.
318 mymakeopts="${mymakeopts} WITHOUT_TESTS= "
319 # Set the SRCTOP to detect the source directory.
320 mymakeopts="${mymakeopts} SRCTOP=${WORKDIR} "
321 # Set the common settings.
322 mymakeopts="${mymakeopts} WITHOUT_MANCOMPRESS= WITHOUT_INFOCOMPRESS= "
324 use profile || mymakeopts="${mymakeopts} NO_PROFILE= "
325 mymakeopts="${mymakeopts} NO_MANCOMPRESS= NO_INFOCOMPRESS= "
328 mymakeopts="${mymakeopts} NO_FSCHG="
330 [[ -z "${BMAKE}" ]] && BMAKE="$(freebsd_get_bmake)"
332 bsdmk_src_install "$@"