summarylogtreecommitdiffstats
path: root/pgo.sh.in
blob: 0bb44b80f39b847631aff141f29623646ebf54ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/bash
#
#   pgo.sh - Compile with, or utilize profile guided optimization
#

[[ -n "$LIBMAKEPKG_BUILDENV_PGO_SH" ]] && return
LIBMAKEPKG_BUILDENV_PGO_SH=1

LIBRARY=${LIBRARY:-'@libmakepkgdir@'}

source "$LIBRARY/util/message.sh"
source "$LIBRARY/util/option.sh"

build_options+=('pgo')
buildenv_functions+=('buildenv_pgo')

buildenv_pgo() {
	if check_buildoption "pgo" "y"; then
		[[ -n ${PROFDEST} ]] && _PROFDEST=$(canonicalize_path ${PROFDEST})
		PROFDEST=${_PROFDEST:-$PROFDEST}
		PROFDEST=${PROFDEST:-$startdir} #default to $startdir if undefined

		if [[ ! -w $PROFDEST ]] ; then
			error "$(gettext "You do not have write permission to store profiles in %s.")" "$PROFDEST"
			plain "$(gettext "Aborting...")"
			exit 1
		fi

		[[ "$INFAKEROOT" == 1 ]] && return

		if [ ! -d "$PROFDEST/$pkgbase.gen" ]; then
			CFLAGS+=" -fprofile-generate -fprofile-dir=$PROFDEST/$pkgbase.gen"
			CXXFLAGS+=" -fprofile-generate -fprofile-dir=$PROFDEST/$pkgbase.gen"
			LDFLAGS+=" -lgcov --coverage"
		else
			[[ ! -d "$PROFDEST/$pkgbase.used" ]] && mv "$PROFDEST/$pkgbase.gen" "$PROFDEST/$pkgbase.used"
			CFLAGS+=" -fprofile-correction -fprofile-use -fprofile-dir=$PROFDEST/$pkgbase.used"
			CXXFLAGS+=" -fprofile-correction -fprofile-use -fprofile-dir=$PROFDEST/$pkgbase.used"
		fi
	fi
}