From: Jérôme Benoit Date: Tue, 7 Mar 2017 15:20:48 +0000 (+0100) Subject: TP11 exo1: Properly make linked list function a library shared and static X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=3bb0a9f80ebc5b3d7c05c78cbf65241c6a6b0490;p=TD_C.git TP11 exo1: Properly make linked list function a library shared and static And build two new binaries for static and dynamic linking against the library. To launch the dynamic binary: LD_LIBRARY_PATH=. ./exo1.dynamic Signed-off-by: Jérôme Benoit --- diff --git a/TP_11/exo1/Makefile b/TP_11/exo1/Makefile index f8cfee7..634334e 100644 --- a/TP_11/exo1/Makefile +++ b/TP_11/exo1/Makefile @@ -14,13 +14,14 @@ BINARY_NAME=exo1 LIBOBJS=clist.o # object to put in the library LIBRARY_NAME=libtpC +#LDLIBS=-L. -ltpC BUILD_TYPE=debug # ==================================== # DO NOT CHANGE STUFF BEYOND THIS LINE # ==================================== -all: $(LIBRARY_NAME).a $(LIBRARY_NAME).so $(BINARY_NAME) +all: $(BINARY_NAME) $(BINARY_NAME).dynamic $(BINARY_NAME).static CC=gcc LD=gcc @@ -70,6 +71,15 @@ $(BINARY_NAME): $(OBJS) @echo "[LD ] $@" @$(LD) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@ +LOCALLDLIBS=-L. -ltpC +$(BINARY_NAME).static: $(OBJDIR)/$(BINARY_NAME).o $(LIBRARY_NAME).a + @echo "[LD ] $@" + @$(LD) $(CFLAGS) $(LDFLAGS) $^ $(LOCALLDLIBS) $(LDLIBS) -o $@ + +$(BINARY_NAME).dynamic: $(OBJDIR)/$(BINARY_NAME).o $(LIBRARY_NAME).so + @echo "[LD ] $@" + @$(LD) $(CFLAGS) $(LDFLAGS) $^ $(LOCALLDLIBS) $(LDLIBS) -o $@ + $(OBJDIR)/%.o: %.c $(DEPDIR)/%.d @echo "[C ] $*" @$(CC) $(DEPFLAGS) $(CFLAGS) -c $< -o $@ @@ -85,6 +95,8 @@ clean: @echo "[CLN]" -@rm -r $(BUILDDIR) -@rm $(BINARY_NAME) + -@rm $(BINARY_NAME).static + -@rm $(BINARY_NAME).dynamic -@rm $(LIBRARY_NAME).so -@rm $(LIBRARY_NAME).a