build # Export CFLAGS export CFLAGS = # Export CXXFLAGS export CXXFLAGS = %{CFLAGS} # Export LDFLAGS export LDFLAGS = # Enable optimisation and compile in debugging information CFLAGS = -O2 -g # Enable all compiler warnings CFLAGS += -Wall # Fail on any string format security issues STRING_FORMAT_SECURITY_CFLAGS = -Werror=format-security CFLAGS += %{STRING_FORMAT_SECURITY_CFLAGS} # Fortify Source CFLAGS += -Wp,-U_FORTIFY_SOURCE -Wp,-D_FORTIFY_SOURCE=3 # libstc++ Assertions CFLAGS += -D_GLIBCXX_ASSERTIONS # Build Position Independent Code CFLAGS += -fPIC # Enable Stack Smashing Protection CFLAGS += -fstack-protector-all # 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} # Avoid creating temporary files CFLAGS += -pipe # Arch: x86_64 CFLAGS_x86_64 = -m64 -march=x86-64-v2 -mtune=generic # Enable Control Flow Technology (CET) CFLAGS_x86_64 += -fcf-protection=full # 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} # Optimise linked binaries https://lwn.net/Articles/192624/ LDFLAGS += -Wl,-O1 # Only link what we actually need LDFLAGS += -Wl,--as-needed # Create an ELF "PT_GNU_RELRO" segment header in the object LDFLAGS += -Wl,-z,relro # When generating an executable or shared library, mark it to tell the # dynamic linker to resolve all symbols when the program is started, # or when the shared library is linked to using dlopen, instead of # deferring function call resolution to the point when the function is # first called. LDFLAGS += -Wl,-z,now # Export default compilers export CC = gcc export CXX = g++ # Show libtool where to find any libraries export LT_SYS_LIBRARY_PATH = %{libdir}: end