1 From e1ce2351f5c00dd90104e0f4ce3bf176da28af08 Mon Sep 17 00:00:00 2001
2 From: Evangelos Foutras <evangelos@foutrelis.com>
3 Date: Thu, 10 Feb 2022 05:15:01 +0200
4 Subject: [PATCH] Make link time optimization flags configurable
6 We want to use -flto=auto in Arch Linux to speed up building, but we
7 can't hardcode it in buildenv/lto.sh because other downstreams might
8 have clang < 13.0.0 which did not recognize -flto=auto as equivalent
11 Introducing an LTOFLAGS variable to makepkg.conf seems the way to go.
13 Signed-off-by: Allan McRae <allan@archlinux.org>
15 doc/makepkg.conf.5.asciidoc | 10 ++++++++--
16 etc/makepkg.conf.in | 1 +
17 scripts/libmakepkg/buildenv/buildflags.sh.in | 2 +-
18 scripts/libmakepkg/buildenv/lto.sh.in | 6 +++---
19 scripts/libmakepkg/lint_config/variable.sh.in | 8 ++++----
20 5 files changed, 17 insertions(+), 10 deletions(-)
22 diff --git a/doc/makepkg.conf.5.asciidoc b/doc/makepkg.conf.5.asciidoc
23 index 39c5c808..a0d9a6d4 100644
24 --- a/doc/makepkg.conf.5.asciidoc
25 +++ b/doc/makepkg.conf.5.asciidoc
26 @@ -81,6 +81,11 @@ Options
27 usage resembling ``-Wl,--hash-style=gnu''. Read ld(1) for more details on
28 available linker flags.
30 +**LTOFLAGS=**"ltoflags"::
31 + Additional compiler and linker flags appended to `CFLAGS`, `CXXFLAGS`
32 + and `LDFLAGS` when building with link time optimization. If empty,
35 **MAKEFLAGS=**"makeflags"::
36 This is often used to set the number of jobs used; for example, `-j2`.
37 Other flags that make accepts can also be passed.
38 @@ -190,8 +195,9 @@ Options
39 package containing the debug symbols when used with `strip'.
42 - Enable building packages using link time optimization. Adds '-flto'
43 - to both CFLAGS and CXXFLAGS.
44 + Enable building packages using link time optimization. Adds the
45 + flags specified in LTOFLAGS to CFLAGS, CXXFLAGS and LDFLAGS (or
46 + ``-flto'' if LTOFLAGS is empty).
49 Enable the automatic addition of libraries to the depends and
50 diff --git a/etc/makepkg.conf.in b/etc/makepkg.conf.in
51 index 0c911cce..edc5f442 100644
52 --- a/etc/makepkg.conf.in
53 +++ b/etc/makepkg.conf.in
54 @@ -41,6 +41,7 @@ CHOST="@CHOST@"
59 #RUSTFLAGS="-C opt-level=2"
60 #-- Make Flags: change this for DistCC/SMP systems
62 diff --git a/scripts/libmakepkg/buildenv/buildflags.sh.in b/scripts/libmakepkg/buildenv/buildflags.sh.in
63 index 74f91988..07b4a730 100644
64 --- a/scripts/libmakepkg/buildenv/buildflags.sh.in
65 +++ b/scripts/libmakepkg/buildenv/buildflags.sh.in
66 @@ -30,6 +30,6 @@ buildenv_functions+=('buildenv_buildflags')
68 buildenv_buildflags() {
69 if check_option "buildflags" "n"; then
70 - unset CPPFLAGS CFLAGS DEBUG_CFLAGS CXXFLAGS DEBUG_CXXFLAGS LDFLAGS RUSTFLAGS DEBUG_RUSTFLAGS
71 + unset CPPFLAGS CFLAGS DEBUG_CFLAGS CXXFLAGS DEBUG_CXXFLAGS LDFLAGS LTOFLAGS RUSTFLAGS DEBUG_RUSTFLAGS
74 diff --git a/scripts/libmakepkg/buildenv/lto.sh.in b/scripts/libmakepkg/buildenv/lto.sh.in
75 index 6e500eab..6492def7 100644
76 --- a/scripts/libmakepkg/buildenv/lto.sh.in
77 +++ b/scripts/libmakepkg/buildenv/lto.sh.in
78 @@ -31,8 +31,8 @@ buildenv_functions+=('buildenv_lto')
81 if check_option "lto" "y" && ! check_option "buildflags" "n"; then
85 + CFLAGS+=" ${LTOFLAGS:--flto}"
86 + CXXFLAGS+=" ${LTOFLAGS:--flto}"
87 + LDFLAGS+=" ${LTOFLAGS:--flto}"
90 diff --git a/scripts/libmakepkg/lint_config/variable.sh.in b/scripts/libmakepkg/lint_config/variable.sh.in
91 index 8327b0a5..03a67ee2 100644
92 --- a/scripts/libmakepkg/lint_config/variable.sh.in
93 +++ b/scripts/libmakepkg/lint_config/variable.sh.in
94 @@ -32,10 +32,10 @@ lint_config_variables() {
95 local array=(DLAGENTS VCSCLIENTS BUILDENV OPTIONS INTEGRITY_CHECK MAN_DIRS
96 DOC_DIRS PURGE_TARGETS COMPRESSGZ COMPRESSBZ2 COMPRESSXZ
97 COMPRESSLRZ COMPRESSLZO COMPRESSZ)
98 - local string=(CARCH CHOST CPPFLAGS CFLAGS CXXFLAGS RUSTFLAGS LDFLAGS DEBUG_CFLAGS
99 - DEBUG_CXXFLAGS DEBUG_RUSTFLAGS DISTCC_HOSTS BUILDDIR STRIP_BINARIES
100 - STRIP_SHARED STRIP_STATIC PKGDEST SRCDEST SRCPKGDEST LOGDEST PACKAGER
101 - GPGKEY PKGEXT SRCEXT)
102 + local string=(CARCH CHOST CPPFLAGS CFLAGS CXXFLAGS RUSTFLAGS LDFLAGS LTOFLAGS
103 + DEBUG_CFLAGS DEBUG_CXXFLAGS DEBUG_RUSTFLAGS DISTCC_HOSTS BUILDDIR
104 + STRIP_BINARIES STRIP_SHARED STRIP_STATIC PKGDEST SRCDEST SRCPKGDEST
105 + LOGDEST PACKAGER GPGKEY PKGEXT SRCEXT)