Buildsystem: be more friendly with cygwin environment
[TD_C.git] / TP_13 / exo1 / Makefile
index 20746ac802aae220d185dd15b2d0a726549b546c..152498c48fc1188a4a3dafeff884d071e6cde775 100644 (file)
@@ -1,10 +1,13 @@
 # Sample Makefile to build simple project.
 #
 # This Makefile expect all source files (.c) to be at the same level, in the
-# current working directory.
+# $(SRC_PATH) directory.
+#
+# This Makefile expect all embedded library source files (.c) to be at the same level, in the
+# $(LIBRARY_PATH) directory.
 #
 # It will automatically generate dependencies, compile all files, and produce a
-# binary using the provided name.
+# binary using the provided name linked against the library if necessary.
 #
 # Set BINARY_NAME to the name of the binary file to build.
 # Set LIBRARY_NAME to the name of the library file to build.
@@ -33,24 +36,42 @@ AR=ar
 
 WARN_FLAGS = -Wall -Wextra
 STD_FLAG = -std=c11
+UNAME := $(shell uname -o)
 
 ifeq ($(BUILD_TYPE),debug)
 BUILDDIR := .build/debug
 DEBUG_FLAG = -g
 STRIP_FLAG =
 OPTI_FLAG = -O0
+LTO_SUPPORT = yes
+GOLD_SUPPORT = yes
 else
 BUILDDIR := .build/release
 DEBUG_FLAG =
 STRIP_FLAG = -s
 OPTI_FLAG = -O3
+LTO_SUPPORT = yes
+GOLD_SUPPORT = yes
+endif
+
+ifeq ($(UNAME),Cygwin)
+GOLD_SUPPORT = no
+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$(SRC_PATH) -I$(LIBRARY_PATH)
-CFLAGS := $(CFLAGS) $(WARN_FLAGS) $(STD_FLAG) $(OPTI_FLAG) $(DEBUG_FLAG) $(INCLUDES)
+INCLUDES := $(INCLUDES) -I$(LIBRARY_PATH)
+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)