From: Jérôme Benoit Date: Thu, 9 Mar 2017 14:07:44 +0000 (+0100) Subject: TP 13 exo1: Makefile: X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=a9c4c876238c3df46b42290f8fd26906a94f8af4;p=TD_C.git TP 13 exo1: Makefile: * Properly map one .c file to one .d and one .o file * Add local headers handling Signed-off-by: Jérôme Benoit --- diff --git a/TP_13/exo1/Makefile b/TP_13/exo1/Makefile index 146115f..8308357 100644 --- a/TP_13/exo1/Makefile +++ b/TP_13/exo1/Makefile @@ -12,10 +12,11 @@ # Automatic dependencies code from: # http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/#tldr BINARY_NAME=exo1 -BINARY_PATH:=src +SRC_PATH:=src LIBRARY_NAME=libexo1 LIBRARY_PATH:=lib BUILD_TYPE=debug +#BUILD_TYPE=release # ==================================== # DO NOT CHANGE STUFF BEYOND THIS LINE @@ -42,7 +43,8 @@ STRIP_FLAG = -s OPTI_FLAG = -O3 endif -CFLAGS := $(CFLAGS) $(WARN_FLAGS) $(STD_FLAG) $(OPTI_FLAG) $(DEBUG_FLAG) +INCLUDES := $(INCLUDES) -I$(SRC_PATH) -I$(LIBRARY_PATH) +CFLAGS := $(CFLAGS) $(WARN_FLAGS) $(STD_FLAG) $(OPTI_FLAG) $(DEBUG_FLAG) $(INCLUDES) LIBCFLAGS := -fPIC $(CFLAGS) LDFLAGS := $(LDFLAGS) $(STRIP_FLAG) LIBLDFLAGS := -shared $(LDFLAGS) @@ -52,7 +54,7 @@ LDLIBS := $(LDLIBS) -L$(LIBRARY_PATH) -l$(BINARY_NAME) OBJDIR := $(BUILDDIR)/objs $(shell mkdir -p $(OBJDIR)) -SRCS=$(wildcard $(BINARY_PATH)/*.c) +SRCS=$(wildcard $(SRC_PATH)/*.c) LIBSRCS=$(wildcard $(LIBRARY_PATH)/*.c) OBJS=$(patsubst %.c,$(OBJDIR)/%.o,$(notdir $(SRCS))) LIBOBJS=$(patsubst %.c,$(OBJDIR)/%.o,$(notdir $(LIBSRCS))) @@ -62,15 +64,6 @@ $(shell mkdir -p $(DEPDIR)) DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$(notdir $*).Td POSTCOMPILE = mv -f $(DEPDIR)/$(notdir $*).Td $(DEPDIR)/$(notdir $*).d -print: - @echo $(basename $(notdir $(SRCS))) - @echo $(notdir $(SRCS)) - @echo $(DEPDIR)/%d - @echo $(wildcard $(patsubst %,$(DEPDIR)/%.d,$(basename $(SRCS)))) - @echo $(OBJS) $(LIBOBJS) - @echo $(SRCS) $(LIBSRCS) - @echo $(POSTCOMPILE) - $(LIBRARY_PATH)/$(LIBRARY_NAME).a: $(LIBOBJS) @echo "[AR StO] $@" @$(AR) rcs $@ $^ @@ -99,14 +92,14 @@ $(BINARY_NAME).dynamic: $(OBJS) $(LIBRARY_PATH)/$(LIBRARY_NAME).so @echo "[LD ] $@" @$(LD) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@ -$(OBJS): $(SRCS) $(DEPDIR)/%.d +$(OBJDIR)/%.o: $(SRC_PATH)/%.c $(DEPDIR)/%.d @echo "[C ] $(notdir $*)" @$(CC) $(DEPFLAGS) $(CFLAGS) -c $< -o $@ @$(POSTCOMPILE) include $(wildcard $(patsubst %,$(DEPDIR)/%.d,$(basename $(SRCS)))) -$(LIBOBJS): $(LIBSRCS) $(DEPDIR)/%.d +$(OBJDIR)/%.o: $(LIBRARY_PATH)/%.c $(DEPDIR)/%.d @echo "[C ] $(notdir $*)" @$(CC) $(DEPFLAGS) $(LIBCFLAGS) -c $< -o $@ @$(POSTCOMPILE)