From: Jérôme Benoit Date: Thu, 9 Mar 2017 12:36:17 +0000 (+0100) Subject: TP 11 exo1: Makefile: differenciate the compiliator flags for libraries X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=a80f64d2e55ee92329a3a8a74ec91ca0c8784964;p=TD_C.git TP 11 exo1: Makefile: differenciate the compiliator flags for libraries building. Signed-off-by: Jérôme Benoit --- diff --git a/TP_11/exo2/Makefile b/TP_11/exo2/Makefile index 3edfbf6..6f840e6 100644 --- a/TP_11/exo2/Makefile +++ b/TP_11/exo2/Makefile @@ -12,9 +12,8 @@ # Automatic dependencies code from: # http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/#tldr BINARY_NAME=exo2 -LIBOBJS=clist.o ui.o# object to put in the library +LIBOBJS=clist.o ui.o # object to put in the library LIBRARY_NAME=libtpC -#LDLIBS=-L. -ltpC BUILD_TYPE=debug # ==================================== @@ -66,7 +65,7 @@ $(LIBRARY_NAME).a: $(OBJSLIB) $(LIBRARY_NAME).so: $(OBJSLIB) @echo "[LD ShO] $@" - @$(LD) $(CFLAGS) $(LIBLDFLAGS) $^ $(LDLIBS) -o $@ + @$(LD) $(CFLAGS) $(LIBLDFLAGS) $^ -o $@ $(BINARY_NAME): $(OBJS) @echo "[LD ] $@" diff --git a/TP_13/exo1/Makefile b/TP_13/exo1/Makefile index 8168c45..146115f 100644 --- a/TP_13/exo1/Makefile +++ b/TP_13/exo1/Makefile @@ -15,7 +15,6 @@ BINARY_NAME=exo1 BINARY_PATH:=src LIBRARY_NAME=libexo1 LIBRARY_PATH:=lib -#LDLIBS=-L$(LIBRARY_PATH) -l$(BINARY_NAME) BUILD_TYPE=debug # ==================================== @@ -43,11 +42,12 @@ STRIP_FLAG = -s OPTI_FLAG = -O3 endif -#FIXME: Add a way to better control the library build flag -CFLAGS := -fPIC $(CFLAGS) $(WARN_FLAGS) $(STD_FLAG) $(OPTI_FLAG) $(DEBUG_FLAG) +CFLAGS := $(CFLAGS) $(WARN_FLAGS) $(STD_FLAG) $(OPTI_FLAG) $(DEBUG_FLAG) +LIBCFLAGS := -fPIC $(CFLAGS) LDFLAGS := $(LDFLAGS) $(STRIP_FLAG) LIBLDFLAGS := -shared $(LDFLAGS) STATICLIBLDFLAGS := -static $(LDFLAGS) +LDLIBS := $(LDLIBS) -L$(LIBRARY_PATH) -l$(BINARY_NAME) OBJDIR := $(BUILDDIR)/objs $(shell mkdir -p $(OBJDIR)) @@ -77,39 +77,38 @@ $(LIBRARY_PATH)/$(LIBRARY_NAME).a: $(LIBOBJS) $(LIBRARY_PATH)/$(LIBRARY_NAME).so: $(LIBOBJS) @echo "[LD ShO] $@" - @$(LD) $(CFLAGS) $(LIBLDFLAGS) $^ $(LDLIBS) -o $@ + @$(LD) $(LIBCFLAGS) $(LIBLDFLAGS) $^ -o $@ #$(BINARY_NAME): $(OBJS) $(LIBOBJS) # @echo "[LD ] $@" -# $(LD) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@ +# @$(LD) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@ $(BINARY_NAME): $(OBJS) $(LIBRARY_PATH)/$(LIBRARY_NAME).a @echo "[LD ] $@" - @$(LD) $(CFLAGS) $(LDFLAGS) $^ $(LOCALLDLIBS) $(LDLIBS) -o $@ + @$(LD) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@ -LOCALLDLIBS=-L$(LIBRARY_PATH) -l$(BINARY_NAME) $(BINARY_NAME).static: $(OBJS) $(LIBRARY_PATH)/$(LIBRARY_NAME).a @echo "[LD ] $@" - @$(LD) $(CFLAGS) $(STATICLIBLDFLAGS) $^ $(LOCALLDLIBS) $(LDLIBS) -o $@ + @$(LD) $(CFLAGS) $(STATICLIBLDFLAGS) $^ $(LDLIBS) -o $@ #$(BINARY_NAME).staticlocal: $(OBJS) $(LIBRARY_PATH)/$(LIBRARY_NAME).a # @echo "[LD ] $@" -# @$(LD) $(CFLAGS) $(LDFLAGS) $^ $(LOCALLDLIBS) $(LDLIBS) -o $@ +# @$(LD) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@ $(BINARY_NAME).dynamic: $(OBJS) $(LIBRARY_PATH)/$(LIBRARY_NAME).so @echo "[LD ] $@" - @$(LD) $(CFLAGS) $(LDFLAGS) $^ $(LOCALLDLIBS) $(LDLIBS) -o $@ + @$(LD) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@ $(OBJS): $(SRCS) $(DEPDIR)/%.d - @echo "[C ] $*" + @echo "[C ] $(notdir $*)" @$(CC) $(DEPFLAGS) $(CFLAGS) -c $< -o $@ @$(POSTCOMPILE) include $(wildcard $(patsubst %,$(DEPDIR)/%.d,$(basename $(SRCS)))) $(LIBOBJS): $(LIBSRCS) $(DEPDIR)/%.d - @echo "[C ] $*" - @$(CC) $(DEPFLAGS) $(CFLAGS) -c $< -o $@ + @echo "[C ] $(notdir $*)" + @$(CC) $(DEPFLAGS) $(LIBCFLAGS) -c $< -o $@ @$(POSTCOMPILE) include $(wildcard $(patsubst %,$(DEPDIR)/%.d,$(basename $(LIBSRCS)))) @@ -118,6 +117,8 @@ $(DEPDIR)/%.d: ; .PRECIOUS: $(DEPDIR)/%.d +#FIXME: add an install target + clean: @echo "[CLN]" -@rm -r $(BUILDDIR)