X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=TP_13%2Fexo1%2FMakefile;h=0e2661f1a1bf58e01246ab349ba383299ede1ad8;hb=25dc671f8b36ed62a1d2b689347902a122493782;hp=830835782ec244e8cf50fd31445bce29eea3f149;hpb=a9c4c876238c3df46b42290f8fd26906a94f8af4;p=TD_C.git diff --git a/TP_13/exo1/Makefile b/TP_13/exo1/Makefile index 8308357..0e2661f 100644 --- a/TP_13/exo1/Makefile +++ b/TP_13/exo1/Makefile @@ -1,13 +1,19 @@ # 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 BUILD_TYPE to either debug or release +# Set LIBRARY_NAME to the name of the library file to build. +# The default path for the library code and object is lib. +# By default the linker will look for $(BINARY_NAME) library name. +# Set BUILD_TYPE to either debug or release. # # Automatic dependencies code from: # http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/#tldr @@ -15,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 @@ -36,17 +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 -INCLUDES := $(INCLUDES) -I$(SRC_PATH) -I$(LIBRARY_PATH) -CFLAGS := $(CFLAGS) $(WARN_FLAGS) $(STD_FLAG) $(OPTI_FLAG) $(DEBUG_FLAG) $(INCLUDES) +# Putting header files in the source directory is not the purpose of this INCLUDES variable +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) @@ -84,10 +104,6 @@ $(BINARY_NAME).static: $(OBJS) $(LIBRARY_PATH)/$(LIBRARY_NAME).a @echo "[LD ] $@" @$(LD) $(CFLAGS) $(STATICLIBLDFLAGS) $^ $(LDLIBS) -o $@ -#$(BINARY_NAME).staticlocal: $(OBJS) $(LIBRARY_PATH)/$(LIBRARY_NAME).a -# @echo "[LD ] $@" -# @$(LD) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@ - $(BINARY_NAME).dynamic: $(OBJS) $(LIBRARY_PATH)/$(LIBRARY_NAME).so @echo "[LD ] $@" @$(LD) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@