+# Export CFLAGS
+export CFLAGS = # empty
-# Export CFLAGS + CXXFLAGS
-GLOBAL_CFLAGS = -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS
-GLOBAL_CFLAGS += -fPIC -fstack-protector-strong --param=ssp-buffer-size=4
-GLOBAL_CFLAGS += -grecord-gcc-switches -fdebug-prefix-map=%{DIR_SRC}=%{debugsourcedir}
-
-CFLAGS_i686 = -m32 -march=i686 -mtune=atom -fasynchronous-unwind-tables
-CFLAGS_x86_64 = -m64 -march=x86-64-v2 -mtune=generic
-CFLAGS_aarch64 = -fstack-clash-protection
-CFLAGS_armv5tel = -march=armv5te -mfloat-abi=soft
-CFLAGS_armv7hl = -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=hard -mthumb
-
-export CFLAGS = %{GLOBAL_CFLAGS} %{CFLAGS_%{DISTRO_ARCH}}
+# 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
+CFLAGS += -Wall -Werror=format-security
+
+# Fortify Source
+CFLAGS += -Wp,-U_FORTIFY_SOURCE-Wp,-D_FORTIFY_SOURCE=3
+
+# Build Position Independent Code
+CFLAGS += -fPIC
+
+# Enable Stack Smashing Protection
+CFLAGS += -fstack-protector-strong
+
+# Enable unwind tables
+CFLAGS += -funwind-tables -fasynchronous-unwind-tables
+
+# Enable Stack Clash Protection
+CFLAGS += -fstack-clash-protection
+
+# Tell the compiler where the source will be put
+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
+
+# Append architecture optimisations
+CFLAGS += %{CFLAGS_%{DISTRO_ARCH}}
+
+# Enable LTO
+LTO_CFLAGS = -flto=auto -ffat-lto-objects
+CFLAGS += %{LTO_CFLAGS}