TP 13 exo1: Add LTO and GOLD support to the Makefile build options
[TD_C.git] / TP_13 / exo1 / Makefile
index fd958781e5a24c5afff621cac8df9daabc8639e3..0e2661f1a1bf58e01246ab349ba383299ede1ad8 100644 (file)
@@ -21,8 +21,8 @@ BINARY_NAME=exo1
 SRC_PATH:=src
 LIBRARY_NAME=libexo1
 LIBRARY_PATH:=lib
-BUILD_TYPE=debug
-#BUILD_TYPE=release
+#BUILD_TYPE=debug
+BUILD_TYPE=release
 
 # ====================================
 # DO NOT CHANGE STUFF BEYOND THIS LINE
@@ -42,18 +42,31 @@ BUILDDIR := .build/debug
 DEBUG_FLAG = -g
 STRIP_FLAG =
 OPTI_FLAG = -O0
+LTO_SUPPORT = no
+GOLD_SUPPORT = no
 else
 BUILDDIR := .build/release
 DEBUG_FLAG =
 STRIP_FLAG = -s
 OPTI_FLAG = -O3
+LTO_SUPPORT = yes
+GOLD_SUPPORT = yes
+endif
+
+ifeq ($(LTO_SUPPORT),yes)
+CFLAGS_LTO = -flto -ffat-lto-objects
+LDFLAGS_LTO = -fuse-linker-plugin -flto
+endif
+
+ifeq ($(GOLD_SUPPORT),yes)
+LDFLAGS_GOLD = -fuse-ld=gold
 endif
 
 # Putting header files in the source directory is not the purpose of this INCLUDES variable
 INCLUDES := $(INCLUDES) -I$(LIBRARY_PATH)
-CFLAGS := $(CFLAGS) $(WARN_FLAGS) $(STD_FLAG) $(OPTI_FLAG) $(DEBUG_FLAG) $(INCLUDES)
+CFLAGS := $(CFLAGS) $(CFLAGS_LTO) $(WARN_FLAGS) $(STD_FLAG) $(OPTI_FLAG) $(DEBUG_FLAG) $(INCLUDES)
 LIBCFLAGS := -fPIC $(CFLAGS)
-LDFLAGS := $(LDFLAGS) $(STRIP_FLAG)
+LDFLAGS := $(LDFLAGS) $(LDFLAGS_LTO) $(LDFLAGS_GOLD) $(STRIP_FLAG)
 LIBLDFLAGS := -shared $(LDFLAGS)
 STATICLIBLDFLAGS := -static $(LDFLAGS)
 LDLIBS := $(LDLIBS) -L$(LIBRARY_PATH) -l$(BINARY_NAME)