+# Export CFLAGS
+export CFLAGS = # empty
-# Export CFLAGS + CXXFLAGS
-GLOBAL_CFLAGS = -O2 -g
+# Export CXXFLAGS
+export CXXFLAGS = %{CFLAGS}
+
+# Export LDFLAGS
+export LDFLAGS = -Wl,-z,relro -Wl,-z,now
+
+# Enable optimisation and compile in debugging information
+CFLAGS = -O2 -g
# Enable all compiler warnings
-GLOBAL_CFLAGS += -Wall
+CFLAGS += -Wall -Werror=format-security
# Fortify Source
-GLOBAL_CFLAGS += -Wp,-U_FORTIFY_SOURCE-Wp,-D_FORTIFY_SOURCE=3
+CFLAGS += -Wp,-U_FORTIFY_SOURCE-Wp,-D_FORTIFY_SOURCE=3
# Build Position Independent Code
-GLOBAL_CFLAGS += -fPIC
+CFLAGS += -fPIC
# Enable Stack Smashing Protection
-GLOBAL_CFLAGS += -fstack-protector-strong
+CFLAGS += -fstack-protector-strong
# Enable unwind tables
-GLOBAL_CFLAGS += -funwind-tables -fasynchronous-unwind-tables
+CFLAGS += -funwind-tables -fasynchronous-unwind-tables
# Enable Stack Clash Protection
-GLOBAL_CFLAGS += -fstack-clash-protection
+CFLAGS += -fstack-clash-protection
# Tell the compiler where the source will be put
-GLOBAL_CFLAGS += -fdebug-prefix-map=%{DIR_SRC}=%{debugsourcedir}
+CFLAGS += -fdebug-prefix-map=%{DIR_SRC}=%{debugsourcedir}
# Arch: x86_64
CFLAGS_x86_64 = -m64 -march=x86-64-v2 -mtune=generic
# Arch: aarch64
CFLAGS_aarch64 = -mbranch-protection=standard
-export CFLAGS = %{GLOBAL_CFLAGS} %{CFLAGS_%{DISTRO_ARCH}}
-export CXXFLAGS = %{CFLAGS}
+# Append architecture optimisations
+CFLAGS += %{CFLAGS_%{DISTRO_ARCH}}
-export LDFLAGS = -Wl,-z,relro -Wl,-z,now
+# Enable LTO
+LTO_CFLAGS = -flto=auto -ffat-lto-objects
+CFLAGS += %{LTO_CFLAGS}