aboutsummarylogtreecommitdiffstats
path: root/pgo.sh.in
diff options
context:
space:
mode:
Diffstat (limited to 'pgo.sh.in')
-rw-r--r--pgo.sh.in48
1 files changed, 48 insertions, 0 deletions
diff --git a/pgo.sh.in b/pgo.sh.in
new file mode 100644
index 000000000000..f2686c89fc53
--- /dev/null
+++ b/pgo.sh.in
@@ -0,0 +1,48 @@
+#!/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
+ pgoflags=" -fprofile-generate -fprofile-dir=$PROFDEST/$pkgbase.gen"
+ pgoldflags=" -lgcov --coverage"
+ msg2 "Profile data will be generated."
+ else
+ [[ -d $PROFDEST/$pkgbase.used ]] && rm -rf $PROFDEST/$pkgbase.used
+ mv $PROFDEST/$pkgbase.{gen,used}
+ pgoflags=" -fprofile-correction -fprofile-use -fprofile-dir=$PROFDEST/$pkgbase.used"
+ pgoldflags=" -lgcov"
+ msg2 "Profile data will be applied."
+ fi
+
+ CFLAGS+="$pgoflags"
+ CXXFLAGS+="$pgoflags"
+ LDFLAGS+="$pgoldflags"
+
+ fi
+}